Exponential regression in R

試著忘記壹切 提交于 2019-11-28 00:35:20

I think that with b = 0, then nls can't calculate the gradient with respect to a and c since b=0 removes x from the equation. Start with a different value of b (oops, I see the comment above). Here's the example...

m <- nls(y ~ I(a*exp(-b*x)+c), data=df, start=list(a=max(y), b=1, c=10), trace=T)
y_est<-predict(m,df$x)
plot(x,y)
lines(x,y_est)
summary(m)

Formula: y ~ I(a * exp(-b * x) + c)

Parameters:
   Estimate Std. Error t value Pr(>|t|)    
a 6.519e+04  1.761e+04   3.702 0.000776 ***
b 6.646e-01  1.682e-01   3.952 0.000385 ***
c 1.896e+03  1.834e+03   1.034 0.308688    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2863 on 33 degrees of freedom

Number of iterations to convergence: 5 
Achieved convergence tolerance: 5.832e-06

You're not wrong, but sometimes it's necessary to change the initial values (kick) to program solve the equation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!