First we define a figure hook:
> options(SweaveHooks = list(fig = function() par(mfrow=c(2,2)))) Then we setup variable definitions without actually evaluating them
> x <- 1:10
> y <- rnorm(x)
Then we put the pieces together:
> x <- 1:10
> y <- rnorm(x)
> lm1 <- lm(y~x)
> summary(lm1) Call:
lm(formula = y ~ x) Residuals:
Min 1Q Median 3Q Max
-0.7125 -0.6122 -0.1006 0.4825 0.9848 Coefficients:
Estimate Std. Error t value Pr(>|t|) (Intercept) 0.08009 0.46293 0.173 0.867
x -0.09574 0.07461 -1.283 0.235
Residual standard error: 0.6777 on 8 degrees of freedom
Multiple R-squared: 0.1707, Adjusted R-squared: 0.06703 F-statistic: 1.647 on 1 and 8 DF, p-value: 0.2353
> plot(lm1)
1
−0.2 0.0 0.2 0.4 0.6
−1.0−0.50.00.5
Fitted values
Residuals
Residuals vs Fitted
7
3 8
−1.5 −0.5 0.5 1.5
−2.0−0.50.5
Theoretical Quantiles
Standardized residuals
Normal Q−Q
7
3 8
−0.2 0.0 0.2 0.4 0.6
0.00.51.01.5
Fitted values
Standardized residuals
Scale−Location
7
3 8
0.00 0.10 0.20 0.30
−2−101
Leverage
Standardized residuals
Cook's distance
1 0.5 0.5
Residuals vs Leverage
7
1 3
2