【问题标题】:nls missing value or infinity producednls 缺失值或无穷大产生
【发布时间】:2020-09-04 00:01:50
【问题描述】:

我正在尝试使用这样的 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)

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

【问题讨论】:

  • 在整洁/嵌套的框架之外,如果你一次只做一个,那么做适合吗?

标签: r dplyr nls tidymodels


【解决方案1】:

如果我了解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))

【讨论】:

  • 谢谢!我几乎可以肯定有一个简单的解决方案。
猜你喜欢
  • 1970-01-01
  • 2019-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多