knitr::opts_chunk$set(echo = TRUE)
library(languageR) library(convenience) library(ggplot2) library(dplyr)
data(lexdec)
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)
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)
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.