Aquat Chem Toxicol Metal分享 http://blog.sciencenet.cn/u/daphnia 重金属环境化学、生态毒理学、水生生态学

博文

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

已有 10609 次阅读 2018-3-25 14:55 |个人分类:R语言|系统分类:科研笔记| R语言, 毒性测试, 数据分析

 

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

下载数据:Cd_test_data_tan2011EST.csv


2. 拟合模型


数据拟合采用“2参数log-logistic”模型:

 

333.png

3. 分别拟合两组数据


3.1 R 语言代码

#读取数据(附件Cd_test_data_tan2011EST)
data<-read.csv(file.choose())
#查看数据表头
head(data)
#作图,将两组实测数据画出
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 作图


2018-03-25_144914.png



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 作图

222.png


毒性测试数据来源:

[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

上一篇:sediment读书笔记-1
下一篇:[R语言]比较两个毒性测试的EC50值是否有显著性差异
收藏 IP: 117.28.251.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-12-5 23:51

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部