我使用了
nls
函数来拟合以下方程。y ~ (C + (A1*exp(-x/h1)) + (A2*exp(-x/h2)))
我的代码如下所示
f <- as.formula(y ~ (C + (A1*exp(-x/h1)) + (A2*exp(-x/h2))))
nls_b <- nls(f, data = df, start = list(C = 0.140, A1 = 0.051, h1 = 586.772, A2 = 0.166, h2 = 33.323))
summary(nls_b)
b_opt <- predict(nls_b, newdata=df)
现在,我已经将模型预测的值和观测值绘制在x轴上。
plot(y=df$y, x=df$x)
lines(y=b_opt, x=df$x, type='l')
现在我该如何得到以下的图表:
![enter image description here](https://istack.dev59.com/Hbxtk.webp)
数据
df = structure(list(x = c(2L, 5L, 10L, 33L, 50L, 100L, 500L, 1500L
), y = c(0.34272, 0.34256, 0.30483, 0.25772, 0.21584, 0.19295,
0.16144, 0.144)), class = "data.frame", row.names = c(NA, -8L
))
dput(df)
的输出,或是它的一大部分吗? - Allan Camerondput()
格式提供了数据。请查看一下。 - UseR10085