R: Handy extensions
http://www.psychol.cam.ac.uk/statistics/R/anova.html

Some functions collated here are from other sources on the web. The sources are given inside the source code (q.v.).

Example .rprofile

An example .Rprofile (save as ".Rprofile" in your home directory). It doesn't do much except auto-set R's column width to the size of your display window. To execute its contents from the web (which is not the same as having it as your .Rprofile), copy this code fragment and paste it into R:

source("http://egret.psychol.cam.ac.uk/statistics/R/extensions/example_Rprofile")

writeForeignMySPSS

From https://stat.ethz.ch/pipermail/r-devel/2008-October/050918.html: a writeForeignMySPSS function to write SPSS format (one datafile, one .SPS syntax file to read it and to set up variable types - the syntax file created knows the name of the datafile, so just execute the syntax file from within SPSS):

source("http://egret.psychol.cam.ac.uk/statistics/R/extensions/writeForeignMySPSS.R")

# you can then use it with:
writeForeignMySPSS(dataframe, datafile, codefile[, varnames] )

Type III sums of squares with ezANOVA v2.1-0

A hack to ezANOVA version 2.1-0 (based on package ez by Mike Lawrence) to allow Type III sums of squares as an option (see ANOVA as to why this might be desirable, and see this discussion on Statistical Analysis about it).

Note that from ez version 3, there is a type= option (use as e.g. “type=3”), making this extension redundant.

source("http://egret.psychol.cam.ac.uk/statistics/R/extensions/hack_ezANOVA.R")

# you can then use it with:
ezANOVA(dataframe,
        dv=.(depvar(s)), wid=.(subjectidentifier),
        within=.(withinsubjectvariable(s)), between=.(betweensubjectvariable(s)),
        otheroptions, detailed=TRUE, type=c("II", "III", 2, 3) )

# example for a two-factor between-subjects design, where data2 is a data frame containing columns depvar (dependent variable), A (factor), B (factor), S (subject label):
ezANOVA(data2, dv=.(depvar), wid=.(S), between=.(A,B), detailed=TRUE, type="III")

Half borders (left/bottom axes only) in ggplot2

This hack to ggplot2 allows left/bottom ("L") borders only, and some other possibilities. See Graphs 2 for usage, but examples include:

Install it with:

source("http://egret.psychol.cam.ac.uk/statistics/R/extensions/rnc_ggplot2_border_themes.r")
Valid HTML 4.01 Transitional
Valid CSS