gpt4 book ai didi

R Power Fit与nls与excel不同

转载 作者:行者123 更新时间:2023-12-04 03:07:04 25 4
gpt4 key购买 nike

我有一个具有幂关系的数据集(如下)。 (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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com