farawayさんの文章を読んでいて,simulateという関数があるということを知りました。これは便利。library(lme4)内にはlmer用のsimulateもあるよう。
> xx <- seq(0,10)
> yy <- 10 + 2*xx + rnorm(length(xx),0,3)
> plot(yy ~ xx, , cex = 2)
> m1 <- lm(yy~xx)
> summary(m1)Call:
lm(formula = yy ~ xx)Residuals:
Min 1Q Median 3Q Max
-5.4638 -1.1599 -0.3412 1.3367 5.1558Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 11.4871 1.6495 6.964 6.58e-05 ***
xx 1.6795 0.2788 6.024 0.000197 ***
- -
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 2.924 on 9 degrees of freedom
Multiple R-squared: 0.8013, Adjusted R-squared: 0.7792
F-statistic: 36.28 on 1 and 9 DF, p-value: 0.0001967> set.seed(123)
> simulate(m1)
sim_1
1 9.84818
2 12.49350
3 19.40403
4 16.73170
5 18.58305
6 24.89965
7 22.91173
8 19.54410
9 22.91436
10 25.29912
11 31.86125