knitr::opts_chunk$set(echo = TRUE)
library(data.table) #all_data <- fread("https://github.com/CrumpLab/statisticsLab/raw/master/stroop_stand.csv") all_data <- fread("data/stroop_stand.csv") RTs <- c(as.numeric(unlist(all_data[,1])), as.numeric(unlist(all_data[,2])), as.numeric(unlist(all_data[,3])), as.numeric(unlist(all_data[,4])) ) Congruency <- rep(rep(c("Congruent","Incongruent"),each=50),2) Posture <- rep(c("Stand","Sit"),each=100) Subject <- rep(1:50,4) stroop_df <- data.frame(Subject,Congruency,Posture,RTs) library(tidyr) stroop_long<- gather(all_data, key=Condition, value=RTs, congruent_stand, incongruent_stand, congruent_sit, incongruent_sit) new_columns <- tstrsplit(stroop_long$Condition, "_", names=c("Congruency","Posture")) stroop_long <- cbind(stroop_long,new_columns) stroop_long <- cbind(stroop_long,Subject=rep(1:50,4)) library(dplyr) library(ggplot2) library(tidyr) plot_means <- stroop_long %>% group_by(Congruency,Posture) %>% summarise(mean_RT = mean(RTs), SEM = sd(RTs)/sqrt(length(RTs))) ggplot(plot_means, aes(x=Posture, y=mean_RT, group=Congruency, fill=Congruency))+ geom_bar(stat="identity", position="dodge")+ geom_errorbar(aes(ymin=mean_RT-SEM, ymax=mean_RT+SEM), position=position_dodge(width=0.9), width=.2)+ theme_classic()+ coord_cartesian(ylim=c(700,1000))
aov_out<-aov(RTs ~ Congruency*Posture, stroop_long) summary_out<-summary(aov_out) summary_out
library(ggplot2) p1<- data.frame(IV1 = c("A","A","B","B"), IV2 = c("1","2","1","2"), means = c(5,5,5,5)) p2<- data.frame(IV1 = c("A","A","B","B"), IV2 = c("1","2","1","2"), means = c(10,10,5,5)) p3<- data.frame(IV1 = c("A","A","B","B"), IV2 = c("1","2","1","2"), means = c(10,13,5,2)) p4<- data.frame(IV1 = c("A","A","B","B"), IV2 = c("1","2","1","2"), means = c(5,10,10,15)) p5<- data.frame(IV1 = c("A","A","B","B"), IV2 = c("1","2","1","2"), means = c(10,18,5,7)) p6<- data.frame(IV1 = c("A","A","B","B"), IV2 = c("1","2","1","2"), means = c(10,2,10,2)) p7<- data.frame(IV1 = c("A","A","B","B"), IV2 = c("1","2","1","2"), means = c(2,12,5,9)) p8<- data.frame(IV1 = c("A","A","B","B"), IV2 = c("1","2","1","2"), means = c(5,10,10,5)) all_22s <- rbind(p1,p2,p3,p4,p5,p6,p7,p8) type <- c(rep("~1, ~2, ~1x2",4), rep("1, ~2, ~1x2",4), rep("1, ~2, 1x2",4), rep("1, 2, ~1x2",4), rep("1, 2, 1x2",4), rep("~1, 2, ~1x2",4), rep("~1, 2, 1x2",4), rep("~1, ~2, 1x2",4)) type<-as.factor(type) all_22s <- cbind(all_22s,type) ggplot(all_22s, aes(x=IV1, y=means, group=IV2, fill=IV2))+ geom_bar(stat="identity", position="dodge")+ theme_classic()+ facet_wrap(~type, nrow=2)+ theme(legend.position = "top")
sims <- rbinom(10000,7,.05) length(sims [sims > 0 ])/10000 n <- 12 factorial_data <- tibble(A = factor(rep(c("L1","L2"), each = n)), B = factor(rep(rep(c("L1","L2"), each = n/2),2)), C = factor(rep(c("L1","L2"), n)), DV = rnorm(n*2,0,1)) summary(aov(DV ~ A*B*C, data = factorial_data)) # set up tibble to save simulation values save_sim <- tibble() # loop to conduct i number of simulations for(i in 1:1000){ #simulate null data for a 2x2 n <- 12 factorial_data <- tibble(A = factor(rep(c("L1","L2"), each = n)), B = factor(rep(rep(c("L1","L2"), each = n/2),2)), C = factor(rep(c("L1","L2"), n)), DV = rnorm(n*2,0,1)) # compute ANOVA output <- summary(aov(DV ~ A*B*C, data = factorial_data)) #save p-values for each effect sim_tibble <- tibble(p_vals = output[[1]]$`Pr(>F)`[1:7], effect = c("A","B","C", "AxB", "AxC","BxC", "AxBxC"), sim = rep(i,7)) #add the saved values to the overall tibble save_sim <-rbind(save_sim,sim_tibble) } type_I_errors <- save_sim %>% filter(p_vals < .05) %>% group_by(sim) %>% count() dim(type_I_errors)[1]/1000
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.