这里的nls函数有什么问题?

时间:2019-06-25 05:30:37

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

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来拟合此数据。 但是会弹出以下错误

  

numericalDeriv(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)

谢谢!

1 个答案:

答案 0 :(得分:0)

如果我采用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

scatter

surface