【问题标题】:Error while using nls function in R, can't get LS estimates在 R 中使用 nls 函数时出错,无法获得 LS 估计值
【发布时间】:2019-10-18 15:00:24
【问题描述】:

我正在尝试用 R 中的负指数模型拟合一些数据,但它似乎不起作用,我找不到错误或解决方法。

    t<-c(1,4,16)
    y<-c(0.8,0.45,0.04)
    tabla<-data.frame(t,y)
    reg<-nls(y~exp(-b*t),tabla,start = list(t=0,b=0))

运行代码后出现以下错误

Error in qr(.swts * attr(rhs, "gradient")) : 
 dims [product 2] do not match the length of object [3]
In addition: Warning message:
In .swts * attr(rhs, "gradient") :
 longer object length is not a multiple of shorter object length

【问题讨论】:

  • 是数据,不知道为什么帖子里没有出现,刚刚编辑过!
  • 不直接相关,但可能将t 重命名为其他名称。虽然R 可以处理这些问题,但t 可能难以调试,因为它也代表transpose 函数。

标签: r nls non-linear-regression


【解决方案1】:

当它是公式中的自变量时,您正在尝试估计 t

t<-c(1,4,16)
y<-c(0.8,0.45,0.04)
tabla<-data.frame(t,y)
reg<-nls(y~exp(-b*t),tabla,start = list(b=0))

这很好用

【讨论】:

  • 谢谢!我很愚蠢,什么都试过了,除了这个
  • 不用担心。在 R 中经常会遗漏一些小事情!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多