开发者

Printing model (nls) characteristics in plot

I have an exponential model calculated with

mod <- nls(y ~ exp(- (x/a)^b), data = DF, start = list(a = 200, b = 1.4))

which I plotted using:

plot(x,y)

lines(sort(DF$x),predict(mod, list(x=sort(DF$x))), lwd=2, col="red")

writting mod I get:

Nonlinear regression model 
  model:  y ~ exp(-(x/a)^b) 
   data:  DF 
       a        b 
    211.7098   0.3908 
 residual sum-of-squares: 17.69

Number of iterations to convergence: 5 
Achieved convergence tolerance: 1.477e-07 

With summary(mod) I get:

Formula: y ~ exp(-(x/a)^b)
Parameters:
   Estimate Std. Error t value Pr(>|t|)       
a 2.117e+02  2.799e+00   75.64   <2e-16 ***
b 3.908e-01  9.154e-03   42.69   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
Residual standard error: 0.08832 on 2268 degrees of freedom
Number of iterations to convergence: 5 
Achieved convergence tolerance: 1.477e-07 
  (8 observations deleted due to missingness)

My question is if there is a way of adding the formula, the parameters and the residual sum-of-squares to the plot? The only way I could come up with was using the text() and copy and paste the info I wanted but I will have to do lots of开发者_如何学Go different models so I would like something automatic. Thanks!


Try this where the first line will produce a plot we can use in this example and the next line adds the desired text:

example(nls)
legend("topleft", legend = capture.output(summary(nlmod)), cex = .5)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜