How get plot from nls in R?

前端 未结 4 1883
野的像风
野的像风 2020-12-30 17:17

In R I use nls to do a nonlinear least-squares fit. How then do I plot the model function using the values of the coefficients that the fit provided?

(Yes, this is a

4条回答
  •  一整个雨季
    2020-12-30 17:52

    coef(x) returns the coefficients for regression results x.

    model<-nls(y~a+b*x^k,my.data,list(a=0.,b=1.,k=1))
    plot(y~x,my.data)
    a<-coef(model)[1]
    b<-coef(model)[2]
    k<-coef(model)[3]
    lines(x<-c(1:10),a+b*x^k,col='red')
    

    For example.

提交回复
热议问题