View source: R/summarySEwithin.R
summarySEwithin | R Documentation |
A collection of functions for calculating summary statistics and error bars for within-subjects designs, implementing the method described in Morey (2008). This is particularly useful for creating plots with appropriate error bars for within-subjects variables in ggplot2.
summarySEwithin(
data = NULL,
measurevar,
betweenvars = NULL,
withinvars = NULL,
idvar = NULL,
na.rm = FALSE,
conf.interval = 0.95,
.drop = TRUE
)
data |
A data frame containing the variables |
measurevar |
The name of the measure variable |
betweenvars |
A vector containing names of between-subjects variables |
withinvars |
A vector containing names of within-subjects variables |
idvar |
The name of the variable that identifies subjects |
na.rm |
Should NA values be removed? (default = FALSE) |
conf.interval |
Confidence interval level (default = 0.95) |
.drop |
Should unused factor levels be dropped? (default = TRUE) |
This implementation follows Morey's (2008) correction for within-subjects designs. It automatically:
Converts non-factor variables to factors
Normalizes the data within subjects
Applies the Morey correction factor
Combines normed and un-normed results
A data frame containing:
N: number of subjects
Original measurevar: raw means
sd: standard deviation
se: standard error
ci: confidence interval
summarySEwithin
: Calculates within-subjects summary statistics
summarySE
: Calculates basic summary statistics
normDataWithin
: Normalizes data for within-subjects variables
http://www.cookbook-r.com/Graphs/Plotting_means_and_error_bars_(ggplot2)/#understanding-within-subjects-error-bars
Morey, R. D. (2008). Confidence intervals from normalized data: A correction to Cousineau (2005). Tutorial in Quantitative Methods for Psychology, 4(2), 61-64.
# Example with one between-subjects and one within-subjects variable
summarySEwithin(data = mydata,
measurevar = "score",
betweenvars = "group",
withinvars = "time",
idvar = "subject")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.