R Power Fit与nls与excel不同

标签 r nls

我有一个具有幂关系的数据集(如下)。 (Y =aX^b)

Excel 和 xmgrace 中的功率拟合为我提供了几乎相同的拟合值。 (0.993 的 R^2) Y = 215.47 X^0.812

然而,当我尝试 R 的 nls() 函数时,我得到了不同的值。另外,它不计算 R^2,因为它在统计上不合理。

但是,如果我取对数,我可以执行 lm() 并获得 0.993 的 R^2。如何使用 R 重现 excel 和 xmgrace 产生的幂拟合值..R nls() 不正确吗??

Drift Time  Mass_Independent CS
2.32    407.3417277
2.32    419.1267553
2.81    503.9859708
2.92    501.0465281
3.78    640.9024985
4.00    688.7906761
4.48    776.3958584
5.67    918.9991003
6.05    949.4448047
6.86    993.9763311
6.86    1064.539603
6.97    1041.422648
7.94    1112.407393
8.42    1183.070416
9.23    1302.622263
9.29    1291.525748

最佳答案

我认为你相信 Excel 估计而不是 R 估计是愚蠢的。 Excel 在回归领域的失败由来已久且有据可查:

 nls(Mass_Ind_CS ~a*Drift_Time^b , dat, start=list(a=100, b=1))
#---------------------
Nonlinear regression model
  model:  Mass_Ind_CS ~ a * Drift_Time^b 
   data:  dat 
       a        b 
227.0176   0.7828 
 residual sum-of-squares: 10224

Number of iterations to convergence: 5 
Achieved convergence tolerance: 3.617e-06 
#---------------------
 plot(dat, xlim=range(dat$Drift_Time), ylim=range(dat$Mass_Ind_CS) )
 par(new=T)
 curve(215.47*x^0.812, from=min(dat$Drift_Time), 
                        to=max(dat$Drift_Time),
                         ylim=range(dat$Mass_Ind_CS) )
 par(new=T)
 curve(227.0176*x^0.7828, from=min(dat$Drift_Time), 
                          to=max(dat$Drift_Time), 
                          ylim=range(dat$Mass_Ind_CS),col="red")

R 估计值以红色绘制。它表明您在不查看 x= 值范围内的预测的情况下专注于参数估计是错误的。虽然您可以使用 anova() 进行模型比较,但没有真正的 R-sq 可以估计单独的非线性模型。欢迎您搜索 nls (Douglas Bates) 的作者不包括它们的原因,因为它实际上是 r-help 邮件列表上的常见问题解答。

enter image description here

关于R Power Fit与nls与excel不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9237068/

相关文章:

r - 使用 minpack.lm 中的 nlsLM 时,是什么导致输入参数不正确?

在 R 中使用 nls 时解决 minFactor 错误

r - 在R中使用mfrow:如何为每个子图赋予不同的y标签和x轴一个标签

r - 包 tm 停止字参数

r - 更改 image.plot 中的图例刻度

R:在 geom_smooth 中的自定义函数中使用时,nls 不获取其他参数

rCharts dplot - 将颜色映射到特定组

r - ggplot2 二维密度权重

r - 在 nls 中使用 "predict"

r - 确定 rstudio 中 nls 函数的最佳初始值