summarySEwithin: Calculate Within-Subjects Summary Statistics with Error Bars

View source: R/summarySEwithin.R

summarySEwithinR Documentation

Calculate Within-Subjects Summary Statistics with Error Bars

Description

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.

Usage

summarySEwithin(
  data = NULL,
  measurevar,
  betweenvars = NULL,
  withinvars = NULL,
  idvar = NULL,
  na.rm = FALSE,
  conf.interval = 0.95,
  .drop = TRUE
)

Arguments

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)

Details

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

Value

A data frame containing:

  • N: number of subjects

  • Original measurevar: raw means

  • sd: standard deviation

  • se: standard error

  • ci: confidence interval

Main Functions

  • summarySEwithin: Calculates within-subjects summary statistics

  • summarySE: Calculates basic summary statistics

  • normDataWithin: Normalizes data for within-subjects variables

Source

http://www.cookbook-r.com/Graphs/Plotting_means_and_error_bars_(ggplot2)/#understanding-within-subjects-error-bars

References

Morey, R. D. (2008). Confidence intervals from normalized data: A correction to Cousineau (2005). Tutorial in Quantitative Methods for Psychology, 4(2), 61-64.

Examples

# Example with one between-subjects and one within-subjects variable
summarySEwithin(data = mydata,
               measurevar = "score",
               betweenvars = "group",
               withinvars = "time",
               idvar = "subject")


ccamp83/mu documentation built on Nov. 7, 2024, 5:17 p.m.