Example R programs
I often use R for computations and graphs. I will post some of the
R code I use. This is only for those interested. Nothing here is required.
If you prefer to use R instead of SAS, be aware of potential
difficulties when we do ANOVA. It can be very
hard to get certain useful quantities from R. You can always
program up the computations, but you don't get them automatically.
- Week 1: Design-based inference
- Week 2 / lab 2: Summary statistics
- tomato.r Summary statistics and
graphics of tomato data
- Week 3 / lab 3: T tests and quantiles/probability calculations
- Week 4 / lab 4: Diagnostics, non-parametric tests
- sparrow2.r Diagnostic plots,
Levene's test, Wilcoxon rank sum test
- Week 5 / lab 5: ANOVA
- judges.r fitting an ANOVA model,
very limited facility for estimates and contrasts.
- Week 6 / lab 6: ANOVA and plots for blocked and paired data
- schiz.r paired t-test, Wilcoxon signed
rank tests, and fitting ANOVA's for blocked data. Again, very
limited facilities for estimates and contrasts
- schiz2.r plotting data from block
designs: either using pair number as the X axis, or the block mean
as the X axis.
- Week 7 / lab 7: Regression and correlation
- corr.r Correlations, including test and
ci
- meat.r Regression, including ANOVA lack of fit test
- boxcox.r Estimating Box-Cox
transformation power for 1-way designs.
- Week 8 / lab 8: Multiple regression
- Week 9 / lab 9: Diagnostics for multiple regression
- brain2.r Case diagnostics
- births2.r Loess and smoothing splines,
Breusch-Pagan
- births3.r Regression with ar(1) error
structure, Information about Durbin-Watson test
- Week 10 / lab 10: Indicator variables
- Week 11 / lab 11: Model selection
- bear.r Model selection in R (at least
the little I know, since I don't use R for this).
- Week 12 / lab 12: ANOVA
- ratweight.r 2 way ANOVA in R.
Beware: R works well for balanced data and badly for unbalanced
data. This is one place SAS is much, much better than R.
- Week 13 / lab 13: random effects