[R语言] 用log-logistic模型拟合多组毒性测试数据

1. 毒性测试数据[1]

 Cd (μg/L) Mortality@pH 7.0 (%) Mortality@8.2 (%) 0 0 0 10 0 30 20 0 42.5 50 40 80 100 90 97.5 200 97.5 100

2. 拟合模型

3. 分别拟合两组数据

3.1 R 语言代码

#读取数据(附件Cd_test_data_tan2011EST)
#查看数据表头
#作图，将两组实测数据画出
plot(r1~x,data=data,pch=1,log="x",xlab="Concentration",ylab="Mortality (%)",xlim=c(1,max(data$x))) points(r2~x,data=data,col="red",pch=1) #用（2参数）log-logistic模型拟合第1组数据 mod.1<-nls(r1 ~ 100/(1+exp(b*(log10(x/x0)))), data=data, start=list(x0=10,b=-1)) #查看拟合结果和置信区间 summary(mod.1) confint(mod.1) #作图，将第1组数据的拟合曲线画出 x<-seq(1,300,1) y<-100/(1+exp(summary(mod.1)$coefficients[2]*(log10(x/summary(mod.1)$coefficients[1])))) lines(x,y,col="grey50",lwd=1) #用（2参数）log-logistic模型拟合第2组数据 mod.2<-nls(r2 ~ 100/(1+exp(b*(log10(x/x0)))), data=data, start=list(x0=10,b=-1)) #查看拟合结果和置信区间 summary(mod.2) confint(mod.2) #作图，将第2组数据的拟合曲线画出 x<-seq(1,300,1) y<-100/(1+exp(summary(mod.2)$coefficients[2]*(log10(x/summary(mod.2)$coefficients[1])))) lines(x,y,col="red",lwd=1) #加网格线，美化 grid() 3.2 拟合结果 （1）“Mortality@pH 7.0”数据拟合结果 参数值： > summary(mod.1) Formula: r1 ~ 100/(1 + exp(b * (log10(x/x0)))) Parameters: Estimate Std. Error t value Pr(>|t|) x0 55.7923 0.7644 72.99 2.11e-07 *** b -8.7897 0.4997 -17.59 6.14e-05 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 1.326 on 4 degrees of freedom Number of iterations to convergence: 8 Achieved convergence tolerance: 5.34e-07 置信区间： > confint(mod.1) Waiting for profiling to be done... 2.5% 97.5% x0 53.72977 58.00931 b -10.45632 -7.59122 （2）“Mortality@pH 8.2”数据拟合结果 参数值： > summary(mod.2) Formula: r2 ~ 100/(1 + exp(b * (log10(x/x0)))) Parameters: Estimate Std. Error t value Pr(>|t|) x0 20.7279 1.9107 10.848 0.00041 *** b -3.6334 0.5151 -7.053 0.00213 ** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 5.173 on 4 degrees of freedom Number of iterations to convergence: 9 Achieved convergence tolerance: 7.255e-06 置信区间： > confint(mod.2) Waiting for profiling to be done... 2.5% 97.5% x0 15.701914 26.782837 b -5.364096 -2.497817 3.3 作图 4. 一并拟合两组数据（共用参数b） 4.1 R 语言代码 #读取数据(附件Cd_test_data_tan2011EST) data<-read.csv(file.choose()) #查看数据表头 head(data) #作图，将两组实测数据画出 plot(r1~x,data=data,pch=1,Cd_test_data_tan2011EST.csvlog="x",xlab="Concentration",ylab="Mortality (%)",xlim=c(1,max(data$x)))
points(r2~x,data=data,col="red",pch=1)
#有几个不同浓度？
n1 <- length(data$r1) n2 <- length(data$r2)
#合并两组数据
y <- c(data$r1,data$r2)
x <- c(data$x,data$x)
mcon1 <- rep(c(1,0), c(n1,n2))
mcon2 <- rep(c(0,1), c(n1,n2))
#一并拟合两组数据，各自使用不同x0值，共用相同b值
mod.common<-nls(y ~ 100/(1+exp(b*(log10(x/(x0_1*mcon1+x0_2*mcon2))))), start = list(b=-1,x0_1=10,x0_2=10))
#查看拟合结果和置信区间
summary(mod.common)
confint(mod.common)
#作图，将第2组数据的拟合曲线画出
x<-seq(1,300,1)
y1<-100/(1+exp(summary(mod.common)$coefficients[1]*(log10(x/summary(mod.common)$coefficients[2]))))
lines(x,y1,col="grey50",lwd=1)
y2<-100/(1+exp(summary(mod.common)$coefficients[1]*(log10(x/summary(mod.common)$coefficients[3]))))
lines(x,y2,col="red",lwd=1)
grid()

4.2 拟合结果

参数值：

> summary(mod.common)

Formula: y ~ 100/(1 + exp(b * (log10(x/(x0_1 * mcon1 + x0_2 * mcon2)))))

Parameters:

Estimate Std. Error t value Pr(>|t|)

b     -5.2707     0.9739  -5.412 0.000996 ***

x0_1  55.2566     6.6770   8.276 7.34e-05 ***

x0_2  21.1349     2.6295   8.038 8.85e-05 ***

---

Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 8.566 on 7 degrees of freedom

Number of iterations to convergence: 10

Achieved convergence tolerance: 4.701e-06

> confint(mod.common)

Waiting for profiling to be done...

2.5%     97.5%

b    -9.082322 -3.556506

x0_1 42.037993 71.640210

x0_2 15.208174 29.657370

4.3 作图

[1] Tan, Q. G., & Wang, W. X. (2011). Acute toxicity of cadmium in daphnia magna under different calcium and ph conditions: importance of influx rate. Environmental Science & Technology, 45(5), 1970-1976.

https://blog.sciencenet.cn/blog-50573-1105645.html

全部作者的其他最新博文

GMT+8, 2022-8-10 00:33