knitr::opts_chunk$set(echo = TRUE)

Load the required packages

library(languageR)
library(convenience)
library(ggplot2)
library(dplyr)

Load lexdec dataset

data(lexdec)

Data prep

Correct trials only for reaction time analysis. All trials for accuracy analysis. Convert the accuracy column to numeric.

lexdec.rt <- lexdec[lexdec$Correct=="correct",]
lexdec.acc <- lexdec

lexdec.acc$accuracy<-ifelse(lexdec.acc$Correct == "correct",1, 0)

Compute standard error

Use the sem function to compute the mean, standard error of the mean, and 1SEM (68%) confidence intervals

sem_summary.rt <- sem(data = lexdec.rt, dv = RT, id = Subject, Class, Complex, NativeLanguage)
print(sem_summary.rt)

sem_summary.acc <- sem(data = lexdec.acc, dv = accuracy, id = Subject, Class, Complex,NativeLanguage)
print(sem_summary.acc)

Plotting

Plot the resulting data with 95% confidence intervals (mean $\pm$ 1.96 * sem). You could also set ymin and ymax to upper and lower if you want error bars representing 1 standard error of the mean.

ggplot(sem_summary.rt, aes(x = Class, color=NativeLanguage, y = mean_RT, ymin = mean_RT - 1.96 * SEM, ymax = mean_RT + 1.96 * SEM)) + facet_wrap(~Complex) + geom_pointrange(position = position_dodge(.9))

ggplot(sem_summary.acc, aes(x = Class, color=NativeLanguage, y = mean_accuracy, ymin = mean_accuracy - 1.96 * SEM, ymax = mean_accuracy + 1.96 * SEM)) + facet_wrap(~Complex) + geom_pointrange(position = position_dodge(.9))

You could also set ymin and ymax to lower and upper if you want error bars representing 1 standard error of the mean.

ggplot(sem_summary.rt, aes(x = Class, color=NativeLanguage, y = mean_RT, ymin = lower, ymax = upper)) + facet_wrap(~Complex) + geom_pointrange(position = position_dodge(.9))

ggplot(sem_summary.acc, aes(x = Class, color=NativeLanguage, y = mean_accuracy, ymin = lower, ymax = upper)) + facet_wrap(~Complex) + geom_pointrange(position = position_dodge(.9))


jasongullifer/convenience documentation built on May 21, 2019, 10:31 a.m.