nls 缺失值或无穷大产生

nls missing value or infinity produced

我正在尝试使用 Chapman-Richards 函数对嵌套数据建模,如下所示: https://image.slideserve.com/575351/testing-eichhorn-s-rule35-n.jpg

我的原始数据如下:

structure(list(Site = c(1, 1, 1, 1, 1, 1, 4, 4, 4, 4, 4, 
4), Height = c(2.4, 11.3, 20.5, 27.4, 32, 34.9, 2.45, 7.45, 13.05, 
17.7, 20.75, 22.8), Volume = c(12, 220, 605, 991, 1288, 1495, 
11, 106, 283, 473, 619, 723)), row.names = c(NA, -12L), class = c("tbl_df", 
"tbl", "data.frame"))

我创建了一个成长模型:

model <- function(data){
  nls(Volume~ a * (Height^b), data=data, start=c(Volume=200, Height=5,a=1,b=1))
}

当我嵌套数据为每个嵌套创建模型时:

Silver %>% group_by(Site_class) %>% nest() %>% 
  mutate(mod= map(.x=data, model))

我收到以下错误:

fitting parameters ‘a’, ‘b’ without any variables
Error in numericDeriv(form[[3L]], names(ind), env) : 
  Missing value or an infinity produced when evaluating the model
Called from: numericDeriv(form[[3L]], names(ind), env)

我知道数据可能会有很小的变化。

如果我尝试 alg="plinear",我会收到以下错误:

fitting parameters ‘a’, ‘b’ without any variables
Error in qr.solve(QR.B, cc) : singular matrix 'a' in solve
Called from: qr.solve(QR.B, cc)

我尝试将其更改为 robustbase::nlrob 以防效果更好。

这会将错误代码更改为:

Error in parse(text = x, keep.source = FALSE) : 
  <text>:2:0: unexpected end of input
1: ~ 
   ^
Called from: parse(text = x, keep.source = FALSE)

有谁知道是什么导致了我这个问题或如何解决它?非常感谢!

如果我理解 nls 在做什么,它正在估计您的情况下参数 ab 的值。因此,不需要为变量 VolumeHeight 设置起始值。这些只是数据集中的值。如果您从 start 参数中删除它们,错误就会消失,您会得到一个模型。

model <- function(data){
  nls(Volume~ a * (Height^b), data=data, start=c(a = 1, b = 1))
}
  
df %>% group_by(Site) %>% nest() %>% 
  mutate(mod= map(.x=data, model))