【发布时间】:2018-03-15 22:45:32
【问题描述】:
我有一组如下所示的数据:
Time Al Biochar Al FeO Cu Biochar Cu FeO
0 0.218223461 0.218223461 12.39823125 12.39823125
0.5 0.1395087 0.041177135 0.00543732 3.759749493
1 0.08415793 -0.134641447 -12.38861634 -4.177991174
1.5 -0.005332069 -0.316522561 -24.78366292 -12.52075324
2 -0.060324192 -0.500248756 -37.17868817 -20.59065175
2.5 -0.087457366 -0.635370352 -49.57529656 -28.45255875
3 -0.128805357 -0.800601678 -61.9718953 -37.06576867
4 -0.189998798 -0.900340101 -74.36721169 -45.37149157
5 -0.264429401 -1.015069379 -86.76336658 -56.68657815
6.5 -0.303092011 -1.111173198 -99.15624929 -67.18844927
我想将以下双指数衰减方程拟合到我的行中
y = a * exp(-bx) +c * exp(-dx)
我对图形等很好,只是想知道如何拟合指数衰减以给出最佳拟合线并给出该拟合的 r2 值以及 a、b、c 和的值d.
还有我以后如何绘制适合的?
我想知道如何在 R 中做到这一点。
我有以下无法正常工作的代码
mydata <- read.csv("B5cumul.csv")
fitData <- data.frame(mydata$Time, mydata$Al.Biochar)
plot(mydata$Time, mydata$Al.Biochar, type="b",
xlab="Time (hour)", ylab="Al removal (mg/L)")
# a is plateau. b is the amplitude of fast phase, r1 is the fast constant.
# (y[1]-a-b) is the amplitude of slow phase, r2 is the slow constant.
f = function (a, r1, r2, b) {
a + (b * exp(-(r1 * mydata$Time))) + ((mydata$Al.Biochar -a-b) * exp(-(r2 * x)))
}
fit <- nls(f, data=fitData, start=list(a=0.25, r1=0.05, r2=1e-5, b=0.22),
algorithm="port")
而且我不确定 a、b c 和 d 使用哪些值。我得到错误 错误:“闭包”类型的对象不是子集。
【问题讨论】:
标签: r exponential