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

438 Views Asked by At

I want to check non-linear model using nls package.

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

and this is parameters about the model.

enter image description here

It says y= 0.85844 x^1.37629

However, in Excel (below graph). It says y= 0.7553 x^1.419

enter image description here

If I make a graph in R, the graph is the same. Why the same model generates different parameters?

Which equation do I need to more trust? Could you answer me about that?

Many thanks.

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

enter image description here

1

There are 1 best solutions below

2
On BEST ANSWER

Excel does not actually do non-linear regression. It transforms and does linear regression.

Let's simulate some data in R.

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

This is what Excel gives me:

Excel diagram with fit

This is what I get with non-linear regression:

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

coef(fit)
#        a         b 
#0.7128834 1.4932711 

This is the Excel approach:

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

As you see, same result as with Excel.

Now, which of both approaches is "correct" depends on your assumptions regarding the uncertainty. In the non-linear regression approach you have additive errors. In the linear regression on transformed data, you have multiplicative errors.

See also:

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

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