Exponential regression in R

前端 未结 2 1181
梦谈多话
梦谈多话 2020-12-06 15:35

I have some points that look like a logarithmic curve. The curve that I\'m trying to obtain look like: y = a * exp(-b*x) + c

My code:

x <- c(1.564         


        
相关标签:
2条回答
  • 2020-12-06 16:24

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

    0 讨论(0)
  • 2020-12-06 16:25

    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
    

    enter image description here

    0 讨论(0)
提交回复
热议问题