为什么 R 中的 nls(非线性模型)方程与 Excel 不同?

Why nls (non-linear model) equation in R is different from Excel?

我想使用 nls 包检查非线性模型。

power<- nls(formula= agw~a*area^b, data=calibration_6, start=list(a=1, b=1))
summary(power)

这是关于模型的参数。

它说 y= 0.85844 x^1.37629

但是,在 Excel 中(下图)。它说 y= 0.7553 x^1.419

如果我在 R 中制作图表,图表是相同的。为什么同一个模型会产生不同的参数?

我需要更信任哪个方程式?你能回答我吗?

非常感谢。

ggplot(data=calibration_6, aes(x=area, y=agw)) + 
  geom_point (shape=19, color="cadetblue" ,size=2.5) +
  stat_smooth(method = 'nls', formula= y~a*x^b, start = list(a = 0, b=0), se=FALSE, color="Dark Red",level=0.95) +
  scale_x_continuous(breaks = seq(0,25,5),limits = c(0,25)) +
  scale_y_continuous(breaks = seq(0,80,10), limits = c(0,80)) +
  theme_bw() + 
  theme(panel.grid = element_blank())

Excel 实际上并没有做 non-linear 回归。它转换并进行线性回归。

让我们在 R 中模拟一些数据。

x <- 1:20
set.seed(42)
y <- 0.7 * x ^1.5 + rnorm(20, sd = 0.1)

这就是 Excel 给我的:

这是我通过 non-linear 回归得到的结果:

fit <- nls(y ~ a * x ^ b, start = list(a = 1, b = 1))

coef(fit)
#        a         b 
#0.7128834 1.4932711 

这是Excel方法:

fit_linear <- lm(log(y) ~ log(x))
exp(coef(fit_linear)[1])
# (Intercept) 
# 0.7515136 
coef(fit_linear)[2]
#  log(x) 
#1.471128

如您所见,结果与 Excel 相同。

现在,这两种方法中哪一种是“正确的”取决于您对不确定性的假设。在 non-linear 回归方法中,您有附加错误。在转换数据的线性回归中,您有乘法误差。

另请参阅:

https://stats.stackexchange.com/a/254706/11849

https://stats.stackexchange.com/a/255265/11849