2

我有一个指数模型计算

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

我使用以下方法绘制:

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

写作mod我得到:

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 

我得到summary(mod)

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)

我的问题是,是否有办法将公式、参数和残差平方和添加到图中?我能想出的唯一方法是使用text()并复制和粘贴我想要的信息,但我将不得不做很多不同的模型,所以我想要一些自动的东西。谢谢!

4

1 回答 1

2

试试这个,第一行将产生一个我们可以在这个例子中使用的图,下一行添加所需的文本:

example(nls)
legend("topleft", legend = capture.output(summary(nlmod)), cex = .5)
于 2011-06-21T19:46:15.720 回答