簡體   English   中英

為什么 R 中的 nls(非線性模型)方程與 Excel 不同?

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

我想使用 nls package 檢查非線性 model。

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

這是關於 model 的參數。

在此處輸入圖像描述

它說 y= 0.85844 x^1.37629

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

在此處輸入圖像描述

如果我在R做一個圖,圖是一樣的。 為什么相同的model產生不同的參數?

我需要更信任哪個方程式? 你能回答我嗎?

非常感謝。

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實際上並沒有做非線性回歸。 它轉換並進行線性回歸。

讓我們模擬R中的一些數據。

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

這是 Excel 給我的:

適合的Excel圖表

這是我用非線性回歸得到的:

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 相同。

現在,這兩種方法中哪一種是“正確的”取決於您對不確定性的假設。 在非線性回歸方法中,您有附加誤差。 在轉換數據的線性回歸中,您有乘法誤差。

也可以看看:

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM