我使用以下代码为每组观察值拟合不同的指数曲线,并且效果很好。
p = c(10,20,15,25,20,30,25,35,30,40,25,35,20,30,15,25,10,20)
v = c(92,110,104,117,123,139,146,162,165,176,160,176,143,163,118,137,92,110)
group = factor(rep((1:9), each=2))
mm = model.matrix(~ 0 + group)
fit = nls(v ~ drop(mm %*% c(b1, b2, b3, b4, b5, b6, b7, b8, b9))*(1-exp(-k*p)),
start = list(k=0.5, b1=1000, b2=2000, b3=3000, b4=4000, b5=5000, b6=6000, b7=7000, b8=8000, b9=9000))
summary(fit)
Formula: v ~ drop(mm %*% c(b1, b2, b3, b4, b5, b6, b7, b8, b9)) * (1 -
exp(-k * p))
Parameters:
Estimate Std. Error t value Pr(>|t|)
k 0.10928 0.01374 7.954 4.55e-05 ***
b1 129.13042 8.01108 16.119 2.20e-07 ***
b2 126.81086 6.43352 19.711 4.57e-08 ***
b3 141.74666 5.62817 25.185 6.61e-09 ***
b4 161.10250 5.06762 31.791 1.04e-09 ***
b5 174.94417 4.63884 37.713 2.68e-10 ***
b6 175.73100 5.20655 33.752 6.48e-10 ***
b7 165.58007 6.01256 27.539 3.26e-09 ***
b8 146.48962 6.92337 21.159 2.62e-08 ***
b9 129.13042 8.01108 16.119 2.20e-07 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 5.767 on 8 degrees of freedom
Number of iterations to convergence: 8
Achieved convergence tolerance: 5.907e-06
对于不同的实验集(在 for 循环中),我需要多次运行此代码。棘手的部分是,对于每个实验,预测变量(即 b1、b2 等)的数量都会发生变化。
有没有简单的出路?