用nls

时间:2015-12-04 06:43:02

标签: r nls

我不是R的专家,我正在努力将热死亡细菌数据应用于威布尔模型:

log._CFU.ml=c(9.6,9.2,9,8.5,9,7.5,6.8,5.8)
time_min=c(0,10,15,20,25,30,35,45)
ecoli_52=data.frame(log._CFU.ml,time_min)
weibull=function(x,a,b){-(1/2.303)*((x/a)^b)} #first i defined the function

然后,我应用了nls

mod.ecoli_52=nls(ecoli_52$log._CFU.ml~weibull(ecoli_52$time_min,a,b),
                 ecoli_52,start=list(a=1,b=1))

之后,在我看来是错误

Error in numericDeriv(form[[3L]], names(ind), env) : 
  Missing value or an infinity produced when evaluating the model

我确定这个错误与start中的a和b值有关。是否存在估算这些值的方法?

1 个答案:

答案 0 :(得分:2)

如果N是每ml的菌落形成单位数,而N0是0时的数字,那么您可能打算使用模型log(N/N0) ~ ...而不是log(N) ~ ...和自log(N/N0) = log(N) - log(N0)以来我们就有了:

 log_ratio <- with(ecoli_52, log._CFU.ml - log._CFU.ml[1])
 fm <- nls(log_ratio ~ weibull(time_min, a, b), ecoli_52, start = list(a = 1, b = 1))

 plot(log_ratio ~ time_min, ecoli_52)
 lines(fitted(fm) ~ time_min, ecoli_52, col = "red")

,并提供:

> fm
Nonlinear regression model
  model: log_ratio ~ weibull(time_min, a, b)
   data: ecoli_52
     a      b 
13.314  1.804 
 residual sum-of-squares: 0.7894

Number of iterations to convergence: 7 
Achieved convergence tolerance: 6.363e-07

screenshot