【问题标题】:What is the problem with this nls function here?这个 nls 函数在这里有什么问题?
【发布时间】:2019-11-06 21:32:29
【问题描述】:
df <- data.frame(logy, logx1, logx2)

 dput(head(df, 30))

 structure(list(logy = c(2.86483129264695, 2.71422609892467, 6.0029648649718, 
 6.23407114218406, 3.10441832707604, 3.31883951518659, 2.74899119270203, 
 3.33693389469922, 3.08234859652005, 2.86894009277142, 3.14037873461243, 
 6.11999623623735, 5.62536278392782, 1.90161210220208, 2.89764442725342, 
 2.29866776176114, 2.96609825952411, 3.81945083760566, 6.0506839217917, 
 3.98692546692019, 3.58570690810385, 5.80067544663839, 2.97716462828348, 
 2.57262415074674, 3.47367201433336, 5.92714269822862, 2.95481164187758, 
 5.47788379980563, 2.99224877270403, 6.57532728890016), logx1 = 
 c(-1.57461309709751, 
 -1.5307242691139, -0.464080611399306, -0.681847625665562, 
 -1.14374686589473, -1.40571244572209, -1.43873659739373, 
 -1.64132447315449, -1.68256017671134, -0.777132837116422, 
 -0.658365673425322, -0.702903355642565, 
 -1.11411689629791,-1.47169196167472, -2.70413799875517, 
 -2.78595188490397, -2.484906653788, -1.65614025611831, 
 -0.974314573029494, -1.05275482065124, -1.24665025177373, 
 -0.88215772523624, -1.02217658549781, -1.49428048511697, 
 -1.46495693095528, -1.07148362127986, -0.75249014255333, 
 -1.08208298638903, -0.987460406593363, -0.470003629245736), logx2 = 
  c(2.40348089051437, 2.40348089051437, 2.40348089051437, 
  2.40348089051437, 2.40348089051437, 2.40348089051437, 2.40348089051437, 
  2.40348089051437, 2.40348089051437, 2.40348089051437, 
  2.40348089051437, 2.40348089051437, 2.40348089051437, 2.40348089051437, 
  2.40348089051437, 2.40348089051437, 2.40348089051437, 2.40348089051437, 
  2.40348089051437, 2.40348089051437, 2.40348089051437, 2.40348089051437, 
  2.40348089051437, 2.40348089051437, 2.40348089051437, 2.52948456201033, 
  2.52948456201033, 2.52948456201033, 2.52948456201033, 2.65823690571249
  )), row.names = c(NA, 30L), class = "data.frame")
  > 

我正在尝试通过 R 中的 nls 来拟合这些数据。 但是弹出如下错误

numericDeriv(form[[3L]], names(ind), env) 中的错误:
缺失值 或评估模型时产生的无穷大

有人可以检查一下吗?

  mod <- nls(logy ~ a*logx1^b + c*(logx2+1)^d, start = list(a=2.5, b=3.5, 
  c=3, d=2.5), data=df)
  summary(m)

提前致谢!

【问题讨论】:

  • 它抛出的错误不同,您发布的 df 带有变量 y、x1 和 x2,而不是 logB, logGi, logTH。
  • 我已经更正了。
  • 现在我得到了那个错误,但前提是我将df 列名更改为logy、logx1 和logx2。正如发布的所有x1 都是否定的,所以它们必须已经是日志。
  • par(mfcol=c(1,2)); plot(logy ~ logx1, data=df); plot(logy ~ logx2, data=df) 你确定你的型号吗?

标签: r regression nls non-linear-regression nonlinear-functions


【解决方案1】:

如果我取 LOGY 的指数,得到一个“Y = f(LOGX1, LOGX2)”形式的方程,拟合统计量更容易解释。这样做后我进行了方程搜索,发现多项式方程的拟合良好

Y = a + (b * LOGX1) + (c * LOGX2) + (d * LOGX1 * LOGX1) + (e * LOGX2 * LOGX2)

带参数

a = 7.0005922601656552E+04
b = 5.7528536348517446E+02
c = -5.6228145390482874E+04
d = 1.3165613600451343E+02
e = 1.1380943788391935E+04

收益率 RMSE = 128.85 和 R 平方 = 0.5593

【讨论】:

  • summary(lm(exp(logy) ~ logx1 + I(logx1^2) + logx2 + I(logx2^2), data=df))
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-26
  • 2014-06-29
  • 2011-02-13
  • 2011-04-24
  • 2011-08-26
  • 1970-01-01
相关资源
最近更新 更多