diff --git a/.Rhistory b/.Rhistory index 09d73351..18312f18 100644 --- a/.Rhistory +++ b/.Rhistory @@ -1,512 +1,512 @@ -library(tidyverse) -rm1wLONG_df <- rm1wLONG_df%>% -dplyr::group_by(deID)%>% -dplyr::filter(n()==3) +#reading the data back in as a .csv file +#dfOneSample<- read.csv ('dfOneSample.csv', header = TRUE) +#saveRDS(dfOneSample, 'dfOneSample.rds') +#dfOneSample <- readRDS('dfOneSample.rds') +ggpubr::gghistogram(dfOneSample, x = "PhysMins", add = "mean", rug = TRUE, color = "#993366") +ggpubr::ggboxplot(dfOneSample$PhysMins, +ylab = "Minutes with Patient", xlab = FALSE, add="jitter" +) +psych::describe(dfOneSample$PhysMins) +(10.01 - 1.23)/(2.7/sqrt(33)) +qt(p=.05/2, df=32,lower.tail=FALSE) +qt(p=.05/2, df=32,lower.tail=FALSE) +(10.01) - ((2.0369)*(2.7/sqrt(33))) +(10.01) + ((2.0369)*(2.7/sqrt(33))) +#First formula +(10.01 - 1.23)/2.7 +#Second formula +18.68047/sqrt(33) +#pastecs is the package, stat.desc is the function +#we point it to the data and then add the norm=TRUE command +pastecs::stat.desc(dfOneSample, norm=TRUE) +rstatix::t_test(dfOneSample, PhysMins ~ 1, mu = 1.23, detailed = TRUE) +(9.050577 + 10.96577)/2 +mean(dfOneSample$PhysMins) +rstatix::cohens_d(dfOneSample, PhysMins ~ 1, ref.group = NULL, mu = 1.23) +ggpubr::ggboxplot(dfOneSample$PhysMins, +ylab = "Physician Minutes", xlab = FALSE, add="jitter", title = "Figure 1. Physician Time with Patients (in minutes)" +) +pwr::pwr.t.test(d= 3.25,n = 33, power=NULL,sig.level=0.05,type="one.sample",alternative="two.sided") +pwr::pwr.t.test(d= 3.25, n = NULL, power=0.8,sig.level=0.05,type="one.sample",alternative="two.sided") +set.seed(220822) +rdfOneSample <- data.frame(rPhysMins = rnorm(3, mean=10, sd=2.5)) +head(rdfOneSample) +rstatix::t_test(rdfOneSample, rPhysMins ~ 1, mu = 1.23, detailed = TRUE) +rstatix::cohens_d(rdfOneSample, rPhysMins ~ 1, ref.group = NULL, mu = 1.23) +knitr::opts_chunk$set(echo = TRUE) +knitr::opts_chunk$set(comment = NA) #keeps out the hashtags in the knits options(scipen=999)#eliminates scientific notation -big <- readRDS("ReC.rds") -#Creates a list of the variables that belong to that scale -TradPed_vars <- c('ClearResponsibilities', 'EffectiveAnswers','Feedback', 'ClearOrganization','ClearPresentation') -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -big$TradPed <- sjstats::mean_n(big[, TradPed_vars], .75) -#if the scoring script won't run, try this one: -#big$TradPed <- sjstats::mean_n(big[, ..TradPed_vars], .75) -rm1wLONG_df <- (dplyr::select (big, deID, Course, TradPed)) -head(rm1wLONG_df) -str(rm1wLONG_df) -rm1wLONG_df$Course <- factor(rm1wLONG_df$Course, levels = c("ANOVA", "Multivariate", "Psychometrics")) -str(rm1wLONG_df) -rm1wLONG_df <- na.omit(rm1wLONG_df) -nrow(rm1wLONG_df)#counts number of rows (cases) -library(tidyverse) -rm1wLONG_df <- rm1wLONG_df%>% -dplyr::group_by(deID)%>% -dplyr::filter(n()==3) -210/3 -bxp <- ggpubr::ggboxplot(rm1wLONG_df, x = "Course", y = "TradPed", add = "point", color = "Course", -xlab = "Statistics Course", ylab = "Traditional Pedagogy Course Eval Ratings", title = "Course Evaluations across Doctoral Statistics Courses") -bxp -psych::describeBy(TradPed ~ Course, mat = TRUE, type = 1, data = rm1wLONG_df) -psych::describeBy(TradPed ~ Course, mat = TRUE, type = 1, data = rm1wLONG_df) -#running the model -RMres_TradPed <- lm(TradPed ~ Course, data = rm1wLONG_df) -summary(RMres_TradPed) -rm1wLONG_df <- as.data.frame(rm1wLONG_df) -psych::describeBy(TradPed ~ Course, mat = TRUE, type = 1, data = rm1wLONG_df) -rstatix::shapiro_test(residuals(RMres_TradPed)) -ggpubr::ggqqplot(residuals(RMres_TradPed)) -library(tidyverse) -rm1wLONG_df %>% -group_by(Course)%>% -rstatix::identify_outliers(TradPed) -rmAOV <- rstatix::anova_test(data = rm1wLONG_df, dv = TradPed, wid = deID, within = Course) -rmAOV -pwc <- rstatix::pairwise_t_test(TradPed ~ Course, paired = TRUE, p.adjust.method = "bonf", data = rm1wLONG_df) -pwc -pwc <- rstatix::pairwise_t_test(TradPed ~ Course, paired = TRUE, p.adjust.method = "bonf", data = rm1wLONG_df) -pwc -library(tidyverse) -pwc <- pwc %>% -rstatix::add_xy_position(x = "Course") -bxp <- bxp + ggpubr::stat_pvalue_manual(pwc, label = "p.adj.signif", tip.length = 0.02, hide.ns = TRUE, y.position = c(5.3)) -bxp -library(tidyverse) -pwc <- pwc %>% -rstatix::add_xy_position(x = "Course") -bxp <- bxp + ggpubr::stat_pvalue_manual(pwc, label = "p.adj.signif", tip.length = 0.02, hide.ns = FALSE, y.position = c(5.3)) -bxp -library(tidyverse) -pwc <- pwc %>% -rstatix::add_xy_position(x = "Course") -bxp <- bxp + ggpubr::stat_pvalue_manual(pwc, label = "p.adj.signif", tip.length = 0.02, hide.ns = FALSE, y.position = c(5.3, 5,5, 5,7)) -library(tidyverse) -pwc <- pwc %>% -rstatix::add_xy_position(x = "Course") -bxp <- bxp + ggpubr::stat_pvalue_manual(pwc, label = "p.adj.signif", tip.length = 0.02, hide.ns = FALSE, y.position = c(5.3, 5.5, 5.7)) -bxp -options(scipen=999)#eliminates scientific notation -big <- readRDS("ReC.rds") -#Creates a list of the variables that belong to that scale -TradPed_vars <- c('ClearResponsibilities', 'EffectiveAnswers','Feedback', 'ClearOrganization','ClearPresentation') -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -big$TradPed <- sjstats::mean_n(big[, TradPed_vars], .75) -#if the scoring script won't run, try this one: -#big$TradPed <- sjstats::mean_n(big[, ..TradPed_vars], .75) -rm1wLONG_df <- (dplyr::select (big, deID, Course, TradPed)) -head(rm1wLONG_df) -str(rm1wLONG_df) -rm1wLONG_df$Course <- factor(rm1wLONG_df$Course, levels = c("ANOVA", "Multivariate", "Psychometrics")) -str(rm1wLONG_df) -rm1wLONG_df <- na.omit(rm1wLONG_df) -nrow(rm1wLONG_df)#counts number of rows (cases) -library(tidyverse) -rm1wLONG_df <- rm1wLONG_df%>% -dplyr::group_by(deID)%>% -dplyr::filter(n()==3) -210/3 -bxp <- ggpubr::ggboxplot(rm1wLONG_df, x = "Course", y = "TradPed", add = "point", color = "Course", -xlab = "Statistics Course", ylab = "Traditional Pedagogy Course Eval Ratings", title = "Course Evaluations across Doctoral Statistics Courses") -bxp -#R wasn't recognizing the data, so I quickly applied the as.data.frame function -rm1wLONG_df <- as.data.frame(rm1wLONG_df) -psych::describeBy(TradPed ~ Course, mat = TRUE, type = 1, data = rm1wLONG_df) -#running the model -RMres_TradPed <- lm(TradPed ~ Course, data = rm1wLONG_df) -summary(RMres_TradPed) -rstatix::shapiro_test(residuals(RMres_TradPed)) -ggpubr::ggqqplot(residuals(RMres_TradPed)) -library(tidyverse) -rm1wLONG_df %>% -group_by(Course)%>% -rstatix::identify_outliers(TradPed) -rmAOV <- rstatix::anova_test(data = rm1wLONG_df, dv = TradPed, wid = deID, within = Course) -rmAOV -pwc <- rstatix::pairwise_t_test(TradPed ~ Course, paired = TRUE, p.adjust.method = "bonf", data = rm1wLONG_df) -pwc -library(tidyverse) -pwc <- pwc %>% -rstatix::add_xy_position(x = "Course") -bxp <- bxp + ggpubr::stat_pvalue_manual(pwc, label = "p.adj.signif", tip.length = 0.02, hide.ns = FALSE, y.position = c(5.3, 5.5, 5.7)) -bxp -options(scipen=999)#eliminates scientific notation -big <- readRDS("ReC.rds") -#Creates a list of the variables that belong to that scale -TradPed_vars <- c('ClearResponsibilities', 'EffectiveAnswers','Feedback', 'ClearOrganization','ClearPresentation') -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -big$TradPed <- sjstats::mean_n(big[, TradPed_vars], .75) -#if the scoring script won't run, try this one: -#big$TradPed <- sjstats::mean_n(big[, ..TradPed_vars], .75) -rm1wLONG_df <- (dplyr::select (big, deID, Course, TradPed)) -head(rm1wLONG_df) -str(rm1wLONG_df) -rm1wLONG_df$Course <- factor(rm1wLONG_df$Course, levels = c("ANOVA", "Multivariate", "Psychometrics")) -str(rm1wLONG_df) -rm1wLONG_df <- na.omit(rm1wLONG_df) -nrow(rm1wLONG_df)#counts number of rows (cases) -library(tidyverse) -rm1wLONG_df <- rm1wLONG_df%>% -dplyr::group_by(deID)%>% -dplyr::filter(n()==3) -210/3 -bxp <- ggpubr::ggboxplot(rm1wLONG_df, x = "Course", y = "TradPed", add = "point", color = "Course", -xlab = "Statistics Course", ylab = "Traditional Pedagogy Course Eval Ratings", title = "Course Evaluations across Doctoral Statistics Courses") -bxp -#R wasn't recognizing the data, so I quickly applied the as.data.frame function -rm1wLONG_df <- as.data.frame(rm1wLONG_df) -psych::describeBy(TradPed ~ Course, mat = TRUE, type = 1, data = rm1wLONG_df) -#running the model -RMres_TradPed <- lm(TradPed ~ Course, data = rm1wLONG_df) -summary(RMres_TradPed) -rstatix::shapiro_test(residuals(RMres_TradPed)) -ggpubr::ggqqplot(residuals(RMres_TradPed)) -library(tidyverse) -rm1wLONG_df %>% -group_by(Course)%>% -rstatix::identify_outliers(TradPed) -rmAOV <- rstatix::anova_test(data = rm1wLONG_df, dv = TradPed, wid = deID, within = Course) -rmAOV -pwc <- rstatix::pairwise_t_test(TradPed ~ Course, paired = TRUE, p.adjust.method = "bonf", data = rm1wLONG_df) -pwc -library(tidyverse) -pwc <- pwc %>% -rstatix::add_xy_position(x = "Course") -bxp <- bxp + ggpubr::stat_pvalue_manual(pwc, label = "p.adj.signif", tip.length = 0.02, hide.ns = FALSE, y.position = c(5.25, 5.5, 5.75)) -bxp +#will install the package if not already installed +#if(!require(psych)){install.packages("psych")} +#if(!require(tidyverse)){install.packages("tidyverse")} +#if(!require(dplyr)){install.packages("dplyr")} +#if(!require(ggpubr)){install.packages("ggpubr")} +#if(!require(pwr)){install.packages("pwr")} +#if(!require(apaTables)){install.packages("apaTables")} +#if(!require(knitr)){install.packages("knitr")} +#if(!require(rstatix)){install.packages("rstatix")} +set.seed(220815) +#sample size, M, and SD for Black then White patients +Verbal <- c(rnorm(33, mean=8.37, sd=3.36), rnorm(33, mean = 8.41, sd=3.21)) +#set upper bound +Verbal[Verbal>27]<-27 +#set lower bound +Verbal[Verbal<0]<-0 +#sample size, M, and SD for Black then White patients +Nonverbal <- c(rnorm(33, mean=2.68, sd=.84), rnorm(33, mean = 2.93, sd=.77)) +#set upper bound +Nonverbal[Nonverbal>5]<-5 +#set lower bound +Nonverbal[Nonverbal<0]<-0 +ID<-factor(seq(1,66)) +#name factors and identify how many in each group; should be in same order as first row of script +PatientRace<-c(rep("Black", 33), rep("White", 33)) +#groups the 3 variables into a single df: ID#, DV, condition +dfIndSamples <-data.frame(ID, PatientRace, Verbal, Nonverbal) +str(dfIndSamples) +dfIndSamples$PatientRace <- factor(dfIndSamples$PatientRace, levels = c("Black", "White")) +str(dfIndSamples) +#writing the simulated data as a .csv +#write.table(dfIndSamples, file = "dfIndSamples.csv", sep = ',', col.names=TRUE, row.names=FALSE) +#at this point you could clear your environment and then bring the data back in as a .csv +#reading the data back in as a .csv file +#dfIndSamples<- read.csv ('dfIndSamples.csv', header = TRUE) +View(dfIndSamples) +ggpubr::ggboxplot(dfIndSamples, x = "PatientRace", y = "Verbal", color = "PatientRace", palette =c("#00AFBB", "#FC4E07"), add = "jitter") +pwr::pwr.t.test(d= -0.412,n = 33, power=NULL,sig.level=0.05,type="two.sample",alternative="two.sided") +pwr::pwr.t.test(d= -0.412,n = NULL, power=0.8,sig.level=0.05,type="two.sample",alternative="two.sided") +set.seed(230525) +#sample size, M, and SD for Black then White patients +rVerbal <- c(rnorm(93, mean=8.37, sd=3.36), rnorm(93, mean = 8.41, sd=3.21)) +#set upper bound +rVerbal[rVerbal>27]<-3 +#set lower bound +rVerbal[rVerbal<0]<-0 +#sample size, M, and SD for Black then White patients +rNonverbal <- c(rnorm(93, mean=2.68, sd=.84), rnorm(93, mean = 2.93, sd=.77)) +#set upper bound +rNonverbal[rNonverbal>5]<-5 +#set lower bound +rNonverbal[rNonverbal<0]<-0 +rID<-factor(seq(1,186)) +#name factors and identify how many in each group; should be in same order as first row of script +rPatientRace<-c(rep("Black", 93), rep("White", 93)) +#groups the 3 variables into a single df: ID#, DV, condition +rdfIndSamples <-data.frame(rID, rPatientRace, rVerbal, rNonverbal) +rdfIndSamples$rPatientRace <- factor(rdfIndSamples$rPatientRace, levels = c("Black", "White")) +rstatix::t_test(rdfIndSamples, rVerbal~rPatientRace, var.equal=TRUE, detailed=TRUE) +rstatix::cohens_d(rdfIndSamples, rVerbal~rPatientRace, var.equal = TRUE) +knitr::opts_chunk$set(echo = TRUE) +knitr::opts_chunk$set(comment = NA) #keeps out the hashtags in the knits options(scipen=999)#eliminates scientific notation -big <- readRDS("ReC.rds") -#Creates a list of the variables that belong to that scale -TradPed_vars <- c('ClearResponsibilities', 'EffectiveAnswers','Feedback', 'ClearOrganization','ClearPresentation') -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -big$TradPed <- sjstats::mean_n(big[, TradPed_vars], .75) -#if the scoring script won't run, try this one: -#big$TradPed <- sjstats::mean_n(big[, ..TradPed_vars], .75) -rm1wLONG_df <- (dplyr::select (big, deID, Course, TradPed)) -head(rm1wLONG_df) -str(rm1wLONG_df) -rm1wLONG_df$Course <- factor(rm1wLONG_df$Course, levels = c("ANOVA", "Multivariate", "Psychometrics")) -str(rm1wLONG_df) -rm1wLONG_df <- na.omit(rm1wLONG_df) -nrow(rm1wLONG_df)#counts number of rows (cases) -library(tidyverse) -rm1wLONG_df <- rm1wLONG_df%>% -dplyr::group_by(deID)%>% -dplyr::filter(n()==3) -210/3 -bxp <- ggpubr::ggboxplot(rm1wLONG_df, x = "Course", y = "TradPed", add = "point", color = "Course", -xlab = "Statistics Course", ylab = "Traditional Pedagogy Course Eval Ratings", title = "Course Evaluations across Doctoral Statistics Courses") -bxp -#R wasn't recognizing the data, so I quickly applied the as.data.frame function -rm1wLONG_df <- as.data.frame(rm1wLONG_df) -psych::describeBy(TradPed ~ Course, mat = TRUE, type = 1, data = rm1wLONG_df) -#running the model -RMres_TradPed <- lm(TradPed ~ Course, data = rm1wLONG_df) -summary(RMres_TradPed) -rstatix::shapiro_test(residuals(RMres_TradPed)) -ggpubr::ggqqplot(residuals(RMres_TradPed)) -library(tidyverse) -rm1wLONG_df %>% -group_by(Course)%>% -rstatix::identify_outliers(TradPed) -rmAOV <- rstatix::anova_test(data = rm1wLONG_df, dv = TradPed, wid = deID, within = Course) -rmAOV -pwc <- rstatix::pairwise_t_test(TradPed ~ Course, paired = TRUE, p.adjust.method = "bonf", data = rm1wLONG_df) -pwc -library(tidyverse) -pwc <- pwc %>% -rstatix::add_xy_position(x = "Course") -bxp <- bxp + ggpubr::stat_pvalue_manual(pwc, label = "p.adj.signif", tip.length = 0.01, hide.ns = FALSE, y.position = c(5.25, 5.5, 5.75)) -bxp -effectsize::eta2_to_f(.014) -WebPower::wp.rmanova(n=70, ng=1, nm=3, f = .1192, nscor = .891, alpha = .05, power = NULL, type = 1) -WebPower::wp.rmanova(n=NULL, ng=1, nm=3, f = .1192, nscor = .891, alpha = .05, power = .80, type = 1) -mean(rm1wLONG_df$TradPed) -rm1wLONG_df$mDev <- rm1wLONG_df$TradPed - 4.319286 -head(rm1wLONG_df)#shows first six rows of dataset -rm1wLONG_df$mDev2 <- rm1wLONG_df$mDev * rm1wLONG_df$mDev -head(rm1wLONG_df)#shows first six rows of dataset -SST <- sum(rm1wLONG_df$mDev2) -SST -psych::describeBy(TradPed ~ deID, mat=TRUE, type = 1, data = rm1wLONG_df) -SST <- sum(rm1wLONG_df$mDev2) -SST -SSW <- (0.8717798^2 * (3 - 1)) + (0.4163332 ^2 * (3 - 1)) + (0.6928203 ^2 * (3 - 1)) + (0.4000000 ^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.5291503^2 * (3 - 1)) + (0.5291503^2 * (3 - 1)) + (0.7023769^2 * (3 - 1)) + (0.4618802^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (1.2220202^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.9018500^2 * (3 - 1)) + (0.5033223^2 * (3 - 1)) + (0.0000000^2 * (3 - 1)) + (0.9451631^2 * (3 - 1)) + -(1.0066446^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.5484828^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (1.6165808^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.9165151^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.6429101^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.5291503^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.2309401^2 * (3 - 1)) + -(0.1154701^2 * (3 - 1)) + (0.9165151^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.5291503^2 * (3 - 1)) + -(0.5291503^2 * (3 - 1)) + (0.5291503^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + -(0.2309401^2 * (3 - 1)) + (0.2309401^2 * (3 - 1)) + (0.0000000^2 * (3 - 1)) + (0.2000000^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.5033223^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.0000000^2 * (3 - 1)) + (0.2309401^2 * (3 - 1)) + (0.4618802^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.4000000^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.8326664^2 * (3 - 1)) + (0.5773503^2 * (3 - 1)) + -(0.0000000^2 * (3 - 1)) + (0.2000000^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + -(0.4618802^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) -SSW -psych::describeBy(TradPed ~ Course, mat = TRUE, digits = 3, type = 1, data = rm1wLONG_df) -SSR <- 36.895 - 1.460 -SSR -SSB <- 103.9144 - 35.435 -SSB -#calculating degrees of freedom for the residual -67-2 -1.4601/2#MSM -35.435/65#MSR -.7301/.5452 -qf(.05, 2, 65, lower.tail = FALSE) -big <- readRDS("ReC.rds") -View(big) -TradPed_vars <- c('ClearResponsibilities', 'EffectiveAnswers','Feedback', 'ClearOrganization','ClearPresentation') -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -big$TradPed <- sjstats::mean_n(big[, TradPed_vars], .75) -View(big) -rm1wLONG_df <- (dplyr::select (big, deID, Course, TradPed)) -head(rm1wLONG_df) -str(rm1wLONG_df) -rm1wLONG_df$Course <- factor(rm1wLONG_df$Course, levels = c("ANOVA", "Multivariate", "Psychometrics")) -str(rm1wLONG_df) -rm1wLONG_df <- na.omit(rm1wLONG_df) -nrow(rm1wLONG_df)#counts number of rows (cases) -library(tidyverse) -rm1wLONG_df <- rm1wLONG_df%>% -dplyr::group_by(deID)%>% -dplyr::filter(n()==3) -bxp <- ggpubr::ggboxplot(rm1wLONG_df, x = "Course", y = "TradPed", add = "point", color = "Course", -xlab = "Statistics Course", ylab = "Traditional Pedagogy Course Eval Ratings", title = "Course Evaluations across Doctoral Statistics Courses") -bxp -psych::describeBy(TradPed ~ Course, mat = TRUE, type = 1, data = rm1wLONG_df) -#R wasn't recognizing the data, so I quickly applied the as.data.frame function -rm1wLONG_df <- as.data.frame(rm1wLONG_df) -psych::describeBy(TradPed ~ Course, mat = TRUE, type = 1, data = rm1wLONG_df) -#running the model -RMres_TradPed <- lm(TradPed ~ Course, data = rm1wLONG_df) -summary(RMres_TradPed) -rstatix::shapiro_test(residuals(RMres_TradPed)) -ggpubr::ggqqplot(residuals(RMres_TradPed)) -library(tidyverse) -rm1wLONG_df %>% -group_by(Course)%>% -rstatix::identify_outliers(TradPed) -rmAOV <- rstatix::anova_test(data = rm1wLONG_df, dv = TradPed, wid = deID, within = Course) -rmAOV -pwc <- rstatix::pairwise_t_test(TradPed ~ Course, paired = TRUE, p.adjust.method = "bonf", data = rm1wLONG_df) -pwc -pwc <- pwc %>% -rstatix::add_xy_position(x = "Course") +#will install the package if not already installed +#if(!require(psych)){install.packages("psych")} +#if(!require(faux)){install.packages("faux")} +#if(!require(tidyverse)){install.packages("tidyverse")} +#if(!require(dplyr)){install.packages("dplyr")} +#if(!require(ggpubr)){install.packages("ggpubr")} +#if(!require(pwr)){install.packages("pwr")} +#if(!require(apaTables)){install.packages("apaTables")} +#if(!require(knitr)){install.packages("knitr")} +#if(!require(rstatix)){install.packages("rstatix")} library(tidyverse) -pwc <- pwc %>% -rstatix::add_xy_position(x = "Course") -bxp <- bxp + ggpubr::stat_pvalue_manual(pwc, label = "p.adj.signif", tip.length = 0.01, hide.ns = FALSE, y.position = c(5.25, 5.5, 5.75)) -bxp -effectsize::eta2_to_f(.014) -WebPower::wp.rmanova(n=70, ng=1, nm=3, f = .1192, nscor = .891, alpha = .05, power = NULL, type = 1) -WebPower::wp.rmanova(n=NULL, ng=1, nm=3, f = .1192, nscor = .891, alpha = .05, power = .80, type = 1) -WebPower::wp.rmanova(n=70, ng=1, nm=3, f = .1192, nscor = .891, alpha = .05, power = NULL, type = 1) -WebPower::wp.rmanova(n=NULL, ng=1, nm=3, f = .1192, nscor = .891, alpha = .05, power = .80, type = 1) +#Setting the seed. If you choose this practice option, change the number below to something different. +set.seed(220817) +#These define the characteristics of the verbal variable. It is essential that the object names (e.g., A_mean) are not changed because they will be fed to the function in the faux package. +sub_n <- 33 +A_mean <- 8.37 +B_mean <- 8.41 +A_sd <- 3.36 +B_sd <- 3.21 +AB_r <- 0.3 +#the faux package can simulate a variety of data. This function within the faux package will use the objects above to simulate paired samples data +paired_V <- faux::rnorm_multi( +n = sub_n, +vars = 2, +r = AB_r, +mu = c(A_mean, B_mean), +sd = c(A_sd, B_sd), +varnames = c("Verbal_BL", "Verbal_WH") +) +paired_V <- paired_V %>% dplyr::mutate(PhysID = row_number()) +#Here, I repeated the process for the nonverbal variable. +sub_n <- 33 +A_mean <- 2.68 +B_mean <- 2.93 +A_sd <- .84 +B_sd <- .77 +AB_r <- 0.9 +paired_NV <- faux::rnorm_multi( +n = sub_n, +vars = 2, +r = AB_r, +mu = c(A_mean, B_mean), +sd = c(A_sd, B_sd), +varnames = c("NVerb_BL", "NVerb_WH") +) +#This code produced an ID number for each physician +paired_NV <- paired_NV %>% dplyr::mutate(PhysID = row_number()) +#This data joined the two sets of data. +#Note, I did not write any code that assumed tha the verbal and nonverbal data came from the same physician. Full confession: I'm not quite sure how to do that just yet. +dfPairedSamples <- dplyr::full_join(paired_V, paired_NV, by = c("PhysID")) +dfPairedSamples <- dfPairedSamples%>%dplyr::select(PhysID, everything()) +str(dfPairedSamples) +#writing the simulated data as a .csv +#write.table(dfPairedSamples, file = "dfPairedSamples.csv", sep = ',', col.names=TRUE, row.names=FALSE) +#at this point you could clear your environment and then bring the data back in as a .csv +#reading the data back in as a .csv file +#dfPairedSamples<- read.csv ('dfPairedSamples.csv', header = TRUE) +#saveRDS(dfPairedSamples, 'dfPairedSamples.rds') +#dfPairedSamples <- readRDS('dfPairedSamples.rds') +View(dfPairedSamples) +View(dfPairedSamples) +ggpubr::ggpaired(dfPairedSamples, cond1 = "Verbal_BL", cond2 ="Verbal_WH", color = "condition", line.color = "gray", palette =c("npg"), xlab = "Patient Race", ylab = "Verbal Communication Rating") +pwr::pwr.t.test(d=0.02,n = 33, power=NULL,sig.level=0.05,type="paired",alternative="two.sided") +rstatix::cohens_d(df_long, Verbal ~ PtRace, paired=TRUE) +knitr::opts_chunk$set(echo = TRUE) +knitr::opts_chunk$set(comment = NA) #keeps out the hashtags in the knits options(scipen=999)#eliminates scientific notation -big <- readRDS("ReC.rds") -#Creates a list of the variables that belong to that scale -TradPed_vars <- c('ClearResponsibilities', 'EffectiveAnswers','Feedback', 'ClearOrganization','ClearPresentation') -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -big$TradPed <- sjstats::mean_n(big[, TradPed_vars], .75) -#if the scoring script won't run, try this one: -#big$TradPed <- sjstats::mean_n(big[, ..TradPed_vars], .75) -rm1wLONG_df <- (dplyr::select (big, deID, Course, TradPed)) -head(rm1wLONG_df) -str(rm1wLONG_df) -rm1wLONG_df$Course <- factor(rm1wLONG_df$Course, levels = c("ANOVA", "Multivariate", "Psychometrics")) -str(rm1wLONG_df) -rm1wLONG_df <- na.omit(rm1wLONG_df) -nrow(rm1wLONG_df)#counts number of rows (cases) +#will install the package if not already installed +#if(!require(psych)){install.packages("psych")} +#if(!require(faux)){install.packages("faux")} +#if(!require(tidyverse)){install.packages("tidyverse")} +#if(!require(dplyr)){install.packages("dplyr")} +#if(!require(ggpubr)){install.packages("ggpubr")} +#if(!require(pwr)){install.packages("pwr")} +#if(!require(apaTables)){install.packages("apaTables")} +#if(!require(knitr)){install.packages("knitr")} +#if(!require(rstatix)){install.packages("rstatix")} library(tidyverse) -rm1wLONG_df <- rm1wLONG_df%>% -dplyr::group_by(deID)%>% -dplyr::filter(n()==3) -210/3 -bxp <- ggpubr::ggboxplot(rm1wLONG_df, x = "Course", y = "TradPed", add = "point", color = "Course", -xlab = "Statistics Course", ylab = "Traditional Pedagogy Course Eval Ratings", title = "Course Evaluations across Doctoral Statistics Courses") -bxp -#R wasn't recognizing the data, so I quickly applied the as.data.frame function -rm1wLONG_df <- as.data.frame(rm1wLONG_df) -psych::describeBy(TradPed ~ Course, mat = TRUE, type = 1, data = rm1wLONG_df) -#running the model -RMres_TradPed <- lm(TradPed ~ Course, data = rm1wLONG_df) -summary(RMres_TradPed) -rstatix::shapiro_test(residuals(RMres_TradPed)) -ggpubr::ggqqplot(residuals(RMres_TradPed)) -library(tidyverse) -rm1wLONG_df %>% -group_by(Course)%>% -rstatix::identify_outliers(TradPed) -rmAOV <- rstatix::anova_test(data = rm1wLONG_df, dv = TradPed, wid = deID, within = Course) -rmAOV -pwc <- rstatix::pairwise_t_test(TradPed ~ Course, paired = TRUE, p.adjust.method = "bonf", data = rm1wLONG_df) -pwc -library(tidyverse) -pwc <- pwc %>% -rstatix::add_xy_position(x = "Course") -bxp <- bxp + ggpubr::stat_pvalue_manual(pwc, label = "p.adj.signif", tip.length = 0.01, hide.ns = FALSE, y.position = c(5.25, 5.5, 5.75)) -bxp -effectsize::eta2_to_f(.014) -WebPower::wp.rmanova(n=70, ng=1, nm=3, f = .1192, nscor = .891, alpha = .05, power = NULL, type = 1) +#Setting the seed. If you choose this practice option, change the number below to something different. +set.seed(220817) +#These define the characteristics of the verbal variable. It is essential that the object names (e.g., A_mean) are not changed because they will be fed to the function in the faux package. +sub_n <- 33 +A_mean <- 8.37 +B_mean <- 8.41 +A_sd <- 3.36 +B_sd <- 3.21 +AB_r <- 0.3 +#the faux package can simulate a variety of data. This function within the faux package will use the objects above to simulate paired samples data +paired_V <- faux::rnorm_multi( +n = sub_n, +vars = 2, +r = AB_r, +mu = c(A_mean, B_mean), +sd = c(A_sd, B_sd), +varnames = c("Verbal_BL", "Verbal_WH") +) +paired_V <- paired_V %>% dplyr::mutate(PhysID = row_number()) +#Here, I repeated the process for the nonverbal variable. +sub_n <- 33 +A_mean <- 2.68 +B_mean <- 2.93 +A_sd <- .84 +B_sd <- .77 +AB_r <- 0.9 +paired_NV <- faux::rnorm_multi( +n = sub_n, +vars = 2, +r = AB_r, +mu = c(A_mean, B_mean), +sd = c(A_sd, B_sd), +varnames = c("NVerb_BL", "NVerb_WH") +) +#This code produced an ID number for each physician +paired_NV <- paired_NV %>% dplyr::mutate(PhysID = row_number()) +#This data joined the two sets of data. +#Note, I did not write any code that assumed tha the verbal and nonverbal data came from the same physician. Full confession: I'm not quite sure how to do that just yet. +dfPairedSamples <- dplyr::full_join(paired_V, paired_NV, by = c("PhysID")) +dfPairedSamples <- dfPairedSamples%>%dplyr::select(PhysID, everything()) +str(dfPairedSamples) +#writing the simulated data as a .csv +#write.table(dfPairedSamples, file = "dfPairedSamples.csv", sep = ',', col.names=TRUE, row.names=FALSE) +#at this point you could clear your environment and then bring the data back in as a .csv +#reading the data back in as a .csv file +#dfPairedSamples<- read.csv ('dfPairedSamples.csv', header = TRUE) +#saveRDS(dfPairedSamples, 'dfPairedSamples.rds') +#dfPairedSamples <- readRDS('dfPairedSamples.rds') +ggpubr::ggpaired(dfPairedSamples, cond1 = "Verbal_BL", cond2 ="Verbal_WH", color = "condition", line.color = "gray", palette =c("npg"), xlab = "Patient Race", ylab = "Verbal Communication Rating") +#Creating the Verbal_D variable within the dfPairedSamples df +#Doing the "math" that informs that variable +dfPairedSamples$Verbal_D <- (dfPairedSamples$Verbal_BL - dfPairedSamples$Verbal_WH) +#Displaying the first six rows of the df to show that the difference score now exists +head(dfPairedSamples) +.08/(4.14/sqrt(33)) +qt(.05/2, 32, lower.tail=TRUE) +qt(.05/2, 32, lower.tail=FALSE) +qt(.05/2, 32, lower.tail=TRUE) +qt(.05/2, 32, lower.tail=FALSE) +.08-(2.037*((4.14/(sqrt(33))))) +.08+(2.037*((4.14/sqrt(33)))) +.08/4.14 +0.111/(sqrt(33)) +(33*(.08^2))/((33*(.08^2)) + ((33-1)*(4.14^2))) +(0.111^2)/((0.111^2)+(33-1)) +psych::describe(dfPairedSamples, type=1) +rstatix::shapiro_test(dfPairedSamples, Verbal_D) +df_long <- data.table::melt(data.table::setDT(dfPairedSamples), id.vars=c("PhysID"), measure.vars=list(c("Verbal_BL", "Verbal_WH"), c("NVerb_BL", "NVerb_WH"))) +head(df_long) +df_long <- rename(df_long, PatientRace = variable, Verbal = value1, Nonverbal = value2 ) +str(df_long) +df_long$PtRace <- plyr::mapvalues(df_long$PatientRace, from = c(1, 2), to = c("Black", "White")) +rstatix::t_test(df_long, Verbal ~ PtRace, paired=TRUE, detailed=TRUE) +rstatix::cohens_d(df_long, Verbal ~ PtRace, paired=TRUE) +pwr::pwr.t.test(d=0.02,n = NULL, power=0.8,sig.level=0.05,type="paired",alternative="two.sided") +pwr::pwr.t.test(d=0.02,n = 33, power=NULL,sig.level=0.05,type="paired",alternative="two.sided") +pwr::pwr.t.test(d=0.02,n = NULL, power=0.8,sig.level=0.05,type="paired",alternative="two.sided") +set.seed(220820) +#These define the characteristics of the verbal variable. It is essential that the object names (e.g., A_mean) are not changed because they will be fed to the function in the faux package. +sub_n <- 19624 +A_mean <- 8.37 +B_mean <- 8.41 +A_sd <- 3.36 +B_sd <- 3.21 +AB_r <- 0.3 +#the faux package can simulate a variety of data. This function within the faux package will use the objects above to simulate paired samples data +paired_V2 <- faux::rnorm_multi( +n = sub_n, +vars = 2, +r = AB_r, +mu = c(A_mean, B_mean), +sd = c(A_sd, B_sd), +varnames = c("Verbal_BL", "Verbal_WH") +) +paired_V2 <- paired_V2 %>% dplyr::mutate(PhysID = row_number()) +#restructuring data to the long form +df_longV2 <- data.table::melt(data.table::setDT(paired_V2), id.vars=c("PhysID"), measure.vars=list(c("Verbal_BL", "Verbal_WH"))) +df_longV2 <- rename(df_longV2, PatientRace = variable, Verbal = value) +df_longV2$PtRace <- plyr::mapvalues(df_longV2$PatientRace, from = c("Verbal_BL", "Verbal_WH"), to = c("Black", "White")) +rstatix::t_test(df_longV2, Verbal ~ PtRace, paired=TRUE, detailed=TRUE) +rstatix::cohens_d(df_longV2, Verbal ~ PtRace, paired=TRUE) +knitr::opts_chunk$set(echo = TRUE) +knitr::opts_chunk$set(comment = NA) #keeps out the hashtags in the knits options(scipen=999)#eliminates scientific notation -big <- readRDS("ReC.rds") -#Creates a list of the variables that belong to that scale -TradPed_vars <- c('ClearResponsibilities', 'EffectiveAnswers','Feedback', 'ClearOrganization','ClearPresentation') -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -big$TradPed <- sjstats::mean_n(big[, TradPed_vars], .75) -#if the scoring script won't run, try this one: -#big$TradPed <- sjstats::mean_n(big[, ..TradPed_vars], .75) -rm1wLONG_df <- (dplyr::select (big, deID, Course, TradPed)) -head(rm1wLONG_df) -str(rm1wLONG_df) -rm1wLONG_df$Course <- factor(rm1wLONG_df$Course, levels = c("ANOVA", "Multivariate", "Psychometrics")) -str(rm1wLONG_df) -rm1wLONG_df <- na.omit(rm1wLONG_df) -nrow(rm1wLONG_df)#counts number of rows (cases) -library(tidyverse) -rm1wLONG_df <- rm1wLONG_df%>% -dplyr::group_by(deID)%>% -dplyr::filter(n()==3) -210/3 -bxp <- ggpubr::ggboxplot(rm1wLONG_df, x = "Course", y = "TradPed", add = "point", color = "Course", -xlab = "Statistics Course", ylab = "Traditional Pedagogy Course Eval Ratings", title = "Course Evaluations across Doctoral Statistics Courses") -bxp -#R wasn't recognizing the data, so I quickly applied the as.data.frame function -rm1wLONG_df <- as.data.frame(rm1wLONG_df) -psych::describeBy(TradPed ~ Course, mat = TRUE, type = 1, data = rm1wLONG_df) -#running the model -RMres_TradPed <- lm(TradPed ~ Course, data = rm1wLONG_df) -summary(RMres_TradPed) -rstatix::shapiro_test(residuals(RMres_TradPed)) -ggpubr::ggqqplot(residuals(RMres_TradPed)) library(tidyverse) -rm1wLONG_df %>% -group_by(Course)%>% -rstatix::identify_outliers(TradPed) -rmAOV <- rstatix::anova_test(data = rm1wLONG_df, dv = TradPed, wid = deID, within = Course) -rmAOV -pwc <- rstatix::pairwise_t_test(TradPed ~ Course, paired = TRUE, p.adjust.method = "bonf", data = rm1wLONG_df) -pwc -library(tidyverse) -pwc <- pwc %>% -rstatix::add_xy_position(x = "Course") -bxp <- bxp + ggpubr::stat_pvalue_manual(pwc, label = "p.adj.signif", tip.length = 0.01, hide.ns = FALSE, y.position = c(5.25, 5.5, 5.75)) -bxp -effectsize::eta2_to_f(.014) -WebPower::wp.rmanova(n=70, ng=1, nm=3, f = .1192, nscor = .891, alpha = .05, power = NULL, type = 1) -WebPower::wp.rmanova(n=NULL, ng=1, nm=3, f = .1192, nscor = .891, alpha = .05, power = .80, type = 1) -mean(rm1wLONG_df$TradPed) -rm1wLONG_df$mDev <- rm1wLONG_df$TradPed - 4.319286 -head(rm1wLONG_df)#shows first six rows of dataset -rm1wLONG_df$mDev2 <- rm1wLONG_df$mDev * rm1wLONG_df$mDev -head(rm1wLONG_df)#shows first six rows of dataset -SST <- sum(rm1wLONG_df$mDev2) -SST -psych::describeBy(TradPed ~ deID, mat=TRUE, type = 1, data = rm1wLONG_df) -SSW <- (0.8717798^2 * (3 - 1)) + (0.4163332 ^2 * (3 - 1)) + (0.6928203 ^2 * (3 - 1)) + (0.4000000 ^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.5291503^2 * (3 - 1)) + (0.5291503^2 * (3 - 1)) + (0.7023769^2 * (3 - 1)) + (0.4618802^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (1.2220202^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.9018500^2 * (3 - 1)) + (0.5033223^2 * (3 - 1)) + (0.0000000^2 * (3 - 1)) + (0.9451631^2 * (3 - 1)) + -(1.0066446^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.5484828^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (1.6165808^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.9165151^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.6429101^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.5291503^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.2309401^2 * (3 - 1)) + -(0.1154701^2 * (3 - 1)) + (0.9165151^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.5291503^2 * (3 - 1)) + -(0.5291503^2 * (3 - 1)) + (0.5291503^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + -(0.2309401^2 * (3 - 1)) + (0.2309401^2 * (3 - 1)) + (0.0000000^2 * (3 - 1)) + (0.2000000^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.5033223^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.0000000^2 * (3 - 1)) + (0.2309401^2 * (3 - 1)) + (0.4618802^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.4000000^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.8326664^2 * (3 - 1)) + (0.5773503^2 * (3 - 1)) + -(0.0000000^2 * (3 - 1)) + (0.2000000^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + -(0.4618802^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) -SSW -psych::describeBy(TradPed ~ Course, mat = TRUE, digits = 3, type = 1, data = rm1wLONG_df) -(70 * (4.211 - 4.319286)^2) + (70 * (4.332 - 4.319286)^2) + (70 * (4.414 - 4.319286)^2) -SSR <- 36.895 - 1.460 -SSR -SSB <- 103.9144 - 35.435 -SSB -qf(.05, 2, 65, lower.tail = FALSE) -big <- readRDS("ReC.rds") -#Creates a list of the variables that belong to that scale -SRPed_vars <- c('InclusvClassrm', 'EquitableEval','MultPerspectives', 'DEIintegration') -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -big$SRPed <- sjstats::mean_n(big[, SRPed_vars], .75) -#Creates a list of the variables that belong to that scale -SRPed_vars <- c('InclusvClassrm', 'EquitableEval','MultPerspectives', 'DEIintegration') -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -big$SRPed <- sjstats::mean_n(big[, SRPed_vars], .75) -#if the scoring script won't run, try this one: -#big$SRPed <- sjstats::mean_n(big[, ..SRPed_vars], .75) -View(big) -mixt_df <- (dplyr::select (big, deID, Course, Centering, SRPed)) -View(mixt_df) -str(mixt_df) -mixt_df$Course <- factor(mixt_df$Course, levels = c("ANOVA", "Multivariate", "Psychometrics")) -str(mixt_df) -View(mixt_df) -mixt_df <- na.omit(mixt_df) -library(tidyverse) -mixt_df <- mixt_df%>% -dplyr::group_by(deID)%>% -dplyr::filter(n()==3) -198/3 -mixt_box <- ggpubr::ggboxplot(mixt_df, x = "Course", y = "SRPed", color = "Centering", palette = "jco", xlab = "Statistics Sequence", ylab = "Socially Responsive Pedagogy", title = "Socially Responsive Course Evaluations as a Function of Centering and Time") -mixt_box -mixt_box <- ggpubr::ggboxplot(mixt_df, x = "Course", y = "SRPed", color = "Centering", palette = "jco", xlab = "Statistics Sequence", ylab = "Socially Responsive Pedagogy", title = "Socially Responsive Course Evaluations as a Function of Centering and Time", add = "jitter") -mixt_box -mixt_df <- as.data.frame(mixt_df)#my data was not reading as a df so I applied this function -psych::describeBy(SRPed ~ Course + Centering, data = mixt_df, type = 1, mat = TRUE, digits = 3) -mixt_mod <- aov(SRPed ~ Course*Centering, mixt_df) -summary(mixt_mod) -mixt_resid <- residuals(mixt_mod) -shapiro.test(mixt_resid) +set.seed(210731) +#sample size, M and SD for each cell; this will put it in a long file +Negative<-round(c(rnorm(17,mean=1.91,sd=0.73),rnorm(18,mean=3.16,sd=0.19),rnorm(19, mean=3.3, sd=1.05), rnorm(20, mean=3.00, sd=1.07), rnorm(18, mean=2.64, sd=0.95), rnorm(19, mean=2.99, sd=0.80)),3) +#sample size, M and SD for each cell; this will put it in a long file +Positive<-round(c(rnorm(17,mean=4.99,sd=1.38),rnorm(18,mean=3.83,sd=1.13),rnorm(19, mean=4.2, sd=0.82), rnorm(20, mean=4.19, sd=0.91), rnorm(18, mean=4.17, sd=0.60), rnorm(19, mean=3.26, sd=0.94)),3) +ID <- factor(seq(1,111)) +Rater <- c(rep("Dayaknese",35), rep("Madurese", 39), rep ("Javanese", 37)) +Photo <- c(rep("Dayaknese", 17), rep("Madurese", 18), rep("Dayaknese", 19), rep("Madurese", 20), rep("Dayaknese", 18), rep("Madurese", 19)) +#groups the 3 variables into a single df: ID#, DV, condition +Ramdhani_df<- data.frame(ID, Negative, Positive, Rater, Photo) +Ramdhani_df[,'Rater'] <- as.factor(Ramdhani_df[,'Rater']) +Ramdhani_df[,'Photo'] <- as.factor(Ramdhani_df[,'Photo']) +contrasts(Ramdhani_df$Rater) +# tell R which groups to compare +c1 <- c(1, -2, 1) +c2 <- c(-1, 0, 1) +mat <- cbind(c1,c2) #combine the above bits +contrasts(Ramdhani_df$Rater) <- mat # attach the contrasts to the variable +contrasts (Ramdhani_df$Rater) +#subset data +Dayaknese_Ph <- subset(Ramdhani_df, Photo == "Dayaknese") +View(Dayaknese_Ph) +Dykn_simple <- aov(Negative ~ Rater, data = Dayaknese_Ph) +summary(Dykn_simple) +#effect size for simple main effect can add "type = 1,2,3,4" to correspond with the ANOVA that was run +lsr::etaSquared(Dykn_simple, anova = FALSE ) +summary.aov(Dykn_simple, split=list(Rater=list("Javanese v Dayaknese and Madurese"=1, "Dayaknese Madurese" = 2))) +#subset data +Madurese_Ph <- subset(Ramdhani_df, Photo == "Madurese") +#change df to subset, new model name +Mdrs_simple <- aov(Negative ~ Rater, data = Madurese_Ph) +#output for simple main effect +summary(Mdrs_simple) +#effect size for simple main effect can add "type = 1,2,3,4" to correspond with the ANOVA that was run +lsr::etaSquared(Mdrs_simple, anova = FALSE ) +summary.aov(Mdrs_simple, split=list(Rater=list("Javanese v Dayaknese and Madurese"=1, "Dayaknese Madurese" = 2))) +.05/4 +ggpubr::ggboxplot(Ramdhani_df, x = "Photo", y = "Negative", color = "Rater",xlab = "Rater Ethnicity Represented within Photo Stimulus", ylab = "Negative Reaction", add = "jitter", title = "Figure 1. Simple Main Effect of Rater within Photo Stimulus", ylim = c(1, 7)) +Dayaknese_Ph <- subset(Ramdhani_df, Photo == "Dayaknese") +Madurese_Ph <- subset(Ramdhani_df, Photo == "Madurese") +View(Dayaknese_Ph) +contrasts(Dayaknese_Ph$Rater)<-contr.poly(3) +poly_Dy<-aov(Negative ~ Rater, data = Dayaknese_Ph) +summary.lm(poly_Dy) +contrasts(Madurese_Ph$Rater)<-contr.poly(3) +poly_Md<-aov(Negative ~ Rater, data = Madurese_Ph) +summary.lm(poly_Md) +ggpubr::ggboxplot(Ramdhani_df, x = "Photo", y = "Negative", color = "Rater",xlab = "Rater Ethnicity Represented within Photo Stimulus", ylab = "Negative Reaction", add = "jitter", title = "Figure 1. Simple Main Effect of Rater within Photo Stimulus", ylim = c(1, 7)) +6*(6-1)/2 +TwoWay_neg<-aov(Negative~Rater*Photo, Ramdhani_df) +summary(TwoWay_neg) +posthocs <- TukeyHSD(TwoWay_neg, ordered = TRUE) +posthocs +.05/15 +.05/14 +str(posthocs) +write.csv(posthocs$'Rater:Photo', 'posthocsOUT.csv') +.05/7 +TwoWay_neg<-aov(Negative~Rater*Photo, Ramdhani_df) +summary(TwoWay_neg) +posthocs <- TukeyHSD(TwoWay_neg, ordered = TRUE) +posthocs +str(posthocs) +write.csv(posthocs$'Rater:Photo', 'posthocsOUT.csv') +set.seed(2022) +#gives me 8 numbers, assigning each number 3 consecutive spots, in sequence +ID<-factor(c(rep(seq(1,8),each=3))) +#gives me a column of 24 numbers with the specified Ms and SD +Resilience<-rnorm(24,mean=c(5.7,6.21,6.26),sd=c(.88,.79,.37)) +#repeats pre, post, follow-up once each, 8 times +Wave<-rep(c("Pre","Post", "FollowUp"),each=1,8) +Amodeo_long<-data.frame(ID, Wave, Resilience) +Amodeo_long$Wave <- factor(Amodeo_long$Wave, levels = c("Pre", "Post", "FollowUp")) +# Create a new df (Amodeo_wide) +# Identify the original df +# We are telling it to connect the values of the Resilience variable its respective Wave designation +Amodeo_wide <- reshape2::dcast(data = Amodeo_long, formula =ID~Wave, value.var = "Resilience") +#doublecheck to see if they did what you think +str(Amodeo_wide) +Amodeo_wide$ID <- factor(Amodeo_wide$ID) +View(Amodeo_long) +View(Amodeo_wide) +#library(car) +waveLevels <- c(1,2,3) +waveFactor <- as.factor(waveLevels) +waveFrame <- data.frame(waveFactor) +waveBind <-cbind(Amodeo_wide$Pre, Amodeo_wide$Post, Amodeo_wide$FollowUp) +waveModel<- lm(waveBind~1) +waveModel +analysis <-car::Anova(waveModel, idata=waveFrame, idesign=~waveFactor) +summary(analysis) +set.seed(2022) +#gives me 8 numbers, assigning each number 3 consecutive spots, in sequence +ID<-factor(c(rep(seq(1,8),each=3))) +#gives me a column of 24 numbers with the specified Ms and SD +Resilience<-rnorm(24,mean=c(5.7,6.21,6.26),sd=c(.88,.79,.37)) +#repeats pre, post, follow-up once each, 8 times +Wave<-rep(c("Pre","Post", "FollowUp"),each=1,8) +Amodeo_long<-data.frame(ID, Wave, Resilience) +Amodeo_long$Wave <- factor(Amodeo_long$Wave, levels = c("Pre", "Post", "FollowUp")) +# Create a new df (Amodeo_wide) +# Identify the original df +# We are telling it to connect the values of the Resilience variable its respective Wave designation +Amodeo_wide <- reshape2::dcast(data = Amodeo_long, formula =ID~Wave, value.var = "Resilience") +#doublecheck to see if they did what you think +str(Amodeo_wide) +Amodeo_wide$ID <- factor(Amodeo_wide$ID) +#library(car) +waveLevels <- c(1,2,3) +waveFactor <- as.factor(waveLevels) +waveFrame <- data.frame(waveFactor) +waveBind <-cbind(Amodeo_wide$Pre, Amodeo_wide$Post, Amodeo_wide$FollowUp) +waveModel<- lm(waveBind~1) +waveModel +analysis <-car::Anova(waveModel, idata=waveFrame, idesign=~waveFactor) +summary(analysis) +2023 - 1966 +#install.packages("tidyverse") +#install.packages("ggpubr") +#install.packages("psych") +set.seed(2023) +# sample size, M and SD for each group +Accurate <- c(rnorm(30, mean = 1.18, sd = 0.8), rnorm(30, mean = 1.83, +sd = 0.58), rnorm(30, mean = 1.76, sd = 0.56)) +# set upper bound for DV +Accurate[Accurate > 3] <- 3 +# set lower bound for DV +Accurate[Accurate < 0] <- 0 +# IDs for participants +ID <- factor(seq(1, 90)) +# name factors and identify how many in each group; should be in same +# order as first row of script +COND <- c(rep("High", 30), rep("Low", 30), rep("Control", 30)) +# groups the 3 variables into a single df: ID, DV, condition +Acc_sim30B <- data.frame(ID, COND, Accurate) +write.table(Acc_sim30B, file = "to_CSVb.csv", sep = ",", col.names = TRUE, +row.names = FALSE) +saveRDS(Acc_sim30B, "to_RobjectB.rds") +from_rds <- readRDS("to_RobjectB.rds") +knitr::opts_chunk$set(echo = TRUE) +knitr::opts_chunk$set(comment = NA) #keeps out the hashtags in the knits options(scipen=999)#eliminates scientific notation -shapiro.test(mixt_resid) -hist(mixt_resid) -qqnorm(mixt_resid) -mixt_df%>% -group_by(Course, Centering)%>% -rstatix::identify_outliers(SRPed) -mixt_df %>% -group_by(Course)%>% -rstatix::levene_test(SRPed ~ Centering) -rstatix::anova_test(data = mixt_df, dv = SRPed, wid = deID, between = Centering, within = Course) -Simple_Course <- mixt_df%>% -group_by(Course)%>% -rstatix::t_test(SRPed ~ Centering, detailed = TRUE, p.adjust.method = "none")%>% -rstatix::add_significance() -Simple_Course -mixt_df%>% -group_by(Course)%>% -rstatix::cohens_d(SRPed ~ Centering) -apaTables::apa.2way.table(iv1=Course, iv2=Centering, dv=SRPed, data=mixt_df, filename = "Mixed_Table.doc", table.number = 1) -Simple_Course <- Simple_Course %>% -rstatix::add_xy_position(x = "Course") -library(tidyverse) -Simple_Course <- Simple_Course %>% -rstatix::add_xy_position(x = "Course") -mixt_box <- mixt_box + ggpubr::stat_pvalue_manual(Simple_Course, label = "p.signif", tip.length = 0.02, hide.ns = TRUE, y.position = c(5.3)) -mixt_box -#include effect size from the interaction effect -effectsize::eta2_to_f(0.039) -WebPower::wp.rmanova(n=66, ng=2, nm=3, f = 0.2014515, nscor = .925, alpha = .05, power = NULL, type = 2) -WebPower::wp.rmanova(n=NULL, ng=2, nm=3, f = 0.2014515, nscor = .925, alpha = .05, power = .80, type = 2) -big <- readRDS("ReC.rds") -View(big) -#Creates a list of the variables that belong to that scale -SRPed_vars <- c('InclusvClassrm', 'EquitableEval','MultPerspectives', 'DEIintegration') -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -big$SRPed <- sjstats::mean_n(big[, SRPed_vars], .75) -View(big) -ANCOVA_df <- (dplyr::select (big, deID, Course, Centering, SRPed)) -View(ANCOVA_df) -ANCOVA_df <- subset(ANCOVA_df, Course == "ANOVA" | Course == "Multivariate") #multiple conditions -str(ANCOVA_df) -View(ANCOVA_df) -ANCOVA_df$Course <- factor(ANCOVA_df$Course, levels = c("ANOVA", "Multivariate")) -str(ANCOVA_df) -ANCOVA_df$Course <- factor(ANCOVA_df$Course, levels = c("ANOVA", "Multivariate")) -str(ANCOVA_df) -ANCOVA_wide<- reshape2::dcast(data = ANCOVA_df, formula = deID + Centering ~ Course, value.var = "SRPed") -# before restructuring a second variable, rename the first variable -View(ANCOVA_wide) -View(ANCOVA_df) -ANCOVA_wide <- dplyr::rename(ANCOVA_wide, SRPed_ANV = "ANOVA", SRPed_MLTV = "Multivariate") -str(ANCOVA_wide) -head(ANCOVA_wide) -ANCOVA_wide <- na.omit(ANCOVA_wide) -library(ggplot2) -ggpubr::ggscatter(ANCOVA_wide, x = "SRPed_ANV", y = "SRPed_MLTV", color = "Centering", add = "reg.line") + ggpubr::stat_regline_equation(aes(label = paste(..eq.label.., ..rr.label.., sep = "~~~~"), color = Centering)) +#will install the package if not already installed +#if(!require(psych)){install.packages("psych")} +#if(!require(faux)){install.packages("faux")} +#if(!require(tidyverse)){install.packages("tidyverse")} +#if(!require(dplyr)){install.packages("dplyr")} +#if(!require(ggpubr)){install.packages("ggpubr")} +#if(!require(pwr)){install.packages("pwr")} +#if(!require(apaTables)){install.packages("apaTables")} +#if(!require(knitr)){install.packages("knitr")} +#if(!require(rstatix)){install.packages("rstatix")} library(tidyverse) -ANCOVA_wide %>% -rstatix::anova_test(SRPed_MLTV ~Centering*SRPed_ANV) -SRPed_mod <- lm(SRPed_MLTV ~ SRPed_ANV + Centering, data = ANCOVA_wide) -SRPed_mod_metrics <- broom::augment(SRPed_mod) -head(SRPed_mod_metrics) -rstatix::shapiro_test(SRPed_mod_metrics$.resid) -SRPed_mod_metrics%>% -rstatix::levene_test(.resid ~ Centering) -SRPed_mod_metrics %>% -filter(abs(.std.resid) > 3) %>% -as.data.frame() -ANCOVA_mod <- ANCOVA_wide %>% -rstatix::anova_test(SRPed_MLTV ~ SRPed_ANV + Centering) -rstatix::get_anova_table(ANCOVA_mod) -emmeans_MLTV <- ANCOVA_wide%>% -rstatix::emmeans_test(SRPed_MLTV ~ Centering, covariate = SRPed_ANV, p.adjust.method = "none") -emmeans_MLTV -emmeans_list <- rstatix::get_emmeans(emmeans_MLTV) -emmeans_list -descripts_means <- psych::describeBy(SRPed_MLTV ~ Centering, data = ANCOVA_wide, mat=TRUE, digits=6) -descripts_means -emmeans_MLTV <- emmeans_MLTV %>% -rstatix::add_xy_position(x = "Centering", fun = "mean_se") -ggpubr::ggline(rstatix::get_emmeans(emmeans_MLTV), x = "Centering", y = "emmean", title = "Figure 1. SRPed Ratings as a Function of Centering, Controlling for Earlier Ratings") + -geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0.2) + -ggpubr::stat_pvalue_manual(emmeans_MLTV, hide.ns = TRUE, tip.length = 0.02, , y.position = c(5.0)) +#Setting the seed. If you choose this practice option, change the number below to something different. +set.seed(220817) +#These define the characteristics of the verbal variable. It is essential that the object names (e.g., A_mean) are not changed because they will be fed to the function in the faux package. +sub_n <- 33 +A_mean <- 8.37 +B_mean <- 8.41 +A_sd <- 3.36 +B_sd <- 3.21 +AB_r <- 0.3 +#the faux package can simulate a variety of data. This function within the faux package will use the objects above to simulate paired samples data +paired_V <- faux::rnorm_multi( +n = sub_n, +vars = 2, +r = AB_r, +mu = c(A_mean, B_mean), +sd = c(A_sd, B_sd), +varnames = c("Verbal_BL", "Verbal_WH") +) +paired_V <- paired_V %>% dplyr::mutate(PhysID = row_number()) +#Here, I repeated the process for the nonverbal variable. +sub_n <- 33 +A_mean <- 2.68 +B_mean <- 2.93 +A_sd <- .84 +B_sd <- .77 +AB_r <- 0.9 +paired_NV <- faux::rnorm_multi( +n = sub_n, +vars = 2, +r = AB_r, +mu = c(A_mean, B_mean), +sd = c(A_sd, B_sd), +varnames = c("NVerb_BL", "NVerb_WH") +) +#This code produced an ID number for each physician +paired_NV <- paired_NV %>% dplyr::mutate(PhysID = row_number()) +#This data joined the two sets of data. +#Note, I did not write any code that assumed tha the verbal and nonverbal data came from the same physician. Full confession: I'm not quite sure how to do that just yet. +dfPairedSamples <- dplyr::full_join(paired_V, paired_NV, by = c("PhysID")) +dfPairedSamples <- dfPairedSamples%>%dplyr::select(PhysID, everything()) +str(dfPairedSamples) +#writing the simulated data as a .csv +#write.table(dfPairedSamples, file = "dfPairedSamples.csv", sep = ',', col.names=TRUE, row.names=FALSE) +#at this point you could clear your environment and then bring the data back in as a .csv +#reading the data back in as a .csv file +#dfPairedSamples<- read.csv ('dfPairedSamples.csv', header = TRUE) +#saveRDS(dfPairedSamples, 'dfPairedSamples.rds') +#dfPairedSamples <- readRDS('dfPairedSamples.rds') +ggpubr::ggpaired(dfPairedSamples, cond1 = "Verbal_BL", cond2 ="Verbal_WH", color = "condition", line.color = "gray", palette =c("npg"), xlab = "Patient Race", ylab = "Verbal Communication Rating") +View(dfPairedSamples) +#Creating the Verbal_D variable within the dfPairedSamples df +#Doing the "math" that informs that variable +dfPairedSamples$Verbal_D <- (dfPairedSamples$Verbal_BL - dfPairedSamples$Verbal_WH) +#Displaying the first six rows of the df to show that the difference score now exists +head(dfPairedSamples) +psych::describe(dfPairedSamples$Verbal_D +psych::describe(dfPairedSamples$Verbal_D +psych::describe(dfPairedSamples$Verbal_D) +#Creating the Verbal_D variable within the dfPairedSamples df +#Doing the "math" that informs that variable +dfPairedSamples$Verbal_D <- (dfPairedSamples$Verbal_BL - dfPairedSamples$Verbal_WH) +#Displaying the first six rows of the df to show that the difference score now exists +head(dfPairedSamples) +psych::describe(dfPairedSamples$Verbal_D) +.08/(4.14/sqrt(33)) +qt(.05/2, 32, lower.tail=TRUE) +qt(.05/2, 32, lower.tail=FALSE) +qt(.05/2, 32, lower.tail=TRUE) +qt(.05/2, 32, lower.tail=FALSE) +.08-(2.037*((4.14/(sqrt(33))))) +.08+(2.037*((4.14/sqrt(33)))) +.08/4.14 +0.111/(sqrt(33)) +(33*(.08^2))/((33*(.08^2)) + ((33-1)*(4.14^2))) +(0.111^2)/((0.111^2)+(33-1)) diff --git a/.Rproj.user/FFFF18A2/bookdown-crossref/11-ANCOVA.Rmd.xref b/.Rproj.user/FFFF18A2/bookdown-crossref/11-ANCOVA.Rmd.xref index 5f613cb8..467bd7fb 100644 --- a/.Rproj.user/FFFF18A2/bookdown-crossref/11-ANCOVA.Rmd.xref +++ b/.Rproj.user/FFFF18A2/bookdown-crossref/11-ANCOVA.Rmd.xref @@ -38,5 +38,4 @@ h3:problem-1-play-around-with-this-simulation. Problem #1: Play around with this h3:problem-2-conduct-a-one-way-ancova-with-the-dv-and-covariate-at-post2. Problem #2: Conduct a one-way ANCOVA with the DV and covariate at post2. h3:problem-3-try-something-entirely-new. Problem #3: Try something entirely new. h3:grading-rubric Grading Rubric -h1:refs References diff --git a/.Rproj.user/FFFF18A2/bookdown-crossref/14-RMmultivariate.Rmd.xref b/.Rproj.user/FFFF18A2/bookdown-crossref/14-RMmultivariate.Rmd.xref index aca913ff..05b957d4 100644 --- a/.Rproj.user/FFFF18A2/bookdown-crossref/14-RMmultivariate.Rmd.xref +++ b/.Rproj.user/FFFF18A2/bookdown-crossref/14-RMmultivariate.Rmd.xref @@ -5,4 +5,5 @@ h2:computing-the-omnibus-f Computing the Omnibus F h3:univariate-results Univariate Results h3:multivariate-results Multivariate Results h3:a-brief-commentary-on-wrappers A Brief Commentary on Wrappers +h1:refs References diff --git a/.Rproj.user/FFFF18A2/pcs/source-pane.pper b/.Rproj.user/FFFF18A2/pcs/source-pane.pper index 8d527b05..dbddc759 100644 --- a/.Rproj.user/FFFF18A2/pcs/source-pane.pper +++ b/.Rproj.user/FFFF18A2/pcs/source-pane.pper @@ -1,4 +1,4 @@ { - "activeTab": 3, + "activeTab": 7, "activeTabSourceWindow0": 1 } \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/rmd-outputs b/.Rproj.user/FFFF18A2/rmd-outputs index b1b12bff..a899ba68 100644 --- a/.Rproj.user/FFFF18A2/rmd-outputs +++ b/.Rproj.user/FFFF18A2/rmd-outputs @@ -1,7 +1,7 @@ -C:/Users/lhbik/OneDrive/ReCentering Volumes/ReCenterPsychStats/Worked_Examples/docs/index.html C:/Users/lhbik/OneDrive/ReCentering Volumes/ReCenterPsychStats/docs/index.html -C:/Users/lhbik/OneDrive/ReCentering Volumes/ReCenterPsychStats/docs/appendices.html -C:/Users/lhbik/OneDrive/ReCentering Volumes/ReCenterPsychStats/docs/examples-for-follow-up-to-factorial-anova.html +C:/Users/lhbik/OneDrive/ReCentering Volumes/ReCenterPsychStats/docs/index.html +C:/Users/lhbik/OneDrive/ReCentering Volumes/ReCenterPsychStats/docs/index.html +C:/Users/lhbik/OneDrive/ReCentering Volumes/ReCenterPsychStats/docs/index.html diff --git a/.Rproj.user/FFFF18A2/sources/prop/15B9FA2B b/.Rproj.user/FFFF18A2/sources/prop/15B9FA2B index f8bd29a7..9c64a4c8 100644 --- a/.Rproj.user/FFFF18A2/sources/prop/15B9FA2B +++ b/.Rproj.user/FFFF18A2/sources/prop/15B9FA2B @@ -2,5 +2,5 @@ "source_window_id": "", "Source": "Source", "cursorPosition": "45,123", - "scrollLine": "31" + "scrollLine": "0" } \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/sources/prop/72AA8F9A b/.Rproj.user/FFFF18A2/sources/prop/72AA8F9A index 360375bf..8be3b3c2 100644 --- a/.Rproj.user/FFFF18A2/sources/prop/72AA8F9A +++ b/.Rproj.user/FFFF18A2/sources/prop/72AA8F9A @@ -1,6 +1,6 @@ { "source_window_id": "", "Source": "Source", - "cursorPosition": "4,0", + "cursorPosition": "0,16", "scrollLine": "0" } \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/sources/prop/7435801E b/.Rproj.user/FFFF18A2/sources/prop/7435801E index e2bf0a34..6e3d4b20 100644 --- a/.Rproj.user/FFFF18A2/sources/prop/7435801E +++ b/.Rproj.user/FFFF18A2/sources/prop/7435801E @@ -2,5 +2,5 @@ "source_window_id": "", "Source": "Source", "cursorPosition": "233,13", - "scrollLine": "222" + "scrollLine": "0" } \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/sources/prop/756A025A b/.Rproj.user/FFFF18A2/sources/prop/756A025A index 15bde155..9f45e36d 100644 --- a/.Rproj.user/FFFF18A2/sources/prop/756A025A +++ b/.Rproj.user/FFFF18A2/sources/prop/756A025A @@ -1,7 +1,7 @@ { "source_window_id": "", "Source": "Source", - "cursorPosition": "459,5", - "scrollLine": "448", + "cursorPosition": "749,0", + "scrollLine": "724", "docOutlineVisible": "1" } \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/sources/prop/83EA2CAA b/.Rproj.user/FFFF18A2/sources/prop/83EA2CAA index 253e6f37..1662798f 100644 --- a/.Rproj.user/FFFF18A2/sources/prop/83EA2CAA +++ b/.Rproj.user/FFFF18A2/sources/prop/83EA2CAA @@ -1,7 +1,7 @@ { "source_window_id": "", "Source": "Source", - "cursorPosition": "110,38", - "scrollLine": "101", + "cursorPosition": "110,35", + "scrollLine": "105", "docOutlineVisible": "1" } \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/sources/prop/87F751F5 b/.Rproj.user/FFFF18A2/sources/prop/87F751F5 index fb10445b..221aad3e 100644 --- a/.Rproj.user/FFFF18A2/sources/prop/87F751F5 +++ b/.Rproj.user/FFFF18A2/sources/prop/87F751F5 @@ -2,5 +2,5 @@ "source_window_id": "", "Source": "Source", "cursorPosition": "94,152", - "scrollLine": "44" + "scrollLine": "0" } \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/sources/prop/A1C8C035 b/.Rproj.user/FFFF18A2/sources/prop/A1C8C035 index 20a6d762..4661273c 100644 --- a/.Rproj.user/FFFF18A2/sources/prop/A1C8C035 +++ b/.Rproj.user/FFFF18A2/sources/prop/A1C8C035 @@ -2,5 +2,5 @@ "source_window_id": "", "Source": "Source", "cursorPosition": "43,54", - "scrollLine": "37" + "scrollLine": "0" } \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/sources/prop/C5BA3162 b/.Rproj.user/FFFF18A2/sources/prop/C5BA3162 index b4576aab..8f356a7d 100644 --- a/.Rproj.user/FFFF18A2/sources/prop/C5BA3162 +++ b/.Rproj.user/FFFF18A2/sources/prop/C5BA3162 @@ -1,7 +1,7 @@ { "source_window_id": "", "Source": "Source", - "cursorPosition": "8,0", - "scrollLine": "0", + "cursorPosition": "241,38", + "scrollLine": "240", "docOutlineVisible": "0" } \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/017077A5-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/017077A5-contents deleted file mode 100644 index af0675af..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/017077A5-contents +++ /dev/null @@ -1,487 +0,0 @@ -```{r include = FALSE} -options(scipen=999) -``` - -## Homeworked Example - -[Screencast Link](https://youtu.be/gstP-tx4YUQ) - -For more information about the data used in this homeworked example, please refer to the description and codebook located at the end of the [introduction](ReCintro). - -### Working the Problem with R and R Packages - -#### Narrate the research vignette, describing the IV and DV. Miniminally, the data should allow the analysis of a 2 x 3 (or 3 X 2) design. At least one of the problems you work should have a significant interaction effect so that follow-up is required {-} - -I want to ask the question, do course evaluation ratings for the traditional pedagogy dimension differ for students in the ANOVA class as a function of: - -* **Stage** in the transition - - STABLE: 2017 represents the last year of "stability during the old way" when we taught with SPSS and during the 2nd year of the doctoral programs. - - TRANSITION: 2018 & 2019 represent the transition to R, when the classes were 30% larger because each of the IOP and CPY departments were transitioning to the 1st year (they did it separately, so as not to double the classes) - - RESETTLED: 2020 & 2021 represent the "resettled" phase where the transition to R was fairly complete and the class size returned to normal because the classes were offered in the first year. -* **Department** - - CPY: Clinical Psychology - - ORG: Industrial-Organizational Psychology - -*If you wanted to use this example and dataset as a basis for a homework assignment, you could create a different subset of data. I worked the example for students taking the ANOVA class. You could choose multivariate or psychometrics. You could also choose a different dependent variable. I chose the traditional pedagogy subscale. Two other subscales include socially responsive pedagogy and valued by the student.* - -#### Simulate (or import) and format data {-} - -```{r} -big <- readRDS("ReC.rds") -``` - -Let's first create the "Stage" variable that represents the three levels of transition. The ProgramYear variable contains the information I need, but the factor labels are not intuitive. Let me remap them. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -big$Stage <- plyr::mapvalues(big$ProgramYear, from = c("Second", "Transition", "First"), to = c("Stable", "Transition", "Resettled")) -``` - -Let's check the structure: -```{r} -str(big$Stage) -``` - -The TradPed (traditional pedagogy) variable is an average of the items on that scale. I will first create that variable. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Creates a list of the variables that belong to that scale -TradPed_vars <- c('ClearResponsibilities', 'EffectiveAnswers','Feedback', 'ClearOrganization','ClearPresentation') - -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -big$TradPed <- sjstats::mean_n(big[, TradPed_vars], .75) - -#if the scoring script won't run, try this one: -#big$TradPed <- sjstats::mean_n(big[, ..TradPed_vars], .75) -``` - -Each student in the dataset could contribute up to three course evaluations (i.e., one each for ANOVA, multivariate, psychometrics). Including all three would introduce *dependency* into the dataset and violate the assumption of independence. With our variables properly formatted let's create a subset with just the students who took ANOVA. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -TwoWay_df <- subset(big, Course == "ANOVA") -``` - -Next, let's trim it to just the variables we need. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -TwoWay_df <-(dplyr::select(TwoWay_df, Stage, Dept, TradPed)) -``` - -Although we would handle missing data more carefully in a "real study," I will delete all cases with any missingness. This will prevent problems in the hand-calculations section, later (and keep the two sets of results more similar). - -```{r} -df <- na.omit(TwoWay_df) -``` - -Before we continue, this data has a hiccup that makes it less than ideal for a 2 x 3 ANOVA. In 2017 everyone enrolled in the CPY section of the course. That is, there was no distinction between CPY and ORG students. In this dataset I do not have another variable with three levels. I will recode some data which MAKES THE STORY UNTRUE, but will allow me to demo 2-way ANOVA (sighhhh). For your homework, you are very welcome to engage in such practices (it's actually good for learning!) however, we would never do so in the analysis of real data. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -TwoWay_df <- na.omit(TwoWay_df) #the next operation required non-missing data -TwoWay_df[TwoWay_df$Stage == "Stable" & TwoWay_df$TradPed < 4.3, "Dept"]<- "ORG" -``` - -Although the homework assignment doesn't require it, I think it's useful to create a figure that shows what I intend to do. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -Box2way <- ggpubr::ggboxplot(TwoWay_df, x = "Dept", y = "TradPed", color = "Stage", xlab = "Academic Department", - ylab = "Students' Evaluations of Traditional Pedagogy", add = "jitter", - title = "Course Evaluations as a Function of Department and Stage in Transition") -Box2way -``` - -#### Evaluate statistical assumptions {-} - -**Is the dependent variable normally distributed at all levels of the combinations of the levels within the grouping variables?** - -I'll start with an inspection of skew and kurtosis for all combinations of the levels of the two grouping variables. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describeBy(TradPed ~ Stage + Dept, mat = TRUE, data = TwoWay_df, digits = 3, type = 1) -``` - -Following Kline's (2016) recommendations, skew for each combination of levels of the two IVs are < |3.0|. Kurtosis for each combination of levels of the two IVs are < |10.0|. - -The Shapiro-Wilk examines residuals from the ANOVA model. We can quickly/preliminarily run the two-way ANOVA. We do this to produce an object that holds the *model residuals.* -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -TwoWay_TradPed <- aov(TradPed ~ Stage * Dept, TwoWay_df) -summary(TwoWay_TradPed) -``` -The *residuals()* function serves to extract the residuals. We can apply the model-baesd *shapiro.test()* function from base R to see if the model residuals are non-normally distributed. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -resid_TradPed <- residuals(TwoWay_TradPed) -shapiro.test(resid_TradPed) -``` - -A statistically significant Shapiro-Wilks' test of normality suggests that we violated the assumption $W = 0.949, p < 0.001$. - -Let's plot the residuals -```{r} -hist(resid_TradPed) -``` -The histogram does look somewhat different (negatively skewed) from a normal distribution. -```{r} -qqnorm(resid_TradPed) -``` - -The dots stray from the expected diagonal; this also visualizes the non-normality of the data. - -Summary so far: - ->Factorial ANOVA assumes that the dependent variable is normally is distributed for all cells in the design. Although our analysis suggested skew and kurtosis were within the bounds considered to be normally distributed, the Shapiro-Wilk normality test (applied to the residuals from the factorial ANOVA model) suggested that the plotting of the residuals differed significantly from a normal distribution $W = 0.949, p < 0.001$. - -**Are there outliers?** - -Given the non-normality of the data, we can use the following procedure to see if there are outliers that could be transformed, truncated, or removed. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -TwoWay_df %>% - rstatix::identify_outliers(TradPed) -``` - -There are four outliers; none are extreme. Given that these are all on the low-side (of a negatively skewed distribution where most scores are higher), I feel it is important to retain them as they reflect more students' experiences. If this were for something other than a homework demonstration, I might also take a look at the case to see if there was evidence of inattention or something else. - -**Are the variances of the dependent variable similar across the all combinations of the levels within the grouping variables?** - -We can evaluate the homogeneity of variance test with Levene's test for the equality of error variances. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::levene_test(TwoWay_df, TradPed ~ Dept * Stage) -``` - -Levene’s test has indicated a violation of the homogeneity of variance assumption $(F[5, 106] = 6.412, p < .001)$. This is not surprising. The boxplots shows some widely varying variances. - -Do we have to stop? If cell sizes are reasonably large (e.g., at least 15) and balanced (equal), ANOVA is a relatively robust to violations of normality. Unfortunately, we don't have 15 in all cells AND our cells are unequal AND this was not an experiment. So.....this probably isn't the best approach (but it'll work for a class demo). - ->A 2 X 3 ANOVA was conducted to evaluate the effects of academic department (2 levels, CPY and ORG) and stage of transition (3 levels, stable, transitioning, resettled) on traditional pedagogy course evaluation ratings. - ->Factorial ANOVA assumes that the dependent variable is normally is distributed for all cells in the design. Although our analysis suggested skew and kurtosis were within the bounds considered to be normally distributed, the Shapiro-Wilk normality test (applied to the residuals from the factorial ANOVA model) suggested that the plotting of the residuals differed significantly from a normal distribution $W = 0.949, p < 0.001$. Further, Levene’s test has indicated a violation of the homogeneity of variance assumption $(F[5, 106] = 6.412, p < .001)$. Owing to a rather desperate need to provide a demonstration of the two-way ANOVA, I have decided to proceed and keep these violations in mind in the interpretation of results. - -#### Conduct omnibus ANOVA (w effect size) {-} - -We can use the *rstatix::anova_test()* function. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -omnibus2w <- rstatix::anova_test(TwoWay_df, TradPed ~ Dept * Stage, type = "2", detailed = TRUE) -omnibus2w -``` - -Let's write the F strings from the above table: - -* Department main effect: $F(1, 106) = 11.395, p = 0.001, \eta^2 = 0.097$ -* Stage main effect: $F(2, 106) = 10.070 , p < 0.001, \eta^2 = 0.160$ -* Interaction effect: $F(2, 106) = 4.904, p = 0.009, \eta^2 = 0.085$ - -So far we have statistically significant effects for the main and interaction effects. Here are the results so far: - ->Computing sums of squares with a Type II approach, the results for the omnibus ANOVA indicated a significant effects for the main effect of department, $F(1, 106) = 11.395, p = 0.001, \eta^2 = 0.097$; the main effect for stage in transition, $F(2, 106) = 10.070, p < 0.001, \eta^2 = 0.160$; and the interaction effect, $F(2, 106) = 4.904, p = 0.009, \eta^2 = 0.085$. - -#### Conduct one set of follow-up tests; narrate your choice {-} - -There are so many choices for following up a significant interaction effect. Regardless, we always follow a statistically significant interaction effect with an analysis of simple main effects. I think I am interested in the simple main effects for stage within department. This means I will conduct one-way ANOVAS for CPY and ORG, separately. And, if either is significant, I will look for differences across the stages. - -Although we could do something more complicated (like orthogonal contrast coding), given that those completing homework are often having early experiences with ANOVA, I will choose a more streamlined path by examining the the simple main effect of stage within department. - -Functionally, this computes two one-way ANOVAs, comparing the three stages within each of the departments. If the result is statistically significant, we will need to follow-up with more testing. - -The *rstatix::anova_test* does not allow me to specify a control for Type I error. Therefore, if I wanted to do so, I would need to monitor it outside of the R package. I *could* evaluate each of the *p* values for the two one-way ANOVAs at 0.025 (05/2). Rather than tracking Type I error at this level, I will wait and do so when I get to the pairwise comparisons that follow a statistically significant one-way ANOVA. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -TwoWay_df %>% - dplyr::group_by(Dept)%>% - rstatix::anova_test(TradPed ~ Stage) -``` -Results suggest statistically significant differences in department across the stages within the CPY department, but not the ORG department: - -* For CPY: $F(2, 58) = 18.497, p < 0.001, \eta^2 = 0.389$ -* For ORG: $F(2, 48) = 1.417, p = 0.252, \eta^2 = 0.056$ - -I would write up this stage of the analysis this way: - ->To explore the significant interaction effect, we followed with a test of simple main effect of the stage in transition within the academic department. We began with separate one-way ANOVAs. Results indicated significant differences within the CPY deparmtent $(F[2, 58] = 18.497, p < 0.001, \eta^2 = 0.389)$, but not for the ORG department $(F[2, 48] = 1.417, p = 0.252, \eta^2 = 0.056)$. - -Because there are three stages of transition, we need to followup with pairwise comparisons to see where the differences lie. Because I want to results from the significance tests to update the figure, I will save the output as an object. - -Although, technically, we only needed to compare 3 pairwise tests, this test (and figure) will compute them all. The Holm's Sequential Bonferroni is a very reasonable approach (balancing Type I error with sensibility) and so I will use it to evaluate the six pairwise comparisons that will be produced. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwTRwiDP <- TwoWay_df %>% - dplyr::group_by(Dept) %>% - rstatix::emmeans_test(TradPed ~ Stage, p.adjust.method = "holm") -pwTRwiDP -``` - - -Consistent with the significant one-way ANOVA for the ORG factor, there were non-significant differences between all pairs of stages. Within the CPY student evaluations, there were statistically significant differences between stable and transition and stabled and resettled comparisons. Both comparisons favored the stable level. - - -Here'w how I would assemble the entire APA style results: - ->A 2 X 3 ANOVA was conducted to evaluate the effects of academic department (2 levels, CPY and ORG) and stage of transition (3 levels, stable, transitioning, resettled) and on traditional pedagogy course evaluation ratings. - ->Factorial ANOVA assumes that the dependent variable is normally is distributed for all cells in the design. Although our analysis suggested skew and kurtosis were within the bounds considered to be normally distributed, the Shapiro-Wilk normality test (applied to the residuals from the factorial ANOVA model) suggested that the plotting of the residuals differed significantly from a normal distribution $W = 0.949, p < 0.001$. Further, Levene’s test has indicated a violation of the homogeneity of variance assumption $(F[5, 106] = 6.412, p < .001)$. Owing to a rather desperate need to provide a demonstration of the two-way ANOVA, I have decided to proceed and keep these violations in mind in the interpretation of results. - ->Computing sums of squares with a Type II approach, the results for the omnibus ANOVA indicated a significant effects for the main effect of department, $F(1, 106) = 11.395, p = 0.001, \eta^2 = 0.097$; the main effect for stage in transition, in transition $F(2, 106) = 10.07 , p < 0.001, \eta^2 = 0.160$, and the interaction effect, $F(2, 106) = 4.904, p = 0.009, \eta^2 = 0.085$. - -> To explore the significant interaction effect, we followed with a test of simple main effect of the stage in transition within the academic department. We began with separate one-way ANOVAs. Results indicated significant differences within the CPY deparmtent $(F[2, 58] = 18.497 , p < 0.001, \eta^2 = 0.389)$, but not for the ORG department $(F[2, 48] = 1.417, p = 0.252, \eta^2 = 0.056)$. - ->We followed the significant one-way ANOVAs with pairwise comparisons between the groups using the estimated marginal means. We specified the Holm's sequential Bonferroni for managing Type I error. For CPY students, comparisons between the stable and transition $(t[106] = 4.997, p < 0.001)$ and stable and resettled $(t[106] = 2.893, p = 0.005)$ stages were statistically significantly different. Cell means, marginal means, and standard deviations are presented in Table 1; results are illustrated in Figure 1. - -#### Describe approach for managing Type I error {-} - -I managed Type I error with the Holm's sequential Bonferroni. The Holm's is less conservative than the traditional Bonferroni because it adjusts the thresshold for statistical significance in a stepwise manner that takes into consideration the rank order of the *p* values and the number of comparisons made. - -#### APA style results with table(s) and figure {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -apaTables::apa.2way.table(Dept, Stage, TradPed, data = TwoWay_df, filename = "2Way.doc", table.number = 1, show.marginal.means = TRUE, landscape = TRUE) -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwTRwiDP <- pwTRwiDP %>% - rstatix::add_xy_position(x = "Dept") #x should be whatever the variable was used in the group_by argument -Box2way <- Box2way + ggpubr::stat_pvalue_manual(pwTRwiDP, label = "p.adj.signif", tip.length = 0.02, hide.ns = TRUE, y.position = c(5.3, 5.5)) -Box2way -``` -#### Conduct power analyses to determine the power of the current study and a recommended sample size {-} - -The *pwr.2way()* and *ss.2way()* functions require the following: - -* **a** number of groups in Factor A -* **b** number of groups in Factor B -* **alpha** significant level (Type I error probability) -* **beta** Type II error probability (Power = 1 - beta; traditionally set at .1 or .2) -* **f.A** the *f* effect size of Factor A -* **f.B** the *f* effect size of Factor B -* **B** Iteration times, default is 100 - -We need to convert our effect size ($\eta^2$) for the *interaction* to $f$ effect size (this is not the same as the *F* test). The *effectsize* package has a series of converters. We can use the *eta2_to_f()* function. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -effectsize::eta2_to_f(0.097) #FactorA -- Dept -effectsize::eta2_to_f(0.160) #Factor B -- Stage -effectsize::eta2_to_f(0.085) #interaction -``` - -The size.A and size.B are the sample size per group within the factor. Because ours differ, i divided the N by the number of groups. -```{r} -112/2 -112/3 -112/6 -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr2::pwr.2way(a = 2, b = 3, alpha = 0.05, size.A = 56, size.B = 37, f.A = 0.3277495, f.B = 0.4364358) -``` -At 100% (Dept), 100 (Stage), and 100% (interaction), our power to detect statistically significant main and interaction effects was strong - -I will use a different function to estimate what sample size would be sufficiently powerful. In this syntax: - -* beta is the Type II error probability (Power = 1-beta); usually set at 80 -* B is the iteration times, the default is 100 - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr2::ss.2way(a = 2, b = 3, alpha = 0.05, beta = 0.8, f.A = 0.3277495, f.B = 0.4364358, B = 100) -``` -```{r} -18*3 -``` -This recommends a sample size of 54; 18 in each group. - -### Hand Calculations - -Before we continue: - ->You may notice that the results from the hand calculation are slightly different from the results I will obtain with the R packages. This is because the formula we have used for the hand-calculations utilizes an approach to calculating the sums of squares that presumes that we have a balanced design (i.e., that the cell sizes are equal). When cell sizes are unequal (i.e., an unbalanced design) the Type II package in *rstatix::anova_test* will produce different result. - -> Should we be concerned? No (and yes). My purpose in teaching hand calculations is for creating a conceptual overview of what is occurring in ANOVA models. If this lesson was a deeper exploration into the inner workings of ANOVA, we would take more time to understand what is occurring. My goal is to provide you with enough of an introduction to ANOVA that you would be able to explore further which sums of squares type would be most appropriate for your unique ANOVA model. - -#### Calculate sums of squares total (SST) for the omnibus ANOVA. Steps in this calculation must include calculating a grand mean and creating variables representing the mean deviation and mean deviation squared {-} - -Here is the formula I will use for calculating the sums of squares total: $$SS_{T}= \sum (x_{i}-\bar{x}_{grand})^{2}$$ - -I will use *psych::describe()* to obtain the overall mean: - -```{r} -psych::describe(TwoWay_df) -``` - -The overall (grand) mean is 4.06. - -I will create a variable that represents the mean deviation: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -TwoWay_df <- TwoWay_df %>% - dplyr::mutate(m_dev = TradPed - 4.06) - -head(TwoWay_df) -``` - -Now I will square the mean deviation: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -TwoWay_df <- TwoWay_df %>% - mutate(m_devSQ = m_dev^2) -head(TwoWay_df) -``` - -SST is the sum of the mean deviation squared values: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SST <- sum(TwoWay_df$m_devSQ, na.rm=TRUE) -SST -``` -Our sums of squares total is 83.0332 - - -#### Calculate the sums of squares for the model (SSM) for the omnibus ANOVA. A necessary step in this equation is to calculate group means for all combinations of the levels in the factorial design {-} - -Here is the formula for calculating SSM: $$SS_{M}= \sum n_{k}(\bar{x}_{k}-\bar{x}_{grand})^{2}$$ - -The formula indicates that we need: - -* *n* (sample size for each group) -* Group means -* Grand mean (earlier we learned it was 4.06) - -I will obtain group means and $n$s with *psych::desribeBy*. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describeBy(TradPed ~ Dept + Stage, mat = TRUE, data = TwoWay_df, digits = 3) -``` - -To calculate it: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SSM <- 25 * (4.832 - 4.06)^2 + 25 * (3.864 - 4.06)^2 + 26 * (3.769 - 4.06)^2 + - 15 * (3.560 - 4.06)^2 + 10 * (4.010 - 4.06)^2 + 11 * (4.145 - 4.06)^2 -SSM -``` -Sums of squares for the model is 21.91618. - -#### Calculate the sums of squares residual (SSR) for the omnibus ANOVA. A necessary step in this equation is to calculate the variance for each group {-} - -I will use the following formula to calculate SSR: $$SS_{R}= s_{group1}^{2}(n-1) + s_{group2}^{2}(n-1) + s_{group3}^{2}(n-1) + s_{group4}^{2}(n-1) + s_{group5}^{2}(n-1) + s_{group6}^{2}(n-1))$$ - -This requires: - -* *n* (sample size for each group) -* group variance (I can square the standard deviation for each group) - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SSR <- ((0.236^2)*(25-1))+ ((0.582^2)*(25-1)) + ((0.878^2)*(26-1)) + ((1.338^2)*(15-1)) + ((0.578^2)*(10-1)) + ((0.658^2)*(11-1)) -SSR -``` -Our sums of squares for the residual is 61.13799. - -#### Calculate sums of squares model (SSM) for each of the factors in the model {-} - -**SSM for the Department main effect:** - -Reminder of the formula: $SS_{a:Dept}= \sum n_{k}(\bar{x}_{k}-\bar{x}_{grand})^{2}$ - -Earlier I learned the grand mean = 4.06 - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describeBy(TradPed ~ Dept, mat=TRUE, data = TwoWay_df, digits=3) -``` -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SSM_dept <- 61 * (4.244 - 4.06)^2 + 51 * (3.835 - 4.06)^2 -SSM_dept -``` -Sums of squares model for the department factor is 4.647091. - -**SSM for the Stage main effect:** - -Reminder of the formula: $SS_{a:Stage}= \sum n_{k}(\bar{x}_{k}-\bar{x}_{grand})^{2}$ - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describeBy(TradPed ~ Stage, mat=TRUE, data = TwoWay_df, digits=3) -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SSM_stage <- 50 * (4.348 - 4.06)^2 + 42 * (3.693 - 4.06)^2 + 32 * (4.081 - 4.06)^2 -SSM_stage -``` -Sums of squares model for the stage factor is 9.81825 - -**SSM for the Department x Stage interaction term:** - -I can calculate the SSM for the interaction term with this formula: $SS_{axb} = SS_M - (SS_a + SS_b)$ - - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SSM_int <- 21.91618 - (4.647091 + 9.81825) -SSM_int -``` - -#### Create a source table that includes the sums of squares, degrees of freedom, mean squares, *F* values, and *F* critical values {-} - -It is easiest for me when I put these in a table. - -|Summary ANOVA for TradPed as a Function of Dept & Stage -|:-------------------------------------------------------| - -|Source |SS |df |$MS = \frac{SS}{df}$ |$F = \frac{MS_{source}}{MS_{resid}}$ |$F_{CV}$| -|:---------|:--------|:----------|:------|:------|:------| -|Model |21.916 |5 |4.383 |7.596 |2.300 | -|a:Dept |4.647 |1 |4.647 |8.054 |3.931 | -|b:Stage |9.818 |2 |4.909 |8.508 |3.082 | -|aXb |7.451 |2 |3.726 |6.458 |3.082 | -|Residual |61.138 |106 |0.577 | | | -|Total |83.033 | | | | | - -Main effect for department: $F(1, 106) = 8.054, p < 0.05$ -Main effect for stage: $F(2, 106) = 8.508, p < 0.05$ -Interaction effect: $F(2, 106) = 6.458, p < 0.05$ - -You may notice that these calculations don't exactly follow the rules of the lecture. For example, The "model and "residual" should equal the total. I believe this is because there are different cell sizes which causes an unbalanced design and throws off the otherwise perfect calculations. This issue of unbalanced design is an important one in ANOVA. - -Checking to see if my sums of squares a, b, and axb equal the SSM; and that SSM + SSR = SST. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -21.916 + 61.138 -(4.647 + 9.818 + 7.451) + 61.138 -4.647 + 9.818 + 7.451 -``` -Below are the calculations for the mean square values: -```{r} -21.916 /5 -4.647/1 -9.818/2 -7.451/2 -61.138/106 -``` -Below are the calculations for the *F* tests: - -```{r} -4.383/0.577 -4.647/0.577 -4.909/0.577 -3.726/0.577 -``` -Looking up the *F* critical values (requires alpha level and degrees of freedom for the numerator and denominator [model and residual]): - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -qf(0.05, 5, 106, lower.tail = FALSE) #omnibus -qf(0.05, 1, 106, lower.tail = FALSE) #Dept main effect -qf(0.05, 2, 106, lower.tail = FALSE) #Stage main effect -qf(0.05, 2, 106, lower.tail = FALSE) #interaction term -``` - -#### Are the *F*-tests for the main and interaction effects statistically significant? Why or why not? {-} - -In the hand calculations, the main and interaction effects are significant when the *F* value exceeds the *F* critical value. All three are. - -#### Calculate and interpret the $\eta^2$ effect sizes for the main and interaction effects {-} - -The formula for eta squared is: - -$$\eta ^{2}=\frac{SS_{M}}{SS_{T}}$$ - -The values of .01, .06, and .14 are considered small, medium, and large in ANOVA models. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -4.647/83.033 #eta squared for department main effect -9.818/83.033 #eta squared for stage main effect -7.451/83.033 #eta squared for interaction effect -``` - -The $\eta ^{2}$ values are 0.056 (medium), 0.118 (medium-to-large), and 0.090 (medium-to-large) for the department, stage, and interaction effects, respectively. - -#### Assemble the results into their statistical strings {-} - -Main effect for department: $F(1, 106) = 8.054, p < 0.05, \eta ^{2} = 0.056$ -Main effect for stage: $F(2, 106) = 8.508, p < 0.05, \eta ^{2} = 0.118$ -Interaction effect: $FF(2, 106) = 6.458, p < 0.05, \eta ^{2} = 0.090$ \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/04F7774E-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/04F7774E-contents deleted file mode 100644 index 1d18e6dc..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/04F7774E-contents +++ /dev/null @@ -1,93 +0,0 @@ ---- -title: "ReCentering Psych Stats" -author: "Lynette H. Bikos, PhD, ABPP (she/her)" -date: "Last updated `r format (Sys.Date(), '%d %b %Y')`" -documentclass: book -site: bookdown::bookdown_site -bibliography: STATSnMETH.bib #This is my own bibtex file from my Zotero account. If this file is not in the project folder there will be an error and the book will not build. -citation-style: apa-single-spaced.csl #if you want APA style -link-citations: yes -urlcolor: blue #without this the links in the PDF do not show -fontsize: 11pt -geometry: margin=1in -highlight: tango -#DID NOT WORK, BUT DID NOT HURT EITHER I THINK IT NEEDS TO BE CONNECTED TO A PKG -#line-wrapping-in-code: true #wrap overflowing lines in code blocks? -url: https://lhbikos.github.io/ReCenterPsychStats/ #a link to the GitHub pages where it is rendered -cover-image: images/ReCenterPsychStats-bookcover2.jpg #link to the image for the book which will show up in any previews -description: | - ReCentering Psych Stats is an open education resource for teaching statistics with the open-source program, R, in a socially and culturally responsive manner. The series provides workflows and worked examples in R and each statistic is accompanied by an example APA style presentation of results. A core focus of the ReCentering series is simulated data from published articles that focus on issues of social justice and are, themselves, conducted in a socially responsive manner. -github-repo: lhbikos/ReCenterPsychStats - ---- - -```{r, include=FALSE} -options(tinytex.verbose = TRUE) -``` - - -# BOOK COVER {-} - -![An image of the book cover. It includes four quadrants of non-normal distributions representing gender, race/ethnicty, sustainability/global concerns, and journal articles](images/ReCenterPsychStats-bookcover2.jpg) -This open education resource is available in three formats: - -* Formatted as an [html book](https://lhbikos.github.io/ReCenterPsychStats/) via GitHub Pages -* As a [PDF](https://github.com/lhbikos/ReCenterPsychStats/blob/main/docs/ReCenterPsychStats.pdf) available in the [docs](https://github.com/lhbikos/ReCenterPsychStats/tree/main/docs) folder at the GitHub repository -* As an [ebook](https://github.com/lhbikos/ReCenterPsychStats/blob/main/docs/ReCenterPsychStats.epub) available in the [docs](https://github.com/lhbikos/ReCenterPsychStats/tree/main/docs) folder at the GitHub repository -* As a [Word document](https://github.com/lhbikos/ReCenterPsychStats/blob/main/docs/ReCenterPsychStats.docx) available in the [docs](https://github.com/lhbikos/ReCenterPsychStats/tree/main/docs) folder at the GitHub repository - -All materials used in creating this OER are available at its [GitHub repo](https://github.com/lhbikos/ReCenterPsychStats). - -As a perpetually-in-progress, open education resource, feedback is always welcome. This IRB-approved (SPU IRB #202102010R, no expiration) [Qualtrics-hosted survey](https://spupsych.az1.qualtrics.com/jfe/form/SV_0OnBLfut3VIOIS2) includes formal rating scales, open-ended text boxes, and a portal for uploading attachments (e.g., marked up PDFs). You are welcome to complete only the portions that are relevant to you. - -# PREFACE {-} - -**If you are viewing this document, you should know that this is a book-in-progress. Early drafts are released for the purpose teaching my classes and gaining formative feedback from a host of stakeholders. The document was last updated on `r format (Sys.Date(), '%d %b %Y')`**. Emerging volumes on other statistics are posted on the [ReCentering Psych Stats](https://lhbikos.github.io/BikosRVT/ReCenter.html) page at my research team's website. - -[Screencasted Lecture Link](https://youtu.be/yy0z85Wla7o) - -To *center* a variable in regression means to set its value at zero and interpret all other values in relation to this reference point. Regarding race and gender, researchers often center male and White at zero. Further, it is typical that research vignettes in statistics textbooks are similarly seated in a White, Western (frequently U.S.), heteronormative, framework. The purpose of this project is to create a set of open educational resources (OER) appropriate for doctoral and post-doctoral training that contribute to a socially responsive pedagogy -- that is, it contributes to justice, equity, diversity, and inclusion. - -Statistics training in doctoral programs are frequently taught with fee-for-use programs (e.g., SPSS/AMOS, SAS, MPlus) that may not be readily available to the post-doctoral professional. In recent years, there has been an increase and improvement in R packages (e.g., *psych*, *lavaan*) used for analyses common to psychological research. Correspondingly, many graduate programs are transitioning to statistics training in R (free and open source). This is a challenge for post-doctoral psychologists who were trained with other software. This OER will offer statistics training with R and be freely available (specifically in a GitHub repository and posted through GitHub Pages) under a Creative Commons Attribution - Non Commercial - Share Alike license [CC BY-NC-SA 4.0]. - -Training models for doctoral programs in health service psychology are commonly scholar-practitioner, scientist-practitioner, or clinical-scientist. An emerging model, the *scientist-practitioner-advocacy* training model, incorporates social justice advocacy so that graduates are equipped to recognize and address the sociocultural context of oppression and unjust distribution of resources and opportunities [@mallinckrodt_scientist-practitioner-advocate_2014]. In statistics textbooks, the use of research vignettes engages the learner around a tangible scenario for identifying independent variables, dependent variables, covariates, and potential mechanisms of change. Many students recall examples in Field's [-@field_discovering_2012] popular statistics text: Viagra to teach one-way ANOVA, beer goggles for two-way ANOVA, and bushtucker for repeated measures. What if the research vignettes were more socially responsive? - -In this OER, research vignettes will be from recently published articles where: - -* the author’s identity is from a group where scholarship is historically marginalized (e.g., BIPOC, LGBTQ+, LMIC[low-middle income countries]), -* the research is responsive to issues of justice, equity, inclusion, diversity, -* the lesson’s statistic is used in the article, and -* there is sufficient information in the article to simulate the data for the chapter example(s) and practice problem(s); or it is publicly available. - -In training for multicultural competence, the saying, "A fish doesn't know that it's wet" is often used to convey the notion that we are often unaware of our own cultural characteristics. In recent months and years, there has been an increased awakening to institutional and systemic factors that contribute to discrimination as a function of race, gender, nationality, class, and so forth. Queuing from the water metaphor, I am hopeful that a text that is recentered in the ways I have described can contribute to *changing the water* in higher education and in the profession of psychology. - - -## Copyright with Open Access {-} -Creative Commons License - -This book is published under a a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. This means that this book can be reused, remixed, retained, revised and redistributed (including commercially) as long as appropriate credit is given to the authors. If you remix, or modify the original version of this open textbook, you must redistribute all versions of this open textbook under the same license: CC BY-SA 4.0. - -A [GitHub open-source repository](https://github.com/lhbikos/ReCenterPsychStats) contains all of the text and source code for the book, including data and images. - -# ACKNOWLEDGEMENTS {-} - -As a doctoral student at the University of Kansas (1992-1996), I learned that "a foreign language" was a graduation requirement. *Please note that as one who studies the intersections of global, vocational, and sustainable psychology, I regret that I do not have language skills beyond English.* This could have been met with credit from high school, but my rural, mid-Missouri high school did not offer such classes. This requirement would have typically been met with courses taken during an undergraduate program -- but my non-teaching degree in the University of Missouri's School of Education was exempt from this. The requirement could have also been met with a computer language (FORTRAN, C++) -- but I did not have any of those either. There was a tiny footnote on my doctoral degree plan that indicated that a 2-credit course, "SPSS for Windows" would substitute for the language requirement. Given that it was taught by my one of my favorite professors, I readily signed up. As it turns out, Samuel B. Green, PhD, was using the course to draft chapters in the textbook [@green_using_2017] that has been so helpful for so many. Unfortunately, Drs. Green (1947 - 2018) and Salkind (1947 - 2017) are no longer with us. I have worn out numerous versions of their text. Another favorite text of mine has been Dr. Barbara Byrne's [-@byrne_structural_2016], "Structural Equation Modeling with AMOS." I loved the way she worked through each problem and paired it with a published journal article, so that the user could see how the statistical evaluation fit within the larger project/article. I took my tea-stained text with me to a workshop she taught at APA and was proud of the signature she added to it. Dr. Byrne created SEM texts for a number of statistical programs (e.g., LISREL, EQS, MPlus). As I was learning R, I wrote Dr. Byrne, asking if she had an edition teaching SEM/CFA with R. She promptly wrote back, saying that she did not have the bandwidth to learn a new statistics package. We lost Dr. Byrne in December 2020. I am so grateful to these role models for their contributions to my statistical training. I am also grateful for the doctoral students who have taken my courses and are continuing to provide input for how to improve the materials. - -The inspiration for training materials that re*center statistics and research methods came from the [Academics for Black Survival and Wellness Initiative](https://www.academics4blacklives.com/). This project, co-founded by Della V. Mosley, Ph.D., and Pearis L. Bellamy, M.S., made clear the necessity and urgency for change in higher education and the profession of psychology. - -At very practical levels, I am indebted to SPU's Library, and more specifically, SPU's Education, Technology, and Media Department. Assistant Dean for Instructional Design and Emerging Technologies, R. John Robertson, MSc, MCS, has offered unlimited consultation, support, and connection. Senior Instructional Designer in Graphics & Illustrations, Dominic Wilkinson, designed the logo and bookcover. Psychology and Scholarly Communications Librarian, Kristin Hoffman, MLIS, has provided consultation on topics ranging from OERS to citations. I am alo indebted to Associate Vice President, Teaching and Learning at Kwantlen Polytechnic University, Rajiv Jhangiani, PhD. Dr. Jhangiani's text [-@jhangiani_research_2019] was the first OER I ever used and I was grateful for his encouraging conversation. - -The creation of this OER has relied on strong peer and student support. Many thanks to Thane Erickson, PhD for being the first to pilot the resource (and approach to teaching) in his class. Students (both paid and unpaid) have served as editorial assistants in copyediting the text and correcting the text captions. Students who have held the Editorial Assistant role include Sarah Day, Ellie Smith, Tara Shelby, Keyera Gaulden, Kiana Clay, Lexa Gambrill, Ashley Righetti, and Jaylee York. - -Financial support for this project has been provided the following: - -* *Call to Action on Equity, Inclusion, Diversity, Justice, and Social Responsivity Request for Proposals* grant from the Association of Psychology Postdoctoral and Internship Centers (2021-2022). -* *Diversity Seed Grant*, Office of Inclusive Excellence and Advisory Council for Diversity and Reconciliation (ACDR), Seattle Pacific University. -* *ETM Open Textbook & OER Development Funding*, Office of Education, Technology, & Media, Seattle Pacific University. - -```{r include=FALSE} -# automatically create a bib database for R packages -knitr::write_bib(c( - .packages(), 'bookdown', 'knitr', 'rmarkdown' -), 'packages.bib') -``` diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/09AAD2C3-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/09AAD2C3-contents deleted file mode 100644 index 1ce86c2a..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/09AAD2C3-contents +++ /dev/null @@ -1,93 +0,0 @@ ---- -title: "ReCentering Psych Stats" -author: "Lynette H. Bikos, PhD, ABPP (she/her)" -date: "Last updated `r format (Sys.Date(), '%d %b %Y')`" -documentclass: book -site: bookdown::bookdown_site -bibliography: STATSnMETH.bib #This is my own bibtex file from my Zotero account. If this file is not in the project folder there will be an error and the book will not build. -citation-style: apa-single-spaced.csl #if you want APA style -link-citations: yes -urlcolor: blue #without this the links in the PDF do not show -fontsize: 11pt -geometry: margin=1in -highlight: tango -#DID NOT WORK, BUT DID NOT HURT EITHER I THINK IT NEEDS TO BE CONNECTED TO A PKG -#line-wrapping-in-code: true #wrap overflowing lines in code blocks? -url: https://lhbikos.github.io/ReCenterPsychStats/ #a link to the GitHub pages where it is rendered -cover-image: images/ReCenterPsychStats-bookcover2.jpg #link to the image for the book which will show up in any previews -description: | - ReCentering Psych Stats is an open education resource for teaching statistics with the open-source program, R, in a socially and culturally responsive manner. The series provides workflows and worked examples in R and each statistic is accompanied by an example APA style presentation of results. A core focus of the ReCentering series is simulated data from published articles that focus on issues of social justice and are, themselves, conducted in a socially responsive manner. -github-repo: lhbikos/ReCenterPsychStats - ---- - -```{r, include=FALSE} -options(tinytex.verbose = TRUE) -``` - - -# BOOK COVER {-} - -![An image of the book cover. It includes four quadrants of non-normal distributions representing gender, race/ethnicty, sustainability/global concerns, and journal articles](images/ReCenterPsychStats-bookcover2.jpg) -This open education resource is available in three formats: - -* Formatted as an [html book](https://lhbikos.github.io/ReCenterPsychStats/) via GitHub Pages -* As a [PDF](https://github.com/lhbikos/ReCenterPsychStats/blob/main/docs/ReCenterPsychStats.pdf) available in the [docs](https://github.com/lhbikos/ReCenterPsychStats/tree/main/docs) folder at the GitHub repository -* As an [ebook](https://github.com/lhbikos/ReCenterPsychStats/blob/main/docs/ReCenterPsychStats.epub) available in the [docs](https://github.com/lhbikos/ReCenterPsychStats/tree/main/docs) folder at the GitHub repository -* As a [Word document](https://github.com/lhbikos/ReCenterPsychStats/blob/main/docs/ReCenterPsychStats.docx) available in the [docs](https://github.com/lhbikos/ReCenterPsychStats/tree/main/docs) folder at the GitHub repository - -All materials used in creating this OER are available at its [GitHub repo](https://github.com/lhbikos/ReCenterPsychStats). - -As a perpetually-in-progress, open education resource, feedback is always welcome. This IRB-approved (SPU IRB #202102010R, no expiration) [Qualtrics-hosted survey](https://spupsych.az1.qualtrics.com/jfe/form/SV_0OnBLfut3VIOIS2) includes formal rating scales, open-ended text boxes, and a portal for uploading attachments (e.g., marked up PDFs). You are welcome to complete only the portions that are relevant to you. - -# PREFACE {-} - -**If you are viewing this document, you should know that this is a book-in-progress. Early drafts are released for the purpose teaching my classes and gaining formative feedback from a host of stakeholders. The document was last updated on `r format (Sys.Date(), '%d %b %Y')`**. Emerging volumes on other statistics are posted on the [ReCentering Psych Stats](https://lhbikos.github.io/BikosRVT/ReCenter.html) page at my research team's website. - -[Screencasted Lecture Link](https://youtu.be/yy0z85Wla7o) - -To *center* a variable in regression means to set its value at zero and interpret all other values in relation to this reference point. Regarding race and gender, researchers often center male and White at zero. Further, it is typical that research vignettes in statistics textbooks are similarly seated in a White, Western (frequently U.S.), heteronormative, framework. The purpose of this project is to create a set of open educational resources (OER) appropriate for doctoral and post-doctoral training that contribute to a socially responsive pedagogy -- that is, it contributes to justice, equity, diversity, and inclusion. - -Statistics training in doctoral programs are frequently taught with fee-for-use programs (e.g., SPSS/AMOS, SAS, MPlus) that may not be readily available to the post-doctoral professional. In recent years, there has been an increase and improvement in R packages (e.g., *psych*, *lavaan*) used for analyses common to psychological research. Correspondingly, many graduate programs are transitioning to statistics training in R (free and open source). This is a challenge for post-doctoral psychologists who were trained with other software. This OER will offer statistics training with R and be freely available (specifically in a GitHub repository and posted through GitHub Pages) under a Creative Commons Attribution - Non Commercial - Share Alike license [CC BY-NC-SA 4.0]. - -Training models for doctoral programs in health service psychology are commonly scholar-practitioner, scientist-practitioner, or clinical-scientist. An emerging model, the *scientist-practitioner-advocacy* training model, incorporates social justice advocacy so that graduates are equipped to recognize and address the sociocultural context of oppression and unjust distribution of resources and opportunities [@mallinckrodt_scientist-practitioner-advocate_2014]. In statistics textbooks, the use of research vignettes engages the learner around a tangible scenario for identifying independent variables, dependent variables, covariates, and potential mechanisms of change. Many students recall examples in Field's [-@field_discovering_2012] popular statistics text: Viagra to teach one-way ANOVA, beer goggles for two-way ANOVA, and bushtucker for repeated measures. What if the research vignettes were more socially responsive? - -In this OER, research vignettes will be from recently published articles where: - -* the author’s identity is from a group where scholarship is historically marginalized (e.g., BIPOC, LGBTQ+, LMIC[low-middle income countries]), -* the research is responsive to issues of justice, equity, inclusion, diversity, -* the lesson’s statistic is used in the article, and -* there is sufficient information in the article to simulate the data for the chapter example(s) and practice problem(s); or it is publicly available. - -In training for multicultural competence, the saying, "A fish doesn't know that it's wet" is often used to convey the notion that we are often unaware of our own cultural characteristics. In recent months and years, there has been an increased awakening to institutional and systemic factors that contribute to discrimination as a function of race, gender, nationality, class, and so forth. Queuing from the water metaphor, I am hopeful that a text that is recentered in the ways I have described can contribute to *changing the water* in higher education and in the profession of psychology. - - -## Copyright with Open Access {-} -Creative Commons License - -This book is published under a a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. This means that this book can be reused, remixed, retained, revised and redistributed (including commercially) as long as appropriate credit is given to the authors. If you remix, or modify the original version of this open textbook, you must redistribute all versions of this open textbook under the same license: CC BY-SA 4.0. - -A [GitHub open-source repository](https://github.com/lhbikos/ReCenterPsychStats) contains all of the text and source code for the book, including data and images. - -# ACKNOWLEDGEMENTS {-} - -As a doctoral student at the University of Kansas (1992-1996), I learned that "a foreign language" was a graduation requirement. *Please note that as one who studies the intersections of global, vocational, and sustainable psychology, I regret that I do not have language skills beyond English.* This could have been met with credit from high school, but my rural, mid-Missouri high school did not offer such classes. This requirement would have typically been met with courses taken during an undergraduate program -- but my non-teaching degree in the University of Missouri's School of Education was exempt from this. The requirement could have also been met with a computer language (FORTRAN, C++) -- but I did not have any of those either. There was a tiny footnote on my doctoral degree plan that indicated that a 2-credit course, "SPSS for Windows" would substitute for the language requirement. Given that it was taught by my one of my favorite professors, I readily signed up. As it turns out, Samuel B. Green, PhD, was using the course to draft chapters in the textbook [@green_using_2017] that has been so helpful for so many. Unfortunately, Drs. Green (1947 - 2018) and Salkind (1947 - 2017) are no longer with us. I have worn out numerous versions of their text. Another favorite text of mine has been Dr. Barbara Byrne's [-@byrne_structural_2016], "Structural Equation Modeling with AMOS." I loved the way she worked through each problem and paired it with a published journal article, so that the user could see how the statistical evaluation fit within the larger project/article. I took my tea-stained text with me to a workshop she taught at APA and was proud of the signature she added to it. Dr. Byrne created SEM texts for a number of statistical programs (e.g., LISREL, EQS, MPlus). As I was learning R, I wrote Dr. Byrne, asking if she had an edition teaching SEM/CFA with R. She promptly wrote back, saying that she did not have the bandwidth to learn a new statistics package. We lost Dr. Byrne in December 2020. I am so grateful to these role models for their contributions to my statistical training. I am also grateful for the doctoral students who have taken my courses and are continuing to provide input for how to improve the materials. - -The inspiration for training materials that re*center statistics and research methods came from the [Academics for Black Survival and Wellness Initiative](https://www.academics4blacklives.com/). This project, co-founded by Della V. Mosley, Ph.D., and Pearis L. Bellamy, M.S., made clear the necessity and urgency for change in higher education and the profession of psychology. - -At very practical levels, I am indebted to SPU's Library, and more specifically, SPU's Education, Technology, and Media Department. Assistant Dean for Instructional Design and Emerging Technologies, R. John Robertson, MSc, MCS, has offered unlimited consultation, support, and connection. Senior Instructional Designer in Graphics & Illustrations, Dominic Wilkinson, designed the logo and bookcover. Psychology and Scholarly Communications Librarian, Kristin Hoffman, MLIS, has provided consultation on topics ranging from OERS to citations. I am also indebted to Associate Vice President, Teaching and Learning at Kwantlen Polytechnic University, Rajiv Jhangiani, PhD. Dr. Jhangiani's text [-@jhangiani_research_2019] was the first OER I ever used and I was grateful for his encouraging conversation. - -The creation of this OER has relied on strong peer and student support. Many thanks to Thane Erickson, PhD for being the first to pilot the resource (and approach to teaching) in his class. Students (both paid and unpaid) have served as editorial assistants in copyediting the text and correcting the text captions. Students who have held the Editorial Assistant role include Sarah Day, Ellie Smith, Tara Shelby, Keyera Gaulden, Kiana Clay, Lexa Gambrill, Ashley Righetti, and Jaylee York. - -Financial support for this project has been provided the following: - -* *Call to Action on Equity, Inclusion, Diversity, Justice, and Social Responsivity Request for Proposals* grant from the Association of Psychology Postdoctoral and Internship Centers (2021-2022). -* *Diversity Seed Grant*, Office of Inclusive Excellence and Advisory Council for Diversity and Reconciliation (ACDR), Seattle Pacific University. -* *ETM Open Textbook & OER Development Funding*, Office of Education, Technology, & Media, Seattle Pacific University. - -```{r include=FALSE} -# automatically create a bib database for R packages -knitr::write_bib(c( - .packages(), 'bookdown', 'knitr', 'rmarkdown' -), 'packages.bib') -``` diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/09AAE279-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/09AAE279-contents deleted file mode 100644 index 6d2f7e3f..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/09AAE279-contents +++ /dev/null @@ -1,942 +0,0 @@ -# Preliminary Analyses {#preliminaries} - - -[Screencasted Lecture Link](https://youtube.com/playlist?list=PLtz5cFLQl4KOoTRizMIyRU0ioiuSM1tWg) - -```{r include=FALSE} -knitr::opts_chunk$set(echo = TRUE) -knitr::opts_chunk$set(comment = NA) #keeps out the hashtags in the knits -options(scipen=999)#eliminates scientific notation -``` - -The beginning of any data analysis means familiarizing yourself with the data. Among other things, this includes producing and interpreting its distributional characteristics. In this lesson we mix common R operations for formatting, preparing, and analyzing the data with foundational statistical concepts in statistics. - -## Navigating this Lesson - -There is just less than two hours of lecture. If you work through the lesson with me, I would plan for an additional three hours. - -While the majority of R objects and data you will need are created within the R script that sources the lesson, occasionally there are some that cannot be created from within the R framework. Additionally, sometimes links fail. All original materials are provided at the [Github site](https://github.com/lhbikos/ReCenterPsychStats) that hosts the book. More detailed guidelines for ways to access all these materials are provided in the OER's [introduction](#ReCintro) - -### Learning Objectives - -Learning objectives from this lecture include the following: - -* Determine the appropriate scale of measurement for variables and format them properly in R -* Produce and interpret measures of central tendency -* Analyze the distributional characteristics of data -* Describe the steps in calculating a standard deviation. -* Describe the steps in calculating a bivariate correlation coefficient (i.e., Pearson *r*). -* Create an APA Style table and results section that includes means, standard deviations, and correlations and addresses skew and kurtosis. - -### Planning for Practice - -The practice assignment at the end of the lesson is designed as a "get (or 'get back') into it" assignment. You will essentially work through this very same lecture, using the same dataframe; you will simply use a different set of continuous variables. - -### Readings & Resources - -In preparing this chapter, I drew heavily from the following resource(s). Other resources are cited (when possible, linked) in the text with complete citations in the reference list. - -* Revelle, W. (2021). An introduction to the psych package: Part I: data entry and data description. 60. - - Revelle is the author/creator of the *psych* package. His tutorial provides both technical and interpretive information. Read pages 1-17. -* Lui, P. P. (2020). Racial microaggression, overt discrimination, and distress: (In)Direct associations with psychological adjustment. *The Counseling Psychologist, 32*. - - This is the research vignette from which I simulate data that we can use in the lesson and practice problem. - -```{r include=FALSE} -#will install the package if not already installed -#if(!require(tidyverse)){install.packages("tidyverse")} -#if(!require(lsr)){install.packages("lsr")} -#if(!require(psych)){install.packages("psych")} -#if(!require(apaTables)){install.packages("apaTables")} -#if(!require(MASS)){install.packages("MASS")} -#if(!require(knitr)){install.packages("knitr")} -#if(!require(ggpubr)){install.packages("ggpubr")} -#if(!require(dplyr)){install.packages("dplyr")} -#if(!require(pastecs)){install.packages("pastecs")} -``` - -## Research Vignette - -We will use data that has been simulated data from Lui [-@lui_racial_2020] as the research vignette. Controlling for overt discrimination, and neuroticism, Lui examined the degree to which racial microaggressions contributed to negative affect, alcohol consumption, and drinking problems in African American, Asian American, and Latinx American college students (*N* = 713). - -Using the means, standard deviations, correlation matrix, and group sizes (*n*) I simulated the data. Although I provide some narration of what I did, process of simulation is beyond the learning goals of this lesson, so you are welcome to skip it. Simulating data within each chapter makes the lesson more "portable." - -```{r warning=FALSE, message=FALSE, tidy=TRUE, tidy.opts=list(width.cutoff=70)} -set.seed(210807)#sets the random seed so that we consistently get the same results -#for practice, you could change (or remove) the random seed and try to interpret the results (they should be similar) -#There are probably more efficient ways to simulate data. Given the information available in the manuscript, my approach was to first create separate datasets for each of the racial ethnic groups and then bind them together. - -#First, the data for the students who identified as Asian American -Asian_mu <- c(1.52, 1.72, 2.69, 1.71, 2.14, 2.35, 2.42) #creating an object containing the means -Asian_stddev <- c(2.52, 2.04, 0.47, 0.70, 0.80, 2.41, 3.36) # creating an object containing thestandard deviations -Asian_corMat <- matrix(c(1.00, 0.69, 0.19, 0.28, 0.32, 0.08, 0.23, - 0.69, 1.00, 0.20, 0.29, 0.33, 0.13, 0.25, - 0.19, 0.20, 1.00, 0.50, 0.50, -0.04, 0.09, - 0.28, 0.29, 0.50, 1.00, 0.76, 0.04, 0.18, - 0.32, 0.33, 0.50, 0.76, 1.00, 0.10, 0.21, - 0.08, 0.13, -0.04, 0.04, 0.10, 1.00, 0.42, - 0.23, 0.25, 0.09, 0.18, 0.21, 0.42, 1.00), - ncol=7) # creating an object containing the correlation matrix -Asian_covMat <- Asian_stddev %*% t(Asian_stddev) * Asian_corMat #creating a covariance matrix from the above objects - -Asian_dat <- MASS::mvrnorm(n = 398, mu = Asian_mu, Sigma = Asian_covMat, empirical = TRUE) #creating the dataset -Asian_df <- as.data.frame(Asian_dat) #formatting the dataset as a data frame - -library(tidyverse) -#renaming the variables -Asian_df <- rename(Asian_df, OvDisc = V1, mAggr = V2, Neuro = V3, nAff = V4, psyDist = V5, Alcohol = V6, drProb = V7) - -#set upper and lower bound for each variable -Asian_df$OvDisc[Asian_df$OvDisc > 16] <- 16 -Asian_df$OvDisc[Asian_df$OvDisc < 0] <- 0 - -Asian_df$mAggr[Asian_df$mAggr > 16] <- 16 -Asian_df$mAggr[Asian_df$mAggr < 0] <- 0 - -Asian_df$Neuro[Asian_df$Neuro > 5] <- 5 -Asian_df$Neuro[Asian_df$Neuro < 1] <- 1 - -Asian_df$nAff[Asian_df$nAff > 4] <- 4 -Asian_df$nAff[Asian_df$nAff < 1] <- 1 - -Asian_df$psyDist[Asian_df$psyDist > 5] <- 5 -Asian_df$psyDist[Asian_df$psyDist < 1] <- 1 - -Asian_df$Alcohol[Asian_df$Alcohol > 12] <- 12 -Asian_df$Alcohol[Asian_df$Alcohol < 0] <- 0 - -Asian_df$drProb[Asian_df$drProb > 12] <- 12 -Asian_df$drProb[Asian_df$drProb < 0] <- 0 - -Asian_df$RacEth <- "Asian" - -#Second, the data for the students who identified as Black/African American -Black_mu <- c(4.45, 3.84, 2.60, 1.84, 2.10, 2.81, 2.14) -Black_stddev <- c(4.22, 3.08, 0.89, 0.80, 0.81, 2.49, 3.24) -Black_corMat <- matrix(c( 1.00, 0.81, 0.17, 0.15, 0.09, 0.05, -0.16, - 0.81, 1.00, 0.17, 0.21, 0.11, 0.09, -0.01, - 0.17, 0.17, 1.00, 0.59, 0.54, 0.05, 0.24, - 0.15, 0.21, 0.59, 1.00, 0.72, 0.12, 0.22, - 0.09, 0.11, 0.54, 0.72, 1.00, 0.21, 0.40, - 0.05, 0.09, 0.05, 0.12, 0.21, 1.00, 0.65, - -0.16,-0.01, 0.24, 0.22, 0.40, 0.65, 1.00), - ncol = 7) -Black_covMat <- Black_stddev %*% t(Black_stddev) * Black_corMat -Black_dat <- MASS::mvrnorm(n = 133, mu = Black_mu, Sigma = Black_covMat, empirical = TRUE) -Black_df <- as.data.frame(Black_dat) -Black_df <- rename(Black_df, OvDisc = V1, mAggr = V2, Neuro = V3, nAff = V4, psyDist = V5, Alcohol = V6, drProb = V7) - -#set upper and lower bound for each variable -Black_df$OvDisc[Black_df$OvDisc > 16] <- 16 -Black_df$OvDisc[Black_df$OvDisc < 0] <- 0 - -Black_df$mAggr[Black_df$mAggr > 16] <- 16 -Black_df$mAggr[Black_df$mAggr < 0] <- 0 - -Black_df$Neuro[Black_df$Neuro > 5] <- 5 -Black_df$Neuro[Black_df$Neuro < 1] <- 1 - -Black_df$nAff[Black_df$nAff > 4] <- 4 -Black_df$nAff[Black_df$nAff < 1] <- 1 - -Black_df$psyDist[Black_df$psyDist > 5] <- 5 -Black_df$psyDist[Black_df$psyDist < 1] <- 1 - -Black_df$Alcohol[Black_df$Alcohol > 12] <- 12 -Black_df$Alcohol[Black_df$Alcohol < 0] <- 0 - -Black_df$drProb[Black_df$drProb > 12] <- 12 -Black_df$drProb[Black_df$drProb < 0] <- 0 - -Black_df$RacEth <- "Black" - -#Third, the data for the students who identified as Latinx American -Latinx_mu <- c(1.56, 2.34, 2.69, 1.81, 2.17, 3.47, 2.69) -Latinx_stddev <- c(2.46, 2.49, 0.86, 0.71, 0.78, 2.59, 3.76) -Latinx_corMat <- matrix(c( 1.00, 0.78, 0.27, 0.36, 0.42, -0.06, 0.08, - 0.78, 1.00, 0.33, 0.26, 0.35, -0.11, -0.02, - 0.27, 0.33, 1.00, 0.62, 0.64, -0.04, 0.15, - 0.36, 0.26, 0.62, 1.00, 0.81, -0.08, 0.17, - 0.42, 0.35, 0.64, 0.81, 1.00, -0.06, 0.15, - -0.06,-0.11, -0.04, -0.08, -0.06, 1.00, 0.60, - 0.08, -0.02, 0.15, 0.17, 0.15, 0.60, 1.00), - ncol = 7) -Latinx_covMat <- Latinx_stddev %*% t(Latinx_stddev) * Latinx_corMat -Latinx_dat <- MASS::mvrnorm(n = 182, mu = Latinx_mu, Sigma = Latinx_covMat, empirical = TRUE) -Latinx_df <- as.data.frame(Latinx_dat) -Latinx_df <- rename(Latinx_df, OvDisc = V1, mAggr = V2, Neuro = V3, nAff = V4, psyDist = V5, Alcohol = V6, drProb = V7) - -Latinx_df$OvDisc[Latinx_df$OvDisc > 16] <- 16 -Latinx_df$OvDisc[Latinx_df$OvDisc < 0] <- 0 - -Latinx_df$mAggr[Latinx_df$mAggr > 16] <- 16 -Latinx_df$mAggr[Latinx_df$mAggr < 0] <- 0 - -Latinx_df$Neuro[Latinx_df$Neuro > 5] <- 5 -Latinx_df$Neuro[Latinx_df$Neuro < 1] <- 1 - -Latinx_df$nAff[Latinx_df$nAff > 4] <- 4 -Latinx_df$nAff[Latinx_df$nAff < 1] <- 1 - -Latinx_df$psyDist[Latinx_df$psyDist > 5] <- 5 -Latinx_df$psyDist[Latinx_df$psyDist < 1] <- 1 - -Latinx_df$Alcohol[Latinx_df$Alcohol > 12] <- 12 -Latinx_df$Alcohol[Latinx_df$Alcohol < 0] <- 0 - -Latinx_df$drProb[Latinx_df$drProb > 12] <- 12 -Latinx_df$drProb[Latinx_df$drProb < 0] <- 0 - -Latinx_df$RacEth <- "Latinx" - -#binding the datasets together -Lui_sim_df <-bind_rows(Asian_df, Black_df, Latinx_df) -``` - -If you have simulated the data, you can continue using the the "Lui_sim_df" object that we created. In your own research you will likely work with a datafile stored on your computer. Although I will hashtag the code out (making it inoperable until the hashtags are removed), here is script to save the simulated data both .csv (think "Excel lite") and .rds (it retains all the properties we specified in R) files and then bring/import them back into R. For more complete instructions see the [Ready_Set_R](#Ready) lesson. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#write the simulated data as a .csv -#write.table(Lui_sim_df, file="Lui_CSV.csv", sep=",", col.names=TRUE, row.names=FALSE) -#bring back the simulated dat from a .csv file -#df <- read.csv ("Lui_CSV.csv", header = TRUE) -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#to save the df as an .rds (think "R object") file on your computer; -#it should save in the same file as the .rmd file you are working with -#saveRDS(Lui_sim_df, "Lui_RDS.rds") -#bring back the simulated dat from an .rds file -#df <- readRDS("Lui_RDS.rds") -``` - -You may have noticed a couple of things in each of these operations - -* First, I named the data object to include a "df" (i.e., dataframe). - - It is a common (but not required) practice for researchers to simply use "df" or "dat" as the name of the object that holds their data. This practice has advantages (e.g., as making the re-use of code quite easy across datasets) and disadvantages (e.g., it is easy to get confused about what data is being used). -* Second, when you run the code, any updating *replaces* the prior object. - - While this is irrelevant today (we are saving the same data with different names), it points out the importance of creating a sensible and systematic *order of operations* in your .rmd files and then knowing where you are in the process. - -Because the data is simulated, I can simply use the data I created in the simulation, however, I will go ahead and use the convention of renaming it, "df", which (in this case) stands for *dataframe* and is the common term for a dataset for users of R. *A quick note: in statistics "df" is also an abbreviation for "degrees of freedom."* - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -df <- Lui_sim_df -``` - -## Variable Types (Scale of Measurement) - -When working with raw data, we begin by inspecting and preparing it for the planned analyses. The *type* of variables we have influences what statistics we will utilize. Further, the data must be formatted as that type in order for the statistic to properly execute. Variable types (or formats) are directly connected to the statistical concept of *measurement scale* (or *scale of measurement*). Researchers often think of the *categorical versus continuous* distinction, but it's even more nuanced than that. - -### Measurement Scale - -**Categorical** variables name *discrete* or *distinct* entities where the categorization has no inherent value or order. When there are two categories, the variable type is **binary** (e.g., pregnant or not, treatment and control conditions). When there are more than two categories, the variable type is **nominal** (e.g., teacher, student, or parent; Republican, Democrat, or Independent). - -**Ordinal** variables are also categorical variables where the score reflects a logical order or relative rank (e.g., the order of finishing in a race). A challenge with the ordinal scale is the inability to determine the distance between rankings. The percentile rank is a (sometimes surprising) example of the ordinal scale. Technically, Likert type scaling (e.g., providing ratings on a 1-to-5 scale) is ordinal because it is uncertain that the distance between each of the anchors is equal. Practically, though, most researchers treat the Likert type scale as interval. This is facilitated, in part, because most Likert-type scales have multiple items which are averaged into a single score. Navarro[-@navarro_book_2020] uses the term, **quasi-interval** to describe Likert-type scaling. - -**Continuous** variables can take on any value in the measurement scale that is being used. **Interval** level data has equal distances between each unit on the scale. Two classic examples of interval level data are temperature and year. Whether using Fahrenheit or Celsius, the rating of 0 does not mean there is an absence of temperature, rather, it is simply a number along a continuum of temperature. Another interval example is calendrical time. In longitudinal research, we frequently note the date or year (e.g., 2019) of an event. It is highly unlikely that the value zero will appear in our research and if it did, it would not represent the absence of time. A researcher can feel confident that a variable is on the interval scale if the values can be meaningfully added and subtracted. - -**Ratio** level data also has equal distances between each unit on the scale, plus it has a true zero point where the zero indicates absence. Examples are behavioral counts (e.g., cigarettes smoked) and time-on-task (e.g., 90 seconds). Ratio data offers more manipulative power because researchers can add, subtract, multiply, and divide ratio level data. - -### Corresponding Variable Structure in R - -With these definitions in mind, we will see if R is reading our variables correctly. R will provide the following designations of variables: - -|Abbreviation |Unabbreviated | Used for |Scale of Measurement -|:------------|:-------------|:----------------------------------------|:---------------------------------| -|num |numerical |numbers that allow decimals or fractional values|quasi-interval, interval, or ratio| -|int |integer |whole numbers (no decimals) |quasi-interval, interval, or ratio| -|chr |character |sometimes termed "string" variables, these are interpreted as words|NA| -|Factor |factor |two or more categories; R imposes an alphabetical order; the user can re-specify the order based on the logic of the design|nominal| - -Looking back at the Lui [-@lui_racial_2020] article we can determine what the scale of measurement is for each variable and what the corresponding R format for that variable should be: - -|Name |Variable |How assessed |Scale of measurement |R format| -|:-----|:------------------|:----------------------------|:--------------------|:--------- | -|OvDis |Overt racial discrimination|9 items, 1-to-4 Likert scaling for frequency and stressfulness assessed separately, then multiplied|quasi-interval|numerical| -|mAggr |Racial and ethnic microaggressions|28 items, 1-to-4 Likert scaling for frequency and stressfulness assessed separately, then multiplied|quasi-interval|numerical| -|Neuro |Neuroticism|4 items, 1-to-5 Likert scaling |quasi-interval|numerical| -|nAff |Negative affect|6 items, 1-to-4 Likert scaling |quasi-interval|numerical| -|psyDist |Psychological distress|6 items, 1-to-5 Likert scaling |quasi-interval|numerical| -|Alcohol|Hazardous alcohol use|10 items, 0-to-4 Likert scaling |quasi-interval|numerical| -|drProb|Drinking problems|10 items, 0-to-4 Likert scaling |quasi-interval|numerical| -|RacEth|Race Ethnicity|3 categories |nominal|factor| - -We can examine the accuracy with which R interpreted the type of data with the *structure()* command. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -str(df) -``` - -Only Race/Ethnicity needs to be transformed from a character ("chr) variable to a factor. I will use the *mutate()* function in the *dplyr* package to convert the RacEth variable to be a factor with three levels. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -df <- df %>% - dplyr::mutate( - RacEth = as.factor(RacEth)) -``` - -Let's check the structure again. Below we see that the RacEth variable is now a factor. R has imposed an alphabetical order: Asian, Black, Latinx. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#checking the structure of the data -str(df) -``` - -## Descriptive Statistics - -While the majority of this OER (and statistics training in general) concerns the ability to make predictions or inferences (hence *inferential statistics*) from data, we almost always begin data analysis by describing it (hence, *descriptive statistics*). - -Our research vignette contains a number of variables. Lui [-@lui_racial_2020] was interested in predicting negative affect, alcohol consumption, and drinking problems from overt discrimination, microaggressions, neuroticism, through psychological distress. This research model is a *mediation* model (or model of indirect effects) and is beyond the learning objectives of today's instruction. In demonstrating descriptive statistics, we will focus on one of the dependent variables: negative affect. - -As we begin to explore the descriptive and distributional characteristics of this variable, it may be helpful to visualize it through a histogram. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70), warning=FALSE} -ggpubr::gghistogram(df$nAff, xlab="Negative Affect", ylab = "Frequency", add = "mean", rug=TRUE, color = "#00AFBB", title = "Frequencies of Negative Affect") -``` - -### Measures of Central Tendency - -Describing data almost always begins with *measures of central tendency*: the mean, median, and mode. - -#### Mean - -The **mean** is simply a mathematical average of the non-missing data. The mathematical formula is frequently expressed this way: - -$$\bar{X} = \frac{X_{1} + X_{2} + X_{3}...+ X_{N}}{N}$$ -Because this formula is clumsy to write, there is statistical shorthand to help us convey it more efficiently (not necessarily, more easily). - -Placing information below (where to start), above (where to stop), and to the right (what data to use) of the summation operator ($\sum$), provides information about the nature of the data. In the formula below, we learn from the notation to the right that we use the individual data in the vector X. We start with the first piece of data (*i* = 1) and stop with the *Nth* (or last) case. - -$$\sum_{i=1}^{N}X_{i}$$ -The $\frac{1}{N}$ notation to the left tells us that we are calculating the mean. - -$$\bar{X}=\frac{1}{N}\sum_{i=1}^{N}X_{i}$$ -R is an incredible tool in that we can type out mathematical operations, use functions from base R, and use packages to do the work for us. If we had the following toy dataset (2, 3, 2, 1, 5, NA) we could calculate the mean by typing it out: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -(2 + 3 + 2 + 1 + 5)/5 -``` -Alternatively we could use the built-in functions in base R to do the work for us. Let me add a little complexity by creating a single variable (a vector of data) and introducing a little missingness (i.e., the "NA"). -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -toy <- c(2, 3, 2, 1, 5, NA) -toy<-as.data.frame(toy) -``` - -I can use the base R function *mean()*. Inside the parentheses I point to the data. The function automatically sums the values. When there is missingness, adding *na.rm=TRUE* tells the function to exclude the missing variables from the count (i.e., the denominator would still be 5). - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -mean(toy$toy, na.rm=TRUE) -``` -In my simulation of the research vignette, we have no missing values, none-the-less, it is, perhaps a good habit to include the *na.rm=TRUE* specification in our code. Because we have an entire dataframe, we just point to the dataframe and the specific variable (i.e., negative affect). - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -mean(df$nAff, na.rm=TRUE) -``` - -#### Median - -The middle value in a set of values is the **median**. The easiest way to calculate the median is to sort the numbers: - -|Unsorted |Sorted -|:-----------------|:-------------:| -|2, 3, 2, 1, 5, |1, 2, 2, 3, 5 | - -And select the middle value. Because we have an odd number of values (*N* = 5), our median is 2. If we had an even number of values, we would take the average of the middle two numbers. - -We can use a base R function to calculate the median for us. Let's do it first with the toy data: -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -median(toy$toy, na.rm=TRUE) -``` -Let's also calculate it for the negative affect variable from the research vignette. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -median(df$nAff, na.rm=TRUE) -``` - -#### Mode - -The **mode** is the score that occurs most frequently. When a histogram is available, spotting the mode is easy because it will have the tallest bar. Determining the mode can be made complicated if there are ties for high frequencies of values. A common occurrence of this happens in the **bimodal** distribution. - -Unfortunately, there is no base R function that will call a mode. In response, Navarro developed and included a function in the *lsr* package that accompanies her [-@navarro_book_2020] textbook. Once the package is installed, you can include two colons, the function name, and then the dataset to retrieve the mode. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -lsr::modeOf(toy$toy) -``` -From our toy data, we the *modeOf()* function returns a 2. - -Let's retrieve the mode from the negative affect variable in our research vignette. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -lsr::modeOf(df$nAff) -``` -The value is a 1.0 and is likely an artifact of how I simulated the data. Specifically, to ensure that the values fell within the 1-to-4 range, I rounded up to 1.0 any negative values and rounded down to 4.0 any values that were higher than 4.0. - -#### Relationship between mean, median, and mode - -Many inferential statistics rely on manipulations of the mean. The mean, though, can be misleading when it is influenced by outliers. Therefore, as we engage in preliminary exploration, it can be quite useful to calculate all three measures of central tendency, as well as exploring other distributional characteristics. - -As a bit of an advanced cognitive organizer, it may be helpful to know that in a normal distribution, the mean, median, and mode are the same number (or quite close). In a positively skewed distribution, the mean is higher than the median which is higher than the mode. In a negatively skewed distribution, the mean is lower than the median, which is lower than the mode. - -```{r} -mean(df$nAff, na.rm=TRUE) -median(df$nAff, na.rm=TRUE) -lsr::modeOf(df$nAff, na.rm=TRUE) -``` -In our research vignette, the mean (1.81) is higher than the median (1.75) is higher than the mode (1.0). This would suggest a positive skew. Here is a reminder of our histogram: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70), warning=FALSE} -ggpubr::gghistogram(df$nAff, xlab="Negative Affect", ylab = "Frequency", add = "mean", rug=TRUE, color = "#00AFBB", title = "Frequencies of Negative Affect") -``` - -## Variability - -Researchers are critically interested in the spread or dispersion of the scores. - -### Range - -The **range** is the simplest assessment of variability and is calculated by identifying the highest and lowest scores and subtracting the lowest from the highest. In our toy dataset, arranged from low-to-high (1, 2, 2, 3, 5 ) we see that the low is 1 and high is 5; 4 is the range. We can retrieve this data with three base R functions that ask for the minimum score, the maximum score, or both together -- the range: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -min(toy$toy, na.rm=TRUE) -max(toy$toy, na.rm=TRUE) -range(toy$toy, na.rm=TRUE) -``` -The negative affect variable from our research vignette has the following range: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -min(df$nAff) -max(df$nAff) -range(df$nAff) -``` -With a low of 1 and high of 4, the range of negative affect is 3. This is consistent with the description of the negative affect measure. - -One limitation of the range is that it is easily influenced by extreme scores. - -### Percentiles, Quantiles, Interquartile Range - -The **interquartile range** is middle 50% of data, or the scores that fall between 25th and 75th percentiles. Before calculating that, let's first define **quantiles** and **percentiles**. **Quantiles** are values that split a data into equal portions. **Percentiles** divide the data into 100 equal parts. Percentiles are commonly used in testing and assessment. You may have encountered them in standardized tests such as the SAT and GRE where both the score obtained and its associated percentile are reported. When graduate programs evaluate GRE scores, depending on their criteria and degree of competitiveness they may set a threshold based on percentiles (e.g., using a cut of of the 50th, 75th, or higher percentile for the verbal or quantitative GRE scores). - -We have already learned the value of the median. The median is also the 50th percentile. We can now use the *quantile()* function and indicate we want the value at the 50% percentile. - -Let's first examine the toy dataset: -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -median(toy$toy, na.rm=TRUE) -quantile(toy$toy, probs = .50, na.rm=TRUE ) -``` -As shown by our calculation, the value at the median and the 50th percentile is 2.0. Let's look at those values for the research vignette: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -median (df$nAff, na.rm=TRUE) -quantile(df$nAff, probs = .50, na.rm=TRUE ) -``` -Again, we see the same result. Half of the values for negative affect are below 1.76; half are above. - -The *quantile()* function is extremely useful. We can retrieve the raw score at any percentile, and we could ask for as many as we desired. Here's an example. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -quantile(df$nAff, probs=c(.10, .20, .30, .40, .50, .60, .70, .80, .90)) -``` - -**Quartiles** divide the data into four equal parts. The **interquartile range** is the spread of data between the 25th and 75th percentiles (or quartiles). We calculate the interquartile range by first obtaining those values, and then subtracting the lower from the higher. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -quantile(df$nAff, probs = c(.25,.75) ) -``` -We see that a score of 1.29 is at the 25th percentile and a score of 2.24 is at the 75th percentile. If we subtract 1.29 from 2.24... - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -2.24 - 1.29 -``` -...we learn that the interquartile range is 0.95. We could also obtain this value by using the *IQR()* function in base R. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -IQR(df$nAff, na.rm=TRUE) -``` - -You may be asking, "When would we use the interquartile range?" When data are influenced by **outliers** (i.e., extreme scores), using a more truncated range (the middle 50%, 75%, 90%) may be an option (if the dataset it large enough). At this point, though, the goal of this lesson is simply to introduce different ways of examining the variability in a dataset. Ultimately, we are working our way to the **standard deviation**. The next logical step is the **mean deviation.** - -### Deviations around the Mean - -Nearly all statistics include assessments of variability in their calculation and most are based on deviations around the mean. In fact it might be good to pause for a moment and consider as the lessons in this OER (and those that follow) continue, we will be engaged in *mathematical and statistical modeling*. In a featured article in the *American Psychologist*, Rodgers [-@rodgers_epistemology_2010] described models as a representation of reality that has two features: - -* the model describes reality in some important ways, and -* the model is simpler than reality. - -Albeit one of the simplest, the mean is a statistical model. Rodgers noted this when he wrote, "The mean and variance have done yeoman service to psychology and other behavioral sciences," [-@rodgers_epistemology_2010, p. 4]. These next statistical operations will walk through the use of the mean, particularly in its role in understanding variance. In later lessons, means and variances are used in understanding relations and differences. - -A first step in understanding mean deviation is to ask, "How far does each individual score deviates from the mean of scores?" We can demonstrate this with our toy dataset. I am taking more steps than necessary to (a) make clear how the mean deviation (abbreviated, mdev) is calculated and (b) practice using R. - -First, I will create a variable representing the mean: -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Dissecting the script, -#each variable is referenced by df_nameDOLLARSIGNvariable_name -toy$mean <- mean(toy$toy, na.rm=TRUE) -head(toy)#displays the first 6 rows of the data -``` - -Next, I will subtract the mean from each individual score. The result -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -toy$mdev <- toy$toy - toy$mean -head(toy)#displays the first 6 rows of the data -``` -The variable, *mdev* (short for "mean deviation") lets us know how far the individual score is from the mean. Unfortunately, it does not provide an overall estimate of variation. Further, summing and averaging these values all result in zero. Take a look: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Dissecting the script, -#Wrapping the sum and mean script in "round" and following with the desired decimal places, provides a rounde result. -round(sum(toy$mdev, na.rm=TRUE),3) -round(mean(toy$mdev, na.rm=TRUE),3) -``` -One solution is to create the *mean absolute deviation*. We first transform the mean deviation score to their absolute values, and then sum them. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -toy$abslt_m <- abs(toy$mdev) -head(toy) -``` - -And now to average them: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -round(mean(toy$abslt_m, na.rm=TRUE),3) -``` -This value tells how far individual observations are from the mean, "on average." In our toy dataset, the average distance from the mean is 1.12. - -So that we can keep statistical notation in our mind, this is the formula calculating the absolute mean deviation: - -$$\sum_{i=1}^{n}|X_{i} - \bar{X}|$$ -Let's quickly repeat the process with the negative affect variable in our research vignette. So that we can more clearly see the relationship of the new variables to negative affect, let me create a df containing only nAff: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -df_nAff <- df%>%dplyr::select(nAff) -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -df_nAff$mdevNA <- df_nAff$nAff - mean(df_nAff$nAff, na.rm=TRUE) -df_nAff$abNAmdev <- abs(df_nAff$mdevNA) -head(df_nAff) -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -round(mean(df_nAff$abNAmdev, na.rm=TRUE),3) -``` -Thus, the absolute mean deviation for the negative affect variable in our research vignette is 0.521. - -Although relatively intuitive, the absolute mean deviation is not all that useful. Most statistics texts include it because it is one of the steps toward variance, and ultimately, the standard deviation. - -### Variance - -Variance is considered to be an *average* dispersion calculated by summing the squared deviations and dividing by the number of observations (minus 1; more on that in later lessons). - -Our next step is to square the mean deviations. This value is also called the *sum of squared errors*, *sum of squared deviations around the mean*, or *sums of squares* and is abbreviated as *SS*. Below are common statistical representations: - -$$SS = \sum_{i=1}^{n}(X_{i} - \bar{X})^{^{2}}$$ -Let's do it with our toy data. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -toy$mdev2 <- (toy$mdev)*(toy$mdev) -sum(toy$mdev2, na.rm=TRUE)#sum of squared deviations -head(toy) -``` -Thus, our *SS* (sums of squares or sums of squared errors) is 9.2. - -To obtain the variance we divide by *N* (or *N* - 1; described in later lessons). Here are the updated formulas: - -$$s^{2}=\frac{SS}{N-1}=\frac{\sum_{i=1}^{n}(X_{i} - \bar{X})^{^{2}}}{N-1}$$ -Let's do this with the toy data: -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -9.2/(5-1)#calculated with the previously obtained values -#to obtain the "correct" calculation by using each of these individual R commands, we need to have non-missing data -toy <- na.omit(toy) -sum(toy$mdev2, na.rm=TRUE)/((nrow(toy)-1))#variance - -``` -Of course R also has a function that will do all the steps for us: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -mean(toy$toy, na.rm=TRUE) -var(toy$toy, na.rm=TRUE) -``` -The variance around the mean (2.6) of our toy data is 2.3. - -Let's quickly repeat this process with the negative affect variable from the research vignette. In prior steps we had calculated the mean deviations by subtracting the mean from each individual score. Next we square the mean deviations.... - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -df_nAff$NAmd2 <- (df_nAff$mdevNA)*(df_nAff$mdevNA) -head(df_nAff) -``` -... and sum them. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -sum(df_nAff$NAmd2, na.rm=TRUE)#sum of squared deviations -``` -Our sums of squared deviations around the mean is 283.44. When we divide it by *N* - 1, we obtain the variance. We can check our work with (a) the values we calculated at each step, (b) the steps written in separate R code, and (c) the *var()* function. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -283.44/(713-1)# calculating with the individual pre-calculated values -sum(df_nAff$NAmd2, na.rm=TRUE)/((nrow(df_nAff)-1))#calculated with steps from separate R code -var(df_nAff$nAff) #calculated using the base R function -``` -Unfortunately, because the mean deviations were squared, this doesn't interpret well. Hence, we move to the *standard deviation*. - -### Standard Deviation - -The standard deviation is simply the square root of the variance. Stated another way, it is an estimate of the average spread of data, presented in the same metric as the data. - -Calculating the standard deviation requires earlier steps: - -1. Calculating the mean. -2. Calculating mean deviations by subtracting the mean from each individual score. -3. Squaring the mean deviations. -4. Summing the mean deviations to create the *SS*, or sums of squares. -5. Dividing the *SS* by *N* - 1; this results in the *variance* around the mean. - -The 6th step is to take the square root of variance. It is represented in the formula, below: - - -$$s=\sqrt{\frac{SS}{N-1}}=\sqrt{\frac{\sum_{i=1}^{n}(X_{i} - \bar{X})^{^{2}}}{N-1}}$$ -Repeated below are each of the six steps for the toy data: -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#six steps wrapped into 1 -toy$mdev <- toy$toy - mean(toy$toy, na.rm=TRUE) -toy$mdev2 <- (toy$mdev)*(toy$mdev) -#I can save the variance calculation as an object for later use -toy_var <- sum(toy$mdev2)/(nrow(toy)-1) -#checking work with the variance function -var(toy$toy) -``` -The seventh step is to take the square root of variance. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#grabbing the mean for quick reference -mean(toy$toy) -#below the "toy_var" object was created in the prior step -sqrt(toy_var) -#checking work with the R function to calculate standard deviation -sd(toy$toy) -``` -It is common to report means and standard deviations for continuous variables in our datasets. For the toy data our mean is 2.6 with a standard deviation of 1.52. - -Let's repeat the process for the negative affect variable in the research vignette. First the six steps to calculate variance. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#six steps wrapped into 1 -df_nAff$mdevNA <- df_nAff$nAff - mean(df_nAff$nAff, na.rm=TRUE) -df_nAff$NAmd2 <- (df_nAff$mdevNA)*(df_nAff$mdevNA) -#I can save the variance calculation as an object for later use -nAff_var <- sum(df_nAff$NAmd2)/(nrow(df)-1) -#checking work with the variance function -var(df_nAff$nAff) -``` -The seventh step is to take the square root of variance. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#grabbing the mean for quick reference -mean(df_nAff$nAff) -#below the "toy_var" object was created in the prior step -sqrt(nAff_var) -#checking work with the R function to calculate standard deviation -sd(df_nAff$nAff) -``` - -In APA Style we use *M* and *SD* as abbreviations for mean and standard deviation, respectively. In APA Style, non-Greek statistical symbols such as these are italicized. Thus we would write *M* = 1.81(*SD* = 0.63) in a statistical string of results. - -We can examine the standard deviation in relation to its mean to understand how narrowly or broadly the data is distributed. Relative to a same-sized mean, a small standard deviation means that the mean represents the data well. A larger standard deviation, conveys that there is greater variability and the mean, alone, is a less valid representation of the score. - -In later lessons we will explore the standard deviation in more detail -- learning how we can use it in the determination of the significance and magnitude of relations and differences. - -## Are the Variables Normally Distributed? - -Statistics that we use are accompanied by assumptions about the nature of variables in the dataset. A common assumption is that the data are *normally distributed*. That is, the data presumes a standard normal curve. - -For a streamlined presentation, let me create a df with three, continuously scaled, variables of interest. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#I have opened the tidyverse library so that I can use the pipe -library(tidyverse) -df_3vars <- df%>%dplyr::select(nAff, mAggr, drProb) -``` - -### Skew and Kurtosis - -Skew and kurtosis are indicators of non-normality. Skew refers to the degree to which the data is symmetrical. In the figure below, the symmetrical distribution in the center (the black line) has no apparent evidence of skew. In contrast, the red figure whose curve (representing a majority of observations) in the left-most part of the graph (with the tail pulling to the right) is positively skewed; the blue figure whose curve (representing a majority of cases) is in the right-most part of the graph (with the tail pulling to the left) is negatively skewed. - - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70) , echo=FALSE} -curve(dbeta(x,10,10), xlim=c(0,1), lwd=3, yaxt="n", ylab="", xlab="", xaxt="n") -curve(dbeta(x,2, 5), add=T, col='red',lwd=3, yaxt="n", ylab="", xlab="", xaxt="n") -curve(dbeta(x,5,2), add=T, col='blue',lwd=3, yaxt="n", ylab="", xlab="", xaxt="n") -legend(par('usr')[2], par('usr')[4], xjust=1, - c('normal', 'positive skew', 'negative skew'), - lwd=c(3,3,1), lty=1, - col=c(par('fg'),'red','green')) -title("Positive, Normal, and Negative Skew") -``` -Kurtosis refers to the degree to which the distribution of data is flat or peaked. Mesokurtic distributions are considered to be closest to normal. Leptokurtic distributions are peaked and platykurtic distributions are flat. As we will learn as we progress, visual observation of data is a legitimate component in evaluating skew and kurtosis. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70) , echo=FALSE} -curve(dbeta(x,10,10), xlim=c(0,1), lwd=3, yaxt="n", ylab="", xlab="", xaxt="n") -curve(dbeta(x,5, 5), add=T, col='red',lwd=3, yaxt="n", ylab="", xlab="", xaxt="n") -curve(dbeta(x,2,2), add=T, col='blue',lwd=3, yaxt="n", ylab="", xlab="", xaxt="n") -legend(par('usr')[2], par('usr')[4], xjust=1, - c('leptokurtic', 'mesokurtic', 'platykurtic'), - lwd=c(3,3,1), lty=1, - col=c(par('fg'),'red','green')) -title("Kurtosis: Platykurtic, Mesokurtic, Leptokurtic") -``` -There have been numerous approaches to calculating and interpreting skew and kurtosis. Consequently, different statistics packages calculate skew and kurtosis differently. The *psych* package (a go-to-for a variety of tasks) offers three different options for calculating skew and kurtosis. These are specified in the script as "type=#" (i.e., 1, 2, or 3 [the default]). Revelle [-@revelle_introduction_2021] refers readers to Joanes and Gill's [-@joanes_comparing_1998] article for detailed information about each. A very helpful resource to understand skew, kurtosis, and its interpretation is found in chapter four (Data Preparation and Psychometrics Review) of Kline's [-@kline_data_2016] SEM text is helpful in the interpretation of skew and kurtosis. Summarizing by simulation studies for structural equation modeling (i.e., multivariate statistics that are generally characterized as large sample studies using maximum likelihood estimation), Kline suggested that *type=1* skew values greater than the absolute value of 3.0 are "severely" skewed. Regarding *type=1* kurtosis, Kline noted the literature has suggested that values from 8.0 to 20.0 have been described as severely kurtotic. As an interpretive framework, Kline suggested that absolute values greater than 10.0 are problematic and values greater than 20 are serious. He added that this rule-of-thumb errs on the conservative side. - -The *psych::describe* specification of "type=1" results in the *skew index* and *kurtosis index*. For simplicity sake, I will refer to this specific variation of skew and kutosis as "type=1." This is a very quick way to obtain initial values. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describe(df_3vars, type=1) -``` - -Using Kline's [-@kline_data_2016] guidelines for evaluation, a quick review of the type=1 output indicates that no skew value exceeded the absolute value of 3.0. That is, across the nAff, mAggr, and drProb variables the highest type=1 skew value was 0.93 Regarding kurtosis, no value had a greater magnitude then .59 and all fell below the absolute value of 10. A limitation of the type=1 output and Kline's interpretative guidelines is that the simulation studies that led to the interpretive guidelines were based on structural equation modeling. These statistics are multivariate in nature, they typically use maximum likelihood estimators, and are based on large samples. - -An alternative tool for identifying distributions that are severely skewed or kurtotic is the "skew.2SE" and "kurt.2SE" output from *pastecs::stat.desc*. - -These values represent the type=1 skew (or kurtosis) value divided by two-times its respective standard error (i.e., the standard error of the skew or kurtosis distribution, not the *se* value associated with the variable). The result is a standardized value that, on its own, indicates statistical significance. In the case of skew.2SE and kurt2SE, values of 1 (*p* < .05), 1.29 (*p* < .01), and 1.65 (*p* < .001) represent statistically significant departures from symmetry (skew) and normal peakedness (kurtosis). Unfortunately, this tool is not without criticism. - -$skew.2SE = \frac{S-0}{2*SE_{skewness}}$ and $kurt.2SE = \frac{S-0}{2*SE_{kurtosis}}$ - -The skew.2SE and kurt.2SE values can be obtained with *pastecs::stat.desc* by adding the "norm = TRUE" statement. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pastecs::stat.desc(df_3vars, norm=TRUE) -``` - -Statisticians have noted that these standardized values are quite sensitive to sample size [@field_discovering_2012; @kline_data_2016]. In large samples even minor deviations from normality may appear as statistically significant. In contrast, small samples with lower power may be severely non-normal, but skew and kurtosis could go undetected. When sample sizes are smaller, using the 1.96 (or "2") criteria is acceptable in determining a significant skew or kurtosis, however, as the sample size increases, the probability of rejecting the hypothesis that skew (or kurtosis) also zero increases. Field [-@field_discovering_2012] noted that in such cases it is appropriate to relax the standard and evaluate skew or kurtosis against the 1.29 (*p* < .01) criteria. Further, when samples are larger than 200, it may be more appropriate to abandon the interpretation of the *z*-values and, instead, examine the shape of the distribution rather than to interpret these standardized values. - -Comparing the skewness and kurtosis type=1 values to the skew.2SE and kurt.2SE values, we can see the interpretive challenges. - - -|Variable |skewness |skew.2SE |kurtosis |kurt.2SE -|:-----------|:--------:|:--------:|:--------:|:--------:| -|nAff |0.575 |3.141*** |-0.176 |-0.481 | -|mAggr |0.926 |5.059*** |0.575 |1.572** | -|drProb |0.783 |4.278*** |-0.168 |-0.460 | - -Values in the "skewness" column are concerning when they are exceed the absolute value of 3.0; none are. Values in the "skew.2SE" column are statistically significant at $p < .001$ when they exceed 1.65. Here, the two approaches to interpreting skew both suggest positive skew (i.e., heavy distribution in the left with a long tail to the right), but only the "skew.2SE" results suggest that the degree of skewness is significant/concerning. - -Regarding kurtosis, values in the "kurtosis" column become concerning when they exceed the absolute value of 10; none are. Values in the "kurt.2SE" become statistically significant when they exceed 1.0. The mAggr variable's value of 1.572 is statistically significant at $p < .01$. - -So how do we think about skewness and kurtosis in our data? First, I simulated a dataset with more than 700 cases. This far exceeds the "large" sample size of 200. Therefore, interpreting the type 1 skewness and kurtosis values according to Kline's [-@kline_data_2016] criteria of less than the absolute values of 3 and 10, respectively, is probably most appropriate. Further, skewness and kurtosis are only two dimensions of assessing whether or not a distribution is normally distributed. Thus, I will keep these results in mind as I examine additional metrics (especially when we look at histograms with superimposed curve). - -In this OER, I will predominantly use the type=1 output from the *psych::describe* package and use Kline's [-@kline_data_2016] interpretive criteria. I do think the "skew.2SE" and "kurt.2SE" metrics can be useful when sample sizes are smaller (perhaps $N = 100$ or less) and ordinary least squares (such as used in ANOVA and regression models) statistics will be utilized. In any case, if I have significant concerns about normality, I always return to more extensive and authoritative sources to make my decisions about preparing my data for analysis. - -### Shapiro-Wilk Test of Normality - -In addition to skew and kurtosis, there are formal statistical tests that evaluate whether or not our data is statistically significantly different than a normal distribution. One of those is the Shapiro-Wilk test of normality. The output we obtained from *pastecs::stat.desc* included the Shapiro-Wilk test value and the associated *p* value. When $p < .05$, our data is statistically significantly different from a normal distribution. - -In our simulated data, all variables were statistically significantly different than a normal distribution ($nAff: W = 0.948, p < .001; mAggr: W = 0.913, p < .001; drProb: W = 0.900, p < .001$). - -Just because data is skewed, kurtotic, or non-normally distributed does not (necessarily) mean that we cannot use it. As we move through the lessons in this OER we will evaluate the quality of the data according to the statistical assumptions associated with the statistic we are using. Often there are tools that we can use (e.g., variations of the statistic that are robust to violations of assumptions, deleting univariate or multivariate outliers) in spite of our data characteristics. - -## Relations between Variables - -Preliminary investigation of data almost always includes a report of their bivariate relations. Correlation coefficients express the magnitude of relationships on a scale ranging from -1 to +1. A correlation coefficient of - -* -1.0 implies a 1:1 inverse relationship, such that for every unit of increase in variable A, there is a similar decrease in variable B, -* 0.0 implies no correspondence between two variables, -* 1.0 implies that as A increases by one unit, so does B. - -Correlation coefficients are commonly represented in two formulas. In a manner that echoes the calculation of *variance*, the first part of the calculation estimates the covariation (i.e., *covariance*) of the two variables of interest. - -$$ -\mbox{Cov}(X,Y) = \frac{1}{N-1} \sum_{i=1}^N \left( X_i - \bar{X} \right) \left( Y_i - \bar{Y} \right) -$$ - -The problem is that the result is unstandardized and difficult to interpret. Therefore, the second part of the calculation of the correlation coefficient results in the standardization of the metric in the -1 to +1 scale. -$$ -r_{XY} = \frac{\mbox{Cov}(X,Y)}{ \hat{\sigma}_X \ \hat{\sigma}_Y} -$$ -Covariation and correlation matrices are central to many of our statistics therefore, those of who teach statistics believe that it is important to take a look "under the hood." From our research vignette, let's calculate the relationship between negative affect and psychological distress. - -Examining the first formula, some parts should look familiar: - -* $(X_i - \bar{X})$: We can see that we need to subtract the mean from the first(X) variable in involved in the correlation; we saw this when we calculated *mean deviations*. -* $(Y_i - \bar{Y})$: We repeat the *mean deviation* process for the second (Y) variable. - -Let's work step-by-step through the calculation of a correlation coefficient. So that we can more easily see what we are doing with the variables, I will create a super tiny dataframe with the two variables of interest (negative affect and microaggressions): - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#just in case it turned off, I'm reopening tidyverse so that I can use the pipe -library(tidyverse) -#using the dplyr package to select the two variables in this tiny df -df4corr <- df%>%dplyr::select(nAff, mAggr) -#displaying the first 6 rows of df4corr ("dataframe for correlations" -- I made this up) -head(df4corr) -``` - -First we calculate the mean deviations for negative affect and microaggressions. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#calculating the mean deviation for negative affect -df4corr$MDnAff <- df4corr$nAff - mean(df4corr$nAff) -#calculating the mean deviation for microaggressions -df4corr$MDmAggr <- df4corr$mAggr - mean(df4corr$mAggr) -#displaying the first 6 rows of df4corr -head(df4corr) -``` -The next part of the formula $\sum_{i=1}^N \left( X_i - \bar{X} \right) \left( Y_i - \bar{Y} \right)$ suggests that we sum the cross-products of these mean deviations. Here we multiply the mean deviations to create the "cross-product." - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Creating a crossproduct variabl by multiplying negative affect by psych distress -df4corr$crossproductXY <- df4corr$MDnAff * df4corr$MDmAggr -#displaying the first 6 rows of df4corr -head(df4corr) -``` -Next, we sum the column of cross-products. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -sum(df4corr$crossproductXY) -``` -To obtain the covariance, the next part of the formula suggests that we multiply the sum of cross-products by $\frac{1}{N-1}$. I will do this in one step. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#I have created the object "cov" so I can use it in a calculation, later -#The "nrow" function will count the number of rows and use that value -cov <- 1/(nrow(df4corr) - 1)* sum(df4corr$crossproductXY) -#Because I created an object, R markdown won't automatically display it; I have to request it by listing it -cov -``` -The covariance between negative affect and psychological distress is 0.373. - -We now move to the second part of the formula to create the interpretable, standardized, correlation coefficient. - -$$ -r_{XY} = \frac{\mbox{Cov}(X,Y)}{ \hat{\sigma}_X \ \hat{\sigma}_Y} -$$ -We will use our covariance value in the numerator. The denominator involves the multiplication of the standard deviations of X and Y. Because we have already learned how to calculate standard deviation in a step-by-step manner, I will use code to simplify that process: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -cov/(sd(df4corr$nAff)*sd(df4corr$mAggr)) -``` -Our results suggest that the relationship between negative affect and psychological distress is positive, as one increases so does the other. Is it strong? This really depends on your field of scholarship. The traditional values of .10, .30, and .50 are interpreted as small, medium, and large [@cohen_applied_2003]. Hence, when *r* = 0.27, we can say that it is (more-or-less) medium. - -Is it statistically significant? Because this is an introductory chapter, we will not calculate this in a stepwise manner, but use the *cor.test()* function in base R to check our prior math and retrieve the *p* value associated with the correlation coefficient. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -cor.test(df4corr$nAff, df4corr$mAggr) -``` -In a statistical string we would report the result of this Pearson correlation coefficient as: *r* = 0.27 (*p* < .001). - -## Shortcuts to Preliminary Analyses - -Unless you teach statistics (or take another statistics class), you may never need to work through all those individual steps again. Rather, a number of R packages make retrieval of these values relatively simple and efficient. - -### SPLOM - -The *pairs.panels()* function in the *psych* package produces a SPLOM (i.e., scatterplot matrix) which includes: - -* histograms of each individual variable within the dataframe with a curve superimposed (located on the diagonal), -* scatterplots of each bivariate combination of variables (located below the diagonal), and -* corrrelation coefficients of each bivariate combination of variables (located above the diagonal). - -To provide a simple demonstration this, I will use our df with the three continuously scaled variables of interest: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#in the code below, psych points to the package -#pairs.panels points to the function -#we simply add the name of the df; if you want fewer variables than that are in the df, you may wish to create a smaller df -#adding the pch command is optional and produces a finer resolution -psych::pairs.panels(df_3vars, pch = ".") -``` -What do we observe? - -* There is a more-or-less moderate correlation between negative affect and microaggressions ($r = 0.27$) -* There is a small-to-moderate correlation between negative affect and drinking problems ($r = 0.18$) -* There is a small correlation between microaggressions and drinking problems ($r = 0.09$) -* All variables have a positive skew (with pile-up of scores on the lower end and tail pulling to the right); this is consistent with the values we calculated earlier -* The scatterplots can provide clues to relations that are not necessarily linear. - - Look at the relationship between negative affect and drinking problems. As negative affect hits around 2.75, there is a change in the relationship, such that drinking problems increase. - - Taking time to look at plots such as these can inform subsequent analyses. - -### apaTables - -Writing up an APA style results section frequently involves tables. A helpful package for doing this is *apaTables*. An instructional article notes the contributions of tools like this to the *reproducibility* of science by reducing errors made when the author or analyst retypes or copies text from output to the manuscript. When the R script is shared through an open science framework, reproducibility is further enhanced [@stanley_reproducible_2018]. - -We pass the desired df to the *apaTables::apa.cor.table*. Commands allow us to specify what is included in the table and whether it should be displayed in the console or saved as a document to the project's folder. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#the apa.cor.table function removes any categorical variables that might be in the df -Table1_Cor <- apaTables::apa.cor.table(df_3vars, filename = "Table1_Cor.doc", table.number = 1, show.conf.interval = FALSE, landscape = TRUE) - -#swap in this command to see it in the R Markdown file -print(Table1_Cor) -``` -Because I added: *filename = "Table1_Cor.doc"*, a word version of the table will appear in the same file folder as the .rmd file and data. It is easily manipulated with tools in your word processing package. - - -## An APA Style Writeup - -The statistics used in this lesson are often presented in the preliminary results portion of an empirical manuscript. Some of the results are written in text and some are presented in tables. APA Style recommends that the narration of results not duplicate what is presented in the tables. Rather, the write-up only highlights and clarifies what is presented in the table(s). - -At the outset, let me note that a primary purpose of the Lui [-@lui_racial_2020] article was to compare the relations of variables between three racial/ethic groups in the U.S. identified as Asian American, Black, and Latinx. Because we did not run separate analyses for each of the groups, my write-up does not make these distinctions. I highly recommend that you examine the write-up of results and the accompanying tables in Lui's article. The presentation is clear and efficient (i.e., it conveys maximal information in as little space as possible). - -Below is an example of how I might write up these preliminary results: - -**Preliminary Results** - ->Our sample included 713 participants who self-identified as Asian American, Black/African American, and Latinx American. Inspection of the characteristics of the three variables of interest (negative affect, microaggressions, drinking problems) indicated that all variables were positively skewed, however the values of skew and kurtosis did not exceed commonly used thressholds of concern [@kline_data_2016]. In contrast, Shapiro-Wilk tests of normality suggested that the distribution of all three variables were statistically significantly different than a normal distribution ($nAff: W = 0.948, p < .001$; $mAggr: W = 0.913, p < .001$; $drProb: W = 0.900, p < .001$). Means, standard deviations, and a correlation matrix are presented in Table 1. We noted that the correlation between negative affect and microaggressions was moderate $(r = 0.27)$; correlations between remaining variables were smaller. - -## Practice Problems - -The three exercises described below are designed to "meet you where you are" and allow you to challenge your skills depending on your goals as well as your comfort with statistics and R. - -Regardless which you choose, work one or more of the problems with R packages: - -* Create a smaller df from a larger df selecting a minimum of three continuously scaled variables -* Calculate and interpret descriptive statistics -* Create the SPLOM (pairs.panels) -* Use the *apaTables* package to make an APA style table with means, standard deviations, and correlations -* Write an APA Style results section for these preliminary analyses - -Additionally, please complete at least one set of *hand calculations*, that is using the code demonstrated in the chapter to work through the formulas that compute the descriptive statistics that are the focus of this lesson. At this stage in your learning, you may ignore any missingness in your dataset by excluding all rows with missing data in your variables of interest. - -### Problem #1: Change the Random Seed - -If this topic feels a bit overwhelming, simply change the random seed in the data simulation (at the very top), then rework the lesson exactly as written. This should provide minor changes to the data (maybe in the second or third decimal point), but the results will likely be very similar. - -### Problem #2: Swap Variables in the Simulation - -Use the simulated data from the Lui [-@lui_racial_2020] study. However, select three continuous variables (2 must be different from mine) and then conduct the analyses. Be sure to select from the variables that are considered to be *continuous* (and not *categorical*). - -### Problem #3: Use (or Simulate) Your Own Data - -Use data for which you have permission and access. This could be IRB approved data you have collected or from your lab; data you simulate from a published article; data from an open science repository; or data from other chapters in this OER. - -### Grading Rubrics - -Regardless which option(s) you chose, use the elements in the grading rubrics to guide you through the practice. Worked examples are provided in the [Appendix]({#woRked}). - - -|Working the problem with R and R packages | Points Poss | Points Earned -|:-----------------------------------------|:-------------:|:--------------| -|1. Create a df with 3 continuously scaled variables of interest| 3 |_______| -|2. Produce descriptive statistics | 3 | _______ -|3. Produce SPLOM/pairs.panels | 3 | _______| -|4. Produce an apaTables matrix | 3 | _______| -|5. Produce an APA Style write-up of the preliminary analyses| 5 | _______| -|6. Explanation/discussion with a grader | 5 |_______| -|**Totals | 22 | _______| - -|Hand Calculations | Points Possible | Points Earned -|:-----------------------------------------|:---------------:|:--------------| -|1. Create a variable that represents the mean.| 2 | _______| -|2. Create a variable that represents the mean deviation. | 2 |_______ | -|3. What is the value of the *sum* of mean deviations? |2 |_______ | -|4. Create a variable that represents the absolute mean deviation. What is the *sum* of the absolute mean deviation? What is the value of the *mean* of the absolute mean deviation? What does this value tell you?| 4 |_______| -|5. Create a variable that represents the mean deviation squared. | 2 | _______| -|6. What are the values of the sum of squared deviations around the mean $SS$, variance $s^2$, and standard deviation ($s$)? |3 |_______ | -|7. Using the same general approach, calculate the mean deviation and standard deviation for a second, continuously scaled variable. | 5 |_______ | -|8. Create a variable that represents the *cross-product* (of the mean deviations). What is the sum of these cross-products? |2 |_______ | -|9. Calculate the value of their covariance. |2 |_______ | -|8. Calculate value of correlation coefficient. |2 |_______ | -|**Totals** | 26 |_______ | - - - -```{r, child= 'Worked_Examples/15-2-woRked_Preliminaries.Rmd'} -``` - -```{r include=FALSE} -sessionInfo() -``` - - diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/0D3540CF-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/0D3540CF-contents deleted file mode 100644 index 278db253..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/0D3540CF-contents +++ /dev/null @@ -1,297 +0,0 @@ -```{r include = FALSE} -options(scipen=999) -``` -## Homeworked Example - -[Screencast Link](https://youtu.be/9pJtCXceht4) - -For more information about the data used in this homeworked example, please refer to the description and codebook located at the end of the [introduction](ReCintro). - -### Working the Problem with R and R Packages - -#### Narrate the research vignette, describing the variables and their role in the analysis {-} - -I want to ask the question, "Do students' evaluations of traditional pedagogy (TradPed) change from ANOVA (the first course in the series) to Multivariate (the second course in the series)?." Unlike the independent samples *t*-test where we compared students in two different departments, we are comparing *the same* students across two different conditions. In this particular analysis, there is also an element of time. That is the ANOVA class always precedes the multivariate class (with a regression class, taught by a different instructor) in the intervening academic quarter. - -This research design has some clear limitations. Threats to internal validity are caused by issues like history and maturation. None-the-less, for the purpose of a statistical demonstration, this dataset works. - -*If you wanted to use this example and dataset as a basis for a homework assignment, you could compare a different combination of courses and/or score one of the other course evaluation subscales (e.g., socially responsive pedagogy or valued-by-me). * - -Like most data, some manipulation is required before we can begin the analyses. - -#### Simulate (or import) and format data {-} - -Let's import the larger dataset. -```{r} -larger <- readRDS("ReC.rds") -``` - -The TradPed (traditional pedagogy) variable is an average of the items on that scale. I will first create that variable. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Creates a list of the variables that belong to that scale -TradPed_vars <- c('ClearResponsibilities', 'EffectiveAnswers','Feedback', 'ClearOrganization','ClearPresentation') - -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -larger$TradPed <- sjstats::mean_n(larger[, ..TradPed_vars], .75) - -``` - -From the "larger" data, let's select only the variable we will use in the analysis. I have included "long" in the filename because the structure of the dataset is that course evaluation by each student is in its own row. That is, each student could have up to three rows of data. - -We need both "long" and "wide" forms to conduct the analyses required for both testing the statistical assumptions and performing the paired samples *t*-test. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -paired_long <-(dplyr::select (larger, deID, Course, TradPed)) -``` - -From that reduced variable set, let's create a subset with students only from those two courses. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -paired_long <- subset(paired_long, Course == "ANOVA" | Course == "Multivariate") -``` - -Regarding the structure of the data, we want the conditions (ANOVA, multivariate) to be factors and the TradPed variable to be continuously scaled. The format of the deID variable can be any numerical or categorical format -- just not a "chr" (character) variable. - -```{r} -str(paired_long) -``` -R correctly interpreted our variables. - -For analyzing the assumptions associated with the paired-samples *t*-test, the format needs to be "wide" form (where each student has both observations on one row). Our data is presently in "long" form (where each observation is listed in each row). Here's how to reshape the data. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -paired_wide <- reshape2::dcast(data = paired_long, formula =deID ~ Course, value.var = "TradPed") -``` - -Let's recheck the structure. -```{r} -str(paired_wide) -``` -You will notice that there is a good deal of missingness in the Multivariate condition. This is caused because the most recent cohort of students had not yet taken the course. While managing missingness is more complex than this, for the sake of simplicity, I will create a dataframe with non-missing data. - -Doing so should also help with the hand-calculations later in the worked example. - -```{r} -paired_wide <- na.omit(paired_wide) -``` - -#### Evaluate statistical assumptions {-} - -We need to evaluate the *distribution of the difference score* in terms of skew and kurtosis. We want this distribution of difference scores to be normally distributed. - -This means we need to create a difference score: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -paired_wide$DIFF <- paired_wide$ANOVA - paired_wide$Multivariate -``` - -We can use the *psych::describe()* function to obtain skew and kurtosis. -```{r} -psych::describe(paired_wide) -``` - -Regarding the DIFF score, the skew (0.56) and kurtosis (3.15) values were well below the threshholds of concern identified by Klein (2016). - -We can formally test for deviations from normality with a Shapiro-Wilk. We want the results to be non-significant. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::shapiro_test(paired_wide, DIFF) -``` -Results of the Shapiro-Wilk test of normality are statistically significant $(W = 0.943, p = 0.002)$. This means that the distribution of difference scores are statistically significantly different from a normal distribution. - -Although not required in the formal test of instructions, a *pairs panel* of correlations and distributions can be useful in undersatnding our data. - -```{r} -psych::pairs.panels(paired_wide) -``` -Visual inspection of the distributions of the specific course variables were negatively skewed, with values clustered at the high end of the course evaluation ratings. However, the distribution for the DIFF variable seems relatively normal (although maybe a bit leptokurtic). This is consistent with the statistically significant Shapiro-Wilk test. - -Before moving forward, I want to capture my analysis of assumptions: - ->We began by analyzing the data to see if it met the statistical assumptions for analysis with a paired samples t-test. Regarding the assumption of normality, the skew (0.56) and kurtosis (3.15) values associated with the difference between conditions (ANOVA and multivariate) were below the threshholds of concern identified by Klein (2016). In contrast, results of the Shapiro-Wilk test of normality suggested that the distribution of difference scores was statistically significantly different than a normal distribution $(W = 0.943, p = 0.002)$. - -#### Conduct a paired samples t-test (with an effect size & 95% CIs) {-} - -So this may be a bit tricky, but our original "long" form of the data has more ANOVA evaluations (students who had taken ANOVA had not yet taken multivariate) than multivariate. The paired samples *t* test requires the design to be balanced. When we used the *na.omit()* function with the wide case, we effectively balanced the design, eliminating students who lacked observations across both courses. Let's restructure that wide format back to long format so that the design will be balanced. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -paired_long2 <- data.table::melt(data.table::setDT(paired_wide), id.vars = c("deID"), measure.vars = list(c("ANOVA", "Multivariate"))) - -paired_long2 <- dplyr::rename(paired_long2, Course = variable, TradPed = value) - -head(paired_long2) -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::t_test(paired_long2, TradPed ~ Course, paired = TRUE, detailed = TRUE) -``` - -I'll begin the *t* string with this output: $t(76) = -1.341, p = 0.184, CI95(-0.305, 0.069)$. The difference in course evaluations is not statistically significantly difference. We are 955 confident that the true difference in means is as low as -0.301 or as high as 0.060. - -We calculate the Cohen's *d* (the effect size) this way: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::cohens_d(paired_long2, TradPed ~ Course, paired = TRUE) -``` -The value of -0.153 is quite small. We can add this value to our statistical string: $t(76) = -1.341, p = 0.184, CI95(-0.305, 0.069), d = -0.153$ - -#### APA style results with table(s) and figure {-} - ->A paired samples *t*-test was conducted to evaluate the hypohtesis that there would be statistically significant differences in students' course evaluations of ANOVA and multivariate statistics classses. - ->We began by analyzing the data to see if it met the statistical assumptions for analysis with a paired samples t-test. Regarding the assumption of normality, the skew (0.56) and kurtosis (3.15) values associated with the difference between conditions (ANOVA and multivariate) were below the threshholds of concern identified by Klein (2016). In contrast, results of the Shapiro-Wilk test of normality suggested that the distribution of difference scores was statistically significantly different than a normal distribution $(W=0.943, p = 0.002) - ->Results of the paired samples *t*-test suggested nonsignificant differences $t(76) = -1.341, p = 0.184,d = -0.153$. The 95% confidence interval crossed zero, ranging from -0.305 to 0.069. Means and standard deviations are presented in Table 1 and illustrated in Figure 1. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) #needed to use the pipe -# Creating a smaller df to include only the variables I want in the -# table -Descripts_paired <- paired_wide %>% - select(ANOVA, Multivariate, DIFF) -# using the apa.cor.table function for means, standard deviations, -# and correlations the filename command will write the table as a -# word document to your file -apaTables::apa.cor.table(Descripts_paired, table.number = 1, filename = "Tab1_PairedT.doc") -``` -For the figure, let's re-run the paired samples *t* test, save it as an object, and use the "add_significance" function so that we can add it to our figure. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -paired_T <- rstatix::t_test(paired_long2, TradPed ~ Course, paired = TRUE, detailed = TRUE)%>% - rstatix::add_significance() -paired_T -``` -Next, we create boxplot: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pairT.box <- ggpubr::ggpaired(paired_long2, x = "Course", y = "TradPed", order = c("ANOVA", - "Multivariate"), line.color = "gray", palette = c("npg"), color = "Course", - ylab = "Traditional Pedagogy", xlab = "Statistics Course", title = "Figure 1. Evaluation of Traditional Pedagogy as a Function of Course") - -paired_T <- paired_T %>% - rstatix::add_xy_position(x = "Course") #autocomputes p-value labels positions - -pairT.box <- pairT.box + ggpubr::stat_pvalue_manual(paired_T, tip.length = 0.02, y.position = c(5.5)) + labs(subtitle = rstatix::get_test_label(paired_T, detailed = TRUE)) - -pairT.box -``` - -#### Conduct power analyses to determine the power of the current study and a recommended sample size {-} - -Script for estimating current power: - -* d is Cohen's *d* -* n is number of pairs, but set to NULL if we want to estimate sample size -* power is conventionally set at .80, but left at NULL when we want to estimate power -* sig.level is conventionlaly set at 0.05 -* type indicates the type of *t*-test; in this example it is "paired" -* alternative indicates one or two.sided - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.t.test(d=-0.153, n = 77, power=NULL, sig.level=0.05, type="paired", alternative="two.sided") -``` -We had a 26% chance of finding a statistically significant result if, in fact, one existed. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.t.test(d=-0.153,n = NULL, power=.80,sig.level=0.05,type="paired",alternative="two.sided") -``` -If we presumed power were at 80%, we would need a sample size of 337. - -### Hand Calculations - -For these hand calculations I will used the "paired_wide" dataframe that we had prepared for the homework assignment intended for R and R packages. - -#### Using traditional NHST (null hypothesis testing language), state your null and alternative hypotheses {-} - -The null hypotheses states that the true difference in means is zero. -$H_{O}: \mu _{D} = 0$ - -The alternative hypothesis states that the true difference in means is not zero. -$H_{A}: \mu _{D}\neq 0$ - -#### Using an R package or functions in base R (and with data in the "wide" format), calculate the *difference* score between the two observations of the dependent variable {-} - -We had already calculated a difference score in the earlier assignment. Here it is again. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -paired_wide$DIFF <- paired_wide$ANOVA - paired_wide$Multivariate -``` - - -#### Obtain the mean and standard deviation of the *difference* score {-} - -We can obtain the mean and standard deviation for the difference score with this script. - -```{r} -psych::describe(paired_wide$DIFF) -``` - -The mean difference ($\bar{D}$) is -0.12; the standard deviation ($\hat\sigma_D$) of the difference score is 0.8. - -#### Calculate the paired samples *t*-test {-} - -Here is the formula for the paired samples *t*-test: - -$$t = \frac{\bar{D}}{\hat\sigma_D / \sqrt{N}}$$ -Using the values we located we can calculate the value of the *t* statistic. - - -```{r} --0.12/(0.8/sqrt(77)) -``` -The value we calculated with the *rstatix::t_test()* function was -1.34. Considering rounding error, I think we got it! - -#### Identify the degrees of freedom associated with your paired samples *t*-test {-} - -We have 77 pairs. The degrees of freedom for the paired samples *t*-test is $N - 1$. Therefore, df = 76. - -#### Locate the test critical value for your paired samples *t*-test {-} - -I could look at the [table of critical values](https://www.statology.org/t-distribution-table/) for the *t*-distribution. Because I have non-directional hypotheses, I would use the column for a *p*-value of .05 for a two-tailed test. I roll down to the closest sample size (I'll pick 60). This suggests that my *t*-test statistic would need to be greater than 2.0 in order to be statistically significant. - -I can also use the *qt()* function in base R. This function requires that I specify the alpha level (0.05), whether the test is one- or two-tailed (2), and my degrees of freedom (76). Specifying "TRUE" and "FALSE" after the lower.tail command gives the positive and negative regions of rejection. - -```{r} -qt(0.05/2, 76, lower.tail = TRUE) -qt(0.05/2, 76, lower.tail = FALSE) -``` -It is not surprising that these values are a smidge lower than 2.0. Why? Because in the table we stopped at df of 60, when it is actually 76. - -#### Is the paired samples *t*-test statistically significant? Why or why not? {-} - -The paired samples *t*-test is not statistically significant because the *t*-value of -1.316245 does not exceed -1.992. - -#### What is the confidence interval around the mean difference? {-} - -Here is the formula for hand-calculating the confidence interval. - -$$\bar{D}\pm t_{cv}(s_{d}/\sqrt{n})$$ - -* $\bar{D}$ the mean difference score -* $t_{cv}$ the test critical value for a two-tailed model (even if the hypothesis was one-tailed) where $\alpha = .05$ and the degrees of freedom are $N-1$ -* $s_{d}$ the standard deviation of $\bar{D}$ -* $N$ sample size - -Let's calculate it: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} --0.12-(-1.991673*((0.8/(sqrt(77))))) --0.12+(-1.991673*((0.8/sqrt(77)))) -``` -These values indicate the range of scores in which we are 95% confident that our true $\bar{D}$ lies. Stated another way, we are 95% confident that the true mean difference lies between -0.302 and 0.062. Because this interval crosses zero, we cannot rule out that the true mean difference is 0.00. This result is consistent with our non-significant *p* value. For these types of statistics, the 95% confidence interval and *p* value will always be yoked together. - -#### Calculate the effect size (i.e., Cohen's *d* associated with your paired samples *t*-test {-} - -Cohen's *d* measures, in standard deviation units, the distance between the two means. Regardless of sign, values of .2, .5, and .8 are considered to be small, medium, and large, respectively. - -Because the paired samples *t*-test used the difference score in the numerator, there are two easy options for calculating this effect: - -$$d=\frac{\bar{D}}{\hat\sigma_D}=\frac{t}{\sqrt{N}}$$ -Here's a demonstration of both: - -```{r} --0.12/.8 --1.316245/sqrt(77) -``` - -#### Assemble the results into a statistical string {-} - -$t(76) = -1.316, p > .05, CI95(-0.302, 0.062), d = -0.15$ diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/1791852A-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/1791852A-contents deleted file mode 100644 index a7b1367c..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/1791852A-contents +++ /dev/null @@ -1,320 +0,0 @@ -# Examples for Follow-up to Factorial ANOVA {-} - -```{r include=FALSE} -knitr::opts_chunk$set(echo = TRUE) -knitr::opts_chunk$set(comment = NA) #keeps out the hashtags in the knits -options(scipen=999)#eliminates scientific notation -``` - -As noted in the lesson on [factorial ANOVA](#between), the options for follow-up to a significant interaction effect are infinite. In order to maintain a streamlined chapter with minimal distractions to student learning (through numerous examples and changes in R packages), I have moved examples of some these variations to this section. - -As a quick reminder, I will describe and re-simulate the data. The narration will presume familiarity with the [factorial ANOVA](#between) lesson. - -## Research Vignette {-} - -The research vignette for this example was located in Kalimantan, Indonesia and focused on bias in young people from three ethnic groups. The Madurese and Dayaknese groups were engaged in ethnic conflict that spanned 1996 to 2001. The last incidence of mass violence was in 2001 where approximately 500 people (mostly from the Madurese ethnic group) were expelled from the province. Ramdhani et al.'s [-@ramdhani_affective_2018] research hypotheses were based on the roles of the three ethnic groups in the study. The Madurese appear to be viewed as the transgressors when they occupied lands and took employment and business opportunities from the Dayaknese. Ramdhani et al. also included a third group who were not involved in the conflict (Javanese). The research participants were students studying in Yogyakara who were not involved in the conflict. They included 39 Madurese, 35 Dyaknese, and 37 Javanese; 83 were male and 28 were female. - -In the study [@ramdhani_affective_2018], participants viewed facial pictures of three men and three women (in traditional dress) from each ethnic group (6 photos per ethnic group). Participant were asked, "How do you feel when you see this photo? Please indicate your answers based on your actual feelings." Participants responded on a 7-point Likert scale ranging from 1 (*strongly disagree*) to 7 (*strongly agree*). Higher scores indicated ratings of higher intensity on that scale. The two scales included the following words: - -* Positive: friendly, kind, helpful, happy -* Negative: disgusting, suspicious, hateful, angry - -### Quick Resimulating of the Data {-} - -Below is script to simulate data for the negative reactions variable from the information available from the manuscript [@ramdhani_affective_2018]. If you would like more information about the details of this simulation, please visit the lesson on [factorial ANOVA](#between). - -```{r message = FALSE, warning = FALSE, tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -set.seed(210731) -#sample size, M and SD for each cell; this will put it in a long file -Negative<-round(c(rnorm(17,mean=1.91,sd=0.73),rnorm(18,mean=3.16,sd=0.19),rnorm(19, mean=3.3, sd=1.05), rnorm(20, mean=3.00, sd=1.07), rnorm(18, mean=2.64, sd=0.95), rnorm(19, mean=2.99, sd=0.80)),3) -#sample size, M and SD for each cell; this will put it in a long file -Positive<-round(c(rnorm(17,mean=4.99,sd=1.38),rnorm(18,mean=3.83,sd=1.13),rnorm(19, mean=4.2, sd=0.82), rnorm(20, mean=4.19, sd=0.91), rnorm(18, mean=4.17, sd=0.60), rnorm(19, mean=3.26, sd=0.94)),3) -ID <- factor(seq(1,111)) -Rater <- c(rep("Dayaknese",35), rep("Madurese", 39), rep ("Javanese", 37)) -Photo <- c(rep("Dayaknese", 17), rep("Madurese", 18), rep("Dayaknese", 19), rep("Madurese", 20), rep("Dayaknese", 18), rep("Madurese", 19)) -#groups the 3 variables into a single df: ID#, DV, condition -Ramdhani_df<- data.frame(ID, Negative, Positive, Rater, Photo) - -Ramdhani_df[,'Rater'] <- as.factor(Ramdhani_df[,'Rater']) -Ramdhani_df[,'Photo'] <- as.factor(Ramdhani_df[,'Photo']) -``` - -If you want to export this data as a file to your computer, remove the hashtags to save it (and re-import it) as a .csv ("Excel lite") or .rds (R object) file. This is not a necessary step. - -The code for .csv will likely lose the formatting (i.e., making the Rater and Photo variables factors), but it is easy to view in Excel. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#write the simulated data as a .csv -#write.table(Ramdhani_df, file="RamdhaniCSV.csv", sep=",", col.names=TRUE, row.names=FALSE) -#bring back the simulated dat from a .csv file -#Ramdhani_df <- read.csv ("RamdhaniCSV.csv", header = TRUE) -#str(Ramdhani_df) -``` - -The code for the .rds file will retain the formatting of the variables, but is not easy to view outside of R. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#to save the df as an .rds (think "R object") file on your computer; it should save in the same file as the .rmd file you are working with -#saveRDS(Ramdhani_df, "Ramdhani_RDS.rds") -#bring back the simulated dat from an .rds file -#Ramdhani_df <- readRDS("Ramdhani_RDS.rds") -#str(Ramdhani_RDS) -``` - - -## Analysis of Simple Main Effects with Orthogonal Contrasts {-} - -This example follows a significant interaction effect. Specifically, we will analyze the effects of ethnicity of rater (three levels) within photo stimulus (two levels). We will conduct two one-way ANOVAs for the Dayaknese and Madurese photos, separately. In this example, we will utilize orthogonal contrast-coding for rater ethnicity. - -In the lesson on [factorial ANOVA](#between) I used the *rstatix* package. I am not aware of a way to do this type of analysis in *rstatix*, therefore this worked example will use functions from base R. - -This is our place on the ANOVA workflow. - -![Image our place in the Two-Way ANOVA Workflow -- analysis of simple main effects of factor A within levels of factor B with orthogonal contrasts](images/factorial/WrkFlw_IntORTH.jpg) - -Among the requirements for orthogonal contrasts are these critical ones: - -* there be one fewer contrast than the number of groups, (i.e., *k* -1), and -* once a group is singled out, it cannot be compared again. - -Thus, with a limit of two contrasts I want to compare the - -* Javanese to the Dayaknese and Madurese combined (asking, "Do the Javanese evaluations of the photo differ from the combined Dyaknese/Madurese evaluations?"), then -* Dayaknese to Madurese (asking, "Do the Dayknese and Madurese evaluations of the photos differ from each other?") - -Such contrasts should be theoretically or rationally defensible. In the case of none, low, and high dose intervention/exposure designs this is an easy requirement to meet. Typically, the no-dose is compared to the combined low and high dosage conditions. Then the low and high dosage conditions are compared. I would argue that because the Javanese were observers to the conflict, we can single them out in the first contrast, then compare the two groups who were directly involved in the conflict. - -It helps to know what the default contrast codes are; we can get that information with the *contrasts()* function. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -contrasts(Ramdhani_df$Rater) -``` - -Next, we set up the contrast conditions. In the code below, - -* c1 indicates that the Javanese (noted as -2) are compared to the Dayaknese (1) and Madurese (1) -* c2 indicates that the Dayaknese (-1) and Madurese (1) are compared; Javanese (0) is removed from the contrast. - -```{r message=FALSE, warning=FALSE, tidy=TRUE, tidy.opts=list(width.cutoff=70)} -# tell R which groups to compare -c1 <- c(1, -2, 1) -c2 <- c(-1, 0, 1) -mat <- cbind(c1,c2) #combine the above bits -contrasts(Ramdhani_df$Rater) <- mat # attach the contrasts to the variable -``` - -This allows us to recheck the contrasts. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -contrasts (Ramdhani_df$Rater) -``` -With this output we can confirm that, in contrast 1 (the first column) we are comparing the Javanese to the combined Dayaknese and Madurese. In contrast 2 (the second column) we are comparing the Dayaknese to the Madurese. - -We will conduct these contrasts with one group at a time. First, we must create a subset of all observations of the Dayaknese photo: - -```{r message=FALSE, warning=FALSE, tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#subset data -Dayaknese_Ph <- subset(Ramdhani_df, Photo == "Dayaknese") -``` - -Next we use the *aov()* function from base R for the one-way ANOVA. Like magic, the contrast that we specified is assigned to the Rater variable. We can apply the *summary()* function to the *aov()* object that we created to see the results. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -Dykn_simple <- aov(Negative ~ Rater, data = Dayaknese_Ph) -summary(Dykn_simple) -``` - -We can apply the *etaSquared()* function from the *lsr* package to retrieve an $\eta^2$. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#effect size for simple main effect can add "type = 1,2,3,4" to correspond with the ANOVA that was run -lsr::etaSquared(Dykn_simple, anova = FALSE ) -``` - -We can capture the *F* string from this output: *F* [2, 51]) = 13.32, *p* < .001, $\eta ^{2}$ = 0.343. - -This code produces the contrasts we specified. Note that in our code we can improve the interpretability of the output by adding labels. We know the specific contrasts from our prior work. - -```{r message=FALSE, warning=FALSE, tidy=TRUE, tidy.opts=list(width.cutoff=70)} -summary.aov(Dykn_simple, split=list(Rater=list("Javanese v Dayaknese and Madurese"=1, "Dayaknese Madurese" = 2))) -``` -An APA style reporting of results-so-far might look like this - ->The simple main effect evaluating differences between rater ethnicity when evaluating photos of Dayaknese ethnic group was statistically significant: $F(2, 5)1 = 13.32, p < .001, \eta ^{2} = 0.343$. Follow-up testing indicated non-significant differences when the ratings from members of the Javanese ethnic group were compared to the Dayaknese and Madurese, combined $(F [1, 51] = 0.095, p = .759)$. There was a statistically significant difference when Dayaknese and Madurese raters were compared $(F [1, 51] =26.554, p < .001)$. - -We repeat the simple main effect process for evaluation of the Madurese photos. - -```{r message=FALSE, warning=FALSE, tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#subset data -Madurese_Ph <- subset(Ramdhani_df, Photo == "Madurese") -#change df to subset, new model name -Mdrs_simple <- aov(Negative ~ Rater, data = Madurese_Ph) -#output for simple main effect -summary(Mdrs_simple) -#effect size for simple main effect can add "type = 1,2,3,4" to correspond with the ANOVA that was run -lsr::etaSquared(Mdrs_simple, anova = FALSE ) -``` -Let's capture the *F* string for ratings of the Madurese photos: $F(2, 54) = 0.679, p = .512, \eta ^{2} = 0.024$. - -We can use the procedure described above to obtain our orthogonal contrasts. - -```{r message=FALSE, warning=FALSE, tidy=TRUE, tidy.opts=list(width.cutoff=70)} -summary.aov(Mdrs_simple, split=list(Rater=list("Javanese v Dayaknese and Madurese"=1, "Dayaknese Madurese" = 2))) -``` -Here's a write-up of this portion of the result. - ->The simple main effect evaluating differences between rater ethnicity when evaluating photos of Madurese ethnic group was not statistically significant: $F(2, 54) = 0.679, p = .512, \eta ^{2} = 0.024$. Correspondingly, follow-up testing indicated non-significant differences when the ratings of the Javanese were compared to Dayaknese and Madurese, combined $(F[1, 54] = 1.008, p = .320)$ and when the ratings of the Dayaknese and Madurese were compared $(F[1, 54] = 0.349, p = .557)$ - -In this series of analyses we did not have an opportunity to "let R manage Type I error for us." Therefore, we will need to do it manually. We had 4 follow-up contrasts (2 for Dayaknese, 2 for Madurese). Using a traditional Bonferroni we could control Type I error with .05/4 = .0125 - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -.05/4 -``` - -**APA Write-up of the simple main effect of photo stimulus within rater ethnicity.** - -This would be added to the write-up of the omnibus two-way ANOVA test. - ->To explore the interaction effect, we followed with tests of simple effect of rater ethnicity within the photo stimulus. That is, we examined the effect of each each rater's ethnicity within the Madurese and Dayaknese photo stimulus, separately. Our first analysis evaluated the effect of the rater's ethnicity when evaluating the Dayaknese photo; our second analysis evaluated effect of the rater's ethnicity when evaluating the Madurese photo. To control for Type I error across the two simple main effects, we set alpha at .0125 (.05/4). The simple main effect evaluating differences between rater ethnicity when evaluating photos of Dayaknese ethnic group was statistically significant: $F(2, 51) = 13.32, p < .001, \eta ^{2} = 0.343$. Follow-up testing indicated non-significant differences when the ratings from members of the Javanese ethnic group were compared to the Dayaknese and Madurese, combined $(F [1, 51] = 0.095, p = .759)$. There was a statistically significant difference when Dayaknese and Madurese raters were compared $(F [1, 51] =26.554, p < .001)$. The simple main effect evaluating differences between rater ethnicity when evaluating photos of Madurese ethnic group was not statistically significant: $F(2, 54) = 0.679, p = .512, \eta ^{2} = 0.024$. Correspondingly, follow-up testing indicated non-significant differences when the ratings of the Javanese were compared to Dayaknese and Madurese, combined $(F[1, 54] = 1.008, p = .320)$ and when the ratings of the Dayaknese and Madurese were compared $(F[1, 54] = 0.349, p = .557)$. This moderating effect of ethnicity of the rater on the negative reaction to the photo stimulus is illustrated in Figure 1. - -I am not aware of an integration of packages that would represent this type of orthogonal contrast in a figure. Therefore, I would simply present the boxplots clustered by photo stimulus. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ggpubr::ggboxplot(Ramdhani_df, x = "Photo", y = "Negative", color = "Rater",xlab = "Rater Ethnicity Represented within Photo Stimulus", ylab = "Negative Reaction", add = "jitter", title = "Figure 1. Simple Main Effect of Rater within Photo Stimulus", ylim = c(1, 7)) -``` - -## Analysis of Simple Main Effects with a Polynomial Trend {-} - -In the context of the significant interaction effect, we might be interested in polynomial trends for any simple main effects where three or more cells are compared. - -Why? If there are only two cells being compared, then the significance of that has already been tested and if significant, it is also a significant linear effect (because the shape between any two points is a line). - -Here is where we are in the workflow: - -![Image our place in the Two-Way ANOVA Workflow.](images/factorial/WrkFlw_Poly.jpg) - -At the outset, let me acknowledge that this is not the best example to demonstrate a polynomial trend. Why? We do not necessarily have an ordered prediction across categories for this vignette. Other research scenarios (e.g., when dosage, intervention, or exposure is none, low, high) are more readily suited for this analytic strategy. - -In our example, Rater has three groups. Thus, we could evaluate a polynomial for the simple main effect of ethnicity of the rater within photo stimulus. That is, we conduct polynomial analyses separately for the Dayaknese and Madurese photo stimuli. - -If you haven't already, we need to subset the data, creating separate datasets for the evaluations of the Dayaknese photos and Madurese photos: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -Dayaknese_Ph <- subset(Ramdhani_df, Photo == "Dayaknese") -Madurese_Ph <- subset(Ramdhani_df, Photo == "Madurese") -``` - -We will work the entire contrast for each of the datasets, separately. - -First, we assign the polynomial contrast to the Rater variable. This is easily accomplished because the *contr.poly(#)* argument is built into base R. We simply indicate the number of levels in the variable. With Javanese, Dayaknese, and Madurese ethnic groups, we have three. - -Second, we calculate the one-way ANOVA. Because we are using the *aov()* function in base R, we will need to extract the results. This time we need to use the *summary.lm()* function. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -contrasts(Dayaknese_Ph$Rater)<-contr.poly(3) -poly_Dy<-aov(Negative ~ Rater, data = Dayaknese_Ph) -summary.lm(poly_Dy) -``` -We are interested in the regression output that end in the extensions ".L" (for linear trend) and ".Q" (for quadratic trend). In the event that more than one polynomial trend is significant, select the higher one. For example, if both linear and quadratic are selected, interpret the quadratic trend - -Results of polynomial trend analysis indicated a statistically significant linear trend for evaluation of the Dayaknese photos across the three raters $t(51) = 5.153, p < .001$. - -Let's repeat the process for the Madurese photos. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -contrasts(Madurese_Ph$Rater)<-contr.poly(3) -poly_Md<-aov(Negative ~ Rater, data = Madurese_Ph) -summary.lm(poly_Md) -``` -Results of a polynomial trend analyses were non-significant when ethnicity of the rater was evaluated when rating Madurese photos. Compared to the significant linear trend for the Dayaknese photos, results for ratings of the Madurese photos were non-significant ($t[54] = 0.591, p = 0.557$). - -Here's how I might write up the results. In the case of polynomials, I will sometimes add them to an analysis that uses post hoc comparisons, particularly if the polynomial is helpful in conveying meaningful information about the result. - ->We followed up a significant interaction effect with a simple main effect of rater ethnicity within photo stimulus. Specifically, we were curious to see if there was a polynomial trend across rater ethnicity (ordered as Dayaknese, Javanese, and Madurese). Results indicated a statistically significant linear trend for evaluation of the Dayaknese photos $t(51) = 5.153, p < .001$, but not for the Madurese photos ($t[54] = 0.591, p = 0.557$). - -The figure we have been using would be appropriate to illustrate the significant linear trend. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ggpubr::ggboxplot(Ramdhani_df, x = "Photo", y = "Negative", color = "Rater",xlab = "Rater Ethnicity Represented within Photo Stimulus", ylab = "Negative Reaction", add = "jitter", title = "Figure 1. Simple Main Effect of Rater within Photo Stimulus", ylim = c(1, 7)) -``` - -## All Possible Post Hoc Comparisons {-} - -Another option is the comparison possible cells. These are termed *post hoc comparisons.* They are an alternative to simple main effects; you would not report both. A potential criticism of this approach is that it is atheoretical. Without compelling justification, reviewers may criticize this approach as "fishing," "p-hacking," or "HARKing" (hypothesizing after results are known). None-the-less, particularly when our results are not as expected, I do think having these tools available can be a helpful resource. - -The figure shows our place on the Two-Way ANOVA Workflow. - -![Image our place in the Two-Way ANOVA Workflow.](images/factorial/WrkFlw_IntPH.jpg) - -As the numbers of levels increase, post hoc comparisons become somewhat unwieldy. Even though this procedure produces them all, you can select which sensible number you want to compare and control for Type I error according to the number in that set. - -With rater ethnicity (3 levels) and photo stimulus (2 levels), we have 6 groupings. When *k* is the number of groups, the total number of paired comparisons is: k(k-1)*2 - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -6*(6-1)/2 -``` - -Before running this analysis, we must calculate the omnibus ANOVA with the *aov()* function in base R and save the result as an object. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -TwoWay_neg<-aov(Negative~Rater*Photo, Ramdhani_df) -summary(TwoWay_neg) -``` - -We can calculate the 15 post-hoc paired comparisons with the *TukeyHSD()* function from base R. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -posthocs <- TukeyHSD(TwoWay_neg, ordered = TRUE) -posthocs -``` - -If we want to consider all 15 pairwise comparisons and also control for Type I error, a Holm's sequential Bonferroni [@green_using_2017] will help us take a middle-of-the-road approach (not as strict as .05/15 with the traditional Bonferroni; not as lenient as "none") to managing Type I error. - -With the Holms, we rank order the *p* values associated with the 15 comparisons in order from lowest (e.g., .0000018) to highest (e.g., 1.000). The first *p* value is evaluated with the most strict criterion (.05/15; the traditional Bonferonni approach). Then, each successive comparison calculates the *p* value by using the number of *remaining* comparisons as the denominator (e.g., .05/14, .05/13, .05/12). As the *p* values rise and the alpha levels relax, there will be a cut-point where remaining comparisons are not statistically significant. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -.05/15 -.05/14 -``` - -To facilitate this contrast, let's extract the 15 TukeyHSD tests and work with them in Excel. - -First, obtain the structure of the *posthoc* object - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -str(posthocs) -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -write.csv(posthocs$'Rater:Photo', 'posthocsOUT.csv') -``` - -In Excel, I would sort my results by their *p* values (low to high) and consider my threshold (*p* < .0033) to determine which effects were statistically significant. Using the strictest criteria of *p* < .0033, we would have four statistically significant values. - -![Image of the results of the Holms sequential Bonferroni.](images/factorial/Holmsequential.jpg) - -I would ask, "Is this what we want?" Similar to the simple main effects we just tested, I am interested in two sets of comparisons: - -First, how are the two sets of photos (Madurese and Dayaknese) rated within each set of raters. - -* Javanese:Madurese - Javanese:Dayaknese -* Dayaknese:Madurese - Dayaknese:Dayaknese -* Madurese:Madurese - Madurese:Dayaknese - -Second, focused on each photo, what are the relative ratings. - -* Javanese:Madurese - Dayaknese:Madurese -* Madurese: Madurese - Dayaknese:Madurese -* Javanese:Dayaknese - Dayaknese:Dayaknese -* Madurese: Dayaknese - Dayaknese:Dayaknese - -This is only seven sets of comparisons and would considerably reduce the alpha: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -.05/7 -``` -Below I have greyed-out the comparisons that are less interesting to me and left the seven that are my focal interest. I have highlighted in green the two comparisons that are statistically significant based on the Holms' sequential criteria. In this case, it does not make any difference in our interpretation of these focal predictors. - -![Image of the results of the Holms sequential Bonferroni.](images/factorial/HolmsSelect.jpg) -Given that my "tinkering around" analysis resembles the results of the simple main effects analyses in the [factorial lessonn](#between), I will not write this up as an APA style results section, but rather offer this is as a set of tools when you would like to explore the data in an atheoretical manner. - - diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/1F2DC6B3-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/1F2DC6B3-contents deleted file mode 100644 index 59644e18..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/1F2DC6B3-contents +++ /dev/null @@ -1,89 +0,0 @@ -```{r include = FALSE} -options(scipen=999) -``` - -## Homeworked Example - -[Screencast Link](https://youtu.be/ZrQUt9lidCM) - -Several elements of the practice problems (i.e., download base R and R studio) are not easily demonstrated and not replicated here. These are skipped. - -*If you wanted to use this example and dataset as a basis for a homework assignment, you could simply change the seed -- again. For a greater challenge, you could adjust the simulation to have different sample sizes, means, or standard deviations.* - -#### Perform a simple mathematical operation:{-} - -In the .rmd file, open a chunk and perform a simple mathematical operation of your choice (e.g., subtract your birth year from this year). - -```{r} -2023 - 1966 -``` - - -#### Install at least three packages we will commonly use {-} - -Below is code for installing three packages. Because continuous reinstallation can be problematic, I have hashtagged them so that they will not re-run. -```{r} -#install.packages("tidyverse") -#install.packages("ggpubr") -#install.packages("psych") -``` - -#### Copy the simulation in this lesson to your .rmd file. Change the random seed and run the simulation {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -set.seed(2023) -# sample size, M and SD for each group -Accurate <- c(rnorm(30, mean = 1.18, sd = 0.8), rnorm(30, mean = 1.83, - sd = 0.58), rnorm(30, mean = 1.76, sd = 0.56)) -# set upper bound for DV -Accurate[Accurate > 3] <- 3 -# set lower bound for DV -Accurate[Accurate < 0] <- 0 -# IDs for participants -ID <- factor(seq(1, 90)) -# name factors and identify how many in each group; should be in same -# order as first row of script -COND <- c(rep("High", 30), rep("Low", 30), rep("Control", 30)) -# groups the 3 variables into a single df: ID, DV, condition -Acc_sim30B <- data.frame(ID, COND, Accurate) -``` - -#### Save the resulting data as a .csv or .rds file in the same file as you saved the .rmd file {-} - -You only need to save it as a .csv or .rds file. I have demonstrated both. - -Saving as a .csv file -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -write.table(Acc_sim30B, file = "to_CSVb.csv", sep = ",", col.names = TRUE, - row.names = FALSE) -``` - -Saving as an .rds file -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -saveRDS(Acc_sim30B, "to_RobjectB.rds") -``` - -#### Clear your environment (broom in upper right) {-} - -You only need to import the .csv or .rds file; I have demonstrated both. -Open the .csv file from my local drive. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -from_CSV <- read.csv("to_CSVb.csv", header = TRUE) -``` - -Open the .rds file from my local drive. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -from_rds <- readRDS("to_RobjectB.rds") -``` - -#### Run the describe() function from the psych package with your simulated data that you imported from your local drive {-} - -You only need to retrieve descriptives from the .csv or .rds file; I have demonstrated both. -```{r} -psych::describe(from_CSV) -``` - -```{r} -psych::describe(from_rds) -``` - diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/2298DD3B-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/2298DD3B-contents deleted file mode 100644 index f204781e..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/2298DD3B-contents +++ /dev/null @@ -1,387 +0,0 @@ -```{r include = FALSE} -options(scipen=999) -``` - - -## Homeworked Example -[Screencast Link](https://youtu.be/rLyN9GspdWU) - -For more information about the data used in this homeworked example, please refer to the description and codebook located at the end of the [introduction](ReCintro). - -### Working the Problem with R and R Packages - -#### Narrate the research vignette, describing the IV and DV. The data you analyze should have at least 3 levels in the independent variable; at least one of the attempted problems should have a significant omnibus test so that follow-up is required) {-} - -I want to ask the question, do course evaluation ratings for traditional pedagogy differ for students as we enacted a substantive revision to our statistics series. The evaluative focus is on the ANOVA course and we will compare ratings from the stable, transition, and resettled stages of the transitional period. The variable (Stage) of interest will have three levels: - -* STABLE: 2017 represents the last year of "stability during the old way" when we taught with SPSS and during the 2nd year of the doctoral programs. -* TRANSITION: 2018 & 2019 represent the transition to R, when the classes were 30% larger because each of the IOP and CPY departments were transitioning to the 1st year (they did it separately, so as not to double the classes) -* RESETTLED: 2020 & 2021 represent the "resettled" phase where the transition to R was fairly complete and the class size returned to normal because the classes were offered in the first year. - -This is not a variable that was included in the dataset posted to the OSF repository, so we will need to create it. - -*If you wanted to use this example and dataset as a basis for a homework assignment, you could create a different subset of data. I worked the example for students taking the ANOVA class. You could choose multivariate or psychometrics. You could also choose a different dependent variable. I chose the traditional pedagogy subscale. Two other subscales include socially responsive pedagogy and valued by the student.* - -#### Simulate (or import) and format data {-} - -```{r} -big <- readRDS("ReC.rds") -``` - -This df includes course evaluations from ANOVA, multivariate, and psychometrics. To include up to three evaluations per student would violate the assumption of independence, therefore, I will only select the students in ANOVA course. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -big <- subset(big, Course == "ANOVA") -``` - -Let's first create the "Stage" variable that represents the three levels of transition. - -The ProgramYear variable contains the information I need, but the factor labels are not intuitive. Let me remap them. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -big$Stage <- plyr::mapvalues(big$ProgramYear, from = c("Second", "Transition", "First"), to = c("Stable", "Transition", "Resettled")) -``` - -Let's check the structure: - -```{r} -str(big$Stage) -``` - -The TradPed (traditional pedagogy) variable is an average of the items on that scale. I will first create that variable. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Creates a list of the variables that belong to that scale -TradPed_vars <- c('ClearResponsibilities', 'EffectiveAnswers','Feedback', 'ClearOrganization','ClearPresentation') - -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -#big$TradPed <- sjstats::mean_n(big[, ..TradPed_vars], .75) -big$TradPed <- sjstats::mean_n(big[, TradPed_vars], .75) -``` - -With our variables properly formatted, let's trim it to just the variables we need. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -OneWay_df <-(dplyr::select (big, Stage, TradPed)) -``` - -Although we would handle missing data more carefully in a "real study," I will delete all cases with any missingness. This will prevent problems in the hand-calculations section, later (and keep the two sets of results more similar). - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -OneWay_df <- na.omit(OneWay_df) -``` - -Although the assignment doesn't require it, I will make a quick plot to provide a visualizaiton of our analysis. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ggpubr::ggboxplot(OneWay_df, x = "Stage", y = "TradPed", add = "jitter", - color = "Stage", title = "Figure 1. Evaluations of Traditional Pedagogy as a Result of Transition") # -``` - - -#### Evaluate statistical assumptions {-} - -**Is the dependent variable normally distributed across levels of the factor?** - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describeBy(TradPed ~ Stage, mat = TRUE, digits = 3, data = OneWay_df, type = 1) -``` - -We'll use Kline's (2016) threshholds of the absolute values of 3 (skew) and 10 (kurtosis). The highest absolute value of skew is -0.881; the highest absolute value of kurtosis is -0.629. These are well below the areas of concern. - -the Shapiro-wilk test is a formal assessment of normality. It is a 2-part test that begins with creating an ANOVA model from which we can extract residuals, then testing the residuals. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -TradPed_res <- lm(TradPed ~ Stage, data = OneWay_df) -#TradPed_res -rstatix::shapiro_test(residuals(TradPed_res)) -``` -The Shapiro-Wilk test suggests that the our distribution of residuals is statistically significantly different from a normal distribution $(W = 0.941, p < .001)$. - -It is possible to plot the residuals to see how and where they deviate from the line. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ggpubr::ggqqplot(residuals(TradPed_res)) -``` -Ooof! at the ends of the distribution they really deviate. - -**Should we remove outliers?** - -The *rstatix::identify_outliers()* function identifies outliers and extreme outliers. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -OneWay_df %>% - rstatix::identify_outliers(TradPed) -``` - -There are 4 cases identified with outliers; none of those is extreme. I also notice that these outliers are low course evaluations. It seems only fair to retain the data from individuals who were not satisfied with the course. - -**Are the variances of the dependent variable similar across the levels of the grouping factor?** - -We want the results of the Levene's homogeneity of variance test to be non-significant. This would support the notion that the TradPed variance is equivalent across the three stages of the transition. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::levene_test(OneWay_df, TradPed ~ Stage) -``` -The non-significant *p* value suggests that the variances across the three stages are not statistically significantly different: $F(2, 109) = 4.523, p = 0.013$. - - -Before moving on, I will capture our findings in an APA style write-up of the testing of assumptions: - ->Regarding the assumption of normality, skew and kurtosis values at each of the levels of program year fell well below the thresholds that Kline (2016a) identified as concerning (i.e., below |3| for skew and |10| for kurtosis). In contrast, results of a model-based Shapiro-Wilk test of normality, indicated that the model residuals differed from a normal distribution $(W = 0.941, p < .001)$. Although 4 outliers were identified none were extreme, thus we retained all cases. Finally, Levene’s homogeneity of variance test indicated a violation of the homogeneity of variance assumption $F(2, 109) = 4.523, p = 0.013$. ANOVA is relatively robust to this violation when there are at least 15 cases per cell and the design is balanced (i.e., equivalent cell sizes). While we have at least 15 cases per cell, we have a rather unbalanced design. We will need to keep this limitation in mind as we interpret the results. - -#### Conduct omnibus ANOVA (w effect size) {-} - -The *rstatix::anova_test()* function calculates the one-way ANOVA and includes the effect size, $\eta^2$ in the column, *ges*. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -omnibus1w <- rstatix::anova_test(OneWay_df, TradPed ~ Stage, detailed = FALSE) -omnibus1w -``` -The one-way ANOVA is statistically significant. This means that there should be at least one statistically significant difference between levels of the design. Before moving on, I will capture the *F* string: $F(2, 109) = 7.199, p = 0.001, \eta^2 = 0.117$. Regarding the effect size, values of .01, .07, and .14 are considered to be small, medium, and large. The value of .11 would be medium-to-large. - -#### Conduct one set of follow-up tests; narrate your choice {-} - -I will simply calculate post-hoc comparisons. That is, all possible pairwise comparisons. I will specify the traditional Bonferroni as the approach to managing Type I error. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -phoc <- rstatix::t_test(OneWay_df, TradPed ~ Stage, p.adjust.method = "bonferroni", detailed = TRUE) -phoc -``` - -The post hoc tests suggested statistically significant differences between the stable transition resettled stages, favoring the stable period of time (i.e., using SPSS and taught in the second year). - -#### Describe approach for managing Type I error {-} - -We used the Bonferroni. The Bonferroni divides the overall alpha (.05) by the number of comparisons (3). In this case, a *p* value woul dhave to be lower than 0.017 to be statistically significant. The calulation reverse-engineers this so that we can interpret the *p* values by the traditional. 0.05. In the output, it is possible to see the higher threshholds necessary to claim statistical significance. - -#### APA style results with table(s) and figure {-} - ->A one-way analysis of variance was conducted to evaluate the effects of significant transitions (e.g., from SPSS to R; to the second to the first year in a doctoral program) on students ratings of traditional pedagogy. The independent variable, stage, included three levels: stable (with SPSS and taught in the second year of a doctoral program), transitioning (with R and students moving from second to first year), and resettled (with R and in the first year of the program). - ->Regarding the assumption of normality, skew and kurtosis values at each of the levels of program year fell well below the thresholds that Kline (2016a) identified as concerning (i.e., below |3| for skew and |10| for kurtosis). In contrast, results of a model-based Shapiro-Wilk test of normality, indicated that the model residuals differed from a normal distribution $(W = 0.941, p < .001)$. Although 4 outliers were identified none were extreme, thus we retained all cases. Finally, Levene’s homogeneity of variance test indicated a violation of the homogeneity of variance assumption $F(2, 109) = 4.523, p = 0.013$. ANOVA is relatively robust to this violation when there are at least 15 cases per cell and the design is balanced (i.e., equivalent cell sizes). While we have at least 15 cases per cell, we have a rather unbalanced design. We will need to keep this limitation in mind as we interpret the results. - ->Results of the omnibus ANOVA indicated a statistically significant effect of stage on students assessments of traditional pedagogy, $F(2, 109) = 7.199, p = 0.001, \eta^2 = 0.117$. The effect size was medium-to-large. We followed up the significant omnibus with all possible pairwise comparisons. We controlled for Type I error with the traditional Bonferroni adjustment. Results suggested that there were statistically significant differences between the stable and transition stages $(Mdiff = 0.655, p = 0.003)$, but not between stable and resettled $(Mdiff = 0.267,p = 0.324)$ or transition and resettled $(Mdiff= -0.388,p = 0.217)$ stages. Given that the doctoral programs are unlikely to transition back to SPSS or into the second year, the instructor(s) are advised to consider ways that could result in greater student satisfaction. Means and standard deviations are presented in Table 1 and complete ANOVA results are presented in Table 2. Figure 1 provides an illustration of the results. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -apaTables::apa.1way.table(iv = Stage, dv = TradPed, show.conf.interval = TRUE, data = OneWay_df, table.number = 1, filename = "1wayHWTable.doc") -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -omnibus1wHW_b <- aov(TradPed ~ Stage, data = OneWay_df) -apaTables::apa.aov.table(omnibus1wHW_b, table.number = 2, filename = "1wayHWTable2.doc") -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -phoc <- phoc %>% - rstatix::add_xy_position(x = "Stage") - -ggpubr::ggboxplot(OneWay_df, x = "Stage", y = "TradPed", add = "jitter", - color = "Stage", title = "Figure 1. Evaluations of Traditional Pedagogy as a Result of Transition") + - ggpubr::stat_pvalue_manual(phoc, label = "p.adj.signif", tip.length = 0.02, - hide.ns = TRUE, y.position = c(5.5)) -``` - -#### Conduct power analyses to determine the power of the current study and a recommended sample size {-} - -The *pwr.anova.test()* has five parameters: - -* *k* = # groups -* *n* = sample size per group -* *f* = effect sizes, where 0.1/small, 0.25/medium, and 0.4/large - - In the absence from an estimate from our own data, we make a guess about the expected effect size value based on our knowledge of the literature -* *sig.level* = *p* value that you will use -* *power* = .80 is the standard value - -In the script below, we simply add our values. So long as we have four values, the fifth will be calculated for us. - -Because this calculator requires the effect size in the metric of Cohen's *f* (this is not the same as the *F* ratio), we need to convert it. The *effectsize* package has a series of converters. We can use the *eta2_to_f()* function. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -effectsize::eta2_to_f(.117) -``` -We simply plug this value into the "f =". - -First let's ask what our level of power was? Our goal would be 80%. - -Given that our design was unbalanced (21, 44, 47 across the three stages), I used 38 (114/3). - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.anova.test (k = 3, f = .3640094, sig.level = .05, n = 38) -``` -Our power was 0.94. That is, we had 94% chance to find a statistically significant result if one existed. In the next power analysis, let's see what sample size is recommended. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.anova.test (k = 3, f = .3640094, sig.level = .05, power = .80) -``` -In order to be at 80% power to find a statistically significant result if there is one, we would need only 25 people per group. We currently had an unbalanced design of 50, 41, 21. - -### Hand Calculations - -Before we continue: - ->You may notice that the results from the hand calculation are slightly different from the results I will obtain with the R packages. This is because the formula we have used for the hand-calculations utilizes an approach to calculating the sums of squares that presumes that we have a balanced design (i.e., that the cell sizes are equal). When cell sizes are unequal (i.e., an unbalanced design) the Type II package in *rstatix::anova_test* may produce different result. - -> Should we be concerned? No (and yes). My purpose in teaching hand calculations is for creating a conceptual overview of what is occurring in ANOVA models. If this lesson was a deeper exploration into the inner workings of ANOVA, we would take more time to understand what is occurring. My goal is to provide you with enough of an introduction to ANOVA that you would be able to explore further which sums of squares type would be most appropriate for your unique ANOVA model. - -#### Using traditional NHST (null hypothesis testing language), state your null and alternative hypotheses {-} - -Regarding the evaluation of traditional pedgagoy across three stages of transitions to a doctoral ANOVA course, the null hypothesis predicts no differences between the three levels of the dependent variable: - -$$H_{O}: \mu _{1} = \mu _{2} = \mu _{3}$$ - -In contrast, the alternative hypothesis suggests there will be differences. Apriorily, I did not make any specific predictions. - -$$H_{a1}: \mu _{1} \neq \mu _{2} \neq \mu _{3}$$ - -#### Calculate sums of squares total (SST). Steps in this calculation must include calculating a grand mean and creating variables representing the mean deviation and mean deviation squared {-} - -I will use this approach to calculating sums of squares total: - -$$SS_{T}= \sum (x_{i}-\bar{x}_{grand})^{2}$$ - -I will use the *psych::describe()* function to obtain the overall mean: - -```{r} -psych::describe(OneWay_df) -``` - -Next, I will subtract this value from each person's TradPed value. This will create a mean deviation. - - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -OneWay_df$mdevTP <- OneWay_df$TradPed - 4.06 -#I could also calculate it by using the "mean" function -#I had to include an na.rm=TRUE; this appears to be connected to missingness -OneWay_df$mdevTPb <- OneWay_df$TradPed - mean(OneWay_df$TradPed, na.rm=TRUE) -head(OneWay_df) -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -OneWay_df <- OneWay_df %>% - dplyr::mutate(m_devSQTP = mdevTP^2) - -#so we can see this in the textbook -head(OneWay_df) -``` - -I will ask for a sum of the mean deviation squared column. The function was not running, sometimes this occurs when there is missing data. While I didn't think that was true, adding "na.rm = TRUE" solved the problem. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SST <- sum(OneWay_df$m_devSQTP, na.rm = TRUE) -SST -``` -SST = 83.0332 - -#### Calculate the sums of squares for the model (SSM). A necessary step in this equation is to calculate group means {-} - -The formula for SSM is $$SS_{M}= \sum n_{k}(\bar{x}_{k}-\bar{x}_{grand})^{2}$$ - -We will need: - -* *n* for each group, -* Grand mean (earlier we learned it was 4.06), -* Group means - -We can obtain the group means several ways. I think the *psych::describeBy()* function is one of the easiest. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describeBy(TradPed ~ Stage, mat = TRUE, digits = 3, data = OneWay_df, type = 1) -``` - -Now we can pop these values into the formula. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SSM <- 50 * (4.348 -4.06)^2 + 41 * (3.693 - 4.06)^2 + 21 * (4.081 - 4.06)^2 -SSM -``` -SSM = 9.67871 - - -#### Calculate the sums of squares residual (SSR). A necessary step in this equation is to calculate the variance for each group {-} - -The formula for I will use to calculate SSR is $$SS_{R}= s_{group1}^{2}(n-1) + s_{group2}^{2}(n-1) + s_{group3}^{2}(n-1))$$ - -We will need: - -* *n* for each group, -* variance (standard deviation, squared) for each group - -We can obtain these values from the previous run of the *psych::describeBy()* function. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SSR <- (0.658^2)*(50 - 1) + (1.057^2)*(41 - 1) + (0.610^2)*(21-1) -SSR -``` -SSR = 73.3472 - - -#### Calculate the mean square model, mean square residual, and *F*-test {-} - -The formula for mean square model is $$MS_M = \frac{SS_{M}}{df{_{M}}}$$ - -* $SS_M$ was 9.67871 -* $df_M$ is *k* - 1 (where *k* is number of groups/levels) - -```{r} -MSM <- 9.67871/2 -MSM -``` -MSM is 4.839 - -The formula for mean square residual is $$MS_R = \frac{SS_{R}}{df{_{R}}}$$ - -* $SS_R$ was 79.292 -* $df_R$ is $N - k$ (112 - 3 = 109) - -```{r} -MSR = 73.3472/109 -MSR -``` - -The formula for the *F* ratio is $$F = \frac{MS_{M}}{MS_{R}}$$ - -```{r} -F <- 4.839/0.6729101 -F -``` -*F* = 7.191154 - - -#### What are the degrees of freedom for your numerator and denominator? {-} - -Numerator or $df_M$: 2 -Denominator or $df_R$: 109 - -#### Locate the test critical value for your one-way ANOVA {-} - -We could use use a [table of critical values](https://www.statology.org/how-to-read-the-f-distribution-table/) for the *F* distribution. - -The closest *N* in the table I am using is 120. If we set alpha at 0.05, our test value would need to exceed the absolute value of 3.0718. - -We can also use a look-up function, which follows this general form: qf(p, df1, df2. lower.tail=FALSE) -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -qf(.05, 2, 109, lower.tail=FALSE) -``` -Not surprisingly the values are quite similar. - -#### Is the *F*-test statistically significant? Why or why not? {-} - -Because the value of the *F* test (7.191) exceeded the absolute value of the critical value (3.080), the *F* test is statistically significant. - -#### Calculate and interpret the $\eta^2$ effect size {-} - -The formula to calculate the effect size is $$\eta ^{2}=\frac{SS_{M}}{SS_{T}}$$ - -* $SS_M$ was 9.679 -* $SS_T$ was 83.0332 - -```{r} -etaSQ <- 9.679/83.0332 -etaSQ -``` -Eta square is 0.117. Values of .01, .06, and .14 are interpreted as small, medium, and large. Our value of 0.12 is medium-to-large. - - -#### Assemble the results into a statistical string {-} - -$$F(2, 109) = 7.191, p < .05, \eta^2 = 0.117$$ \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/2454FB2B-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/2454FB2B-contents deleted file mode 100644 index be2de983..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/2454FB2B-contents +++ /dev/null @@ -1,297 +0,0 @@ -```{r include = FALSE} -options(scipen=999) -``` -## Homeworked Example - -[Screencast Link](https://youtu.be/9pJtCXceht4) - -For more information about the data used in this homeworked example, please refer to the description and codebook located at the end of the [introduction](ReCintro). - -### Working the Problem with R and R Packages - -#### Narrate the research vignette, describing the variables and their role in the analysis {-} - -I want to ask the question, "Do students' evaluations of traditional pedagogy (TradPed) change from ANOVA (the first course in the series) to Multivariate (the second course in the series)?." Unlike the independent samples *t*-test where we compared students in two different departments, we are comparing *the same* students across two different conditions. In this particular analysis, there is also an element of time. That is the ANOVA class always precedes the multivariate class (with a regression class, taught by a different instructor) in the intervening academic quarter. - -This research design has some clear limitations. Threats to internal validity are caused by issues like history and maturation. None-the-less, for the purpose of a statistical demonstration, this dataset works. - -*If you wanted to use this example and dataset as a basis for a homework assignment, you could compare a different combination of courses and/or score one of the other course evaluation subscales (e.g., socially responsive pedagogy or valued-by-me). * - -Like most data, some manipulation is required before we can begin the analyses. - -#### Simulate (or import) and format data {-} - -Let's import the larger dataset. -```{r} -larger <- readRDS("ReC.rds") -``` - -The TradPed (traditional pedagogy) variable is an average of the items on that scale. I will first create that variable. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Creates a list of the variables that belong to that scale -TradPed_vars <- c('ClearResponsibilities', 'EffectiveAnswers','Feedback', 'ClearOrganization','ClearPresentation') - -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -larger$TradPed <- sjstats::mean_n(larger[, ..TradPed_vars], .75) - -``` - -From the "larger" data, let's select only the variable we will use in the analysis. I have included "long" in the filename because the structure of the dataset is that course evaluation by each student is in its own row. That is, each student could have up to three rows of data. - -We need both "long" and "wide" forms to conduct the analyses required for both testing the statistical assumptions and performing the paired samples *t*-test. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -paired_long <-(dplyr::select (larger, deID, Course, TradPed)) -``` - -From that reduced variable set, let's create a subset with students only from those two courses. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -paired_long <- subset(paired_long, Course == "ANOVA" | Course == "Multivariate") -``` - -Regarding the structure of the data, we want the conditions (ANOVA, multivariate) to be factors and the TradPed variable to be continuously scaled. The format of the deID variable can be any numerical or categorical format -- just not a "chr" (character) variable. - -```{r} -str(paired_long) -``` -R correctly interpreted our variables. - -For analyzing the assumptions associated with the paired-samples *t*-test, the format needs to be "wide" form (where each student has both observations on one row). Our data is presently in "long" form (where each observation is listed in each row). Here's how to reshape the data. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -paired_wide <- reshape2::dcast(data = paired_long, formula =deID ~ Course, value.var = "TradPed") -``` - -Let's recheck the structure. -```{r} -str(paired_wide) -``` -You will notice that there is a good deal of missingness in the Multivariate condition. This is caused because the most recent cohort of students had not yet taken the course. While managing missingness is more complex than this, for the sake of simplicity, I will create a dataframe with non-missing data. - -Doing so should also help with the hand-calculations later in the worked example. - -```{r} -paired_wide <- na.omit(paired_wide) -``` - -#### Evaluate statistical assumptions {-} - -We need to evaluate the *distribution of the difference score* in terms of skew and kurtosis. We want this distribution of difference scores to be normally distributed. - -This means we need to create a difference score: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -paired_wide$DIFF <- paired_wide$ANOVA - paired_wide$Multivariate -``` - -We can use the *psych::describe()* function to obtain skew and kurtosis. -```{r} -psych::describe(paired_wide) -``` - -Regarding the DIFF score, the skew (0.56) and kurtosis (3.15) values were well below the threshholds of concern identified by Klein (2016). - -We can formally test for deviations from normality with a Shapiro-Wilk. We want the results to be non-significant. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::shapiro_test(paired_wide, DIFF) -``` -Results of the Shapiro-Wilk test of normality are statistically significant $(W = 0.943, p = 0.002)$. This means that the distribution of difference scores are statistically significantly different from a normal distribution. - -Although not required in the formal test of instructions, a *pairs panel* of correlations and distributions can be useful in undersatnding our data. - -```{r} -psych::pairs.panels(paired_wide) -``` -Visual inspection of the distributions of the specific course variables were negatively skewed, with values clustered at the high end of the course evaluation ratings. However, the distribution for the DIFF variable seems relatively normal (although maybe a bit leptokurtic). This is consistent with the statistically significant Shapiro-Wilk test. - -Before moving forward, I want to capture my analysis of assumptions: - ->We began by analyzing the data to see if it met the statistical assumptions for analysis with a paired samples t-test. Regarding the assumption of normality, the skew (0.56) and kurtosis (3.15) values associated with the difference between conditions (ANOVA and multivariate) were below the threshholds of concern identified by Klein (2016). In contrast, results of the Shapiro-Wilk test of normality suggested that the distribution of difference scores was statistically significantly different than a normal distribution $(W = 0.943, p = 0.002)$. - -#### Conduct a paired samples t-test (with an effect size & 95% CIs) {-} - -So this may be a bit tricky, but our original "long" form of the data has more ANOVA evaluations (students who had taken ANOVA had not yet taken multivariate) than multivariate. The paired samples *t* test requires the design to be balanced. When we used the *na.omit()* function with the wide case, we effectively balanced the design, eliminating students who lacked observations across both courses. Let's restructure that wide format back to long format so that the design will be balanced. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -paired_long2 <- data.table::melt(data.table::setDT(paired_wide), id.vars = c("deID"), measure.vars = list(c("ANOVA", "Multivariate"))) - -paired_long2 <- dplyr::rename(paired_long2, Course = variable, TradPed = value) - -head(paired_long2) -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::t_test(paired_long2, TradPed ~ Course, paired = TRUE, detailed = TRUE) -``` - -I'll begin the *t* string with this output: $t(76) = -1.341, p = 0.184, CI95(-0.305, 0.069)$. The difference in course evaluations is not statistically significantly difference. We are 955 confident that the true difference in means is as low as -0.301 or as high as 0.060. - -We calculate the Cohen's *d* (the effect size) this way: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::cohens_d(paired_long2, TradPed ~ Course, paired = TRUE) -``` -The value of -0.153 is quite small. We can add this value to our statistical string: $t(76) = -1.341, p = 0.184, CI95(-0.305, 0.069), d = -0.153$ - -#### APA style results with table(s) and figure {-} - ->A paired samples *t*-test was conducted to evaluate the hypohtesis that there would be statistically significant differences in students' course evaluations of ANOVA and multivariate statistics classses. - ->We began by analyzing the data to see if it met the statistical assumptions for analysis with a paired samples t-test. Regarding the assumption of normality, the skew (0.56) and kurtosis (3.15) values associated with the difference between conditions (ANOVA and multivariate) were below the threshholds of concern identified by Klein (2016). In contrast, results of the Shapiro-Wilk test of normality suggested that the distribution of difference scores was statistically significantly different than a normal distribution $(W=0.943, p = 0.002) - ->Results of the paired samples *t*-test suggested nonsignificant differences $t(76) = -1.341, p = 0.184,d = -0.153$. The 95% confidence interval crossed zero, ranging from -0.305 to 0.069. Means and standard deviations are presented in Table 1 and illustrated in Figure 1. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) #needed to use the pipe -# Creating a smaller df to include only the variables I want in the -# table -Descripts_paired <- paired_wide %>% - select(ANOVA, Multivariate, DIFF) -# using the apa.cor.table function for means, standard deviations, -# and correlations the filename command will write the table as a -# word document to your file -apaTables::apa.cor.table(Descripts_paired, table.number = 1, filename = "Tab1_PairedT.doc") -``` -For the figure, let's re-run the paired samples *t* test, save it as an object, and use the "add_significance" function so that we can add it to our figure. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -paired_T <- rstatix::t_test(paired_long2, TradPed ~ Course, paired = TRUE, detailed = TRUE)%>% - rstatix::add_significance() -paired_T -``` -Next, we create boxplot: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pairT.box <- ggpubr::ggpaired(paired_long2, x = "Course", y = "TradPed", order = c("ANOVA", - "Multivariate"), line.color = "gray", palette = c("npg"), color = "Course", - ylab = "Traditional Pedagogy", xlab = "Statistics Course", title = "Figure 1. Evaluation of Traditional Pedagogy as a Function of Course") - -paired_T <- paired_T %>% - rstatix::add_xy_position(x = "Course") #autocomputes p-value labels positions - -pairT.box <- pairT.box + ggpubr::stat_pvalue_manual(paired_T, tip.length = 0.02, y.position = c(5.5)) + labs(subtitle = rstatix::get_test_label(paired_T, detailed = TRUE)) - -pairT.box -``` - -#### Conduct power analyses to determine the power of the current study and a recommended sample size {-} - -Script for estimating current power: - -* d is Cohen's *d* -* n is number of pairs, but set to NULL if we want to estimate sample size -* power is conventionally set at .80, but left at NULL when we want to estimate power -* sig.level is conventionlaly set at 0.05 -* type indicates the type of *t*-test; in this example it is "paired" -* alternative indicates one or two.sided - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.t.test(d=-0.153, n = 77, power=NULL, sig.level=0.05, type="paired", alternative="two.sided") -``` -We had a 26% chance of finding a statistically significant result if, in fact, one existed. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.t.test(d=-0.153,n = NULL, power=.80,sig.level=0.05,type="paired",alternative="two.sided") -``` -If we presumed power were at 80%, we would need a sample size of 337. - -### Hand Calculations {-} - -For these hand calculations I will used the "paired_wide" dataframe that we had prepared for the homework assignment intended for R and R packages. - -#### Using traditional NHST (null hypothesis testing language), state your null and alternative hypotheses {-} - -The null hypotheses states that the true difference in means is zero. -$H_{O}: \mu _{D} = 0$ - -The alternative hypothesis states that the true difference in means is not zero. -$H_{A}: \mu _{D}\neq 0$ - -#### Using an R package or functions in base R (and with data in the "wide" format), calculate the *difference* score between the two observations of the dependent variable {-} - -We had already calculated a difference score in the earlier assignment. Here it is again. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -paired_wide$DIFF <- paired_wide$ANOVA - paired_wide$Multivariate -``` - - -#### Obtain the mean and standard deviation of the *difference* score {-} - -We can obtain the mean and standard deviation for the difference score with this script. - -```{r} -psych::describe(paired_wide$DIFF) -``` - -The mean difference ($\bar{D}$) is -0.12; the standard deviation ($\hat\sigma_D$) of the difference score is 0.8. - -#### Calculate the paired samples *t*-test {-} - -Here is the formula for the paired samples *t*-test: - -$$t = \frac{\bar{D}}{\hat\sigma_D / \sqrt{N}}$$ -Using the values we located we can calculate the value of the *t* statistic. - - -```{r} --0.12/(0.8/sqrt(77)) -``` -The value we calculated with the *rstatix::t_test()* function was -1.34. Considering rounding error, I think we got it! - -#### Identify the degrees of freedom associated with your paired samples *t*-test {-} - -We have 77 pairs. The degrees of freedom for the paired samples *t*-test is $N - 1$. Therefore, df = 76. - -#### Locate the test critical value for your paired samples *t*-test {-} - -I could look at the [table of critical values](https://www.statology.org/t-distribution-table/) for the *t*-distribution. Because I have non-directional hypotheses, I would use the column for a *p*-value of .05 for a two-tailed test. I roll down to the closest sample size (I'll pick 60). This suggests that my *t*-test statistic would need to be greater than 2.0 in order to be statistically significant. - -I can also use the *qt()* function in base R. This function requires that I specify the alpha level (0.05), whether the test is one- or two-tailed (2), and my degrees of freedom (76). Specifying "TRUE" and "FALSE" after the lower.tail command gives the positive and negative regions of rejection. - -```{r} -qt(0.05/2, 76, lower.tail = TRUE) -qt(0.05/2, 76, lower.tail = FALSE) -``` -It is not surprising that these values are a smidge lower than 2.0. Why? Because in the table we stopped at df of 60, when it is actually 76. - -#### Is the paired samples *t*-test statistically significant? Why or why not? {-} - -The paired samples *t*-test is not statistically significant because the *t*-value of -1.316245 does not exceed -1.992. - -#### What is the confidence interval around the mean difference? {-} - -Here is the formula for hand-calculating the confidence interval. - -$$\bar{D}\pm t_{cv}(s_{d}/\sqrt{n})$$ - -* $\bar{D}$ the mean difference score -* $t_{cv}$ the test critical value for a two-tailed model (even if the hypothesis was one-tailed) where $\alpha = .05$ and the degrees of freedom are $N-1$ -* $s_{d}$ the standard deviation of $\bar{D}$ -* $N$ sample size - -Let's calculate it: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} --0.12-(-1.991673*((0.8/(sqrt(77))))) --0.12+(-1.991673*((0.8/sqrt(77)))) -``` -These values indicate the range of scores in which we are 95% confident that our true $\bar{D}$ lies. Stated another way, we are 95% confident that the true mean difference lies between -0.302 and 0.062. Because this interval crosses zero, we cannot rule out that the true mean difference is 0.00. This result is consistent with our non-significant *p* value. For these types of statistics, the 95% confidence interval and *p* value will always be yoked together. - -#### Calculate the effect size (i.e., Cohen's *d* associated with your paired samples *t*-test {-} - -Cohen's *d* measures, in standard deviation units, the distance between the two means. Regardless of sign, values of .2, .5, and .8 are considered to be small, medium, and large, respectively. - -Because the paired samples *t*-test used the difference score in the numerator, there are two easy options for calculating this effect: - -$$d=\frac{\bar{D}}{\hat\sigma_D}=\frac{t}{\sqrt{N}}$$ -Here's a demonstration of both: - -```{r} --0.12/.8 --1.316245/sqrt(77) -``` - -#### Assemble the results into a statistical string {-} - -$t(76) = -1.316, p > .05, CI95(-0.302, 0.062), d = -0.15$ diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/2D62517A-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/2D62517A-contents deleted file mode 100644 index e69de29b..00000000 diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/2EFC158B-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/2EFC158B-contents deleted file mode 100644 index e8332e98..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/2EFC158B-contents +++ /dev/null @@ -1,60 +0,0 @@ -# APPENDICES {-} - -# Type I Error {-} - -## Type I Error Defined {-} - -*Type I error* is the concern about false positives -- that we would incorrectly reject a true null hypothesis (that we would say that there is a statistically significant difference when there is not one). This concern is increased when there are multiple hypothesis tests. This concern increases when we have a large number of pairwise comparisons. - -Throughout the chapters, I noted the importance and relative risk of Type I error with each statistic and options for follow-up testing. Because there are so many options, I have provided a review and summary of each option in this appendix. For each, I provide a definition, a review of the steps and options for utilizing the statistic, and suggest the types of follow-up for which this approach is indicated. - -## Methods for Managing Type I Error {-} - - -### LSD (Least Significant Difference) Method {-} - -The LSD method is especially appropriate in the one-way ANOVA scenario when there are only three levels in the factor. In this case, Green and Salkind [-@green_using_2017] have suggested that alpha can be retained at the alpha level for the "family" ($\alpha_{family}$), which is conventionally $p = .05$ and used both to evaluate the omnibus and, so long as they don't exceed three in number, the planned or pairwise comparisons that follow. - -### Traditional Bonferroni {-} - -The *traditional Bonferroni* is, perhaps, the most well-known approach to managing Type I error. Although the lessons in this OER will frequently suggest another approach to managing Type I error, I will quickly review it now because, conceptually it is easy to understand. We start by establishing the $\alpha\alpha_{family}$; this is traditionally $p = .05$. - -Next, we determine how many pairwise comparisons that we are going to conduct. If we are going to conduct all possible comparisons, we could use this formula: $N_{pc}=\frac{N_{g}(N-1)}{2}$, where - -* $N_{pc}$ is the number of pairwise comparisons, and -* $N_{g}$ is the number of groups. - -In the one-way ANOVA research vignette, the COND factor had three levels: control, low, high. Thus, if we wanted to conduct all possible comparisons we would detrmine $N_{pc}$ this way: - -```{r} -3*(3-1)/2 -``` -Subsequently, we would compute a new alpha that would be used for each comparison with this formula: $\alpha_{pc}=\frac{\alpha_{family}}{N_{pc}}$. - -In the one-way ANOVA research vignette we would calculate it this way: - -```{r} -.05/3 -``` -If we were to use the traditional Bonferroni to manage Type I error, the resultant $p$ value would need to be < .017 in order for statistical significance to be claimed. - -Luckily, each of these options has been reverse-engineered so that we do not have to determine the more conservative alpha levels. Instead, when we specify these options (and, as you will see, more) in the script, the *p* value is adjusted and we can continue to use the customary $p < .05, p < .01$ and $p < .001$ levels of interpretation. In the case of the traditional Bonferonni, the *p* value an be adjusted upward by multiplying it (i.e., the raw *p* values) by the number of comparisons being completed. This holds the *total* Type I error rate across these tests to be $\alpha$ (usually 0.05). Further, most *R* packages allow specification of one or more types of *p* values in the script. The result is the Type 1 error-adjusted *p* values. - -Although the traditional Bonferroni is easy-to-understand and computer, it has been criticized as being too restrictive. That is, it increases the risk of making a Type II error (i.e., failing to reject the null hypothesis when it is false). This is why the majority of follow-up options to ANOVA did not use the traditional Bonferroni. - -### Tukey HSD {-} - -The Tukey HSD (honestly significant difference test) is a multiple comparison procedure used to identify significant differences between means of multiple groups. In the ANOVA context, it examines which specific pairs of groups differ from one another. The Tukey HSD was designed to control for Type I error. It does so by calculating the difference between the largest and smallest group means, then dividing this mean difference by the standard error of the same mean difference. The resulting statitic, *q* has an associated Studentized Range Distribution. Critical values for this distribution come from a Studentized Range q Table and are based on based on the alpha level, the number of groups, and the denominator degrees of freedom (i.e., $df_W$). - -The Tukey HSD ("Tukey's honestly significantly different") test automatically controls for Type I error (i.e., false positives) by using the studentized range distribution to calculate a critical value. Subsequently, it compares the difference between pairs of means to this critical value. In the *rstatix* package, the *tukey_hsd()* function will perform the t-tests of all possible pairwise combinations. The Tukey HSD *p* value is automatically adjusted. In fact, there is nothing additional that can be specified about *p* values (i.e., there are no other choice options). - -I had intended to demonstrate this with the one-way ANOVA chapter, but could not get the results to render a figure with the significance bars and results. An online search suggested that I am not the only one to have experienced this glitch. - -### Holms Sequential Bonferroni {-} - -The Holm's sequential Bonferroni [@green_using_2017] offers a middle-of-the-road approach (not as strict as .05/9 with the traditional Bonferroni; not as lenient as "none") to managing Type I error. - -If we were to hand-calculate the Holms, we would rank order the *p* values associated with the 9 comparisons in order from lowest (e.g., 0.000001448891) to highest (e.g., 1.000). The first *p* value is evaluated with the most strict criterion (.05/9; the traditional Bonferonni approach). Then, each successive comparison calculates the *p* value by using the number of *remaining* comparisons as the denominator (e.g., .05/8, .05/7, .05/6). As the *p* values increase and the alpha levels relax, there will be a cut-point where remaining comparisons are not statistically significant. Luckily, most R packages offer the Holm's sequential Bonferroni as an option. The algorithm behind the output rearranges the mathematical formula and produces a *p* value that we can interpret according to the traditional values of $p < .05, p < .01$ and $p < .001$. -[@green_using_2017] - - diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/306B27FF-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/306B27FF-contents deleted file mode 100644 index cb9d8e84..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/306B27FF-contents +++ /dev/null @@ -1,272 +0,0 @@ -```{r include = FALSE} -options(scipen=999) -``` - -## Homeworked Example - -[Screencast Link](https://youtu.be/slmvZaXXEU8) - -For more information about the data used in this homeworked example, please refer to the description and codebook located at the end of the [introduction](ReCintro). - -The independent-samples t-test is useful when you want to compare means across two different groups. That is, the people in the comparison groups must be different from each other. - -### Working the Problem with R and R Packages - -#### Narrate the research vignette, describing the variables and their role in the analysis {-} - -I want to ask the question, "Do the course evaluation ratings for the traditional pedagogy subscale differ for CPY and ORG students in the ANOVA class?" - -I will use the mean rating for the traditional pedagogy subscale. As a mean, it retains its continuous, Likert scaling, ranging from 1 to 5 (with higher scores being more positive). - -My predictor variable will be department. It has two levels: CPY and ORG. - -*If you wanted to use this example and dataset as a basis for a homework assignment, you could change the course (i.e., Multivariate or Psychometrics) and/or change the dependent variable to one of the other scales*. - -#### Simulate (or import) and format data {-} - -First, bring in the dataset. - -```{r} -big <- readRDS("ReC.rds") -``` - -To avoid "dependency" in the data, I will just use data from the ANOVA course. Let's first trim it to just students who took ANOVA - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -JustANOVA <- subset(big, Course == "ANOVA") -``` - -I will create a mean score of completed items from the traditional pedagogy scale. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Creates a list of the variables that belong to that scale -TradPed_vars <- c('ClearResponsibilities', 'EffectiveAnswers','Feedback', 'ClearOrganization','ClearPresentation') - -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -JustANOVA$TradPed <- sjstats::mean_n(JustANOVA[, TradPed_vars], .75) - -``` - -To make it easier for teaching, I will make a super tiny df with just the predictor and continuous variable. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -IndT_df <-(dplyr::select(JustANOVA, Dept, TradPed)) -``` - -And further trim to non-missing data -```{r} -IndT_df <- na.omit(IndT_df) -``` - -Are the structures of the variables as follows: -* Grouping variable: factor -* Dependent variable: numerical or integer - -In our case we want Department to be a factor with two levels and the SCRPed variable to be integer or numerical. -```{r} -str(IndT_df) -``` - -Since the Department is a character variable, we need to change it to be a factor. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -IndT_df$Dept <- factor(IndT_df$Dept) -str(IndT_df$Dept) -``` - -Without further coding, R will order the factors alphabetically. This is fine. CPY will be the base/intercept and ORG will be the comparison (this becomes more important in regression). - -#### Evaluate statistical assumptions {-} - -* Evaluate and report skew and kurtosis -* Evaluate and correctly interpret homogeneity of variance (if Levene's < .05; use Welch's formulation) - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describeBy(IndT_df ~ Dept, type =1, mat=TRUE) -``` -Although I included Dept in the descriptives, it is a factor and therefore the values around distribution are rather senseless. - -TradPed, though, is a continuously scored variable: - -Skew = -0.763 (CPY) and -1.183 (ORG) falls below the |3.0| threshold of concern (Klein, 2016) -Kurtosis = 0.156 (CPY) and 0.583 (ORG) falls below the |10.0| threshold of concern (Klein, 2016) - -We can use the Shapiro Wilk test for a formal test of normality -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse)#opening this package so I can use the pipes -shapiro <- IndT_df%>% - group_by(Dept) %>% - rstatix::shapiro_test(TradPed) -shapiro -``` - -The Shapiro-Wilk test of normality indicated that the dependent variable, traditional pedagogy, differed significantly from a normal distribution for both CPY students $(W = 0.918, p < 0.001)$ and ORG students$(W = 0.851, p < 0.001)$. - -Should we be concerned? A general rule of thumb is that when cell sizes are larger than 15 the independent *t*-test should be relatively robust to violations of normality [@green_using_2017]. Although there are more CPY than ORG students, we are well-powered. - -For fun (not required), let's produce a pairs.panels. - -```{r} -psych::pairs.panels(IndT_df) -``` - -We can see that we'll have more CPY students than ORG students. Although our kurtosis was below |10| our distribution looks negatively skewed, with the majority of the scores being on the high end of the scale. - -And now for homogeneity of variance: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::levene_test(IndT_df, TradPed ~ Dept, center=median) -``` - -Levene's test for homogeneity of variance indicated that we did not violate the assumption of homogeneity of variance $(F[1, 110] = 2.460, p = 0.120)$. That is to say, the variance in each of the departments is not statistically significantly different from each other. We can use the regular (Student's) formulation of the *t*-test for independent samples. - - -#### Conduct an independent samples *t*-test (with an effect size and 95%CIs) {-} - -Conduct the independent samples *t*-test (with an effect size) - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -indT.test <- rstatix::t_test(IndT_df, TradPed~Dept, var.equal=TRUE, detailed=TRUE) %>% - rstatix::add_significance() -indT.test -``` - -From this output we learn that the value of the *t*-test is 1.423 and is non-significant *p = 0.148*. We are 95% confident that the mean diference falls between -0.102 and 0.618. Because this threshold crosses zero, we cannot be certain that the true difference in means is not zero. Here's how I would represent these results in a statistical string: $t(110) = 1.423, p = 0.158, CI95(0.102, 0.619)$. - -Calculating the Cohen's *d* as the effect size. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::cohens_d(IndT_df, TradPed ~ Dept, var.equal = TRUE) -``` -The value of Cohen's *d* statistic (interpreted in standard deviation units) is 0.300 and is small. We can add this value to the statistical string: $t(110) = 1.423, p = 0.158, CI95 (0.102, 0.619), d = 0.300$. - -#### APA style results with table(s) and figure {-} - -* Complete content of results (including t, df, p, d-or-eta, CI95%) -* Table -* Figure -* Grammar/formatting - ->An independent samples *t*-test was conducted to evaluate the hypothesis that there would be differences in course evaluation ratings of traditional pedagogy between academic departments (CPY, ORG). - ->We began by analyzing the data to see if it met the statistical assumptions for analysis with an independent samples *t*-test. One assumption is that the dependent variable be normally distributed within the both levels of the grouping variable. We evaluated skew and kurtosis using Kline's [-@kline_data_2016] guidelines of the absolute values of 3 (skew) and 10 (kurtosis). Our results were well-within these boundary conditions. Specifically, the traditional pedagogy ratings for CPY were -0.763 and 0.156 for skew and kurtosis, respectively; they were -1.183 and 0.583 for ORG. The Shapiro-Wilk test of normality indicated that the dependent variable, traditional pedagogy, differed significantly from a normal distribution for both CPY students $(W = 0.918, p < 0.001)$ and ORG students $(W = 0.851, p < 0.001)$. Levene's test for homogeneity of variance indicated that we did not violate the assumption of homogeneity of variance $(F[1, 110] = 2.460, p = 0.120)$. That is to say, the variance in each of the departments is not statistically significantly different from each other. Because the independent samples *t*-test is relatively robust to violations of normality when samples sizes have at least 15 participants per cell [@green_using_2017] and there was no violation of the homogeneity of variance assumption we proceded with the Student's formulation of the *t*-test for independent samples. - ->The independent samples *t*-test was nonsignificant, $t(110) = 1.423, p = 0.158$, the effect size (d = 0.300) was small. The 95% confidence interval for the difference in means ranged from -0.102 to 0.619. Means and standard deviations are presented in Table 1; the results are illustrated in Figure 1. - -We can use the *apaTables* package to create a table of means and standard deviations. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -apaTables::apa.1way.table(Dept, TradPed, IndT_df) -``` -And now a figure. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -indT.box <- ggpubr::ggboxplot(IndT_df, x = "Dept", y = "TradPed", color = "Dept", palette=c("#00AFBB", "#FC4E07"), add = "jitter", title = "Figure 1. Traditional Pedagogy as a Function of Academic Department") -ind.testT <- indT.test %>% rstatix::add_xy_position(x = "Dept") #autocomputes p-value labels positions -indT.box <- indT.box + - ggpubr::stat_pvalue_manual(ind.testT, label = "p.signif", tip.length=.02, hide.ns = FALSE, y.position = c(5.5)) + - labs(subtitle = rstatix::get_test_label(indT.test, detailed=TRUE)) #adds t-test results - -indT.box -``` - -#### Conduct power analyses to determine the power of the current study and a recommended sample size {-} - -We can use Cohen's d in this specification of *d*. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.t.test(d = 0.30, n = 112, power = NULL, sig.level = 0.05,type = "two.sample", alternative = "two.sided") -``` - -We were at 61% power. That is, given the value of the mean difference (), we had a 61% chance of detecting a statistically significant effect if there was one. How big of a sample would it take? - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.t.test(d = 0.3, n = NULL, power = 0.8, sig.level = 0.05, type = "two.sample", alternative = "two.sided") -``` - -To find a statistically significant difference, we would need 175 per group. This large size is consistent with the small effect -- that there isn't really a difference between the two groups. - -### Hand Calculations - -I will use the same example (and same dataset) for hand calculations. Before we continue: - ->You may notice that the results from the hand calculation are slightly different from the results I will obtain with the R packages. This is because the formula we have used for the hand-calculations presumes that we have a balanced design (i.e., that the cell sizes are equal). When cell sizes are unequal (i.e., an unbalanced design) the *rstatix::t_test* will produce different results. - -> Should we be concerned? No (and yes). My purpose in teaching hand calculations is for creating a conceptual overview of what is occurring in these statistics. If this lesson was a deeper exploration into the inner workings of *t*-tests, we would take more time to understand what is occurring. - -#### Using traditional NHST (null hypothesis testing language), state your null and alternative hypotheses {-} - -$$H_0: \mu_1 = \mu_2$$ -$$H_A: \mu_1 \neq \mu_2$$ - -#### Using an R package or functions in base R, calculate the means and standard deviations for both levels of the dependent variable {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describeBy(IndT_df ~ Dept, type =1, mat=TRUE) -``` - -CPY: *M* = 4.130, *SD* = 0.755 -ORG: *M* = 3.871, *SD* = 1.095 - -#### Calulate the SE used in the denominator of the *t*-test {-} - -Just as a reminder, the SE is the denominator in the *t*-test formula: - -$$t = \frac{\bar{X_{1}} -\bar{X_{2}}}{\sqrt{\frac{s_{1}^{2}}{N_{1}}+\frac{s_{2}^{2}}{N_{2}}}}$$ -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -sqrt((0.7547259^2/81) + (1.0948953^2/31)) -``` -The *SE* = 0.214 - -#### Calculate the independent samples *t*-test {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -(4.129630 - 3.870968)/0.2137828 -``` -*I note that this hand calculation differs from the worked in R. I believe this is likely due to an unbalanced design with unequal cell sizes (81 and 31).* - - -#### Identify the degrees of freedom associated with your *t*-test {-} - -$N - 2$ is the degrees of freedom: 112-2, df = 110 - -#### Locate the test critical value for your test {-} - -We can look at a [table of critical values](https://www.statology.org/t-distribution-table/) - -For a two-tailed test, with alpha of 0.05, and a sample size of 120 (close enough), the *t*-statistic must be greater than 1.98. - -We could also obtain a *t* critical value with this code: - -```{r} -qt(0.05/2, 112, lower.tail = TRUE) -qt(0.05/2, 112, lower.tail = FALSE) -``` -#### Is the *t*-test statistically significant? Why or why not? {-} - -In a two-tailed test, if the *t*-statistic falls outside the boundaries of -1.98 and 1.98 the means of the two groups are statistically significantly different from each other. - -My *t* value of 1.209929 does not exceed these boundaries and therefore is not statistically significant. - - -#### Calculate the confidence interval around the difference in sample means {-} - -Calculating a confidence interval around the difference in sample means requires the two-tailed test critical values. We can insert them into this formula: - -$$(\bar{X_{1}} -\bar{X_{2})} \pm t_{cv}(SE)$$ - -```{r} -(4.129630 - 3.870968) - (1.209929 * 0.2137828) -(4.129630 - 3.870968) + (1.209929 * 0.2137828) -``` -We are 95% confident that the mean difference falls between -0.000 and 0.517. Because this interval passes through zero, we cannot be certain that the difference is 0. This is consistent with the non-significant *p* value. - -#### Calculate the effect size (i.e., Cohen’s d associated with your *t*-test {-} - -Here is the formula for Cohen's *d*: - -$$d = t\sqrt{\frac{N_{1}+N_{2}}{N_{1}N_{2}}}$$ - -```{r} -1.209929 * (sqrt((81 + 31)/(81 * 31))) -``` - -#### Assemble the results into a statistical string {-} - -$t(110) = 1.210, p > 0.05, CI95(-0.000, 0.517), d = 0.256$ - diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/3F2D20ED-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/3F2D20ED-contents deleted file mode 100644 index bcfbd529..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/3F2D20ED-contents +++ /dev/null @@ -1,220 +0,0 @@ -```{r include = FALSE} -options(scipen=999) -``` - -## Homeworked Example - -[Screencast Link](https://youtu.be/qtA-tkDma3Q) - -For more information about the data used in this homeworked example, please refer to the description and codebook located at the end of the [introduction](ReCintro). - -The one-sample test comes in handy when you want to compare your dataset to an external benchmark or standard. It can be a real helper in program evaluation - -### Working the Problem with R and R Packages - -#### Narrate the research vignette, describing the variables and their role in the analysis {-} - -From my course evaluation data, I want to ask the question, "Are ratings for the Overall Instructor for the ANOVA course evals statistically significantly different from the overall departmental averages for that same item?" In CPY the overall average for that specific item is 4.4. - -*If you wanted to use this example and dataset as a basis for a homework assignment, you could select a different course (i.e., Multivariate or Psychometrics) and/or compare the mean for the ORG department ($M = 4.1$).* - -#### Simulate (or import) and format data {-} - -First I will open the entire dataset. -```{r} -ReCdf <- readRDS("ReC.rds") -``` - -Let's first trim it to just students who took ANOVA -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -JustANOVA <- subset(ReCdf, Course == "ANOVA") -``` - -And further trim to our variable of interest -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -tiny1 <- JustANOVA %>% - dplyr::select (OvInstructor) -``` - -And further trim to non-missing data -```{r} -tiny1 <- na.omit(tiny1) -``` - -* Is the sample variable on a continuous scale of measurement and formatted as *num* or *int* in R? -* Is the external score evaluated on the same continuous scale? -```{r} -str(tiny1$OvInstructor) -``` -Yes. The format for the OvInstructor variable is integer (which is numerical); the overall course evaluation is on an equivalent (1 to 5) scale. - - -#### Evaluate statistical assumptions {-} - -* Are the skew and kurtosis values within the range expected? -* Does the distribution of the variable differ significantly from a normal distribution? - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pastecs::stat.desc(tiny1$OvInstructor, norm=TRUE) -``` -The skew value is -9.84 and far exceeds the absolute value of 3. The skew.2SE is -2.164 (larger than the absolute value of 2.0) is consistent. Thus, we might have some concern about skew. - -The kurtosis value is -7.410 and is below the absolute value of 10. The kurt.2SE value is -8.212 which is substantially larger than the absolute value of 2.0. Thus, we are similarly concerned about kurtosis. - -The Shapiro Wilk test value is 7.728 (*p* < 0.001). This significant value suggests a distribution that is not normally distributed. - - -#### Conduct a one sample *t* test (with an effect size) {-} - -We will compare the overall instructor from the data to the CPY average of 4.4. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::t_test(tiny1, OvInstructor ~ 1, mu = 4.4, detailed = TRUE) -``` -We can begin to create our *t* string: - -$t(112) = -2.246, p = 0.027, CI95(3.997, 4.374)$ - -Let's interpret the results. With 112 degrees of freedom, our *t* value is -2.245. Because the *p* value is less than .05, this is statistically significant. This means that my course evaluations in ANOVA were statistically significantly lower than the average for CPY. We are 95% confident that the true course evaluation mean (for my courses) fell between 3.997 and 4.374. - -Let's calculate the effect size. We will use a Cohen's *d* which is interpreted in standard deviation units. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::cohens_d(tiny1, OvInstructor ~ 1, ref.group = NULL, mu = 4.4) -``` -Cohen's *d* was 0.211. This is a small effect. We can add it to the *t* string. - -$t(112) = -2.246, p = 0.027, CI95(3.997, 4.374), d = -0.211$ - - -#### APA style results with table(s) and figure {-} - -* t-test results should include t, df, p, d-or-eta, and CI95% -* Table -* Figure -* Grammar/style - ->A one-sample *t*-test was used to evaluate whether the *overall instructor* course evaluation ratings from the ANOVA courses were statistically significant different from the departmental averages for the Clinical (CPY; *M* = 4.4) department. The sample mean for the ANOVA course evaluations was 4.186 (*SD* = 1.013). Although this mean was statistically significantly different from the average CPY course evaluation ratings of the same item, $t(112) = -2.246, p = 0.027, CI95(3.997, 4.374)$, the effect size was quite small $(d = -0.211)$. A distribution of the ANOVA course ratings is found in Figure 1. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ggpubr::ggboxplot(tiny1$OvInstructor, ylab = "Course Evaluation Ratings", xlab = FALSE, add = "jitter", title = "Figure 1. Overall Instructor Ratings for ANOVA") -``` - -#### Conduct power analyses to determine the power of the current study and a recommended sample size {-} - -A quick reminder that the *d* in the power analysis is the difference between the means divided by the pooled standard deviation. This is the same as Cohen's d that we just calculated. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.t.test(d = -0.211 , n = 113, power = NULL, sig.level = 0.05, type = "one.sample", alternative = "two.sided") -``` - -For the comparison to the CPY departmental average, power was 60%. That is, given the value of the mean difference relative to the pooled standard deviation we had a 60% chance of detecting a statistically significant effect if there was one. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.t.test(d = -0.211, n = NULL, power = 0.8, sig.level = 0.05, type = "one.sample", alternative = "two.sided") -``` -For the CPY departmental comparison, the recommended sample size would be 178. This means there would need to be 178 individuals to find a statistically significant difference, if one existed (at a power of 80%). - -### Hand Calculations - -#### Using traditional NHST (null hypothesis testing language), state your null and alternative hypotheses {-} - -$$ -\begin{array}{ll} -H_0: & \mu = 4.4 \\ -H_A: & \mu \neq 4.4 -\end{array} -$$ - -#### Calculate the mean of your sample; identify the mean of your benchmarking sample {-} - -I will continue with the *tiny1* dataset and calculate the mean of the OvInstructor variable from my ANOVA course evaluations. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -mean(tiny1$OvInstructor, na.rm=TRUE) -``` - -The mean of my benchmarking sample is 4.4. This number is a "departmental standard" and did not need to be calculated by me for this purpose. - -#### Using the steps from the previous lesson, hand-calculate the standard deviation of your sample. This should involve variables representing the mean, mean deviation, and mean deviation squared {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#first the mean -tiny1$M_OvInst <- mean(tiny1$OvInstructor, na.rm=TRUE) -#second the mean deviation -tiny1$Mdev_OvInst <- (tiny1$OvInstructor-tiny1$M_OvInst) -#third the mean deviation squared -tiny1$mdev2_OvInst <- (tiny1$Mdev_OvInst * tiny1$Mdev_OvInst) -#fourth the variance -var_OvInst <- sum(tiny1$mdev2_OvInst /((nrow(tiny1) - 1))) -var_OvInst -#finally the standard deviation -sd_OvInst <- sqrt(var_OvInst) -sd_OvInst - -head(tiny1) -``` -The variance is 1.028; the standard deviation is 1.014. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -sd(tiny1$OvInstructor)#checking my work -``` - -#### Calculate the one-sample *t*-test {-} - -Here's the formula: - -$$ -t = \frac{\bar{X} - \mu}{\hat{\sigma}/\sqrt{N} } -$$ - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -(4.185841 - 4.4)/(1.013733/sqrt(113)) -``` - -#### Identify the degrees of freedom associated with your *t*-test {-} - -For the one-sample *t*-test, $df = N - 1$. In our case - -```{r} -113 - 1 -``` - -#### Locate the test critical value for your test {-} -We can use a table of critical values for the one sample *t*-test: https://www.statology.org/t-distribution-table/ - -A 2-tail test, when p - .05, with ~120 individuals is 1.98 - -Or, this code: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -qt(p = 0.05/2, df = 112, lower.tail = FALSE) -``` -#### Is the *t*-test statistically significant? Why or why not? {-} - -Yes *t* = -2.245701 exceeds the (absolute) test critical value of 1.98. - -#### What is the confidence interval around your sample mean? {-} - -Here is a reminder of the formula: - -$$\bar{X} \pm t_{cv}(\frac{s}{\sqrt{n}})$$ - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -(4.185841) - ((1.98118)*(1.013733/sqrt(113))) -(4.185841) + ((1.98118)*(1.013733/sqrt(113))) -``` - -We are 95% confident that the sample mean for the students in the ANOVA classes is between 3.997, 4.375. - -#### Calculate the effect size (i.e., Cohen's *d* associated with your *t*-test {-} - -A reminder of the two formula: - -$$d = \frac{Mean Difference}{SD}=\frac{t}{\sqrt{N}}$$ -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#First formula -(4.185841 - 4.4)/1.013733 -#Second formula --2.245701/sqrt(113) -``` diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/44056237-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/44056237-contents deleted file mode 100644 index 92b3632b..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/44056237-contents +++ /dev/null @@ -1,368 +0,0 @@ -```{r include=FALSE} -options(scipen=999)#eliminates scientific notation -``` - -## Homeworked Example - -[Screencast Link](https://youtu.be/3UhTJXp8uNI) - -For more information about the data used in this homeworked example, please refer to the description and codebook located at the end of the [introduction](ReCintro). - -### Working the Problem with R and R Packages - -#### Narrate the research vignette, describing the IV and DV. The data you analyze should have at least 3 levels in the independent variable; at least one of the attempted problems should have a significant omnibus test so that follow-up is required) {-} - -I want to ask the question, do course evaluation ratings for the traditional pedagogy dimension differ for students across the ANOVA, multivariate, and psychometrics courses (in that order, because that's the order in which the students take the class.) - -The dependent variable is the evaluation of traditional pedagogy. The independent variable is course/time (i.e., each student offers course evaluations in each of the three classes). - -*If you wanted to use this example and dataset as a basis for a homework assignment, the three different classes are the only repeated measures variable. Rather, you could choose a different dependent variable. I chose the traditional pedagogy subscale. Two other subscales include socially responsive pedagogy and valued by the student.* - -#### Check and, if needed, format data {-} - -```{r} -big <- readRDS("ReC.rds") -``` - -The TradPed (traditional pedagogy) variable is an average of the items on that scale. I will first create that variable. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Creates a list of the variables that belong to that scale -TradPed_vars <- c('ClearResponsibilities', 'EffectiveAnswers','Feedback', 'ClearOrganization','ClearPresentation') - -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -big$TradPed <- sjstats::mean_n(big[, TradPed_vars], .75) - -#if the scoring script won't run, try this one: -#big$TradPed <- sjstats::mean_n(big[, ..TradPed_vars], .75) -``` - -Let's trim to just the variables we need. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rm1wLONG_df <- (dplyr::select (big, deID, Course, TradPed)) -head(rm1wLONG_df) -``` - -* Grouping variables: factors -* Dependent variable: numerical or integer - -```{r} -str(rm1wLONG_df) -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rm1wLONG_df$Course <- factor(rm1wLONG_df$Course, levels = c("ANOVA", "Multivariate", "Psychometrics")) -str(rm1wLONG_df) -``` -Let's update the df to have only complete cases. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rm1wLONG_df <- na.omit(rm1wLONG_df) -nrow(rm1wLONG_df)#counts number of rows (cases) -``` -This took us to 307 cases. - -These analyses require that students have completed evaluations for all three courses. In the lesson, I restructured the data from long, to wide, back to long again. While this was useful pedagogy in understanding the difference between the two data structures, there is also super quick code that will simply retain data that has at least three observations per student. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -rm1wLONG_df <- rm1wLONG_df%>% - dplyr::group_by(deID)%>% - dplyr::filter(n()==3) -``` - -This took the data to 210 observations. Since each student contributed 3 observations, we know $N = 70$. - -```{r} -210/3 -``` -Before we start, let's get a plot of what's happening: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -bxp <- ggpubr::ggboxplot(rm1wLONG_df, x = "Course", y = "TradPed", add = "point", color = "Course", - xlab = "Statistics Course", ylab = "Traditional Pedagogy Course Eval Ratings", title = "Course Evaluations across Doctoral Statistics Courses") -bxp -``` - -#### Evaluate statistical assumptions {-} - -**Is the dependent variable normally distributed?** - -Given that this is a one-way repeated measures ANOVA model, the dependent variable must be normally distributed within each of the cells of the factor. - -We can examine skew and kurtosis in each of the levels of the TradPed variable with *psych::describeBy()*. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#R wasn't recognizing the data, so I quickly applied the as.data.frame function -rm1wLONG_df <- as.data.frame(rm1wLONG_df) -psych::describeBy(TradPed ~ Course, mat = TRUE, type = 1, data = rm1wLONG_df) -``` - -Although we note some skew and kurtosis, particularly for the multivariate class, none exceed the critical thresholds of |3| for skew and |10| identified by Kline [-@kline_data_2016]. - -I can formally test for normality with the Shapiro-Wilk test. If I use the residuals from an evaluated model, with one test, I can determine if TradPed is distributed normally within each of the courses. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#running the model -RMres_TradPed <- lm(TradPed ~ Course, data = rm1wLONG_df) -summary(RMres_TradPed) -``` -We will ignore this for now, but use the residuals in the formal Shapiro-Wilk test. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::shapiro_test(residuals(RMres_TradPed)) -``` -The distribution of model residuals is statistically significantly different than a normal distribution $(W = 0.876, p < .001)$. Although we have violated the assumption of normality, ANOVA models are relatively robust to such a violation when cell sizes are roughly equal and greater than 15 each [@green_one-way_2017-1]. - -Creating a QQ plot can let us know how badly the distribution departs from a normal one. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ggpubr::ggqqplot(residuals(RMres_TradPed)) -``` - -We can identify outliers and see if they are reasonable or should be removed. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -rm1wLONG_df %>% - group_by(Course)%>% - rstatix::identify_outliers(TradPed) -``` -Outliers for the TradPed variable are among the lowest evaluations (these can be seen on the boxplot). Although there are six outliers identified, none are extreme. Although they contribute to non-normality, I think it's important that this sentiment be retained in the dataset. - -**Assumption of sphericity** - -We will need to evaluate and include information about violations related to sphericity. Because these are calculated at the same time as the ANOVA, itself, I will simply leave this here as a placeholder. - -Here's how I would write up the evaluation of assumptions so far: - ->We utilized one-way repeated measures ANOVA to determine if there were differences in students' evaluation of traditional pedagogy across three courses -- ANOVA, multivariate, and psychometrics -- taught in that order. - ->Repeated measures ANOVA has several assumptions regarding normality, outliers, and sphericity. Although we note some skew and kurtosis, particularly for the multivariate class, none exceed the critical thresholds of |3| for skew and |10| identified by Kline [-@kline_data_2016]. We formally evaluated the normality assumption with the Shapiro-Wilk test. The distribution of model residuals was statistically significantly different than a normal distribution $(W = 0.876, p < .001)$. Although we violated the assumption of normality, ANOVA models are relatively robust to such a violation when cell sizes are roughly equal and greater than 15 each [@green_one-way_2017-1]. Although our data included six outliers, none were classified as extreme. Because they represented lower course evaluations, we believed it important to retain them in the dataset. PLACEHOLDER FOR SPHERICITY. - -#### Conduct omnibus ANOVA (w effect size) {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rmAOV <- rstatix::anova_test(data = rm1wLONG_df, dv = TradPed, wid = deID, within = Course) -rmAOV -``` -Let's start first with the sphericity test. Mauchly's test for sphericity was statistically significant, $(W = 0.878, p = 0.012)$. Had we not violated the assumption, our *F* string would have been created from the data in the ANOVA section of the output : $F(2, 138) = 2.838, p = 0.062, \eta^2 = 0.14$ However, because we violated the assumption, we need to use the degrees-of-freedom adjusted output under the "Sphericity Corrections" section; $F(1.78, 122.98) = 2.838, p = 0.068, ges = 0.014$. - -While the ANOVA is non-significant, because this is a homework demonstration, I will behave *as if* the test is significant and continue with the pairwise comparisons. - -#### Conduct all possible pairwise comparisons (like in the lecture) {-} - -I will follow up with a test of all possible pairwise comparisons and adjust with the bonferroni. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwc <- rstatix::pairwise_t_test(TradPed ~ Course, paired = TRUE, p.adjust.method = "bonf", data = rm1wLONG_df) -pwc -``` - -Consistent with the non-significant omnibus, there were non-significant differences between the pairs. This included, ANOVA and multivariate $(t[69] = -1.215, p = 0.687)$; ANOVA and psychometrics courses $(t[69] = -2.065, p = 0.128)$; and multivariate and psychometrics $(t[69] = -0.772, p = 1.000)$. - -#### Describe approach for managing Type I error {-} - -I used a traditional Bonferroni for the three, follow-up, pairwise comparisons. - -#### APA style results with figure {-} - ->We utilized one-way repeated measures ANOVA to determine if there were differences in students' evaluation of traditional pedagogy across three courses -- ANOVA, multivariate, and psychometrics -- taught in that order. - ->Repeated measures ANOVA has several assumptions regarding normality, outliers, and sphericity. Although we note some skew and kurtosis, particularly for the multivariate class, none exceed the critical thresholds of |3| for skew and |10| identified by Kline [-@kline_data_2016]. We formally evaluated the normality assumption with the Shapiro-Wilk test. The distribution of model residuals was statistically significantly different than a normal distribution $(W = 0.876, p < .001)$. Although we violated the assumption of normality, ANOVA models are relatively robust to such a violation when cell sizes are roughly equal and greater than 15 each [@green_one-way_2017-1]. Although our data included six outliers, none were classified as extreme. Because they represented lower course evaluations, we believed it important to retain them in the dataset. Mauchly's test indicated a violation of the sphericity assumption $(W = 0.878, p = 0.012)$. - ->Given the violation of the homogeneity of sphericity assumption, we are reporting the Greenhouse-Geyser adjusted values. Results of the omnibus ANOVA were not statistically significant $F(1.78, 122.98) = 2.838, p = 0.068, ges = 0.014$. - ->Although we would normally not follow-up a non-significant omnibus ANOVA with more testing, because this is a homework demonstration, we will follow-up the ANOVA with pairwise comparisons and manage Type I error with the traditional Bonferroni approach. Consistent with the non-significant omnibus, there were non-significant differences between the pairs. This included, ANOVA and multivariate $(t[69] = -1.215, p = 0.687)$; ANOVA and psychometrics courses $(t[69] = -2.065, p = 0.128)$; and multivariate and psychometrics $(t[69] = -0.772, p = 1.000)$. - -I can update the figure to include star bars. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -pwc <- pwc %>% - rstatix::add_xy_position(x = "Course") -bxp <- bxp + ggpubr::stat_pvalue_manual(pwc, label = "p.adj.signif", tip.length = 0.01, hide.ns = FALSE, y.position = c(5.25, 5.5, 5.75)) -bxp -``` - -#### Conduct power analyses to determine the power of the current study and a recommended sample size {-} - -In the *WebPower* package, we specify 6 of 7 interrelated elements; the package computes the missing one. - -* *n* = sample size (number of individuals in the whole study). -* *ng* = number of groups. -* *nm* = number of measurements/conditions/waves. -* *f* = Cohen's *f* (an effect size; we can use an effect size converter to obtain this value) - - Cohen suggests that f values of 0.1, 0.25, and 0.4 represent small, medium, and large effect sizes, respectively. -* *nscor* = the Greenhouse Geiser correction from our ouput; 1.0 means no correction was needed and is the package's default; < 1 means some correction was applied. -* *alpha* = is the probability of Type I error; we traditionally set this at .05 -* *power* = 1 - P(Type II error) we traditionally set this at .80 (so anything less is less than what we want). -* *type* = 0 is for between-subjects, 1 is for repeated measures, 2 is for interaction effect. - -I used *effectsize::eta2_to_f* packages convert our $\eta^2$ to Cohen's *f*. - -```{r message=FALSE, warning=FALSE} -effectsize::eta2_to_f(.014) -``` - -Retrieving the information about our study, we add it to all the arguments except the one we wish to calculate. For power analysis, we write "power = NULL." - -```{r message=FALSE, warning=FALSE, tidy=TRUE, tidy.opts=list(width.cutoff=70)} -WebPower::wp.rmanova(n=70, ng=1, nm=3, f = .1192, nscor = .891, alpha = .05, power = NULL, type = 1) -``` -The study had a power of 13%. That is, we had a 13% probability of finding a statistically significant result if one existed. - -In reverse, setting *power* at .80 (the traditional value) and changing *n* to *NULL* yields a recommended sample size. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -WebPower::wp.rmanova(n=NULL, ng=1, nm=3, f = .1192, nscor = .891, alpha = .05, power = .80, type = 1) -``` -With these new values, we learn that we would need 737 individuals in order to obtain a statistically significant result 80% of the time. - -### Hand Calculations - -For hand calculations, I will use the same dataframe (rm1wLONG_df) as I did for the calculations with R and R packages.Before we continue: - ->You may notice that the results from the hand calculation are slightly different from the results I will obtain with the R packages. This was true in the lesson as well. Hand calculations and those used in the R packages likely differ on how the sums of squares is calculated. While the results are "close-ish" they are not always identical. - -> Should we be concerned? No (and yes). My purpose in teaching hand calculations is for creating a conceptual overview of what is occurring in ANOVA models. If this lesson was a deeper exploration into the inner workings of ANOVA, we would take more time to understand what is occurring. My goal is to provide you with enough of an introduction to ANOVA that you would be able to explore further which sums of squares type would be most appropriate for your unique ANOVA model. - -#### Calculate sums of squares total (SST) for the omnibus ANOVA. Steps in this calculation must include calculating a grand mean and creating variables representing the mean deviation and mean deviation squared {-} - -The formula for sums of squares total: $$SS_{T}= \sum (x_{i}-\bar{x}_{grand})^{2}$$. - -We can use the mean function from base R to calculate the grand mean: - -```{r} -mean(rm1wLONG_df$TradPed) -``` -I will create a mean deviation variable by subtracting the mean from each score: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rm1wLONG_df$mDev <- rm1wLONG_df$TradPed - 4.319286 -head(rm1wLONG_df)#shows first six rows of dataset -``` - -Now I will square the mean deviation: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rm1wLONG_df$mDev2 <- rm1wLONG_df$mDev * rm1wLONG_df$mDev -head(rm1wLONG_df)#shows first six rows of dataset -``` - -Sums of squares total is the sum of the mean deviation squared scores. - -```{r} -SST <- sum(rm1wLONG_df$mDev2) -SST -``` -The sums of squares total is 103.9144. - -#### Calculate the sums of squares within (SSW) for the omnibus ANOVA. A necessary step in this equation is to calculate the variance for each student {-} - -Here is the formula for sums of squares within: - -$$SS_W = s_{person1}^{2}(n_{1}-1)+s_{person2}^{2}(n_{2}-1)+s_{person3}^{2}(n_{3}-1)+...+s_{personk}^{2}(n_{k}-1)$$ - -I can get the use the *psych::describeBy()* to obtain the standard deviations for each student's three ratings. I can square each of those for the variance to enter into the formula. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describeBy(TradPed ~ deID, mat=TRUE, type = 1, data = rm1wLONG_df) -``` - -Someone who codes in R could probably write a quick formula to do this -- in this case, I will take the time (and space) to copy each student's standard deviation into a formula that squares it, multiplies it by $n-1$ and then sums all 70 of those calculations. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SSW <- (0.8717798^2 * (3 - 1)) + (0.4163332 ^2 * (3 - 1)) + (0.6928203 ^2 * (3 - 1)) + (0.4000000 ^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.5291503^2 * (3 - 1)) + (0.5291503^2 * (3 - 1)) + (0.7023769^2 * (3 - 1)) + (0.4618802^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (1.2220202^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.9018500^2 * (3 - 1)) + (0.5033223^2 * (3 - 1)) + (0.0000000^2 * (3 - 1)) + (0.9451631^2 * (3 - 1)) + -(1.0066446^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.5484828^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (1.6165808^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.9165151^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.6429101^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.5291503^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.2309401^2 * (3 - 1)) + -(0.1154701^2 * (3 - 1)) + (0.9165151^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.5291503^2 * (3 - 1)) + -(0.5291503^2 * (3 - 1)) + (0.5291503^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + -(0.2309401^2 * (3 - 1)) + (0.2309401^2 * (3 - 1)) + (0.0000000^2 * (3 - 1)) + (0.2000000^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.5033223^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.0000000^2 * (3 - 1)) + (0.2309401^2 * (3 - 1)) + (0.4618802^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.4000000^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.8326664^2 * (3 - 1)) + (0.5773503^2 * (3 - 1)) + -(0.0000000^2 * (3 - 1)) + (0.2000000^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + -(0.4618802^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) - -SSW -``` -Our sums of squares within is 36.895. - -#### Calculate sums of squares model (SSM) for for the effect of time (or repeated measures) {-} - -The formula for the sums of squares model in repeated measures captures the effect of time (or the repeated measures nature of the design): $$SS_{M}= \sum n_{k}(\bar{x}_{k}-\bar{x}_{grand})^{2}$$ - -Earlier we learned that the grand mean is 4.319286. - -I can obtain the means for each course with *psych::describeBy()*. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describeBy(TradPed ~ Course, mat = TRUE, digits = 3, type = 1, data = rm1wLONG_df) -``` - -I can put it in the formula: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -(70 * (4.211 - 4.319286)^2) + (70 * (4.332 - 4.319286)^2) + (70 * (4.414 - 4.319286)^2) -``` -Sums of squares model is 1.4601 - - -#### Calculate sums of squares residual (SSR) {-} - -In repeated measures ANOVA $SS_W = SS_M + SS_R$. Knowing SSW (34.255) and SSM (1.460), we can do simple arithmetic to obtain SSR. - -```{r} -SSR <- 36.895 - 1.460 -SSR -``` -Sums of squares residual is 35.435. - - -#### Calculate the sums of squares between (SSB) {-} -In repeated measures ANOVA $SS_T = SS_W + SS_B$. Knowing SST (103.9144) and SSW (34.255), we can do simple arithmetic to obtain SSB. - -```{r} -SSB <- 103.9144 - 35.435 -SSB -``` -Sums of squares between is 68.4794. - - -#### Create a source table that includes the sums of squares, degrees of freedom, mean squares, *F* values, and *F* critical values {-} - -|One Way Repeated Measures ANOVA Source Table -|:--------------------------------------------------------------| - -|Source |SS |df |$MS = \frac{SS}{df}$ |$F = \frac{MS_{source}}{MS_{resid}}$ |$F_{CV}$| -|:---------|:--------|:-----------------|:------|:------|:------| -|Within |36.895 |(N-k) = 67 | | | | -|Model |1.4601 |(k-1) = 2 |0.7301 |1.3391 |3.138 | -|Residual |35.435 |(dfw - dfm) = 65 |0.5452 | | | -|Between |68.4794 |(N-1) = 69 | | | | -|Total |103.9144 |(cells-1) = 209 | | | | - -```{r} -#calculating degrees of freedom for the residual -67-2 -``` -Calculating mean square model and residual. -```{r} -1.4601/2#MSM -35.435/65#MSR -``` -Calculating the F ratio -```{r} -.7301/.5452 -``` - -Obtaining the F critical value: - -```{r} -qf(.05, 2, 65, lower.tail = FALSE) -``` - -We can see the same in an [F distribution table](https://www.statology.org/f-distribution-table/). - -#### Is the *F*-tests statistically significant? Why or why not? {-} - -No. The *F* value did not exceed the *F* critical value. To achieve statistical significance, my F value has to exceed 3.138. - -#### Assemble the results into a statistical string {-} - -$F(2, 65) = 1.339, p > 0.05$ - diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/487B5B60-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/487B5B60-contents deleted file mode 100644 index 43338151..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/487B5B60-contents +++ /dev/null @@ -1,228 +0,0 @@ -```{r include=FALSE} -options(scipen=999)#eliminates scientific notation -``` -## Homeworked Example - -[Screencast Link](https://youtu.be/eRCDNibARtg) - -For more information about the data used in this homeworked example, please refer to the description and codebook located at the end of the [introduction](ReCintro). - -### Working the Problem with R and R Packages - -#### Narrate the research vignette, describing the IV, DV, and COV {-} - -I want to ask the question, what are the effects of intentional recentering on students' evaluations of socially responsive pedagogy in the multivariate (last) course as a function of centering status (i.e., pre versus re), controlling for the socially responsive evaluations in the ANOVA (first) course: - -* Continuous DV: SRPed (socially responsive pedagogy) in the multivariate (last) class -* Between-subjects factor: recentering status of the class (Pre, Re) -* Covariate: SRPed in the ANOVA (first) class - - -*If you wanted to use this example and dataset as a basis for a homework assignment, you could choose a different dependent variable. I chose the socially responsive pedagogy subscale. Two other subscales include traditional pedagogy and valued by the student.* - -#### Simulate (or import) and format data {-} - -First I import the larger dataset. -```{r} -big <- readRDS("ReC.rds") -``` - -The SRPed (socially responsive pedagogy) variable is an average of the items on that scale. I will first create that variable. - -```{r} -#Creates a list of the variables that belong to that scale -SRPed_vars <- c('InclusvClassrm', 'EquitableEval','MultPerspectives', 'DEIintegration') - -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -big$SRPed <- sjstats::mean_n(big[, SRPed_vars], .75) - -#if the scoring script won't run, try this one: -#big$SRPed <- sjstats::mean_n(big[, ..SRPed_vars], .75) -``` - -Let's trim it to just the variables of interest. -```{r} -ANCOVA_df <- (dplyr::select (big, deID, Course, Centering, SRPed)) -``` - -And further filter so that there are just evaluations of ANOVA and multivariate courses. -```{r} -ANCOVA_df <- subset(ANCOVA_df, Course == "ANOVA" | Course == "Multivariate") #multiple conditions -``` - -I want the course variable to be factor that is ordered by its sequence: ANOVA, multivariate. - -I want the centering variable to be ordered: Pre, Re - -```{r} -str(ANCOVA_df) -``` -Because R's default is to order alphabetically, the centering variable is correct. I just need to change the course variable. - -```{r} -ANCOVA_df$Course <- factor(ANCOVA_df$Course, levels = c("ANOVA", "Multivariate")) -str(ANCOVA_df) -``` -After checking the structure again, both are correct. - -My data is in the long (person-period) form. For this particular ANOVA I need it to be in the wide (person level) form. -```{r} -ANCOVA_wide<- reshape2::dcast(data = ANCOVA_df, formula = deID + Centering ~ Course, value.var = "SRPed") -# before restructuring a second variable, rename the first variable -ANCOVA_wide <- dplyr::rename(ANCOVA_wide, SRPed_ANV = "ANOVA", SRPed_MLTV = "Multivariate") - -str(ANCOVA_wide) -head(ANCOVA_wide) -``` -The *head* function shows that the multivariate scores are missing. This design still has missingness for (a) some students who took ANOVA but haven't yet had multivariate and (b) others who may have skipped completing course evaluations. I'll take care of that next by requiring rows to have non-missing data. - -```{r} -ANCOVA_wide <- na.omit(ANCOVA_wide) -``` - - -#### Evaluate statistical assumptions {-} - -**Is there a linear relationship between the covariate and outcome at each level of the grouping variable?"** - -This would mean that there is linearity between the evaluation in the first course (covariate/ANOVA) and last course (outcome/Multivariate) at each level of the independent variable (Centering status). - -We can get a visual of this with a scatterplot (with regression lines) between the covariae and outcome. - -```{r} -library(ggplot2) -ggpubr::ggscatter(ANCOVA_wide, x = "SRPed_ANV", y = "SRPed_MLTV", color = "Centering", add = "reg.line") + ggpubr::stat_regline_equation(aes(label = paste(..eq.label.., ..rr.label.., sep = "~~~~"), color = Centering)) -``` - -The plot looks a little funny. This is likely because there are no values below 3(ish) for ANOVA when courses were re-centered. Although we are looking for a linear relationship, the angled lines suggest there could be an interaction effect. The previous lesson (when we included all three courses [ANOVA, psychometrics, multivariate]) showed that there was. Spoiler alert -- mixed design ANOVA is a better analysis for this question, but the data does allow me (statistically) to use it for a homework demonstration. - -**Are the regression lines formed by the covariate and the outcome variable the same for each group?** - -This would mean that there is no interaction between the outcome and covariate. We can test this with an ANOVA model that specifies an interaction. - -```{r} -library(tidyverse) -ANCOVA_wide %>% - rstatix::anova_test(SRPed_MLTV ~Centering*SRPed_ANV) -``` -Curiously, the interaction term was not statistically significant $(F[1, 71] = 1.975, p = 0.164)$. This non-violation of the homogeneity of slopes assumption supports the use of ANCOVA. - -**Are the model residuals normally distributed and equal across groups?** - -First, I create a linear regression model -```{r} -SRPed_mod <- lm(SRPed_MLTV ~ SRPed_ANV + Centering, data = ANCOVA_wide) -``` - -I will use *broom::augment()* to add fitted values and residuals to the model I just created. -```{r} -SRPed_mod_metrics <- broom::augment(SRPed_mod) -head(SRPed_mod_metrics) -``` - -I can now assess the normality of residuals with the Shapiro-Wilk test. -```{r} -rstatix::shapiro_test(SRPed_mod_metrics$.resid) -``` - -The Shapiro-Wilk test suggested that our residuals are not statistically significantly different from a normal distribution $(W = 0.972, p = 0.101)$. - -ANCOVA further presumes that the variances of the residuals is equal for all groups. I can check this with the Levene's test. -```{r} -SRPed_mod_metrics%>% - rstatix::levene_test(.resid ~ Centering) -``` -A non-significant Levene's test indicated no violation of the homogeneity of the residual variances for the groups $(F[1, 73] = 2.675, p = 0.106)$. - - -**Is there evidence of outliers? Are they extreme?** - -I can identify outliers by examining the standardized (or studentized) residuals. These are interpreted as the number of standard errors away from the regression line. - -```{r} -SRPed_mod_metrics %>% - filter(abs(.std.resid) > 3) %>% - as.data.frame() -``` - -No outliers were identified. - -Here's write-up of what I've done so far: - ->A one-way analysis of covariance (ANCOVA) was conducted. The independent variable, centering stage, had two levels: pre-centered, re-centered. The dependent variable was students' evaluation of socially responsive pedagogy during the last statistics course (multivariate) and the covariate was the students' evaluation of the same variable during the first statistics class (ANOVA). - ->A preliminary analysis evaluating the homogeneity-of-slopes assumption indicated that the relationship between the covariate and the dependent variable did not differ significantly as a function of the independent variable, $(F[1, 71] = 1.975, p = 0.164)$. Further, the non-significant Shapiro-Wilk test of normality on the model residuals $(W = 0.972, p = 0.101)$ indicated that the dependent variable was not statistically significantly different from a normal distribution and no outliers were identified. A non-significant Levene’s test indicated no violation of the homogeneity of the residual variances for all groups $(F[1, 73] = 2.675, p = 0.106)$. - - -#### Conduct omnibus ANOVA (w effect size) {-} - -```{r} -ANCOVA_mod <- ANCOVA_wide %>% - rstatix::anova_test(SRPed_MLTV ~ SRPed_ANV + Centering) -rstatix::get_anova_table(ANCOVA_mod) -``` ->There was a significant effect of the evaluation of socially responsive pedagogy at the first course (ANOVA) on the same rating at the last course $(F [1,72] = 39.696, p < .001, \eta^2 = 0.355)$ as well as a statistically significant effect of recentering on evaluations of socially responsive pedagogy during the last class $(F [1,72]) = 10.304, p = 0.002, \eta^2 = 0.125)$. Considering that we interpret values $eta^2$ values of .01, .06, and .14 to be small, medium, and large it appears that both the covariate and independent variable had substantial effects on the results. - -#### Conduct one set of follow-up tests; narrate your choice {-} - -Because this design has only two levels (pre-centered, re-centered), follow-up tests will not tell us any more information. However, investigating the covariate-adjusted mean is useful. - -```{r} -emmeans_MLTV <- ANCOVA_wide%>% - rstatix::emmeans_test(SRPed_MLTV ~ Centering, covariate = SRPed_ANV, p.adjust.method = "none") -emmeans_MLTV -``` -Not surprisingly (since this single pairwise comparison is redundant with the omnibus ANCOVA), results suggest a statistically significant difference between the pre- and re-centered stages in the multivariate class. - -With this script I can obtain the covariate-adjusted (i.e., estimated marginal) means. - -```{r} -emmeans_list <- rstatix::get_emmeans(emmeans_MLTV) -emmeans_list -``` -We can compare these to the unadjusted means: - -```{r} -descripts_means <- psych::describeBy(SRPed_MLTV ~ Centering, data = ANCOVA_wide, mat=TRUE, digits=6) -descripts_means -``` - -While the differences are minor, they do exist. - -#### Describe approach for managing Type I error {-} - -Because we only needed to conduct the omnibus, there was no additional control of Type I error. - -#### APA style results with table(s) and figure {-} - ->A one-way analysis of covariance (ANCOVA) was conducted. The independent variable, centering stage, had two levels: pre-centered, re-centered. The dependent variable was students' evaluation of socially responsive pedagogy during the last statistics course (multivariate) and the covariate was the students' evaluation of the same variable during the first statistics class (ANOVA). - ->A preliminary analysis evaluating the homogeneity-of-slopes assumption indicated that the relationship between the covariate and the dependent variable did not differ significantly as a function of the independent variable, $(F[1, 71] = 1.975, p = 0.100)$. Further, the non-significant Shapiro-Wilk test of normality on the model residuals $(W = 0.972, p = 0.101)$ indicated that the dependent variable was not statistically significantly different from a normal distribution and no outliers were identified. A non-significant Levene’s test indicated no violation of the homogeneity of the residual variances for all groups $(F[1, 73] = 2.675, p = 0.106)$. - ->There was a significant effect of the evaluation of socially responsive pedagogy at the first course (ANOVA) on the same rating at the last course $(F [1,72] = 39.696, p < .001, \eta^2 = 0.355)$ as well as a statistically significant effect of recentering on evaluations of socially responsive pedagogy during the last class $(F]1,72) = 10.304, p = 0.002, \eta^2 = 0.125)$. Considering that we interpret values $eta^2$ values of .01, .06, and .14 to be small, medium, and large it appears that both the covariate and independent variable had substantial effects on the results. As illustrated in Figure 1, results suggested that those in the multivariate condition had more favorable ratings of socially responsive pedagogy than those in the ANOVA class. Table 1 provides unadjusted and covariate-adjusted means for the dependent variable. - - -In the case of ANCOVA, a table that compares unadjusted and covariate-adjusted means can be helpful. The lesson contains some script to export data. I will create a table to demonstrate how this might work: - -|Table 1 -|:--------------------------------------------------| -|Unadjusted and Covariate-Adjusted Descriptive Statistics - -|Centering |Unadjusted |Covariate-Adjusted -|:--------------|:-------------:|:-----------------:| - -| |*M* |*SD* |*EMM* |*SE* -|:--------------|:-------:|:----:|:---------:|:----:| -|Pre-centered |4.381277 |0.633 |4.381639 |0.067 | -|Re-centered |4.732143 |0.425 |4.731534 |0.086 | - - -And now a figure: - -```{r} -emmeans_MLTV <- emmeans_MLTV %>% - rstatix::add_xy_position(x = "Centering", fun = "mean_se") -ggpubr::ggline(rstatix::get_emmeans(emmeans_MLTV), x = "Centering", y = "emmean", title = "Figure 1. SRPed Ratings as a Function of Centering, Controlling for Earlier Ratings") + - geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0.2) + - ggpubr::stat_pvalue_manual(emmeans_MLTV, hide.ns = TRUE, tip.length = 0.02, , y.position = c(5.0)) -``` diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/4999B057-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/4999B057-contents deleted file mode 100644 index 278db253..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/4999B057-contents +++ /dev/null @@ -1,297 +0,0 @@ -```{r include = FALSE} -options(scipen=999) -``` -## Homeworked Example - -[Screencast Link](https://youtu.be/9pJtCXceht4) - -For more information about the data used in this homeworked example, please refer to the description and codebook located at the end of the [introduction](ReCintro). - -### Working the Problem with R and R Packages - -#### Narrate the research vignette, describing the variables and their role in the analysis {-} - -I want to ask the question, "Do students' evaluations of traditional pedagogy (TradPed) change from ANOVA (the first course in the series) to Multivariate (the second course in the series)?." Unlike the independent samples *t*-test where we compared students in two different departments, we are comparing *the same* students across two different conditions. In this particular analysis, there is also an element of time. That is the ANOVA class always precedes the multivariate class (with a regression class, taught by a different instructor) in the intervening academic quarter. - -This research design has some clear limitations. Threats to internal validity are caused by issues like history and maturation. None-the-less, for the purpose of a statistical demonstration, this dataset works. - -*If you wanted to use this example and dataset as a basis for a homework assignment, you could compare a different combination of courses and/or score one of the other course evaluation subscales (e.g., socially responsive pedagogy or valued-by-me). * - -Like most data, some manipulation is required before we can begin the analyses. - -#### Simulate (or import) and format data {-} - -Let's import the larger dataset. -```{r} -larger <- readRDS("ReC.rds") -``` - -The TradPed (traditional pedagogy) variable is an average of the items on that scale. I will first create that variable. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Creates a list of the variables that belong to that scale -TradPed_vars <- c('ClearResponsibilities', 'EffectiveAnswers','Feedback', 'ClearOrganization','ClearPresentation') - -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -larger$TradPed <- sjstats::mean_n(larger[, ..TradPed_vars], .75) - -``` - -From the "larger" data, let's select only the variable we will use in the analysis. I have included "long" in the filename because the structure of the dataset is that course evaluation by each student is in its own row. That is, each student could have up to three rows of data. - -We need both "long" and "wide" forms to conduct the analyses required for both testing the statistical assumptions and performing the paired samples *t*-test. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -paired_long <-(dplyr::select (larger, deID, Course, TradPed)) -``` - -From that reduced variable set, let's create a subset with students only from those two courses. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -paired_long <- subset(paired_long, Course == "ANOVA" | Course == "Multivariate") -``` - -Regarding the structure of the data, we want the conditions (ANOVA, multivariate) to be factors and the TradPed variable to be continuously scaled. The format of the deID variable can be any numerical or categorical format -- just not a "chr" (character) variable. - -```{r} -str(paired_long) -``` -R correctly interpreted our variables. - -For analyzing the assumptions associated with the paired-samples *t*-test, the format needs to be "wide" form (where each student has both observations on one row). Our data is presently in "long" form (where each observation is listed in each row). Here's how to reshape the data. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -paired_wide <- reshape2::dcast(data = paired_long, formula =deID ~ Course, value.var = "TradPed") -``` - -Let's recheck the structure. -```{r} -str(paired_wide) -``` -You will notice that there is a good deal of missingness in the Multivariate condition. This is caused because the most recent cohort of students had not yet taken the course. While managing missingness is more complex than this, for the sake of simplicity, I will create a dataframe with non-missing data. - -Doing so should also help with the hand-calculations later in the worked example. - -```{r} -paired_wide <- na.omit(paired_wide) -``` - -#### Evaluate statistical assumptions {-} - -We need to evaluate the *distribution of the difference score* in terms of skew and kurtosis. We want this distribution of difference scores to be normally distributed. - -This means we need to create a difference score: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -paired_wide$DIFF <- paired_wide$ANOVA - paired_wide$Multivariate -``` - -We can use the *psych::describe()* function to obtain skew and kurtosis. -```{r} -psych::describe(paired_wide) -``` - -Regarding the DIFF score, the skew (0.56) and kurtosis (3.15) values were well below the threshholds of concern identified by Klein (2016). - -We can formally test for deviations from normality with a Shapiro-Wilk. We want the results to be non-significant. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::shapiro_test(paired_wide, DIFF) -``` -Results of the Shapiro-Wilk test of normality are statistically significant $(W = 0.943, p = 0.002)$. This means that the distribution of difference scores are statistically significantly different from a normal distribution. - -Although not required in the formal test of instructions, a *pairs panel* of correlations and distributions can be useful in undersatnding our data. - -```{r} -psych::pairs.panels(paired_wide) -``` -Visual inspection of the distributions of the specific course variables were negatively skewed, with values clustered at the high end of the course evaluation ratings. However, the distribution for the DIFF variable seems relatively normal (although maybe a bit leptokurtic). This is consistent with the statistically significant Shapiro-Wilk test. - -Before moving forward, I want to capture my analysis of assumptions: - ->We began by analyzing the data to see if it met the statistical assumptions for analysis with a paired samples t-test. Regarding the assumption of normality, the skew (0.56) and kurtosis (3.15) values associated with the difference between conditions (ANOVA and multivariate) were below the threshholds of concern identified by Klein (2016). In contrast, results of the Shapiro-Wilk test of normality suggested that the distribution of difference scores was statistically significantly different than a normal distribution $(W = 0.943, p = 0.002)$. - -#### Conduct a paired samples t-test (with an effect size & 95% CIs) {-} - -So this may be a bit tricky, but our original "long" form of the data has more ANOVA evaluations (students who had taken ANOVA had not yet taken multivariate) than multivariate. The paired samples *t* test requires the design to be balanced. When we used the *na.omit()* function with the wide case, we effectively balanced the design, eliminating students who lacked observations across both courses. Let's restructure that wide format back to long format so that the design will be balanced. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -paired_long2 <- data.table::melt(data.table::setDT(paired_wide), id.vars = c("deID"), measure.vars = list(c("ANOVA", "Multivariate"))) - -paired_long2 <- dplyr::rename(paired_long2, Course = variable, TradPed = value) - -head(paired_long2) -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::t_test(paired_long2, TradPed ~ Course, paired = TRUE, detailed = TRUE) -``` - -I'll begin the *t* string with this output: $t(76) = -1.341, p = 0.184, CI95(-0.305, 0.069)$. The difference in course evaluations is not statistically significantly difference. We are 955 confident that the true difference in means is as low as -0.301 or as high as 0.060. - -We calculate the Cohen's *d* (the effect size) this way: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::cohens_d(paired_long2, TradPed ~ Course, paired = TRUE) -``` -The value of -0.153 is quite small. We can add this value to our statistical string: $t(76) = -1.341, p = 0.184, CI95(-0.305, 0.069), d = -0.153$ - -#### APA style results with table(s) and figure {-} - ->A paired samples *t*-test was conducted to evaluate the hypohtesis that there would be statistically significant differences in students' course evaluations of ANOVA and multivariate statistics classses. - ->We began by analyzing the data to see if it met the statistical assumptions for analysis with a paired samples t-test. Regarding the assumption of normality, the skew (0.56) and kurtosis (3.15) values associated with the difference between conditions (ANOVA and multivariate) were below the threshholds of concern identified by Klein (2016). In contrast, results of the Shapiro-Wilk test of normality suggested that the distribution of difference scores was statistically significantly different than a normal distribution $(W=0.943, p = 0.002) - ->Results of the paired samples *t*-test suggested nonsignificant differences $t(76) = -1.341, p = 0.184,d = -0.153$. The 95% confidence interval crossed zero, ranging from -0.305 to 0.069. Means and standard deviations are presented in Table 1 and illustrated in Figure 1. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) #needed to use the pipe -# Creating a smaller df to include only the variables I want in the -# table -Descripts_paired <- paired_wide %>% - select(ANOVA, Multivariate, DIFF) -# using the apa.cor.table function for means, standard deviations, -# and correlations the filename command will write the table as a -# word document to your file -apaTables::apa.cor.table(Descripts_paired, table.number = 1, filename = "Tab1_PairedT.doc") -``` -For the figure, let's re-run the paired samples *t* test, save it as an object, and use the "add_significance" function so that we can add it to our figure. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -paired_T <- rstatix::t_test(paired_long2, TradPed ~ Course, paired = TRUE, detailed = TRUE)%>% - rstatix::add_significance() -paired_T -``` -Next, we create boxplot: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pairT.box <- ggpubr::ggpaired(paired_long2, x = "Course", y = "TradPed", order = c("ANOVA", - "Multivariate"), line.color = "gray", palette = c("npg"), color = "Course", - ylab = "Traditional Pedagogy", xlab = "Statistics Course", title = "Figure 1. Evaluation of Traditional Pedagogy as a Function of Course") - -paired_T <- paired_T %>% - rstatix::add_xy_position(x = "Course") #autocomputes p-value labels positions - -pairT.box <- pairT.box + ggpubr::stat_pvalue_manual(paired_T, tip.length = 0.02, y.position = c(5.5)) + labs(subtitle = rstatix::get_test_label(paired_T, detailed = TRUE)) - -pairT.box -``` - -#### Conduct power analyses to determine the power of the current study and a recommended sample size {-} - -Script for estimating current power: - -* d is Cohen's *d* -* n is number of pairs, but set to NULL if we want to estimate sample size -* power is conventionally set at .80, but left at NULL when we want to estimate power -* sig.level is conventionlaly set at 0.05 -* type indicates the type of *t*-test; in this example it is "paired" -* alternative indicates one or two.sided - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.t.test(d=-0.153, n = 77, power=NULL, sig.level=0.05, type="paired", alternative="two.sided") -``` -We had a 26% chance of finding a statistically significant result if, in fact, one existed. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.t.test(d=-0.153,n = NULL, power=.80,sig.level=0.05,type="paired",alternative="two.sided") -``` -If we presumed power were at 80%, we would need a sample size of 337. - -### Hand Calculations - -For these hand calculations I will used the "paired_wide" dataframe that we had prepared for the homework assignment intended for R and R packages. - -#### Using traditional NHST (null hypothesis testing language), state your null and alternative hypotheses {-} - -The null hypotheses states that the true difference in means is zero. -$H_{O}: \mu _{D} = 0$ - -The alternative hypothesis states that the true difference in means is not zero. -$H_{A}: \mu _{D}\neq 0$ - -#### Using an R package or functions in base R (and with data in the "wide" format), calculate the *difference* score between the two observations of the dependent variable {-} - -We had already calculated a difference score in the earlier assignment. Here it is again. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -paired_wide$DIFF <- paired_wide$ANOVA - paired_wide$Multivariate -``` - - -#### Obtain the mean and standard deviation of the *difference* score {-} - -We can obtain the mean and standard deviation for the difference score with this script. - -```{r} -psych::describe(paired_wide$DIFF) -``` - -The mean difference ($\bar{D}$) is -0.12; the standard deviation ($\hat\sigma_D$) of the difference score is 0.8. - -#### Calculate the paired samples *t*-test {-} - -Here is the formula for the paired samples *t*-test: - -$$t = \frac{\bar{D}}{\hat\sigma_D / \sqrt{N}}$$ -Using the values we located we can calculate the value of the *t* statistic. - - -```{r} --0.12/(0.8/sqrt(77)) -``` -The value we calculated with the *rstatix::t_test()* function was -1.34. Considering rounding error, I think we got it! - -#### Identify the degrees of freedom associated with your paired samples *t*-test {-} - -We have 77 pairs. The degrees of freedom for the paired samples *t*-test is $N - 1$. Therefore, df = 76. - -#### Locate the test critical value for your paired samples *t*-test {-} - -I could look at the [table of critical values](https://www.statology.org/t-distribution-table/) for the *t*-distribution. Because I have non-directional hypotheses, I would use the column for a *p*-value of .05 for a two-tailed test. I roll down to the closest sample size (I'll pick 60). This suggests that my *t*-test statistic would need to be greater than 2.0 in order to be statistically significant. - -I can also use the *qt()* function in base R. This function requires that I specify the alpha level (0.05), whether the test is one- or two-tailed (2), and my degrees of freedom (76). Specifying "TRUE" and "FALSE" after the lower.tail command gives the positive and negative regions of rejection. - -```{r} -qt(0.05/2, 76, lower.tail = TRUE) -qt(0.05/2, 76, lower.tail = FALSE) -``` -It is not surprising that these values are a smidge lower than 2.0. Why? Because in the table we stopped at df of 60, when it is actually 76. - -#### Is the paired samples *t*-test statistically significant? Why or why not? {-} - -The paired samples *t*-test is not statistically significant because the *t*-value of -1.316245 does not exceed -1.992. - -#### What is the confidence interval around the mean difference? {-} - -Here is the formula for hand-calculating the confidence interval. - -$$\bar{D}\pm t_{cv}(s_{d}/\sqrt{n})$$ - -* $\bar{D}$ the mean difference score -* $t_{cv}$ the test critical value for a two-tailed model (even if the hypothesis was one-tailed) where $\alpha = .05$ and the degrees of freedom are $N-1$ -* $s_{d}$ the standard deviation of $\bar{D}$ -* $N$ sample size - -Let's calculate it: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} --0.12-(-1.991673*((0.8/(sqrt(77))))) --0.12+(-1.991673*((0.8/sqrt(77)))) -``` -These values indicate the range of scores in which we are 95% confident that our true $\bar{D}$ lies. Stated another way, we are 95% confident that the true mean difference lies between -0.302 and 0.062. Because this interval crosses zero, we cannot rule out that the true mean difference is 0.00. This result is consistent with our non-significant *p* value. For these types of statistics, the 95% confidence interval and *p* value will always be yoked together. - -#### Calculate the effect size (i.e., Cohen's *d* associated with your paired samples *t*-test {-} - -Cohen's *d* measures, in standard deviation units, the distance between the two means. Regardless of sign, values of .2, .5, and .8 are considered to be small, medium, and large, respectively. - -Because the paired samples *t*-test used the difference score in the numerator, there are two easy options for calculating this effect: - -$$d=\frac{\bar{D}}{\hat\sigma_D}=\frac{t}{\sqrt{N}}$$ -Here's a demonstration of both: - -```{r} --0.12/.8 --1.316245/sqrt(77) -``` - -#### Assemble the results into a statistical string {-} - -$t(76) = -1.316, p > .05, CI95(-0.302, 0.062), d = -0.15$ diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/4A39309A-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/4A39309A-contents deleted file mode 100644 index 269860b0..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/4A39309A-contents +++ /dev/null @@ -1,271 +0,0 @@ -```{r include=FALSE} -options(scipen=999)#eliminates scientific notation -``` -## Homeworked Example - -[Screencast Link](https://youtu.be/6pkF-tnmNuY) - -For more information about the data used in this homeworked example, please refer to the description and codebook located at the end of the [introduction](ReCintro). - -### Working the Problem with R and R Packages - -#### Narrate the research vignette, describing the IV and DV {-} - -**Minimally, the data should allow the analysis of a 2 x 3 (or 3 X 2) design. At least one of the problems you work should have a significant interaction effect so that follow-up is required.** - -I want to ask the question, what are the effects of intentional recentering on students evaluations of socially responsive pedagogy as they progress through three doctoral courses in statistics. My design is a 3 x 2 ANOVA: - -* Within-subjects factor: student as they progress through ANOVA, multivariate, psychometrics -* Between-subjects factor: recentering status of the class (Pre, Re) -* Continuous DV: SRPed (socially responsive pedagogy) - -*If you wanted to use this example and dataset as a basis for a homework assignment, you could choose a different dependent variable. I chose the socially responsive pedagogy subscale. Two other subscales include traditional pedagogy and valued by the student.* - -#### Simulate (or import) and format data {-} - -First I import the larger dataset. -```{r} -big <- readRDS("ReC.rds") -``` - -The SRPed (socially responsive pedagogy) variable is an average of the items on that scale. I will first create that variable. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Creates a list of the variables that belong to that scale -SRPed_vars <- c('InclusvClassrm', 'EquitableEval','MultPerspectives', 'DEIintegration') - -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -big$SRPed <- sjstats::mean_n(big[, SRPed_vars], .75) - -#if the scoring script won't run, try this one: -#big$SRPed <- sjstats::mean_n(big[, ..SRPed_vars], .75) -``` - -Let's trim it to just the variables of interest -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -mixt_df <- (dplyr::select (big, deID, Course, Centering, SRPed)) -``` - -I want the course variable to be factor that is ordered by its sequence: ANOVA, multivariate, psychometrics. - -I want the centering variable to be ordered: Pre, Re - -```{r} -str(mixt_df) -``` -Because R's default is to order alphabetically, the centering variable is correct. I just need to change the course variable. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -mixt_df$Course <- factor(mixt_df$Course, levels = c("ANOVA", "Multivariate", "Psychometrics")) -str(mixt_df) -``` -After checking the structure again, both are correct. - -I want all of my analyses (i.e., testing of assumptions, descriptives, omnibus F, follow-up) to be with the same dataset. Because each of these analyses will use listwise deletion (i.e., deleting cases, potentially differing numbers, when there is missing data), I will take care of this now. Because this is a longitudinal analysis, I will do it in two steps. - -The current dataset is is in *long* form. This means each student has up to three rows of data. I will first delete rows that have any missing data: - -```{r} -mixt_df <- na.omit(mixt_df) -``` - -This took me from 310 observations to 299. - -These analyses, though, require that students have completed evaluations for all three courses. In the chapter, I restructured the data from long, to wide, back to long again. While this was useful pedagogy in understanding the difference between the two datasets, there is also super quick code that will simply retain data that has at least three observations per student. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -mixt_df <- mixt_df%>% - dplyr::group_by(deID)%>% - dplyr::filter(n()==3) -``` - -This took the data to 198 observations. Since each student contributed 3 observations, we know $N = 66$. - -Let's get an a priori peek at what we're doing: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -mixt_box <- ggpubr::ggboxplot(mixt_df, x = "Course", y = "SRPed", color = "Centering", palette = "jco", xlab = "Statistics Sequence", ylab = "Socially Responsive Pedagogy", title = "Socially Responsive Course Evaluations as a Function of Centering and Time", add = "jitter") -mixt_box -``` - -#### Evaluate statistical assumptions {-} - -**Is the dependent variable normally distributed in all combinations of the factors?** - -I can examine skew and kurtosis at the cell level with *psych::describeBy()*. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -mixt_df <- as.data.frame(mixt_df)#my data was not reading as a df so I applied this function -psych::describeBy(SRPed ~ Course + Centering, data = mixt_df, type = 1, mat = TRUE, digits = 3) -``` -Across all 6 conditions: - -* No skew exceeds the threshholds of concern (>3; Kline [2016]) - - the most extreme skew is -1.909 -* No kurtosis exceeds the threshholds of concern (>10; Kline [2016]) - - the most extreme kurtosis is 3.680 - -**Are the model residuals normally distributed?** - -I can use the Shapiro-Wilk test to formally investigate the normality assumption. Examining the distribution of the model residuals is one of the most efficient ways to do this. First, I need to run the model and extract the residuals. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -mixt_mod <- aov(SRPed ~ Course*Centering, mixt_df) -summary(mixt_mod) -``` -We won't look at this yet, but simply focus on testing the assumption of normality. The next step is to extract the residuals. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -mixt_resid <- residuals(mixt_mod) -``` - -The formal test of normality is the Shapiro-Wilk test: - -```{r} -shapiro.test(mixt_resid) -``` -Our test result is $W = 0.859, p < .001.$. The significant *p* value indicates that we have violated the normality assumption. When cell sizes have at least 15 cases each and are roughly equivalent in size, ANOVA models are generally robust to this violation. None-the-less, we should keep it in mind. - -We can plot the residuals to "see" how bad it is: -```{r} -hist(mixt_resid) -``` -Like the data itself, the residuals have a negative skew with a pile-up of scores on the "high" side. - -```{r} -qqnorm(mixt_resid) -``` -Similarly, we see that the residuals sharply deviate from the diagonal at the top. - -**Is there evidence of outliers? Are they extreme?** - -The *rstatix::identify_outliers()* function identifies outliers and extreme outliers. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -mixt_df%>% - group_by(Course, Centering)%>% - rstatix::identify_outliers(SRPed) -``` -There are 9 rows of outliers; none are extreme. Cross-referencing back to the boxplot, these are on the low side of evaluations. As an instructor, it seems important to retain the voices that rated socially responsive pedagogy lower than the other students. Although they contribute to non-normality, to exclude them would bias the data in a positive direction. - -**Are the variances of the dependent variable equivalent across all combinations of the factors?** - -I can use the Levene's test with *rstatix::levene_test()*. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -mixt_df %>% - group_by(Course)%>% - rstatix::levene_test(SRPed ~ Centering) -``` -Levene's test indicated a violation of this assumption between the Pre and Re centering conditions in the multivariate class $(F[1, 64] = 4.787, p = 0.032)$. There was no indication of assumption violation for the ANOVA class $(F[1, 64] = 0.176, p = 0.676)$ nor the psychometrics class $(F[1, 64] = 0.320, p = 0.573)$. - -Before moving on I will write up the portion of the APA results section that evaluates the assumptions: - ->We conducted a 2 X 3 mixed design ANOVA to evaluate students' evaluations of social responsive pedagogy as a function of centering stage (i.e., pre-centered and re-centered) across three doctoral statistics courses in professional psychology (i.e., ANOVA, multivariate, psychometrics; taught in that order). - ->Mixed design ANOVA has a numer of assumptions related to both the within-subjects and between-subjects elements. Data are expected to be normaly distributed at each level of the design. Relative to the thresholds identified by Kline [-@kline_data_2016] there was no evidence of skew (all values were at or below the absolute value of 1.909) and kurtosis (all values were below the absolute value of 3.680). The Shapiro-Wilk test applied to model residuals provided a formal test of normality. The test result was $W = 0.859, p < .001.$ and indicated a violation of the the normality assumption. Visual inspection of boxplots for each wave of the design, assisted by the rstatix::identify_outliers() function (which reports values above Q3 + 1.5xIQR or below Q1 - 1.5xIQR, where IQR is the interquartile range) indicated 9 outliers; none of these at the extreme level. All outliers were among the lowest student ratings of socially responsive pedagogy. We determined that it was important that the dataset retain these perspectives. - -> Regardin the homogeneity of variance assumption, Levene's test indicated a violation between the pre- and re- centering conditions in the multivariate class $(F[1, 64] = 4.787, p = 0.032)$. There was no indication of assumption violation for the ANOVA class $(F[1, 64] = 0.176, p = 0.676)$ nor the psychometrics class $(F[1, 64] = 0.320, p = 0.573)$. PLACEHOLDER FOR SPHERICITY ASSUMPTION. - -#### Conduct omnibus ANOVA (w effect size) {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::anova_test(data = mixt_df, dv = SRPed, wid = deID, between = Centering, within = Course) -``` -Because Course is a repeated measures factor, we evaluate Mauchly's test for the main $(W = 0.919, p = 0.098)$ and interaction $(W = 0.919, p = 0.098)$ effects. Neither was statistically significant, meaning we did not violate the sphericity assumption. - -Let's write the F strings from the above table: - -* Centering main effect: $F(1, 56) = 0.000, p = 0.988, \eta^2 = 0.000$ -* Course effect: $F(2, 112) = 0.550, p = 0.578, \eta^2 = 0.003$ -* Interaction effect: $F(2, 112) = 8.547, p = 0.001, \eta^2 = 0.039$ - ->Regarding the omnibus ANOVA, neither the main effect for centering stage $(F[1, 56] = 0.000, p = 0.988, \eta^2 = 0.000)$ nor course $(F[2, 112] = 0.550, p = 0.578, \eta^2 = 0.003)$. However there was a statistically significant centering x course interaction effect $(F[2, 112] = 8.547, p = 0.001, \eta^2 = 0.039)$. - -#### Conduct one set of follow-up tests; narrate your choice {-} - -With a significant interaction effect, we will want to follow-up with an analysis of simple main effects. I think I am interested in the simple main effects for centering within each of the courses. Because there are two levels of Centering (pre, re) within each of the courses, I can go straight to *t*-tests. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -Simple_Course <- mixt_df%>% - group_by(Course)%>% - rstatix::t_test(SRPed ~ Centering, detailed = TRUE, p.adjust.method = "none")%>% - rstatix::add_significance() -Simple_Course -``` - -I also want effect sizes (Cohen's *d*): - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -mixt_df%>% - group_by(Course)%>% - rstatix::cohens_d(SRPed ~ Centering) -``` - ->We followed the significant interaction effect with an evaluation of simple main effects of centering within course. Because there were only three comparisons following the omnibus evaluation, we used the LSD method (i.e., no additional control) to control for Type I error and left the alpha at .05 (Green & Salkind, 2014b). While there were non-statistically significant difference between pre- and re-centered conditions in the ANOVA $(MDiff = 0.095; t[56.04] = 0.652, p = 0.517, d = 0.162)$ and psychometrics $(MDiff = 0.136; t[60.23 = 0.944, p = 0.349, d = 0.233)$ courses, there was a statistically significant difference in the multivariate course $(MDiff = -0.311; t[61.53] = -2.294, p = 0.025, d = -0.558)$ which suggested an increase in ratings of socially responsive pedagogy. - -#### Describe approach for managing Type I error {-} - -Because there were only three comparisons following the omnibus evaluation, I used the LSD method to control for Type I error and retained the alpha at .05 (Green & Salkind, 2014b). - -#### APA style results with table(s) and figure {-} - ->We conducted a 2 X 3 mixed design ANOVA to evaluate students' evaluations of social responsive pedagogy as a function of centering stage (i.e., pre-centered and re-centered) across three doctoral statistics courses in professional psychology (i.e., ANOVA, multivariate, psychometrics; taught in that order). - ->Mixed design ANOVA has a numer of assumptions related to both the within-subjects and between-subjects elements. Data are expected to be normaly distributed at each level of the design. Relative to the thresholds identified by Kline [-@kline_data_2016] there was no evidence of skew (all values were at or below the absolute value of 1.909) and kurtosis (all values were below the absolute value of 3.680). The Shapiro-Wilk test applied to model residuals provided a formal test of normality. The test result was $W = 0.859, p < .001.$and indicated a violation of the the normality assumption. Visual inspection of boxplots for each wave of the design, assisted by the rstatix::identify_outliers() function (which reports values above Q3 + 1.5xIQR or below Q1 - 1.5xIQR, where IQR is the interquartile range) indicated 9 outliers; none of these at the extreme level. All outliers were among the lowest student ratings of socially responsive pedagogy. We determined that it was important that the dataset retain these perspectives. - -> Regardin the homogeneity of variance assumption, Levene's test indicated a violation between the pre- and re- centering conditions in the multivariate class $(F[1, 64] = 4.787, p = 0.032)$. There was no indication of assumption violation for the ANOVA class $(F[1, 64] = 0.176, p = 0.676)$ nor the psychometrics class $(F[1, 64] = 0.320, p = 0.573)$. Mauchly's test indicated no violation of the sphericity asssumption $(W = 0.919, p = 0.098)$, therefore we proceeded normally. - ->Regarding the omnibus ANOVA, neither the main effect for centering stage $(F[1, 56] = 0.000, p = 0.988, \eta^2 = 0.000)$ nor course $(F[2, 112] = 0.550, p = 0.578, \eta^2 = 0.003)$. However there was a statistically significant centering x course interaction effect $(F[2, 112] = 8.547, p = 0.001, \eta^2 = 0.039)$. - ->We followed the significant interaction effect with an evaluation of simple main effects of centering within course. Because there were only three comparisons following the omnibus evaluation, we used the LSD method (i.e., no additional control) to control for Type I error and left the alpha at .05 (Green & Salkind, 2014b). While there were non-statistically significant difference between pre- and re-centered conditions in the ANOVA $(MDiff = 0.095; t[56.04] = 0.652, p = 0.517, d = 0.162)$ and psychometrics $(MDiff = 0.136; t[60.23 = 0.944, p = 0.349, d = 0.233)$ courses, there was a statistically significant difference in the multivariate course $(MDiff = -0.311; t[61.53] = -2.294, p = 0.025, d = -0.558)$ . - -A quick way to produce a table of means and standard deviations for mixed design ANOVA is this: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -apaTables::apa.2way.table(iv1=Course, iv2=Centering, dv=SRPed, data=mixt_df, filename = "Mixed_Table.doc", table.number = 1) -``` - -I can update my figure with star bars: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -Simple_Course <- Simple_Course %>% - rstatix::add_xy_position(x = "Course") -mixt_box <- mixt_box + ggpubr::stat_pvalue_manual(Simple_Course, label = "p.signif", tip.length = 0.02, hide.ns = TRUE, y.position = c(5.3)) -mixt_box -``` - -#### Conduct power analyses to determine the power of the current study and a recommended sample size {-} - -In the *WebPower* package, we specify 6 of 7 interrelated elements; the package computes the missing element - -* *n* = sample size (number of individuals in the whole study) -* *ng* = number of groups -* *nm* = number of repeated measurements (i.e., waves) -* *f* = Cohen's *f* (an effect size; we can use a conversion calculator); Cohen suggests that f values of 0.1, 0.25, and 0.4 represent small, medium, and large effect sizes, respectively -* *nscor* = the Greenhouse Geiser correction from our ouput; 1.0 means no correction was needed and is the package's default; < 1 means some correction was applied -* *alpha* = is the probability of Type I error; we traditionally set this at .05 -* *power* = 1 - P(Type II error) we traditionally set this at .80 (so anything less is less than what we want) -* *type* = 0 is for between-subjects, 1 is for repeated measures, 2 is for interaction effect; in a mixed design ANOVA we will select "2" - -As in the prior lessons, we need to convert our effect size for the *interaction* to $f$ effect size (this is not the same as the *F* test). The *effectsize* package has a series of converters. We can use the *eta2_to_f()* function to translate the $\eta^{2}$ associated with the interaction effect to Cohen's *f*. - - -```{r message=FALSE, warning = FALSE, tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#include effect size from the interaction effect -effectsize::eta2_to_f(0.039) -``` -We can now retrieve information from our study (including the Cohen's *f* value we just calculated) and insert it into the script for the power analysis. -```{r message=FALSE, warning = FALSE, tidy=TRUE, tidy.opts=list(width.cutoff=70) } -WebPower::wp.rmanova(n=66, ng=2, nm=3, f = 0.2014515, nscor = .925, alpha = .05, power = NULL, type = 2) -``` -We are powered at .274 (we have a 27% of rejecting the null hypothesis, if it is true) - -In reverse, setting *power* at .80 (the traditional value) and changing *n* to *NULL* yields a recommended sample size. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -WebPower::wp.rmanova(n=NULL, ng=2, nm=3, f = 0.2014515, nscor = .925, alpha = .05, power = .80, type = 2) -``` -Given our desire for strong power and our weak effect size, this power analysis suggests a sample size of 252 participants is required to be adequately powered (80%) to detect a significant interaction effect. \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/524F4911-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/524F4911-contents deleted file mode 100644 index e69de29b..00000000 diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/55908E32-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/55908E32-contents deleted file mode 100644 index 55b75016..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/55908E32-contents +++ /dev/null @@ -1,234 +0,0 @@ -```{r include = FALSE} -options(scipen=999) -``` - -## Homeworked Example - -[Screencast Link](https://youtu.be/_IiZ8MbtbVs) - -For more information about the data used in this homeworked example, please refer to the description and codebook located at the end of the [introduction](ReCintro). - -Preliminary analyses often consist of means, standard deviations, and correlations. These can be helpful in determining whether or not data are normally distribution. Correlations and pairs.panels also assess the relatedness of the variables. - -If you wanted to use this example and dataset as a basis for a homework assignment, you could (a) select a different course (i.e., Multivariate or Psychometrics) and/or (b) different variables. - -### Working the Problem with R and R Packages - -#### Create a df with 3 continuously scaled variables of interest {-} - -The ReC.rds is the entire dataset. Let's first open it. - -```{r} -ReCdf <- readRDS("ReC.rds") -``` - -Recall that students (represented by the *deID* variable) could contribute up to three course evaluations (i.e., ANOVA, psychometrics, multivariate) each. In many statistics, repeated observations creates dependencies that need to be accounted for statistically. - -To avoid this dependency and to practice an R skill, let's first filter the data, selecting only those students who took ANOVA. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -JustANOVA <- subset(ReCdf, Course == "ANOVA") -``` - -#### Create a df with 3 continuously scaled variables of interest {-} - -The assignment requires that we downsize to three variables. We could pick any three. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -tiny3 <- JustANOVA %>% - dplyr::select (OvInstructor, OvCourse, MyContribution) -``` - -#### Produce descriptive statistics {-} - -```{r} -psych::describe(tiny3) -``` - -#### Produce SPLOM/pairs.panels {-} - -```{r} -psych::pairs.panels(tiny3) -``` - -#### Produce an apaTables matrix {-} - -```{r} -apaTables::apa.cor.table(tiny3) -``` -#### Produce an APA Style write-up of the preliminary analyses {-} - ->Our sample included 113 doctoral students in Clinical and Industrial-Organizational psychology (PhD) programs who were completing a statistics class focused on analysis of variance. Visual inspection of three dimensions of course evaluation (overall instructor, overall course, my contributions) combined with formal evaluation of skewness and kurtosis suggested that their distributions did not violate the assumption of univariate normality. That is, skew values all fell below the absolute value of 3 and kurtosis values all fell below the absolute value of 10 [@kline_data_2016]. Means, standard deviations, and a correlation matrix are presented in Table 1. All three correlations were strong and statistically significant. We noted that the correlation between the overall instructor and overall course was especially high $(r = .83, p < .001)$ - -### Hand Calculations - -Although these are termed “hand calculations,” you may use the code demonstrated in the chapter to work these problems. - -I am going to continue with the *tiny3* dataset I used when I worked the problem with R and R packages. - -If you need to reimport data, here is a quick recap of the code explained earlier. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ReCdf <- readRDS("ReC.rds") -JustANOVA <- subset(ReCdf, Course == "ANOVA") - -library(tidyverse) -tiny3 <- JustANOVA %>% - dplyr::select (OvInstructor, OvCourse, MyContribution) -``` - -To avoid problems in the code we are used that is caused by missingness, we will eliminate any rows with missing data. -```{r} -tiny3 <- na.omit(tiny3) -``` - - -#### Create a variable that represents the mean {-} - -I will start with the OvInstructor variable. Inspect the dataframe to see that this new variable exists. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -tiny3$M_OvI <- mean(tiny3$OvInstructor, na.rm=TRUE) -``` - -#### Create a variable that represents the mean deviation {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -tiny3$Mdev_OvI <- (tiny3$OvInstructor-tiny3$M_OvI) -head(tiny3) -``` - -Inspect the dataframe to see that this new variable exists. Note that this functions to "center" the mean around zero. - - -#### What is the value of the sum of mean deviations? {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -round(sum(tiny3$Mdev_OvI, na.rm = TRUE), 3) -``` -Yes, zero! - -#### Create a variable that represents the absolute mean deviation {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -tiny3$abslt_mOvI <- abs(tiny3$Mdev_OvI) -head(tiny3) -``` - -Inspect the dataframe to see that this new variable no longer has negative values. - -**What is the value of the sum of the absolute mean deviation?** - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -round(sum(tiny3$abslt_mOvI, na.rm = TRUE), 3) -``` - - -**What is the value of the mean of the absolute mean deviation?** - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -round(mean(tiny3$abslt_mOvI, na.rm = TRUE), 3) -``` - -**What does this value tell you?** - -Average distance of each value from the mean. - -#### Create a variable that represents the mean deviation squared {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -tiny3$mdev2_OvI <- (tiny3$Mdev_OvI * tiny3$Mdev_OvI) -head(tiny3) -``` - -**What is the value of the sum of squared deviations around the mean (also known as sums of squares; sometimes abbreviated as $SS$)?** - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -sum(tiny3$mdev2_OvI, na.rm = TRUE) -``` - -**What is the value of the variance ($s^2$)?** - -There are at least two ways to do this with basic code (and then we can check our work). - -Here's how to do it with "more code." -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -var_OvI <- sum(tiny3$mdev2_OvI/((nrow(tiny3) - 1))) -var_OvI -``` - -Here's how to do it with the numbers that I calculated: -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -115.0973/(113-1) -``` - -Checking my work with the *var* function from base R. If it's wrong, I need to rework some of the previous steps. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -var(tiny3$OvInstructor, na.rm = TRUE) #checking my work -``` - -**What is the value of the standard deviation ($s$)?** - -There are two ways to calculate it with basic code; and then we can check it with more code from base R. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -sd_OvI <- sqrt(var_OvI)#calculating with the object I created -sd_OvI -sqrt (1.027655)#calculated with the actual numbers -sd(tiny3$OvInstructor)#checking my work with the code from baseR -``` - -#### Using the same general approach, calculate the mean deviation and standard deviation for a second, continuously scaled variable {-} - -My second variable is MyContribution -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#first the mean -tiny3$M_MyC <- mean(tiny3$MyContribution, na.rm=TRUE) -#second the mean deviation -tiny3$Mdev_MyC <- (tiny3$MyContribution-tiny3$M_MyC) -#third the mean deviation squared -tiny3$mdev2_MyC <- (tiny3$Mdev_MyC * tiny3$Mdev_MyC) -head(tiny3) - -#fourth the variance -var_MyC <- sum(tiny3$mdev2_MyC/((nrow(tiny3) - 1))) -var_MyC -#finally the standard deviation -sd_MyC <- sqrt(var_MyC) -sd_MyC#checking my work - -sd(tiny3$MyContribution)#checking my work -``` - -#### Create a variable that represents the *cross-product* (of the mean deviations). What is the sum of these cross-products? {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -tiny3$crossproduct <- (tiny3$Mdev_OvI * tiny3$Mdev_MyC) -head(tiny3) -``` - -The sum of the crossproduct is: - -```{r} -xp_sum <- sum(tiny3$crossproduct) -xp_sum -``` - -#### Calculate the value of their covariance {-} - -```{r} -cov <- (1/(113-1)) * 46.74336 -cov -``` - -#### Calculate value of correlation coefficient {-} - -```{r} -0.4173514/(1.013733*0.8338) - -``` -And now I can check my work with a function from base R. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -cor.test(tiny3$OvInstructor, tiny3$MyContribution) -``` -The correlation between ratings of overall instructor and my contribution is $0.493, p < .001$. diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/58E39E74-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/58E39E74-contents deleted file mode 100644 index 587f45fd..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/58E39E74-contents +++ /dev/null @@ -1,788 +0,0 @@ -# *t*-tests {-} - -The lessons offered in the *t*-tests section introduce *inferential statistics*. In the prior chapters, our use of measures of central tendency (i.e., mean, median, mode) and variance (i.e., range, variance, standard deviation) serve to *describe* a sample. - -As we move into *inferential* statistics we evaluate data from a sample and try to determine whether or not we can use it to draw conclusions (i.e, predict or make inferences) about a larger, defined, population. - -The *t*-test lessons begin with an explanation of the *z*-score and progress through one sample, independent samples, and paired samples *t*-tests. Each lesson is centered around a research vignette that was focused on physicians' communication with patients who were critically and terminally ill and in the intensive care unit at a hospial [@elliott_differences_2016]. - -In addition to a conceptual presentation of of each statistic, each lesson includes: - -* a workflow that guides researchers through decision-points in each statistic, -* the presentation of formulas and R code for "hand-calculating" each component of the formula, -* script for efficiently computing the statistic with R packages, -* an "recipe" for an APA style presentation of the results, -* a discussion of *power* in that particular statistic with R script for calculating sample sizes sufficient to reject the null hypothesis, if in fact, it is appropriate to do so, and -* suggestions for practice that vary in degree of challenge. - - -# One Sample *t*-tests {#tOneSample} - -[Screencasted Lecture Link](https://youtube.com/playlist?list=PLtz5cFLQl4KNHCJY45vNolW3BMcV3spvf) - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70), include=FALSE} -knitr::opts_chunk$set(echo = TRUE) -knitr::opts_chunk$set(comment = NA) #keeps out the hashtags in the knits -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -options(scipen=999)#eliminates scientific notation -``` - -Researchers and program evaluators, may wish to know if their data differs from an external standard. In today's research vignette, we will ask if the time physicians spent with their patients differed from an external benchmark. The one sample *t*-test is an appropriate tool for this type of analysis. As we work toward the one sample *t*-test we take some time to explore the standard normal curve and *z*-scores, particularly as they related to probability. - -## Navigating this Lesson - -There is just over one hour of lecture. If you work through the materials with me, plan for an additional hour-and-a-half. - -While the majority of R objects and data you will need are created within the R script that sources the chapter, occasionally there are some that cannot be created from within the R framework. Additionally, sometimes links fail. All original materials are provided at the [Github site](https://github.com/lhbikos/ReCenterPsychStats) that hosts the book. More detailed guidelines for ways to access all these materials are provided in the OER's [introduction](#ReCintro) - -### Learning Objectives - -Learning objectives from this lecture include the following: - -* Convert raw scores to *z*-scores (and back again). -* Using the *z* table, determine the probability of an occurence. -* Recognize the research questions for which utilization of a one sample *t*-test would be appropriate. -* Narrate the steps in conducting a one-sample *t*-test, beginning with testing the statistical assumptions through writing up an APA style results section. -* Calculate a one-sample *t*-test in R (including effect sizes). -* Interpret a 95% confidence interval around a mean difference score. -* Produce an APA style results section for a one-sample *t*-test . -* Determine a sample size that (given a set of parameters) would likely result in a statistically significant effect, if there was one. - -### Planning for Practice - -The suggestions for homework vary in degree of complexity. The more complete descriptions at the end of the chapter follow these suggestions. - -* Rework the one-sample *t*-test in the lesson by changing the random seed in the code that simulates the data. This should provide minor changes to the data, but the results will likely be very similar. -* Rework the one-sample *t*-test in the lesson by changing something else about the simulation. For example, if you are interested in power, consider changing the sample size. -* Conduct a one sample *t*-test with data to which you have access and permission to use. This could include data you simulate on your own or from a published article. - -### Readings & Resources - -In preparing this chapter, I drew heavily from the following resource(s). Other resources are cited (when possible, linked) in the text with complete citations in the reference list. - -* How To Do a One-Sample T-test in R: Best Tutorial You Need. (n.d.). Datanovia. Retrieved May 24, 2023, from https://www.datanovia.com/en/lessons/how-to-do-a-t-test-in-r-calculation-and-reporting/how-to-do-a-one-sample-t-test-in-r/ - - The primary R code we use is from the rstatix/Datanovia tutorial. -*Navarro, D. (2020). Chapter 13: Comparing two means. In [Learning Statistics with R - A tutorial for Psychology Students and other Beginners](https://learningstatisticswithr.com/). Retrieved from https://stats.libretexts.org/Bookshelves/Applied_Statistics/Book%3A_Learning_Statistics_with_R_-_A_tutorial_for_Psychology_Students_and_other_Beginners_(Navarro) - - Navarro's OER includes a good mix of conceptual information about *t*-tests as well as R code. My lesson integrates her approach as well as considering information from Field's [-@field_discovering_2012] and Green and Salkind's [-@green_using_2017] texts. -* Elliott, A. M., Alexander, S. C., Mescher, C. A., Mohan, D., & Barnato, A. E. (2016). Differences in Physicians’ Verbal and Nonverbal Communication With Black and White Patients at the End of Life. *Journal of Pain and Symptom Management, 51*(1), 1–8. https://doi.org/10.1016/j.jpainsymman.2015.07.008 - - The source of our research vignette. - -### Packages - -The script below will (a) check to see if the following packages are installed on your computer and, if not (b) install them. Remove the hashtags for the code to work. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#will install the package if not already installed -#if(!require(psych)){install.packages("psych")} -#if(!require(tidyverse)){install.packages("tidyverse")} -#if(!require(dplyr)){install.packages("dplyr")} -#if(!require(ggpubr)){install.packages("ggpubr")} -#if(!require(knitr)){install.packages("knitr")} -#if(!require(apaTables)){install.packages("apaTables")} -#if(!require(pwr)){install.packages("pwr")} -#if(!require(pastecs)){install.packages("pastecs")} -#if(!require(rstatix)){install.packages("rstatix")} -``` - -## *z* before *t* - -**Probability density functions** are mathematical formula that specifies idealized versions of known distributions. The equations that define these distributions allow us to calculate the probability of obtaining a given score. This is a powerful tool. - -As students progress through statistics, they become familiar with a variety of these distributions including the *t*-distribution (commonly used in *t*-tests), *F*-distribution (commonly used in analysis of variance [ANOVA]), and Chi-square ($X^2$) distributions (used in a variety of statistics, including structural equation modeling). The *z* distribution is the most well-known of these distributions. - -The *z* distribution is also known as the normal distribution, the bell curve, or the standard normal curve. Its mean is always 0.00 and its standard deviation is always 1.00. Regardless of the actual mean and standard deviation: - -* 68.3% of the area falls within 1 standard deviation of the mean -* 95.4% of the distribution falls within 2 standard deviations of the mean -* 99.7% of the distribution falls within 3 standard deviations of the mean - -```{r echo=FALSE, tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#http://rstudio-pubs-static.s3.amazonaws.com/78857_86c2403ca9c146ba8fcdcda79c3f4738.html - - -par(mfrow=c(1,3)) - -x=seq(-3,3,length=200) -y=dnorm(x,mean=0,sd=1) -plot(x,y,type="l") -x=seq(-1,1,length=100) -y=dnorm(x,mean=0,sd=1) -polygon(c(-1,x,1),c(0,y,0),col="#FF99CC") -text(0,0.1,"68.3%") - -x=seq(-3,3,length=200) -y=dnorm(x,mean=0,sd=1) -plot(x,y,type="l") -x=seq(-2,2,length=100) -y=dnorm(x,mean=0,sd=1) -polygon(c(-2,x,2),c(0,y,0),col="#cc99cc") -text(0,0.1,"95.4%") - -x=seq(-3,3,length=200) -y=dnorm(x,mean=0,sd=1) -plot(x,y,type="l") -x=seq(-3,3,length=100) -y=dnorm(x,mean=0,sd=1) -polygon(c(-3,x,3),c(0,y,0),col="#993366") -text(0,0.1,"99.7%") - -title("Properties of the Normal Distribution") -``` -*z*-scores are transformations of raw scores, in standard deviation units. Using the following formula, so long as the mean and standard deviation are known, any set of continuously scaled scores can be transformed to a *z*-scores equivalent: - -$$z=\frac{X-\bar{X}}{s}$$ -We can rearrange the formula to find what raw score corresponds with the *z*-score. - -$$X = \bar{X} + z(s)$$ - -The properties of the *z*-score and the standard normal curve allow us to make inferences about the data. - -### Simulating a Mini Research Vignette - -Later in this larger section on *t*-tests we introduce a research vignette that focuses on time physicians spend with patients. Because working with the *z*-test requires a minimum sample size of 120 (and the research vignette has a sample size of 33), I will quickly create normally distributed sample of 200 with a mean of 10 minutes and a standard deviation of 2 minutes per patient. This will allow us to ask some important questions of the data. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#https://r-charts.com/distribution/histogram-curves/ -set.seed(220821) -PhysTime <- data.frame(minutes = rnorm(200, mean=10, sd=2)) -``` - -Using the *describe()* function from the *psych* package, we can see the resulting descriptive statistics. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describe(PhysTime$minutes) -``` - -Specifically, in this sample size of 200, our mean is 9.9 with a standard deviation of 2.0. - -### Raw Scores, *z*-scores, and Proportions - -With data in hand, let's ask, "What is the range of time that physicians spend with patients that fall within 1 standard deviation of the mean?" We would answer this question by applying the raw score formula ($X = \bar{X} + z(s)$) to +1 and -1 standard deviation. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -9.9 - 1*(2) -9.9 + 1*(2) -``` -Because $\pm 1SD$ covers 68% of the distribution, we now know that 68% of patients have physician visits that are between 7.9 and 11.9 minutes long. - -What about $\pm 2SDs$? Similarly, we would apply the raw score formula, using 2 for the standard deviation. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -9.9 - 2*(2) -9.9 + 2*(2) -``` -Two standard deviations around the mean captures 94.5% of patients; patients in this range receive between visits that range between 5.9 and 13.9 minutes. - -And what about $\pm 3SDs$? This time we use 3 to represent the standard deviation. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -9.9 - 3*(2) -9.9 + 3*(2) -``` - -Three standard deviations around the mean captures 99.7% of patients; patients in this range receive between visits that range between 3.9 and 15.9 minutes. - -### Determining Probabilities - -We can also ask questions of **probability**. For example, what is the probability that a physician spends at least 9.9 minutes with a patient? To answer this question we first calculate the *z*-score associated with 9.9 minutes. - -$$z=\frac{X-\bar{X}}{s}$$ -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -(9.9-9.9)/2 #for 9.9 minutes -``` -We learn that 9.9 minutes (the mean of the distribution of raw scores) corresponds with 0 (the mean of the distribution of *z*-scores). - -Next, we examine a [table of critical *z* values](https://www.statology.org/z-table/) where we see that a score of 0.0 corresponds to an area (probability) of .50. The directionality of our table is such that fewer minutes spent with patients are represented on the left (the shaded portion) and more minutes spent with patients are represented on the right (the unshaded portion). Our question asks, what is the probability that a physician spends *at least* 9.9 minutes with a patient (i.e., 9.9 or more minutes) means that we should use the area on the right. Thus, the probability that a physician spends *at least* 9.9 minutes with a patient is 50%. In this case it is also true that the probability that a physician spends 9.9 minutes or less is also 50%. This 50/50 result helps make the point that the area under the curve is equal to 1.0. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70), echo=FALSE} -#http://rstudio-pubs-static.s3.amazonaws.com/78857_86c2403ca9c146ba8fcdcda79c3f4738.html -x=seq(-3,3,length=200) -y=dnorm(x,mean=0,sd=1) -plot(x,y,type="l") -x=seq(-3,0,length=100) -y=dnorm(x,mean=0,sd=1) -polygon(c(-3,x,0),c(0,y,0),col="#993366") -arrows(.3,.2,0,0,length=.15) -text(.5,0.22,"z = 0.000") -text(-.75,0.1,"0.5000 or 50%") -text(1,0.1,"0.5000 or 50%") - -title("Area Under the Normal Curve") -``` -We can also obtain the probability value with the *pnorm()* function. We enter the score, the mean, and the standard deviation. As shown below, we can enter them in *z* score formula or from the raw scores. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pnorm(0, mean=0, sd=1) -pnorm(9.9, mean=9.9, sd=2) -``` -Next, let's ask a question that requires careful inspection of the asymmetry of the curve. What is the probability that a physician spends less than 5 minutes with a patient? First, we calculate the corresponding *z*-score: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#calculating the z-score -(5-9.9)/2 #for 5 minutes -``` -Second we locate the corresponding area under the normal curve. Examining the table of critical *z*-values we see that a *z*-score of -2.45 corresponds with an area of 0.0071. We can check this with the *pnorm()* function: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pnorm(-2.45, mean=0, sd=1) #using SD or standardized units -pnorm(5, mean=9.9, sd=2) #using raw data units -``` -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70), echo=FALSE} -#http://rstudio-pubs-static.s3.amazonaws.com/78857_86c2403ca9c146ba8fcdcda79c3f4738.html -x=seq(-3,3,length=200) -y=dnorm(x,mean=0,sd=1) -plot(x,y,type="l") -x=seq(-3,-2.45,length=100) -y=dnorm(x,mean=0,sd=1) -polygon(c(-3,x,-2.45),c(0,y,0),col="#993366") -arrows(-2.45,.2,-2.45,0,length=.15) -text(-2.45,0.22,"z = -2.45") -text(-2.3,0.1,"0.007 or .7%") -text(0,0.1,"0.993 or 99.3%") - -title("Area Under the Normal Curve") -``` -There is a .7% (that is less than 1%) probability that physicians spend less than 5 minutes with a patient. The inverse (1 - .7) indicates that we can be 99% confident that patients receive 5 or more minutes with the ICU physician. - -What about operations at the other end of the curve? What is the probability that a patient receives less than 12 minutes with a physician? Again, we start with the calculation of the *z*-score. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -(12-9.9)/2 #for 12 minutes -``` -The 12 minute mark is 1.05 *SD* above the mean. Checking the *z* table lets us know that an area of 0.8531 corresponds with a *z*-score of 1.05. - -```{r} -1-.8531 -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70), echo=FALSE} -x=seq(-3,3,length=200) -y=dnorm(x,mean=0,sd=1) -plot(x,y,type="l") -x=seq(1.05,3,length=100) -y=dnorm(x,mean=0,sd=1) -polygon(c(1.05,x,3),c(0,y,0),col="#993366") -arrows(.5,.2,1.05,0,length=.15) -text(.5,0.22,"z = 1.05") -text(-1,0.1,".8531 or 85%") -text(1.6,0.1,".1469 or 15%") - -title("Area Under the Normal Curve") -``` -The probability of a physician spending 12 minutes *or less* with a patient is 85%; the probability of a physician spending 12 minutes or more with a patient is 15%. - -### Percentiles - -The same values that we just collected are often interpreted as percentiles. Our prior calculations taught us that a physician/patient visit that lasted 9.9 minutes (*z* = 0), is ranked at the 50th percentile. That is, a 9.9 minute visit is longer than 50% of patient/physician visits. - -A visit lasting 5 minutes (*z* = -2.45) is ranked at the .07th percentile. That is fewer than 1% of patient/physician visits are shorter than 5 minutes. - -Finally, a visit lasting 12 minutes (*z* = 1.05) is ranked at the 85th percentile. That is, it is longer than 85% of patient visits. - -While this seems redundant, this something of a prelude to the importance of *z* scores and the standard normal curve in assessment, evaluation, and psychometrics. - -### Transforming Variables to Standard Scores - -At this point, we have hand-calculated each score. It is easy to transform a set of scores into a column of *z*-scores: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -PhysTime$zMinutes <- (PhysTime$minutes - mean(PhysTime$minutes))/sd(PhysTime$minutes) - -head(PhysTime) -``` - -The transformation of scores is considered to be *linear*. That is, this 1:1 relationship would result in a correlation of 1.00. Further, the *z*-version of the variable could be used in analyses, just as the original raw score. Choices to do this are made carefully and usually done to optimize interpretation. I will demonstrate this with set of descriptive statistics produced by the *apa.cor.table()* function from the *apaTables* package. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -apaTables::apa.cor.table(PhysTime) -``` - -### The One-Sample *z* test - -The one-sample *z* test is a common entry point to hypothesis testing. Let's imagine that we have reason to believe that an optimal physician/patient interaction in the ICU is 10.5 minutes. We want to use this value as a contrast to our own data and ask if the physician/patient interactions in our ICU are statistically significantly different. To test this hypothesis, we first set up null ($H_0$) and alternative ($H_A$) hypotheses. Our null hypothesis states that the population mean for physician/patient visits is equal to 10.5; the alternative hypothesis states that it is unequal to 10.5. - -As written, this question is *two-tailed.* That is, the external mean could be larger or smaller, we are just curious to see if it is different. - -$$ -\begin{array}{ll} -H_0: & \mu = 10.5 \\ -H_A: & \mu \neq 10.5 -\end{array} -$$ -Alternatively, we could ask a *one-sided* question. That is, we might hypothesize that our sample mean is smaller than the external mean. - -$$ -\begin{array}{ll} -H_0: & \mu = 10.5 \\ -H_A: & \mu < 10.5 -\end{array} -$$ -Whether the test is one- or two- sided makes a difference in the strictness with which we interpret the results and can impact whether or not the result is statistically significant. We will reject the $H_0$ in favor of the alternative ($H_A$) if the resulting test statistic (a *z* score) falls into the region of rejection (but that region shifts, depending on whether our test is one- or two- tailed). - -Statistician, Sir Ronald Fisher, popularized 5% as the region of rejection. Specifically, if a probability value associated with a *z*-score (or similar) falls into the tails of a distribution that represent 5%, then the $H_0$ is rejected, in favor of the $H_A$. - -Stated another way - -* *p* is the probability that the $H_0$ is true - - *p* > 0.05 suggests that there is a 95% chance or greater that the $H_0$ is true -* 1 minus the *p* value is the probability that the alternative hypothesis is true. - - A statistically significant test result (*p* < 0.05) means that the test hypothesis is false or should be rejected. - - A *p* value greater than 0.05 means that no effect was observed. - -If our hypothesis is two-sided, then we can spread the 5% across both tails of the test. Inspecting a table of *z* values shows that $\pm 1.96$ would be the region of rejection of $H_0$. In contrast, if the hypothesis is directionless (two-tailed), $1.64$ would serve as the boundary for the region of rejection and the corresponding *z*-test would require the same sign (+ or -) as the hypothesized tail of the distribution. So long as the hypothesis is consistent with the data, a one-sided test can be more powerful, that is, there is greater probability (defined as area under the curve) for rejecting the $H_0$, if it is should be rejected. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70), echo=FALSE} -par(mfrow=c(1,3)) - -x=seq(-3,3,length=200) -y=dnorm(x,mean=0,sd=1) -plot(x,y,type="l") -x=seq(-1.96,1.96,length=100) -y=dnorm(x,mean=0,sd=1) -polygon(c(-1.96,x,1.96),c(0,y,0),col="#CCCCCC") -text(-2.3,0.1,"-1.96") -text(2.2,0.1,"1.96") - -x=seq(-3,3,length=200) -y=dnorm(x,mean=0,sd=1) -plot(x,y,type="l") -x=seq(-1.64,3,length=100) -y=dnorm(x,mean=0,sd=1) -polygon(c(-1.64,x,3),c(0,y,0),col="#CCCCCC") -text(-1.75,0.2,"-1.64") - -title("Area Under the Normal Curve") -``` - -The formula for a one-sample *z*-test is as follows: - -$$ -z_{\bar{X}} = \frac{\bar{X} - \mu_0}{\sigma / \sqrt{N}} -$$ -We have already calculated these values. But let's calculate some of them again as a reminder: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describe(PhysTime$minutes) -``` - -* Sample mean is 9.9 -* Population mean (the one we're comparing to) is 10.5 -* Standard deviation is 2 -* *N* is 200 - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -(9.9 - 10.5)/(2/sqrt(200)) -``` -The resulting value, $z = -4.242$ is our test value. Because this far exceeds $\pm 1.96$ we know (from memory) that there is a statistically significant effect. Just to be certain, let's use the *pnorm()* function to obtain the *p* value. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pnorm(-4.24, mean=9.9, sd=2) -``` -Simply with these hand-calculations, we can claim that there was a statistically significant difference between the physician/patient visit times in our simulated sample data and external benchmark criteria: $z(200) = -4.24, p < .001$. - -The one sample *z*-test is rarely sighted in the published literature. However, a close inspection of a table of critical *t*-values, reveals that the very bottom row (i.e., when sample sizes are 120 or greater) is, in fact, the *z* criteria. Thus, it is time to learn about the one sample *t*-test. - -## Introducing the One-Sample *t*-test - -The one-sample *t*-test is used to evaluate whether the mean of a sample differs from another value that, symbolically, is represented as the population mean. Green and Salkind [-@green_using_2017] noted that this value is often the midpoint of set of scores, the average value of the test variable based on past research, or a test value as the chance level of performance. - -![An image of a row with two boxes labeled Condition A (in light blue) and the population mean (in dark blue) to which it is being compared. This represents the use of a one-sample *t*-test.](images/ttests/onesample.jpg) - -This comparison is evident in the numerator of the formula for the *t*-test that shows the population mean $\mu$ being subtracted from the sample mean$\bar{X}$. - -$$ -t = \frac{\bar{X} - \mu}{\hat{\sigma}/\sqrt{N} } -$$ -Although this statistic is straightforward, it is quite limited. If the researcher wants to compare an outcome variable across two groups of people, they should consider the [independent samples *t*-test](#tIndSample). If the participant wants to evaluate an outcome variable with two observations from the same group of people, they should consider the [paired samples *t*-test](#tPaired) - -### Workflow for the One-Sample *t*-test - -The following is a proposed workflow for conducting a one-sample *t*-test. - -![A colorful image of a workflow for the one sample *t*-test](images/ttests/OneSampleWrkFlw.jpg) - -If the data meets the assumptions associated with the research design (e.g., independence of observations and a continuously scaled metric), these are the steps for the analysis of a one-sample *t*-test: - -1. Prepare (upload) data. -2. Explore data with - - graphs - - descriptive statistics -3. Assess normality via skew and kurtosis -4. Select the comparison (i.e., test, population) value -5. Compute the one sample *t*-test -6. Compute an effect size (frequently the *d* statistic) -7. Manage Type I error -8. Sample size/power analysis (which you should think about first, but in the context of teaching statistics, it's more pedagogically sensible, here). - -## Research Vignette - -Empirically published articles where *t*-tests are the primary statistic are difficult to locate. Having exhausted the psychology archives, I located this article in an interdisciplinary journal focused on palliative medicine. The research vignette for this lesson examined differences in physician's verbal and nonverbal communication with Black and White patients at the end of life [@elliott_differences_2016]. - -Elliott and colleagues [-@elliott_differences_2016] were curious to know if hospital-based physicians (56% White, 26% Asian, 7.4% each Black and Hispanic) engaged in verbal and nonverbal communication differently with Black and White patients. Black and White patient participants were matched on characteristics deemed important to the researchers (e.g., critically and terminally ill, prognostically similar, expressed similar treatment preferences). Interactions in the intensive care unit were audio and video recorded and then coded on dimensions of verbal and nonverbal communication. - -Because each physician saw a pair of patients (i.e., one Black patient and one White patient), the researchers utilized a paired samples, or dependent *t*-test. This statistical choice was consistent with the element of the research design that controlled for physician effects through matching (and one we will work in a later lesson). Below are the primary findings of the study. - -| |Black Patients |White Patients | | -|:---------------|:--------------|:--------------|:--------| -|Category |*Mean*(*SD*) |*Mean*(*SD*) |*p*-value| -|Verbal skill score (range 0 - 27)|8.37(3.36) | 8.41(3.21) |0.958| -|Nonverbal skill score (range 0 - 5) |2.68(.84) | 2.93(.77)|0.014| - -In the research vignette Elliott et al. [-@elliott_differences_2016] indicated that physician/patient visits lasted between 3 minutes and 40 seconds to 20 minutes and 13 seconds. For the purpose of demonstrating the one sample *t*-test, we might want to ask whether the length of patient visits in this research study were statistically significantly different than patient in the ICU or in palliative care, more broadly. Elliott et al.[-@elliott_differences_2016] did not indicate a measure of central tendency (i.e., mean, mode, median) therefore, I will simulate the data by randomly generating 33 numbers with a mean of 8 and a standard deviation of 2.5. I will use *random selection with replacement*, which allows the same number to be selected more than once. - -### Data Simulation - -I re-simulated (what may seem like identical data from above)to be consistent with the journal article's research sample of 33. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} - -#Setting the "random" seed ensures that everyone gets the same result, every time they rerun the analysis. -#My personal practice is to create a random seed that represents the day I write up the problem (in this case August, 15, 2022) -#When the Suggestions for Practice invite you to "change the random seed," simply change this number to anything you like (maybe your birthday or today's date) -set.seed(220822) -dfOneSample <- data.frame(PhysMins = rnorm(33, mean=10, sd=2.5)) - -head(dfOneSample) -``` - -A warning: this particularly analysis (the whole lesson, in fact) is "more simulated than usual" and does not represent reality. However, this research vignette lends itself for this type of question. - -With our data in hand, let's examine its structure. The variable representing physician minutes represents the ratio scale of measurement and therefore should be noted as *num* (numerical) in R. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -str(dfOneSample) -``` -Below is code for saving the data to your computer (and then re-importing) as .csv or .rds files. I make choices about saving data based on what I wish to do with the data. If I want to manipulate the data outside of R, I will save it as a .csv file. It is easy to open .csv files in Excel. A limitation of the .csv format is that it does not save any restructuring or reformatting of variables. For this lesson, this is not an issue. - -Although you do not need to save nor re-import the data for this lesson, here is code for saving the data as a .csv and then reading it back into R. I have hashtagged these out, so you will need to remove the hashtags if you wish to run any of these operations. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#writing the simulated data as a .csv -#write.table(dfOneSample, file = "dfOneSample.csv", sep = ',', col.names=TRUE, row.names=FALSE) -#at this point you could clear your environment and then bring the data back in as a .csv -#reading the data back in as a .csv file -#dfOneSample<- read.csv ('dfOneSample.csv', header = TRUE) -``` - -The .rds form of saving variables preserves any formatting (e.g., creating ordered factors) of the data. A limitation is that these files are not easily opened in Excel. Again, you do not need to save nor re-import the data for this lesson. However, if you would like to do so, here is the hashtagged code (remove hashtags if you wish to do this) for writing (and then reading) this data as an .rds file. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#saveRDS(dfOneSample, 'dfOneSample.rds') -#dfOneSample <- readRDS('dfOneSample.rds') -``` - -### Quick Peek at the Data - -Plotting the data is best practice to any data analysis. Further, visualizing the data can help us with a conceptual notion of the statistic we are utilizing. The *ggpubr* package is one of my go-to-tools for quick and easy plots of data. Below, I have plotted the time-with-patient (Physician Seconds) variable and added the mean. As with most plotting packages, ggpubr will "bin" (or cluster) the data for plotting; this is especially true for data with a large number of units (a range from 220 to 1213 is quite large). The "rug = TRUE" command added a lower row of the table to identify where each of the datapoint follows. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ggpubr::gghistogram(dfOneSample, x = "PhysMins", add = "mean", rug = TRUE, color = "#993366") -``` - -Although the histogram is not perfectly normal, we can see at least the suggestion of a normal distribution. With only a sample of 33, I'm encouraged. - -Another view of our data is with a boxplot. The box captures the middle 50% of data with the horizontal bar at the median. The whiskers extend three standard deviations around the mean with dots beyond the whiskers representing outliers. I personally like the *add="jitter"* statement because it shows where each case falls. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ggpubr::ggboxplot(dfOneSample$PhysMins, - ylab = "Minutes with Patient", xlab = FALSE, add="jitter" - ) -``` -We can further evaluate normality by obtaining the descriptive statistics with the *describe()* function from the *psych* package. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describe(dfOneSample$PhysMins) -``` - -Here we see that our minutes range from 4.92 to 17.41 with a mean of 10.01 and a standard deviation of 2.7. We're ready to calculate the one sample *t*-test. - -## Working the One Sample *t*-test (by hand) - -### Stating the Hypothesis - -A quick scan of the literature suggests that health care workers' visits to patients in the ICU are typically quite brief. Specifically, the average duration of a physician visit in a 2018 study was 73.5 seconds or 1.23 minutes [@butler_estimating_2018]. A one-sample *t*-test is appropriate for comparing the visit lengths from our sample to this external metric. - -As noted in the symbolic presentation below, our null hypothesis ($H_0$) states that our data will be equal to the test value of 1.23 minutes. In contrast, the alternative hypothesis ($H_A$) states that these values will not be equal. - -$$ -\begin{array}{ll} -H_0: & \mu = 1.23 \\ -H_A: & \mu \neq 1.23 -\end{array} -$$ - -### Calculating the *t*-test - -In learning the statistic, hand-calculations can help understand what the statistic is doing. Here's the formula again: - -$$ -t = \frac{\bar{X} - \mu}{\hat{\sigma}/\sqrt{N} } -$$ - -The numerator of the formula below subtracts the test value from the sample mean. The denominator involves multiplying the standard deviation by the square root of the sample size. The descriptive statistics provided the values we need to complete the analysis: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -(10.01 - 1.23)/(2.7/sqrt(33)) -``` - -#### Statistical Significance - -If we ask about *statistical significance* then we are engaged in *null hypothesis significance testing* (NHST). In the case of a one sample test, we construct our hypothesis with a null and an alternative that are relatively straightforward. Specifically, we are interested in knowing if our sample mean (10.01) is statistically, significantly different from the test value of 1.23. We can write the hypotheses in this way: - -$$ -\begin{array}{ll} -H_0: & \mu = 1.23 \\ -H_A: & \mu \neq 1.23 -\end{array} -$$ -In two parts, our null hypothesis ($H_0$) states that the population mean ($H_0$) for physician visits with palliative care patients is 1.23; the alternative $\mu \neq$ states that it is not 1.23. - -When we calculated the *t*-test, we obtained a *t* value. We can check the statistical significance by determining the test critical value from a [table of critical values](https://www.statology.org/t-distribution-table/) for the *t* distribution. There are many freely available on the internet. If our *t* value exceeds the value(s) in the table of critical values, then we can claim that our sample mean is statistically significantly different from the hypothesized value. - -Heading to the table of critical values we do the following: - -* For the one-sample *t*-test, the degrees of freedom (DF) is equal to *N* - 1 (32). The closest value in our table is 30, so we will use that row. -* A priorily, we did not specify if we thought the difference would be greater, or lower. Therefore, we will use a column that indicates *two-tails*. -* A *p* value of .05 is customary (but it will be split between two tails). -* Thus, if our *t*-value is lower than -2.042 or higher than 2.042 we know we have a statistically significant difference. - -In our case, the *t* value of 18.68 far exceeded the test critical value of 2.042. We would write the statistical string this way: *t*(32) = 18.68, *p* < .05. - -In base R, the *qt()* function will look up a test critical value. For the one-sample *t*-test, degrees of freedom (df) is equal to $N-1$. We "divide the *p* value by 2" when we want a two-tailed test. Finally, the "lower.tail" command results in positive or negative values in the tail. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -qt(p=.05/2, df=32,lower.tail=FALSE) -``` -Not surprisingly, this value is quite similar to the value we saw in the table. The *qt()* function is more accurate because it used df = 32 (not rounded down to 30). - -#### Confidence Intervals - -How confident are we in our result? With the one sample *t*-test, it is common to report an interval in which we are 95% confident that that our sample mean exists. Below is the formula, which involves: - -* $\bar{X}$ is the sample mean; in our case this is 10.01 -* $t_{cv}$ the test critical value for a two-tailed model (even if the hypothesis was one-tailed) where $\alpha = .05$ and the degrees of freedom are $N-1$ -* $\frac{s}{\sqrt{n}}$ was the denominator of the test statistic it involves the standard deviation of our sample (2.7) and the square root of our sample size (33) - -$$\bar{X} \pm t_{cv}(\frac{s}{\sqrt{n}})$$ -Let's calculate it: - -First, let's calculate the proper *t* critical value. Even though these are identical to the one above, I am including them again. Why? Because if the original hypothesis had been one-tailed, we would need to calculate a two-tailed confidence interval; this is a placeholder to remind us. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -qt(p=.05/2, df=32,lower.tail=FALSE) -``` -Using the values from above, we can specify both the lower and upper bound of our confidence interval. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -(10.01) - ((2.0369)*(2.7/sqrt(33))) -(10.01) + ((2.0369)*(2.7/sqrt(33))) -``` -The resulting interval is the 95% confidence interval around our sample mean. Stated another way, we are 95% certain that the true mean of time with patients in our sample ranges between 9.05 and 10.97 minutes. - -#### Effect size - -If you have heard someone say something like, "I see there is statistical significance, but is the difference *clinically significant*," the person is probably asking about *effect sizes.* Effect sizes provide an indication of the magnitude of the difference. - -The *d* statistic is commonly used with *t*-tests; *d* assesses the degree that the mean on the test variable differs from the test value. Conveniently, *d* represents standard deviation units. A *d* value of 0 indicates that the mean of the sample equals the mean of the test value. As *d* moves away from 0 (in either direction), we can interpret the effect size to be stronger. Conventionally, the absolute values of .2, .5, and .8, represent small, medium, and large effect sizes, respectfully. - -Calculating the *d* statistic is easy. Here are two equivalent formulas: - -$$d = \frac{Mean Difference}{SD}=\frac{t}{\sqrt{N}}$$ -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#First formula -(10.01 - 1.23)/2.7 -#Second formula -18.68047/sqrt(33) -``` -The value of 3.25 indicates that the test value is approximately more than three standard deviations away from the sample mean. This is a very large difference. - -## Working the One-Sample *t*-test with R Packages - -### Evaluating the Statistical Assumptions - -Let's rework the problem in R. We start at the top of the flowchart, evaluating the statistical assumptions. - -![The workflow for the one sample *t*-test highlighting the evaluation of assumptions section](images/ttests/OneSampleAssmptns.jpg) -All statistical tests have some assumptions about the data. The one-sample *t*-test has three. - -* The scores on the test variable as independent of each other. This is a research design issue and the one-sample *t*-test is not robust to violating this assumption. - - If physicians were contributing more than one data point, this vignette potentially violated this assumption. For the sake of simplicity, let's presume that each physician contributed visit length (minutes) for only one patient. If the research scenario was such that physicians contributed multiple datapoints a potential analytic choice that is robust to such a violation is [multilevel modeling](https://lhbikos.github.io/MultilevelModeling/). -* The test variable should be continuously scaled. This is also a matter of research design and no statistical analysis is required. - - Our test variable is measured in minutes; this is continuously scaled and has the properties of *ratio*-level data. -* The test variable is normally distributed. We can check this several ways: - - visually with histograms (perhaps with superimposed curves) and boxplots, - - calculation of skew and kurtosis values, - - calculation of the Shapiro-Wilk test of normality - -#### Is the Test Variable Normally Distributed? - -Thus, we need only to assess whether the test variable is normally distributed. The *pastecs::stat.desc()* function will provide all of this information in one test. We need only add the specification, "norm=TRUE". - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#pastecs is the package, stat.desc is the function -#we point it to the data and then add the norm=TRUE command -pastecs::stat.desc(dfOneSample, norm=TRUE) -``` - -Recall from the lesson on [Preliminary Results](#preliminaries) that there are multiple ways to assess severity of skew and kurtosis. Values greater than the absolute value of 3.0 are concerning for the "skewness" output. The PhysMins skewness values of 0.36 is well below that threshold. Values greater than the absolute value of 10 are concerning for the "kurtosis" output. The PhysMins skewness value of 0.035 is well below that thresshold. The "skew.2SE" and "kurt.2SE" values are standardized. The "2" in the "skew.2SE" is a helpful reminder that, in smaller sample sizes", using the 1.96 (or "2") criteria is acceptable in determining problematic skew or kurtosis. The PhysMins values of 0.44 and 0.022 fall well below those areas of concern. - -Regarding a formal assessment of normality, the *pastecs::stat.descr()* output includes the Shapiro-Wilk value (normtest.W) and statistical significance (normtest.p). Non-significant results indicate that the distribution of the PhysMins variable is not statistically significantly different from a normal distribution. In the case of PhysMins, $W = 0.977, p = 0.682$. - -Considering skewness, kurtosis, and normality estimates together, we are confident that we have not violated the assumption of normality. - -### Computing the *t*-test - -Now we are ready to calculate the *t*-test, itself. - -![The workflow for the one sample *t*-test highlighting the evaluation of assumptions section](images/ttests/OneSampleT.jpg) - -Calculating a one sample *t*-test is possible through base R and a number of packages. Kassambara's [-@kassambara_pipe-friendly_nodate] *rstatix* package is one we can use for the *t*-test and ANOVA problems that we will work. I like it for several reasons. First, it was designed to be "pipe-friendly" in a manner that is consistent with the *tidyverse* approach to working in R and there are numerous tutorials. Additionally, *rstatix* objects work well with *ggpubr*, one of my favorite packages for graphing data and results. - -In the script below: - -* the first element points to the dataframe -* the second element provides a "formula" - - we are predicting "PhysMins" from "1" which represent an invariant/constant hypothesized mean -* the third element identifies the population/comparison mean -* specifying "detailed = TRUE" will produce the 95% confidence interval around the mean (i.e., in this case the average amount of time that physicians in our sample spent with their patients) - - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::t_test(dfOneSample, PhysMins ~ 1, mu = 1.23, detailed = TRUE) -``` - -The results we obtained are identical to those we hand-calculated. The *rstatix* output also includes confidence intervals. In the case of the one-sample *t*-test, this represent the 95% confidence interval around the mean. That is, we are 95% confident that the true mean of the minutes that physicians in our sample spent with patients falls between 9.05 and 10.97. I appreciate that the *rstatix* output reminds us that we are using a *t*-test and that it is a two-sided hypothesis. - - -Knowing what the confidence interval is "around" can be tricky. Whatever the "topic" of the confidence interval will be exactly in the middle of (most) confidence intervals. We can check ourselves by adding the two ends of the confidence interval and dividing by two. -```{r} -(9.050577 + 10.96577)/2 -``` -As we see, 10.008 is the reported as the "estimate." We know from our earlier analysis of the descriptive statistics that this is the value of the mean. If we are uncertain, we can check: - -```{r} -mean(dfOneSample$PhysMins) -``` - -From these results, we can begin to create our *t* string: $t(32) = 18.67, p < .001, CI95(9.05, 10.97)$ - -With a separate command, we can use the *rstatix* package to obtain the effect size, *d*. With the exception of including the "ref.group = NULL" statement, the script is quite similar. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::cohens_d(dfOneSample, PhysMins ~ 1, ref.group = NULL, mu = 1.23) -``` -From these results, we can begin to complete our *t* string: $t(32) = 18.672, p < .001, CI95(9.05, 10.97), d = 3.25$ - - -## APA Style Results - -Let's write up the results. In-so-doing, I would include the boxplot we produced during our initial exploration of the data. - -> Preliminary inspection of the data indicated that we did not violate the assumption of normality. Specifically, our skew (0.36) and kurtosis (0.035) values fell below that absolute values (3.0, 10.0, respectively) that are concerning [@kline_data_2016]. Further, the Shapiro-Wilk test of normality suggested that the distribution of our sample data did not differ significantly from a normal distribution $(W = 0.977, p = 0.682)$ - -> A one-sample *t*-test was used to evaluate whether average amount of time that a sample of physicians (palliative care physicians in the ICU) enrolled in a research study on patient communication was statistically significantly different from the amount of time that ICU physicians spend with their patients, in general. The sample mean 10.008 (*SD* = 2.7016) was significantly different from 1.23, $t(32) = 18.672, p < .001., CI95(9.05, 10.97), d = 3.25$. The effect size, (*d*) indicates a very large effect. Figure 1 illustrates the distribution of time physicians in the research study spent with their patients. The results support the conclusion that physicians in the research study spent more time with their patients than ICU physicians in general. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ggpubr::ggboxplot(dfOneSample$PhysMins, - ylab = "Physician Minutes", xlab = FALSE, add="jitter", title = "Figure 1. Physician Time with Patients (in minutes)" - ) -``` - -Reflecting on these results, I must remind readers that this simulated data that is even further extrapolated. Although "data" informed both the amount of time spent by the physicians in the research study and data used as the test value, there are probably many reasons that the test value was not a good choice. For example, even though both contexts were ICU, palliative physicians may have a different standard of care than ICU physicians "in general." - - -## Power in One-Sample *t*-tests - -Researchers often use power analysis packages to estimate the sample size needed to detect a statistically significant effect, if, in fact, there is one. Utilized another way, these tools allows us to determine the probability of detecting an effect of a given size with a given level of confidence. If the probability is unacceptably low, we may want to revise or stop. A helpful overview of power as well as guidelines for how to use the *pwr* package can be found at a [Quick-R website](https://www.statmethods.net/stats/power.html) [@kabacoff_power_2017]. - -In Champely's *pwr* package, we can conduct a power analysis for a variety of designs, including the one sample *t*-test that we worked in this lesson. There are a number of interrelating elements of power: - -* Sample size, *n* refers to the number of observations; our vignette had 33 -* *d* refers to the difference between means divided by the pooled standard deviation; ours was (10.01-1.23)/2.7; we can use the results from Cohen's *d*. -* *power* refers to the power of a statistical test; conventionally it is set at .80 -* *sig.level* refers to our desired alpha level; conventionally it is set at .05 -* *type* indicates the type of test we ran; this was "one.sample" -* *alternative* refers to whether the hypothesis is non-directional/two-tailed ("two.sided") or directional/one-tailed("less" or "greater") - -In this script, we must specify *all-but-one* parameter; the remaining parameter must be defined as NULL. R will calculate the value for the missing parameter. - -When we conduct a "power analysis" (i.e., the likelihood of a hypothesis test detecting an effect if there is one), we specify, "power=NULL". Using the data from our results, we learn from this first run, that our statistical power was 1.00. That is, given the value of the mean difference relative to the pooled standard deviation we had a 100% chance of detecting a statistically significant effect if there was one. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.t.test(d= 3.25,n = 33, power=NULL,sig.level=0.05,type="one.sample",alternative="two.sided") -``` -Researchers frequently use these tools to estimate the sample size required to obtain a statistically significant effect. In these scenarios we set *n* to *NULL*. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.t.test(d= 3.25, n = NULL, power=0.8,sig.level=0.05,type="one.sample",alternative="two.sided") -``` -Shockingly, this suggests that a sample size of 3 could result in a statistically significant result. Let's see if this is true. Below I will re-simulate the data for the verbal scores, changing only the sample size: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -set.seed(220822) -rdfOneSample <- data.frame(rPhysMins = rnorm(3, mean=10, sd=2.5)) - -head(rdfOneSample) -``` -With the newly simulated data, I will run the one-sample *t*-test: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::t_test(rdfOneSample, rPhysMins ~ 1, mu = 1.23, detailed = TRUE) -rstatix::cohens_d(rdfOneSample, rPhysMins ~ 1, ref.group = NULL, mu = 1.23) -``` - -In this case our difference between the sample data and the external data is so huge, that a sample of three still nets a statistically significant result. This is unusual. Here's the *t* string: $t(2) = 9.379, p = 0.011, d = 5.415, CI95[5.780, 13.492]$. - -## Practice Problems - -The suggestions for homework differ in degree of complexity. I encourage you to start with a problem that feels "do-able" and then try at least one more problem that challenges you in some way. Regardless, your choices should meet you where you are (e.g., in terms of your self-efficacy for statistics, your learning goals, and competing life demands). Using R packages, complete a one-sample *t*-test. - -Additionally, please complete at least one set of *hand calculations*, that is using the code demonstrated in the chapter to work through the formulas that compute the one-sample *t*-test. At this stage in your learning, you may ignore any missingness in your dataset by excluding all rows with missing data in your variables of interest. - -### Problem #1: Rework the research vignette as demonstrated, but change the random seed - -If this topic feels a bit overwhelming, simply change the random seed in the data simulation of the research vignette, then rework the problem. This should provide minor changes to the data but the results will likely be very similar. That said, don't be alarmed if what was non-significant in my working of the problem becomes significant. Our selection of *p* < .05 (and the corresponding 95% confidence interval) means that 5% of the time there could be a difference in statistical significance. - -### Problem #2: Rework the research vignette, but change something about the simulation - -Rework the one sample *t*-test in the lesson by changing something else about the simulation. Perhaps estimate another comparative number. The 1.23 was a dramatic difference from the mean of the research participants. Perhaps suggest (and, ideally, support with a reference) a different value. Alternatively, if you are interested in issues of power, specify a different sample size. - -### Problem #3: Use other data that is available to you - -Using data for which you have permission and access (e.g., IRB approved data you have collected or from your lab; data you simulate from a published article; data from an open science repository; data from other chapters in this OER), complete an independent samples *t* test. - -### Grading Rubric - -Regardless which option(s) you chose, use the elements in the grading rubric to guide you through the practice. - -|Working the problem with R and R packages | Points Possible | Points Earned| -|:---------------------------------------- |:----------------: |:------------:| -|1. Narrate the research vignette, describing the variables and their role in the analysis | 5 |_____ | -|2. Simulate (or import) and format data | 5 |_____ | -|3. Evaluate statistical assumptions | 5 |_____ | -|4. Conduct a one sample *t*-test (with an effect size) |5 | _____ | -|5. APA style results with table(s) and figure | 5 |_____ | -|6. Conduct power analyses to determine the power of the current study and a recommended sample size| 5 |_____ | -|7. Explanation to grader | 5 |_____ | -|**Totals** | 35 |_____ | - - -|Hand Calculations |Points Possible | Points Earned -|:-----------------------------------------|:--------------:|:--------------| -|1. Using traditional NHST (null hypothesis testing language), state your null and alternative hypotheses| 2 |_____ -|2. Calculate the mean of your sample; identify the mean of your benchmarking sample | 2 |_____| -|3. Using the steps from the previous lesson, calculate the standard deviation of your sample. This should involve variables representing the mean, mean deviation, and mean deviation squared |6 |_____| -|4. Calculate the one-sample *t*-test| 4 |_____| -|5. Identify the degrees of freedom associated with your *t*-test | 2 |_____| -|6. Locate the test critical value for your test |2 |_____ | -|7. Is the *t*-test statistically significant? Why or why not? | 2 |_____ | -|8. Calculate the confidence interval around your sample mean |2 |_____ | -|9. Calculate the effect size (i.e., Cohen's *d* associated with your *t*-test |2 |_____ | -|**Totals** | 24 |_____ | - - -```{r, child= 'Worked_Examples/15-3-woRked_tOneSample.Rmd'} -``` - -```{r include=FALSE} -sessionInfo() -``` - - - diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/5E4949E5-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/5E4949E5-contents deleted file mode 100644 index e69de29b..00000000 diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/66352AA2-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/66352AA2-contents deleted file mode 100644 index 95078eae..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/66352AA2-contents +++ /dev/null @@ -1,601 +0,0 @@ -# Paired Samples *t*-test {#tPaired} - -[Screencasted Lecture Link](https://youtube.com/playlist?list=PLtz5cFLQl4KNYvBQJnO_VFpoS5gJJOTJ8) - -```{r include=FALSE} -knitr::opts_chunk$set(echo = TRUE) -knitr::opts_chunk$set(comment = NA) #keeps out the hashtags in the knits -options(scipen=999)#eliminates scientific notation -``` - -Researchers are often interested in knowing if participants score differently on some outcome variable (like affective well-being) across two conditions. These conditions could be before and after an intervention; they could also be interventionless exposures such as scary versus funny movies. In these simple designs, the paired *t*-test can be used to test the researchers' hypotheses. - -## Navigating this Lesson - -There is about 45 minutes of lecture. If you work through the materials with me it would be plan for an additional hour - -While the majority of R objects and data you will need are created within the R script that sources the chapter, occasionally there are some that cannot be created from within the R framework. Additionally, sometimes links fail. All original materials are provided at the [Github site](https://github.com/lhbikos/ReCenterPsychStats) that hosts the book. More detailed guidelines for ways to access all these materials are provided in the OER's [introduction](#ReCintro) - -### Learning Objectives - -Learning objectives from this lecture include the following: - -* Recognize the research questions for which utilization of paired sample *t*-tests would be appropriate. -* Narrate the steps in conducting a paired samples *t*-test, beginning with testing the statistical assumptions through writing up an APA style results section. -* Calculate a paired samples *t*-test in R (including effect sizes). -* Interpret a 95% confidence interval around a mean difference score. -* Produce an APA style results for a paired-samples *t*-test. -* Determine a sample size that (given a set of parameters) would likely result in a statistically significant effect, if there was one. - -### Planning for Practice - -The suggestions for homework vary in degree of complexity. The more complete descriptions at the end of the chapter follow these suggestions. - -* Rework the paired samples *t*-test in the lesson by changing the random seed in the code that simulates the data. This should provide minor changes to the data, but the results will likely be very similar. -* Rework the paired samples *t*-test in the lesson by changing something else about the simulation. For example, if you are interested in power, consider changing the sample size. -* Use the simulated data that is provided, but use the nonverbal variable, instead. -* Conduct paired *t*-test with data to which you have access and permission to use. This could include data you simulate on your own or from a published article. - -### Readings & Resources - -In preparing this chapter, I drew heavily from the following resource(s). Other resources are cited (when possible, linked) in the text with complete citations in the reference list. - -* How to Do Paired T-test in R: The Best Tutorial You Will Love. (n.d.). Datanovia. Retrieved May 25, 2023, from https://www.datanovia.com/en/lessons/how-to-do-a-t-test-in-r-calculation-and-reporting/how-to-do-paired-t-test-in-r/ - - This tutorial provides a demonstration of the paired sampes t-test using the *rstatix* package. -* Navarro, D. (2020). Chapter 13: Comparing two means. In [Learning Statistics with R - A tutorial for Psychology Students and other Beginners](https://learningstatisticswithr.com/). Retrieved from https://stats.libretexts.org/Bookshelves/Applied_Statistics/Book%3A_Learning_Statistics_with_R_-_A_tutorial_for_Psychology_Students_and_other_Beginners_(Navarro) - - Navarro's OER includes a good mix of conceptual information about *t*-tests as well as R code. My lesson integrates her approach as well as considering information from Field's [-@field_discovering_2012] and Green and Salkind's [@green_using_2017] texts (as well as searching around on the internet). -* Elliott, A. M., Alexander, S. C., Mescher, C. A., Mohan, D., & Barnato, A. E. (2016). Differences in Physicians’ Verbal and Nonverbal Communication With Black and White Patients at the End of Life. *Journal of Pain and Symptom Management, 51*(1), 1–8. https://doi.org/10.1016/j.jpainsymman.2015.07.008 - - The source of our research vignette. - -### Packages - -The script below will (a) check to see if the following packages are installed on your computer and, if not (b) install them. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#will install the package if not already installed -#if(!require(psych)){install.packages("psych")} -#if(!require(faux)){install.packages("faux")} -#if(!require(tidyverse)){install.packages("tidyverse")} -#if(!require(dplyr)){install.packages("dplyr")} -#if(!require(ggpubr)){install.packages("ggpubr")} -#if(!require(pwr)){install.packages("pwr")} -#if(!require(apaTables)){install.packages("apaTables")} -#if(!require(knitr)){install.packages("knitr")} -#if(!require(rstatix)){install.packages("rstatix")} -``` - -## Introducing the Paired Samples *t*-test - -There are a couple of typical use cases for the paired samples *t*-test. Repeated measures or change-over-time is a very common use. In this case, the research participant may take a pre-test, be exposed to an intervention or other type of stimulus, then take a post-test. Owing to the limitations of the statistics, all participants must be exposed to the same intervention/stimulus. - -![An image of a row with three boxes: pre-test (in blue), intervention or exposure to stimulus (in light red), post-test (in blue) representing the use of a paired samples *t*-test in a repeated measures design](images/ttests/prepost_paired.jpg) - -A second common use is the assessment of a research participant in two competing conditions. An example might be the galvanic skin response ratings when a participant's hand is submerged in ice versus the GSR ratings when the hand is not exposed in ice. A strength of this design is the within-subjects' control of the participant. - -![An image of a row with two boxes labeled Condition A in light blue) and Condition B (in dark blue). This represents the use of a paired samples *t*-test to compare across conditions](images/ttests/conditions_paired.jpg) - -In the formula for the paired samples *t*-test we see a $\bar{D}$ in the numerator. This represents the *difference* between the continuously scaled scores in the two conditions. The denominator involves a standard deviation of the difference scores ($\hat\sigma_D$) and the square root of the sample size. - -$$t = \frac{\bar{D}}{\hat\sigma_D / \sqrt{N}}$$ -Although these types of research design and analyses are quite handy, they have some limitations. First, the paired samples *t*-test cannot establish causality because it lacks elements such as comparing conditions (e.g., treatment vs. control) and random assignment to those conditions. If a research wants to compare pre-post change as a result of participating in more-than-one condition, a [mixed design ANOVA](#Mixed) would be a better option. Second, the paired samples *t*-test cannot accommodate more than two comparison conditions. If the researcher wants to compare three or or more time periods or conditions, they will want to consider [repeated measures ANOVA](#Repeated) or [multilevel/hierarchical linear modeling](https://lhbikos.github.io/MultilevelModeling/). - -### Workflow for Paired Samples *t*-test - -The following is a proposed workflow for conducting the paired samples *t*-test. - -![A colorful image of a workflow for the paired samples *t*-test](images/ttests/PairedSampleWrkFlw.jpg) - -If the data meets the assumptions associated with the research design (e.g., independence of difference scores and a continuously scaled metric for that difference score), these are the steps for the analysis of an independent samples *t*-test: - -1. Prepare (upload) data. -2. Explore data with - - graphs - - descriptive statistics -3. Assess normality of the difference scores via skew and kurtosis -4. Compute the paired samples *t*-test -5. Compute an effect size (frequently the *d* or *eta* statistic) -6. Manage Type I error -7. Sample size/power analysis (which you should think about first, but in the context of teaching statistics, it's more pedagogically sensible, here). - -## Research Vignette - -Empirically published articles where *t*-tests are the primary statistic are difficult to locate. Having exhausted the psychology archives, I located this article in an interdisciplinary journal focused on palliative medicine. The research vignette for this lesson examined differences in physician's verbal and nonverbal communication with Black and White patients at the end of life [@elliott_differences_2016]. - -Elliott and colleagues [-@elliott_differences_2016] were curious to know if hospital-based physicians (56% White, 26% Asian, 7.4% each Black and Hispanic) engaged in verbal and nonverbal communication differently with Black and White patients. Black and White patient participants were matched on characteristics deemed important to the researchers (e.g., critically and terminally ill, prognostically similar). Interactions in the intensive care unit were audio and video recorded and then coded on dimensions of verbal and nonverbal communication. - -Because each physician saw a pair of patients (i.e., one Black patient and one White patient), the researchers utilized a paired samples, or dependent *t*-test. This statistical choice was consistent with the element of the research design that controlled for physician effects through matching patients on critical characteristics. Below are the primary findings of the study. - - -| |Black Patients |White Patients | | -|:---------------|:--------------|:--------------|:--------| -|Category |*Mean*(*SD*) |*Mean*(*SD*) |*p*-value| -|Verbal skill score (range 0 - 27)|8.37(3.36) | 8.41(3.21) |0.958| -|Nonverbal skill score (range 0 - 5) |2.68(.84) | 2.93(.77)|0.014| - -The primary analysis utilized by Elliott and colleagues [-@elliott_differences_2016] was the paired samples *t*-test. We will replicate that exact analysis with simulated data. - -### Simulating Data for the Paired Samples *t*-test - -Below is the code I used to simulate the data. The following code assumes 33 physician participants who had separate interactions with critically ill, end-of-life stage patients, who were identified as Black and White. The Elliott et al. [-@elliott_differences_2016] manuscript describe the process for coding verbal and nonverbal communication for video/audio recordings of the physician/patient interactions. Using that data, I simulate verbal and nonverbal communication scores for 33 physicians who rate patients who identify as Black and White, respectively. This creates four variables. - -In the lesson, we will compare verbal communication scores. The nonverbal communication score is available as an option for practice. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -#Setting the seed. If you choose this practice option, change the number below to something different. -set.seed(220817) -#These define the characteristics of the verbal variable. It is essential that the object names (e.g., A_mean) are not changed because they will be fed to the function in the faux package. -sub_n <- 33 -A_mean <- 8.37 -B_mean <- 8.41 -A_sd <- 3.36 -B_sd <- 3.21 -AB_r <- 0.3 - -#the faux package can simulate a variety of data. This function within the faux package will use the objects above to simulate paired samples data -paired_V <- faux::rnorm_multi( - n = sub_n, - vars = 2, - r = AB_r, - mu = c(A_mean, B_mean), - sd = c(A_sd, B_sd), - varnames = c("Verbal_BL", "Verbal_WH") - ) - -paired_V <- paired_V %>% dplyr::mutate(PhysID = row_number()) - -#Here, I repeated the process for the nonverbal variable. -sub_n <- 33 -A_mean <- 2.68 -B_mean <- 2.93 -A_sd <- .84 -B_sd <- .77 -AB_r <- 0.9 - -paired_NV <- faux::rnorm_multi( - n = sub_n, - vars = 2, - r = AB_r, - mu = c(A_mean, B_mean), - sd = c(A_sd, B_sd), - varnames = c("NVerb_BL", "NVerb_WH") - ) - -#This code produced an ID number for each physician -paired_NV <- paired_NV %>% dplyr::mutate(PhysID = row_number()) - -#This data joined the two sets of data. -#Note, I did not write any code that assumed tha the verbal and nonverbal data came from the same physician. Full confession: I'm not quite sure how to do that just yet. -dfPairedSamples <- dplyr::full_join(paired_V, paired_NV, by = c("PhysID")) -dfPairedSamples <- dfPairedSamples%>%dplyr::select(PhysID, everything()) -``` - -Before beginning our analysis, let's check the format of the variables to see if they are consistent with the scale of measurement of the variables. In our case, we expect to see four variables representing the verbal and nonverbal communication of the physicians with the patients who are identified as Black and White. Each of the variables should be continuously scaled and, therefore, should be formatted as *num* (numerical). - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -str(dfPairedSamples) -``` -The four variables of interest are correctly formatted as *num*. Because PhysID (physician ID) will not be used in our analysis, its structure is irrelevant. - -Below is code for saving (and then importing) the data in .csv or .rds files. I make choices about saving data based on what I wish to do with the data. If I want to manipulate the data outside of R, I will save it as a .csv file. It is easy to open .csv files in Excel. A limitation of the .csv format is that it does not save any restructuring or reformatting of variables. For this lesson, this is not an issue. - -Here is code for saving the data as a .csv and then reading it back into R. I have hashtagged these out, so you will need to remove the hashtags if you wish to run any of these operations. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#writing the simulated data as a .csv -#write.table(dfPairedSamples, file = "dfPairedSamples.csv", sep = ',', col.names=TRUE, row.names=FALSE) -#at this point you could clear your environment and then bring the data back in as a .csv -#reading the data back in as a .csv file -#dfPairedSamples<- read.csv ('dfPairedSamples.csv', header = TRUE) -``` - -The .rds form of saving variables preserves any formatting (e.g., creating ordered factors) of the data. A limitation is that these files are not easily opened in Excel. Here is the hashtagged code (remove hashtags if you wish to do this) for writing (and then reading) this data as an .rds file. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#saveRDS(dfPairedSamples, 'dfPairedSamples.rds') -#dfPairedSamples <- readRDS('dfPairedSamples.rds') -``` -### Quick Peek at the Data - -Plotting the data is a helpful early step in any data analysis. Further, visualizing the data can help us with a conceptual notion of the statistic we are utilizing. The *ggpubr* package is one of my go-to-tools for quick and easy plots of data. The *ggpaired()* function is especially appropriate for paired data. A [tutorial](https://rpkgs.datanovia.com/ggpubr/reference/ggpaired.html) is available at datanovia. - -Especially unique about this function is that the lines connect the scores of each person across time or conditions. In this research scenario, the lines present the amount of time the physicians spent with each of the two patients they treated. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ggpubr::ggpaired(dfPairedSamples, cond1 = "Verbal_BL", cond2 ="Verbal_WH", color = "condition", line.color = "gray", palette =c("npg"), xlab = "Patient Race", ylab = "Verbal Communication Rating") -``` -The box of the boxplot covers the middle 50% (the interquartile range). The horizontal line is the median. The whiskers represent three standard deviations above and below the mean. Any dots beyond the whiskers are outliers. - - -## Working the Paired Samples *t*-Test (by hand) - -### Stating the Hypothesis - -In this lesson, I will focus on differences in the verbal communication variable. Specifically, I hypothesize that physician verbal communication scores for Black and White patients will differ. In the hypotheses below, the null hypothesis ($\mu_D$) states that the difference score is zero; the alternative hypothesis ($\mu_D$) states that the difference score is different from zero. - -$$H_{O}: \mu _{D} = 0$$ -$$H_{A}: \mu _{D} \neq 0$$ - -Notice the focus on a *difference* score. Even though the R package we will use does not require one for calculation, creating one in our df will be useful for preliminary exploration. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Creating the Verbal_D variable within the dfPairedSamples df -#Doing the "math" that informs that variable -dfPairedSamples$Verbal_D <- (dfPairedSamples$Verbal_BL - dfPairedSamples$Verbal_WH) -#Displaying the first six rows of the df to show that the difference score now exists -head(dfPairedSamples) -``` -Examining this new variable, because we subtracted the verbal communication ratings of physicians with White patients from those of Black patients a negative score means that physicians had lower verbal engagement with Black patients; a positive score means that physicians had more verbal engagement with White patients. - -### Calculating the Paired Samples *t*-Test - -Let's take another look at the formula for calculating paired samples *t*-test. - -$$t = \frac{\bar{D}}{\hat\sigma_D / \sqrt{N}}$$ -We can use the data from our preliminary exploration in the calculation. -```{r} -psych::describe(dfPairedSamples$Verbal_D) -``` - -* The mean difference was .08 -* The standard deviation of that difference was 4.14 -* The sample size is 33 - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -.08/(4.14/sqrt(33)) -``` -The resultant *t* value is 0.111. - -Hopefully, this hand-calculation provided an indication of how the means, standard deviation, and sample sizes contribute to the estimate of this *t*-test value. Now we ask, "But it is statistically significant?" - -#### Statistical Significance - -Our *t*-value was 0.111. We compare this value to the test critical value in a table of *t* critical values. In-so-doing we must know our degrees of freedom. Because the numerator in a paired samples *t*-test is a single difference score $\bar{D}$, the associated degrees of freedom is $N-1$. We must also specify the *p* value (in our case .05) and whether-or-not our hypothesis is unidirectional or bi-directional. Our question only asked, "Are the verbal communication levels different?" In this case, the test is two-tailed, or bi-directional. - -Let's return to the [table of critical values](https://www.statology.org/t-distribution-table/) for the *t* distribution to compare our *t*-value (0.111) to the column that is appropriate for our: - -* Degrees of freedom (in this case $N-1$ or 32) -* Alpha, as represented by $p < .05$ -* Specification as a one-tailed or two-tailed test - - Our alternative hypothesis made no prediction about the direction of the difference; therefore we will use a two-tailed test - -In the linked table, when the degrees of freedom reaches 30, there larger intervals. We will use the row representing degrees of freedom of 30. If our *t*-test value is lower than an absolute value of -2.042 or greater than the absolute value of 2.042, then our means are statistically significantly different from each other. In our case, we have not achieved statistical significance and we cannot say that the means are different. The *t* string would look like this: $t(32) = 0.111, p > .05$ - -We can also use the *qt()* function in base R. In the script below, I have indicated an alpha of .05. The "2" that follows indicates I want a two-tailed test. The 32 represents my degrees of freedom ($N-1$). In a two-tailed test, the regions of rejection will be below the lowerbound (lower.tail=TRUE) and above the upperbound (lower.tail=FALSE). - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -qt(.05/2, 32, lower.tail=TRUE) -qt(.05/2, 32, lower.tail=FALSE) -``` -If our *t* value is below the lowerbound (-2.04) or above the upper bound (2.04), then we have rejected the null hypothesis in favor of the alternative. As we demonstrated in the hand-calculations, we have not. The ratings of physicians' verbal engagement with patients who are racially identified as Black and White are not statistically significant. - -#### Confidence Intervals - -How confident are we in our result? With paired samples *t*-tests, it is common to report an interval in which we are 95% confident that our true mean difference exists. Below is the formula, which involves: - -* $\bar{D}$ the mean difference score -* $t_{cv}$ the test critical value for a two-tailed model (even if the hypothesis was one-tailed) where $\alpha = .05$ and the degrees of freedom are $N-1$ -* $s_{d}$ the standard deviation of $\bar{D}$ -* $N$ sample size - -$$\bar{D}\pm t_{cv}(s_{d}/\sqrt{n})$$ -Let's calculate it: - -First, let's get the proper *t* critical value: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -qt(.05/2, 32, lower.tail=TRUE) -qt(.05/2, 32, lower.tail=FALSE) -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -.08-(2.037*((4.14/(sqrt(33))))) -.08+(2.037*((4.14/sqrt(33)))) -``` -These values indicate the range of scores in which we are 95% confident that our true $\bar{D}$ lies. Stated another way, we are 95% confident that the true mean difference lies between -1.39 and 1.55. Because this interval crosses zero, we cannot rule out that the true mean difference is 0.00. This result is consistent with our non-significant *p* value. For these types of statistics, the 95% confidence interval and *p* value will always be yoked together. - -#### Effect Size - -Effect sizes address the magnitude of difference. There are two common effect sizes that are used with the paired samples *t*-test. The first is the *d* statistic, which measures, in standard deviation units, the distance between the two means. Regardless of sign, values of .2, .5, and .8 are considered to be small, medium, and large, respectively. - -Because the paired samples *t*-test used the difference score in the numerator, there are two easy options for calculating this effect: - -$$d=\frac{\bar{D}}{\hat\sigma_D}=\frac{t}{\sqrt{N}}$$ - -The first is to use the mean and standard deviation associated with the difference score: -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -.08/4.14 -``` -The formula uses the *t* value and *N*. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -0.111/(sqrt(33)) -``` -Within rounding error, both calculations result in a value ($d = 0.02$) that is quite small. - -Eta squared, $\eta^2$ is the proportion of variance of a test variable that is a function of the grouping variable. A value of 0 indicates that mean of the difference scores is equal to 0, where a value of 1 indicates that the difference scores in the sample are all the same nonzero value, and the test scores do not differ within each group. The following equation can be used to compute $\eta^2$. Conventionally, values of .01, .06, and .14 are considered to be small, medium, and large effect sizes, respectively. - -$$\eta^{2} =\frac{N(\bar{D}^{2})}{N(\bar{D}^{2}+(N-1)(\hat\sigma_D^{^{2}})}=\frac{t^{2}}{t^{2}+(N_{1}-1)}$$ -The first calculation option uses the N and the mean difference score: -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -(33*(.08^2))/((33*(.08^2)) + ((33-1)*(4.14^2))) -``` -The second calculation option uses the *t* values and sample size: -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -(0.111^2)/((0.111^2)+(33-1)) -``` -Within rounding errors, and similar to our *d* statistic, the $\eta^2$ value (0.0004) is quite small. - -## Working the Paired Samples *t*-Test with R Packages - -Let's rework the problem in R. We start at the top of the flowchart, evaluating the statistical assumptions. - -### Evaluating the Statistical Assumptions - -With an eye on our data, we can begin to explore the statistical assumptions associated with the paired samples *t*-test. Here's where we are in the workflow: - -![A colorful image of a workflow for the paired samples *t*-test highlighting the portion focused on assumptions](images/ttests/PairedAssmptns.jpg) -All statistical tests have some assumptions about the data. The paired-samples *t*-test has three: - -* The difference scores (i.e., the difference on the outcome across time or conditions) on the test variable are independent of each other. This is a matter of research design and no further statistical evaluation is required. -* The test variable should be continuously scaled. This is also a matter of research design and no statistical analysis is required. - - Our test variable is measured in minutes; this is continuously scaled and has the properties of *interval*-level data. -* The *difference scores* of the test variable are normally distributed. We can check this several ways: - - visually with histograms (perhaps with superimposed curves) and boxplots, - - calculation of skew and kurtosis values, - - calculation of the Shapiro-Wilk test of normality - -#### Are the difference scores of the test variable normally distributed? - -We can begin to evaluate normality by obtaining the descriptive statistics with the *describe()* function from the *psych* package. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describe(dfPairedSamples, type=1) -``` - -We observe that the skew and kurtosis values for Verbal_BL and Verbal_WH are well below the areas of concern (below the absolute value of 3 for skew; below the absolute values of 10 for kurtosis) identified by Kline [-@kline_data_2016]. - -Recall, though that the normality assumption for the paired samples *t*-test concerns the *difference score* (Verbal_D). We see that the mean difference is 0.08 (*SD* = 4.14). Its skew (-0.42) and kurtosis (-0.54) are also well-below the thresholds of concern. - -Beyond skew and kurtosis, we can formally test for deviations from normality with a Shapiro-Wilk. We want the results to be non-significant. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::shapiro_test(dfPairedSamples, Verbal_D) -``` -Results of the Shapiro-Wilk test of normality are not statistically significant $(W = 0.97, p = 0.57)$. This means that the distribution of difference scores is not statistically significantly different from a normal distribution. - -#### APA style write-up of testing the assumptions - -My practice is to create APA style drafts of the different sections of the analysis as I work along. Here's how I might capture our evaluation of the statistical assumptions: - ->We began by analyzing the data to see if it met the statistical assumptions for analysis with a paired samples *t*-test. One assumption is that the difference scores of dependent variable are normally distributed. We evaluated skew and kurtosis using Kline's [-@kline_data_2016] guidelines of the absolute values of 3 (skew) and 10 (kurtosis). Our results were well-within these boundary conditions. Further, a non-significant Shapiro-Wilk test of normality suggested that the distribution of difference scores was not statistically significant from a normal distribution $(W = 0.97, p = 0.57)$. - -### Computing the Paired Samples *t*-Test - -We are ready to compute the paired samples *t*-test. - -![A colorful image of a workflow for the paired samples *t*-test](images/ttests/PairedT.jpg) - -Calculating a paired samples *t*-test is possible through base R and a number of packages. Kassambara's [-@kassambara_pipe-friendly_nodate] *rstatix* package is one we can use for all of the *t*-test and ANOVA problems that we will work. - -A challenge in evaluating within-persons data is the *shape* of the data. The simulation resulted in a *wide* (also termed person-level or multivariate) format, where each of the 33 physicians has the verbal and non-verbal communication scores with Black and White patients. We need to reshape the data to a long (also termed person-period or univariate) format. Although it may seem a bit tricky at first, this is a skill you will return to in many longitudinal or repeated measures analyses. - -In the script below we are using the *melt()* and *setDT* functions from the *data.table* package. We put stable (i.e., time-invarient, "one-per-person") variables in a concatonated variable list of "id.vars." We create separate lists of the variables that change over time. In this case, each physician saw one Black patient and one White patient. Therefore, every physician will have two rows of data. For each variable collected at both points, we create concatonated lists. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -df_long <- data.table::melt(data.table::setDT(dfPairedSamples), id.vars=c("PhysID"), measure.vars=list(c("Verbal_BL", "Verbal_WH"), c("NVerb_BL", "NVerb_WH"))) -head(df_long) -``` -While that code performed the magic, it did not name the variables. We must provide that in separate code. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -df_long <- rename(df_long, PatientRace = variable, Verbal = value1, Nonverbal = value2 ) -``` - -After the reshaping, let's recheck the structure of our data: - -```{r} -str(df_long) -``` -The dependent variables Verbal and Nonverbal are continuously scaled, so the *num* designation is appropriate. Similarly, PatientRace is categorical, so *Factor* is appropriate. Because labels (instead of numbers) can minimize misinterpretation (or forgetting), I would prefer to use "Black" and "White" as opposed to "1" and "2". To further reduce the possibility of error, it is easy enough to create a second, parallel, variable. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -df_long$PtRace <- plyr::mapvalues(df_long$PatientRace, from = c(1, 2), to = c("Black", "White")) -``` - -We are now ready to perform the paired samples *t*-test. In the script below: - -* the first element points to the dataframe -* the second element provides a "formula" - - we are predicting "Verbal" from "PtRace" -* specifying "detailed = TRUE" will produce the 95% confidence interval around the difference - - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::t_test(df_long, Verbal ~ PtRace, paired=TRUE, detailed=TRUE) -``` - -This output provides information to get us started in drafting the APA style results. Identical to all the information we hand-calculated, we would write the *t* string this way: $t(32) = 0.113, p = .911, CI95(-1.39, 1.55)$. Our results show that the mean difference in physician verbal communication scores with Black and White patients was 0.081. Taking a look at the confidence interval, we are 95% confident that the true difference in means falls between the values of -1.386 and 1.549. What is critically important is that this confidence interval crosses zero. There is an important link between the CI95% and statistical significance. When the CI95% includes zero, *p* will not be lower than 0.05. - -We still need to calculate the effect size. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::cohens_d(df_long, Verbal ~ PtRace, paired=TRUE) -``` -Keeping in mind the interpretive criteria of .2, .5, and .8, as small, medium, and large effect sizes, we see that $d = 0.020$ is quite small. We can add it to our *t*-string and draft the results: $t(32) = 0.113, p = .911, d = 0.020, CI95(-1.39, 1.55)$. - - -## APA Style Results - -Putting it altogether we can assemble an APA style results section. Code for a table of means, standard deviations, and correlation follow the write-up of results. For inclusion in a manuscript, I would rework the export of the table to delete the difference score (i.e., Verbal_D). I might also exclude the rows of confidence intervals around the correlations. - ->We began by analyzing the data to see if it met the statistical assumptions for analysis with a paired samples *t*-test. One assumption is that the difference scores of dependent variable are normally distributed. We evaluated skew and kurtosis using Kline's [-@kline_data_2016] guidelines of the absolute values of 3 (skew) and 10 (kurtosis). Our results were well-within these boundary conditions. Further, a non-significant Shapiro-Wilk test of normality suggested that the distribution of difference scores was not statistically significant from a normal distribution $(W = 0.97, p = 0.57)$. - ->A paired samples *t*-test was conducted to evaluate the hypothesis that there would be differences in the degree of physicians' verbal engagement as a function of the patient's race (Black, White). The paired samples *t*-test was nonsignificant, *t*(32) = 0.133, *p* = .911. The small magnitude of the effect size (*d* = 0.02) was consistent with the nonsignificant result. The 95% confidence interval for the difference in means was quite wide and included the value of zero (95%CI[-1.386, 1.549]). Means and standard deviations are presented in Table 1; the results are illustrated in Figure 1. - - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse)#needed to use the pipe -#Creating a smaller df to include only the variables I want in the table -PairedDescripts <- dfPairedSamples%>% - select(Verbal_BL, Verbal_WH, Verbal_D) -#using the apa.cor.table function for means, standard deviations, and correlations -#the filename command will write the table as a word document to your file -apaTables::apa.cor.table(PairedDescripts, table.number=1, filename="Tab1_PairedV.doc") -``` -The figure we created earlier in the lesson would be sufficient for a journal article. However, using *rstatix* in combination with *ggpubbr* can be quite powerful. The result can be a figure that includes the *t*-test results and "significance bars." To do this, we first need to re-run the *rstatix::t_test*, but adding to it by - -* including "add_significance()" script after the pipe, and -* saving it as an object, which I'm naming "pair.test." - -We could have done this in the initial run (but I didn't want to make the test-statistic unnecessarily confusing). - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -pair.test <- rstatix::t_test(df_long, Verbal ~ PtRace, paired=TRUE, detailed=TRUE) %>% - rstatix::add_significance() -pair.test -``` - -Next, we create boxplot code with the long form of our data: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pair.box <- ggpubr::ggpaired(df_long, x = "PtRace", y = "Verbal", order = c("Black", "White"), line.color = "gray", palette =c("npg"), color = "PtRace", ylab = "Verbal Communication Rating", xlab = "Patient Race", title = "Figure 1. Physician Verbal Engagement as a Function of Patient Race") - -pair.test <- pair.test %>% rstatix::add_xy_position(x = "PtRace") #autocomputes p-value labels positions - -pair.box <- pair.box + - ggpubr::stat_pvalue_manual(pair.test, tip.length=.01, y.position = c(15) ) + - labs(subtitle = rstatix::get_test_label(pair.test, detailed=TRUE)) - -pair.box -``` -The tools available offer a great deal of flexibility. Determining which figure is best will likely depend on your outlet, your audience, and your personal preferences. For example, a print journal might prefer a black-and-white figure (with no fill in the boxes). This is accomplished easily enough by removing (or, hashtagging out) the "fill = PtRace" argument. - - -## Power in Paired Samples *t*-Tests - -Researchers often use power analysis packages to estimate the sample size needed to detect a statistically significant effect, if, in fact, there is one. Utilized another way, these tools allows us to determine the probability of detecting an effect of a given size with a given level of confidence. If the probability is unacceptably low, we may want to revise or stop. A helpful overview of power as well as guidelines for how to use the *pwr* package can be found at a [Quick-R website](https://www.statmethods.net/stats/power.html) [@kabacoff_power_2017]. - -In Champely's *pwr* package, we can conduct a power analysis for a variety of designs, including the paired *t*-test that we worked in this chapter. There are a number of interrelating elements of power: - -* Sample size, *n* refers to the number of pairs; our vignette had 33 -* *d* refers to the difference between means divided by the pooled standard deviation; we can use the value of Cohen's *d* for this -* *power* refers to the power of a statistical test; conventionally it is set at .80 -* *sig.level* refers to our desired alpha level; conventionally it is set at .05 -* *type* indicates the type of test we ran; ours was "paired" -* *alternative* refers to whether the hypothesis is non-directional/two-tailed ("two.sided") or directional/one-tailed("less" or "greater") - -In this script, we must specify *all-but-one* parameter; the remaining parameter must be defined as NULL. R will calculate the value for the missing parameter. - -When we conduct a "power analysis" (i.e., the likelihood of a hypothesis test detecting an effect if there is one), we specify, "power=NULL". Using the data from our results, we learn from this first run, that our statistical power was at 5%. That is, given the low value of the mean difference (.08) and the relatively large standard deviation (4.14), we had only a 5% chance of detecting a statistically significant effect if there was one. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.t.test(d=0.02,n = 33, power=NULL,sig.level=0.05,type="paired",alternative="two.sided") -``` -The results indicate that we were powered at 5%. That is, we had a 5% chance of finding a statistically significant difference, if in fact there was one. - -Researchers frequently use these tools to estimate the sample size required to obtain a statistically significant effect. In these scenarios we set *n* to *NULL*. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.t.test(d=0.02,n = NULL, power=0.8,sig.level=0.05,type="paired",alternative="two.sided") -``` -Using the results from the simulation of our research vignette, you can see that we would have needed 19624 individuals for the *p* value to be < .05, if, in fact there were a significant difference. - -Let's see if this is true. Below I will re-simulate the data for the verbal scores, changing only the sample size: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -set.seed(220820) -#These define the characteristics of the verbal variable. It is essential that the object names (e.g., A_mean) are not changed because they will be fed to the function in the faux package. -sub_n <- 19624 -A_mean <- 8.37 -B_mean <- 8.41 -A_sd <- 3.36 -B_sd <- 3.21 -AB_r <- 0.3 - -#the faux package can simulate a variety of data. This function within the faux package will use the objects above to simulate paired samples data -paired_V2 <- faux::rnorm_multi( - n = sub_n, - vars = 2, - r = AB_r, - mu = c(A_mean, B_mean), - sd = c(A_sd, B_sd), - varnames = c("Verbal_BL", "Verbal_WH") - ) - -paired_V2 <- paired_V2 %>% dplyr::mutate(PhysID = row_number()) - -#restructuring data to the long form -df_longV2 <- data.table::melt(data.table::setDT(paired_V2), id.vars=c("PhysID"), measure.vars=list(c("Verbal_BL", "Verbal_WH"))) -df_longV2 <- rename(df_longV2, PatientRace = variable, Verbal = value) -df_longV2$PtRace <- plyr::mapvalues(df_longV2$PatientRace, from = c("Verbal_BL", "Verbal_WH"), to = c("Black", "White")) -``` - -Now I will conduct the paired samples *t*-test and corresponding effect size. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::t_test(df_longV2, Verbal ~ PtRace, paired=TRUE, detailed=TRUE) -rstatix::cohens_d(df_longV2, Verbal ~ PtRace, paired=TRUE) -``` -The new results remain non-significant: $t(19623) = -1.243, p = 0.241, d = -0.009, 95CI (-0.088, 0.020)$. This tells me these means are quite similar and this is not a function of being under powered. - -Conducting power analyses requires that researchers speculate about their values. In this case, in order to estimate sample size, the researcher would need to make some guesses about the difference scores means and standard deviations. These values could be estimated from prior literature or a pilot study. - -## Practice Problems - -The suggestions for homework differ in degree of complexity. I encourage you to start with a problem that feels "do-able" and then try at least one more problem that challenges you in some way. Regardless, your choices should meet you where you are (e.g., in terms of your self-efficacy for statistics, your learning goals, and competing life demands). - -Additionally, please complete at least one set of *hand calculations*, that is use the code demonstrated in the chapter to work through the formulas that compute the paired samples *t*-test. At this stage in your learning, you may ignore any missingness in your dataset by excluding all rows with missing data in your variables of interest. - -### Problem #1: Rework the research vignette as demonstrated, but change the random seed - -If this topic feels a bit overwhelming, simply change the random seed in the data simulation of the research vignette, then rework the problem. This should provide minor changes to the data (maybe even in the second or third decimal point), but the results will likely be very similar. That said, don't be alarmed if what was non-significant in my working of the problem becomes significant. Our selection of *p* < .05 (and the corresponding 95% confidence interval) means that 5% of the time there could be a difference in statistical significance. - -### Problem #2: Rework the research vignette, but change something about the simulation - -Rework the paired samples *t*-test in the lesson by changing something else about the simulation. For example, if you are interested in understanding more about power, consider changing the sample size. Alternatively, you could specify different means and/or standard deviations. - -### Problem #3: Rework the research vignette, but swap one or more variables - -Use the simulated data, but select the nonverbal communication variables that were evaluated in the Elliott et al. [-@elliott_differences_2016] study. Compare your results to those reported in the mansucript. - -### Problem #4: Use other data that is available to you - -Using data for which you have permission and access (e.g., IRB approved data you have collected or from your lab; data you simulate from a published article; data from an open science repository; data from other chapters in this OER), complete a paired samples *t*-test. - -### Grading Rubric - -Regardless which option(s) you chose, use the elements in the grading rubric to guide you through the practice. - -|Assignment Component | Points Possible | Points Earned| -|:-------------------------------------- |:----------------: |:------------:| -|1. Narrate the research vignette, describing the variables and their role in the analysis | 5 |_____ | -|2. Simulate (or import) and format data | 5 |_____ | -|3. Evaluate statistical assumptions | 5 |_____ | -|4. Conduct a paired samples *t*-test (with an effect size & 95%CIs) |5 | _____ | -|5. APA style results with table(s) and figure | 5 |_____ | -|6. Conduct power analyses to determine the power of the current study and a recommended sample size | 5 |_____ | -|7. Explanation to grader | 5 |_____ | -|**Totals** | 35 |_____ | - - -|Hand Calculations | Points Poss | Points Earned -|:-----------------------------------------|:-------------:|:--------------| -|1. Using traditional NHST (null hypothesis testing language), state your null and alternative hypotheses| 2 | -|2. Using an R package or functions in base R (and with data in the "wide" format), calculate the *difference* score between the two observations of the dependent variable | 2 | | -|3. Obtain the mean and standard deviation of the *difference* score |2 | | -|4. Calculate the paired samples *t*-test | 4 || -|5. Identify the degrees of freedom associated with your paired samples *t*-test | 2 | -|6. Locate the test critical value for your paired samples *t*-test |2 | | -|7. Is the paired samples *t*-test statistically significant? Why or why not? | 2 | | -|8. What is the confidence interval around the mean difference? |4 | | -|9. Calculate the effect size (i.e., Cohen's *d* associated with your paired samples *t*-test |4 | | -|10. Assemble the results into a statistical string |4 | | -|**Totals* ** | 28 | | -```{r, child= 'Worked_Examples/15-5-woRked_tPaired.Rmd'} -``` - -```{r include=FALSE, tidy=TRUE, tidy.opts=list(width.cutoff=70)} -sessionInfo() -``` - - - - - diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/67994787-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/67994787-contents deleted file mode 100644 index 844f35e9..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/67994787-contents +++ /dev/null @@ -1,234 +0,0 @@ -```{r include = FALSE} -options(scipen=999) -``` - -## Homeworked Example - -[Screencast Link](https://youtu.be/_IiZ8MbtbVs) - -For more information about the data used in this homeworked example, please refer to the description and codebook located at the end of the [introduction](ReCintro). - -Preliminary analyses often consist of means, standard deviations, and correlations. These can be helpful in determining whether or not data are normally distribution. Correlations and pairs.panels also assess the relatedness of the variables. - -If you wanted to use this example and dataset as a basis for a homework assignment, you could (a) select a different course (i.e., Multivariate or Psychometrics) and/or (b) different variables. - -### Working the Problem with R and R Packages {-} - -#### Create a df with 3 continuously scaled variables of interest {-} - -The ReC.rds is the entire dataset. Let's first open it. - -```{r} -ReCdf <- readRDS("ReC.rds") -``` - -Recall that students (represented by the *deID* variable) could contribute up to three course evaluations (i.e., ANOVA, psychometrics, multivariate) each. In many statistics, repeated observations creates dependencies that need to be accounted for statistically. - -To avoid this dependency and to practice an R skill, let's first filter the data, selecting only those students who took ANOVA. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -JustANOVA <- subset(ReCdf, Course == "ANOVA") -``` - -#### Create a df with 3 continuously scaled variables of interest {-} - -The assignment requires that we downsize to three variables. We could pick any three. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -tiny3 <- JustANOVA %>% - dplyr::select (OvInstructor, OvCourse, MyContribution) -``` - -#### Produce descriptive statistics {-} - -```{r} -psych::describe(tiny3) -``` - -#### Produce SPLOM/pairs.panels {-} - -```{r} -psych::pairs.panels(tiny3) -``` - -#### Produce an apaTables matrix {-} - -```{r} -apaTables::apa.cor.table(tiny3) -``` -#### Produce an APA Style write-up of the preliminary analyses {-} - ->Our sample included 113 doctoral students in Clinical and Industrial-Organizational psychology (PhD) programs who were completing a statistics class focused on analysis of variance. Visual inspection of three dimensions of course evaluation (overall instructor, overall course, my contributions) combined with formal evaluation of skewness and kurtosis suggested that their distributions did not violate the assumption of univariate normality. That is, skew values all fell below the absolute value of 3 and kurtosis values all fell below the absolute value of 10 [@kline_data_2016]. Means, standard deviations, and a correlation matrix are presented in Table 1. All three correlations were strong and statistically significant. We noted that the correlation between the overall instructor and overall course was especially high $(r = .83, p < .001)$ - -### Hand Calculations - -Although these are termed “hand calculations,” you may use the code demonstrated in the chapter to work these problems. - -I am going to continue with the *tiny3* dataset I used when I worked the problem with R and R packages. - -If you need to reimport data, here is a quick recap of the code explained earlier. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ReCdf <- readRDS("ReC.rds") -JustANOVA <- subset(ReCdf, Course == "ANOVA") - -library(tidyverse) -tiny3 <- JustANOVA %>% - dplyr::select (OvInstructor, OvCourse, MyContribution) -``` - -To avoid problems in the code we are used that is caused by missingness, we will eliminate any rows with missing data. -```{r} -tiny3 <- na.omit(tiny3) -``` - - -#### Create a variable that represents the mean {-} - -I will start with the OvInstructor variable. Inspect the dataframe to see that this new variable exists. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -tiny3$M_OvI <- mean(tiny3$OvInstructor, na.rm=TRUE) -``` - -#### Create a variable that represents the mean deviation {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -tiny3$Mdev_OvI <- (tiny3$OvInstructor-tiny3$M_OvI) -head(tiny3) -``` - -Inspect the dataframe to see that this new variable exists. Note that this functions to "center" the mean around zero. - - -#### What is the value of the sum of mean deviations? {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -round(sum(tiny3$Mdev_OvI, na.rm = TRUE), 3) -``` -Yes, zero! - -#### Create a variable that represents the absolute mean deviation {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -tiny3$abslt_mOvI <- abs(tiny3$Mdev_OvI) -head(tiny3) -``` - -Inspect the dataframe to see that this new variable no longer has negative values. - -**What is the value of the sum of the absolute mean deviation?** - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -round(sum(tiny3$abslt_mOvI, na.rm = TRUE), 3) -``` - - -**What is the value of the mean of the absolute mean deviation?** - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -round(mean(tiny3$abslt_mOvI, na.rm = TRUE), 3) -``` - -**What does this value tell you?** - -Average distance of each value from the mean. - -#### Create a variable that represents the mean deviation squared {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -tiny3$mdev2_OvI <- (tiny3$Mdev_OvI * tiny3$Mdev_OvI) -head(tiny3) -``` - -**What is the value of the sum of squared deviations around the mean (also known as sums of squares; sometimes abbreviated as $SS$)?** - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -sum(tiny3$mdev2_OvI, na.rm = TRUE) -``` - -**What is the value of the variance ($s^2$)?** - -There are at least two ways to do this with basic code (and then we can check our work). - -Here's how to do it with "more code." -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -var_OvI <- sum(tiny3$mdev2_OvI/((nrow(tiny3) - 1))) -var_OvI -``` - -Here's how to do it with the numbers that I calculated: -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -115.0973/(113-1) -``` - -Checking my work with the *var* function from base R. If it's wrong, I need to rework some of the previous steps. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -var(tiny3$OvInstructor, na.rm = TRUE) #checking my work -``` - -**What is the value of the standard deviation ($s$)?** - -There are two ways to calculate it with basic code; and then we can check it with more code from base R. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -sd_OvI <- sqrt(var_OvI)#calculating with the object I created -sd_OvI -sqrt (1.027655)#calculated with the actual numbers -sd(tiny3$OvInstructor)#checking my work with the code from baseR -``` - -#### Using the same general approach, calculate the mean deviation and standard deviation for a second, continuously scaled variable {-} - -My second variable is MyContribution -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#first the mean -tiny3$M_MyC <- mean(tiny3$MyContribution, na.rm=TRUE) -#second the mean deviation -tiny3$Mdev_MyC <- (tiny3$MyContribution-tiny3$M_MyC) -#third the mean deviation squared -tiny3$mdev2_MyC <- (tiny3$Mdev_MyC * tiny3$Mdev_MyC) -head(tiny3) - -#fourth the variance -var_MyC <- sum(tiny3$mdev2_MyC/((nrow(tiny3) - 1))) -var_MyC -#finally the standard deviation -sd_MyC <- sqrt(var_MyC) -sd_MyC#checking my work - -sd(tiny3$MyContribution)#checking my work -``` - -#### Create a variable that represents the *cross-product* (of the mean deviations). What is the sum of these cross-products? {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -tiny3$crossproduct <- (tiny3$Mdev_OvI * tiny3$Mdev_MyC) -head(tiny3) -``` - -The sum of the crossproduct is: - -```{r} -xp_sum <- sum(tiny3$crossproduct) -xp_sum -``` - -#### Calculate the value of their covariance {-} - -```{r} -cov <- (1/(113-1)) * 46.74336 -cov -``` - -#### Calculate value of correlation coefficient {-} - -```{r} -0.4173514/(1.013733*0.8338) - -``` -And now I can check my work with a function from base R. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -cor.test(tiny3$OvInstructor, tiny3$MyContribution) -``` -The correlation between ratings of overall instructor and my contribution is $0.493, p < .001$. diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/6800C260-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/6800C260-contents deleted file mode 100644 index 3268cc12..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/6800C260-contents +++ /dev/null @@ -1,89 +0,0 @@ -```{r include = FALSE} -options(scipen=999) -``` - -## Introduction to the Data Set Used for Homeworked Examples - -[Screencast Link]() - -Each lesson concludes with streamlined example of working the primary statistic from each lesson. This section is intended to be helpful in two ways: - -* The worked example focuses on the operations and interpretations and more closely mimics "how you would work a problem in real life." -* The grading rubric from the end of each lesson serves as the outline for the process. -* This dataset could be used for the practice problems. For homework that you submit for grading, please choose *different variables* than the ones worked in the examples. - -### The Data Set - -The dataset used in the "homeworked" examples is from my own research. Along long with the pre-registration and codebooks, it is publicly available in a [pre-registered repository](https://osf.io/z84kh/) on the Open Science Framework (OSF). I have also provided a copy of it in the [GitHub repository](https://github.com/lhbikos/ReCenterPsychStats/blob/main/Worked_Examples/ReC.rds) that hosts the ReCentering Psych Stats OER. - -This data is from an IRB-approved study. The informed consent of the IRB specified that the data could be used in research as well as in teaching demonstrations and would be made available to the general public. You may notice there are student- and teacher- IDs. These numbers are *not** the institution's identification numbers. Rather, they have been further anonymized. - -The purpose of the research project was to evaluate efforts to recenter – in a socially responsive way – courses in the statistics and research methods sequence in scientist-practitioner psychology (PhD) programs. The recentering occurred in two phases: (a) a transition from SPSS to R and (b) an explicit recentering. Data were from end-of-course evaluations three courses I taught: Research Methods I: Analysis of Variance [ANOVA], Research Methods III: Multivariate Modeling [multivariate], and Research Methods IV: Psychometrics/Theory of Test Construction [psychometrics]) that were offered 2017 through 2022. - -Because students could contribute up to three course evaluations, each, multilevel modeling was used for the primary analyses. The nature of the data, though, allows me to demonstrate all of the statistics utilized the OER with this data. For each analysis, I have tried to derive a sensible question that *could be* answered by the data. In-so-doing, I try to point out when the alignment of research question and statistic is less than ideal. - -The data file is titled *ReC.rds* and can be retrieved with this code: - -```{r} -dfReC <- readRDS("ReC.rds") -``` - -The following can serve as a codebook: - -|Variable |Definition or Description |Scaling| -|:---------------|:----------------------------------------------------|:------------------------| -|deID |Anonymized identification for each student Each student could contribute up to three course evaluations |Nominal/factor | -|CourseID |Unique number for each course taught (i.e., ANOVA has unique numbers across department and year). |Nominal/factor| -|Dept |CPY (Clinical Psychology), ORG (Industrial Organizational Psychology)|Nominal/factor| -|Course |ANOVA (analysis of variance), Multivariate (multivariate modeling), Psychometrics (psychometrics/theory of test construction), taught in that order | Nominal/factor| -|StatsPkg |SPSS, R | Nominal/factor| -|Centering |Pre (before explicit recentering), Re (included explicit recentering) | Nominal/factor| -|Year |Calendar year in which the course was taught |Calendrical time| -|Quarter |Academic term in which course was taught (fall, winter, spring)| Nominal/factor| -|ProgramYear |A potential confound to the study. During the changes from SPSS to R and the explicit recentering, the program was also moving the stats sequence from the second to the first year of the doctoral program. First = course taken during first year; Second = course taken during second year; Transition = course taken during the transition period. | Nominal/factor| -|SPFC.Decolonize.Opt.Out|Students were given the opportunity to exclude their data from analysis. Such data was removed prior to any analysis and not included in this set. | Character| - -COURSE EVALUATION ITEMS; 5-point Likert scaling from 1(*strongly disagree*) to 5(*strongly agree*). Higher scores are more favorable evaluations. - -|Variable |Complete Item | -|:---------------|:-------------------------------------------------------------------| -|IncrInterest |My interest in the subject matter increased over the span of the course.| -|IncrUnderstanding |My understanding of the subject matter increased over the span of the course.| -|ValObjectives |This course has objectives that are valuable in furthering my education.| -|ApprAssignments |This course has had an appropriate workload, given the course objectives.| -|EffectiveAnswers|The instructor has effectively answered student questions.| -|Respectful |The instructor has shown respect to students.| -|ClearResponsibilities|The instructor has made student responsibilities clear.| -|Feedback |The instructor has provided feedback to me about my learning progress.| -|OvInstructor |My overall rating of this instructor for this course is:| -|MultPerspectives|The instructor has helped students consider issues from multiple perspectives, where applicable.| -|OvCourse |My overall rating of the course content is:| -|InclsvClssrm |The instructor has been intentional in fostering an inclusive classroom for students with diverse backgrounds and abilities.| -|DEIintegration |The instructor has, when appropriate, discussed the relationships between race/ethnicity/culture and course content.| -|ClearPresentation|The instructor has presented course material clearly.| -|ApprWorkload |This course has had an appropriate workload, given the course objectives.| -|MyContribution |My overall rating of my contribution in this course is:| -|InspiredInterest|The instructor has inspired student interest in the subject matter of this course.| -|Faith |The instructor has, when appropriate, discussed the relationship between the Christian faith and course content.| -|EquitableEval |The instructor used methods of evaluating student course work that were equitable.| -|ClearOrganization|This course has had a clear overall organization.| -|RegPrepare |I regularly read, reviewed, visited/logged on, or completed assigned readings and tasks.| -|EffectiveLearning|This course has consisted of course activities/tasks that were effective in helping me learn (e.g., discussions, readings, assignments, labs, or other activities).| -|AccessibleInstructor|The instructor has been accessible (e.g., discussion sessions, virtual office hours, phone, chat, email, online forum or conference, etc.).| - -From these variables, I created three scales to assess valued by the student (Valued), traditional pedagogy (TradPed), and socially responsive pedagogy (SRped). I will use these in the demonstrations. - -* **Valued by the student** includes the items: ValObjectives, IncrUnderstanding, IncrInterest - -* **Traditional pedagogy** includes the items: ClearResponsibilities, EffectiveAnswers, Feedback, ClearOrganization, ClearPresentation - -* **Socially responsive pedagogy** includes the items: InclusvClassrm, EquitableEval, MultPerspectives, DEIintegration - -In the examples where the scale scores are used, I provide code for calculating the means. - -Here's how to import the data: - -```{r} -ReCdf <- readRDS("ReC.rds") -``` - diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/6A63C791-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/6A63C791-contents deleted file mode 100644 index a7edf89a..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/6A63C791-contents +++ /dev/null @@ -1,117 +0,0 @@ -# One-Way Repeated Measures with a Multivariate Approach {-} - -```{r include=FALSE} -knitr::opts_chunk$set(echo = TRUE) -knitr::opts_chunk$set(comment = NA) #keeps out the hashtags in the knits -options(scipen=999)#eliminates scientific notation -``` - -[Screencasted Lecture Link](https://youtu.be/1c3N733nSM0) - -As noted in the lesson on [one-way repeated measures ANOVA](#Repeated), the researcher can use a univariate or multivariate approach to analyzing the data. The *rstatix::anova_test()* is limited to the univariate approach. In order to maintain a streamlined chapter with minimal distractions to student learning I have chosen to provide a quick and separate demonstration of the multivariate approach in this appendix. In-so-doing, I will use the *car* package. - -As a quick reminder, I will describe and resimulate the data. The narration will presume familiarity with the [one-way repeated measures ANOVA](#Repeated) lesson. - -## Research Vignette {-} - -Amodeo [@amodeo_empowering_2018] and colleagues conducted a mixed methods study (qualitative and quantitative) to evaluate the effectiveness of an empowerment, peer-group-based, intervention with participants (*N* = 8) who experienced transphobic episodes. Focus groups used qualitative methods to summarize emergent themes from the program (identity affirmation, self-acceptance, group as support) and a one-way, repeated measures ANOVA provided evidence of increased resilience from pre to three-month followup. - -Eight participants (seven transgender women and one genderqueer person) participated in the intervention. The mean age was 28.5 (*SD* = 5.85). All participants were located in Italy. - -The within-subjects condition was wave, represented by T1, T2, and T3: - -* T1, beginning of training -* Training, three 8-hour days, - - content included identity and heterosexism, sociopolitical issues and minority stress, resilience, and empowerment -* T2, at the conclusion of the 3-day training -* Follow-up session 3 months later -* T3, at the conclusion of the +3 month follow-up session - -The dependent variable (assessed at each wave) was a 14-item resilience scale [@wagnild_development_1993]. Items were assessed on a 7-point scale ranging from *strongly disagree* to *strongly agree* with higher scores indicating higher levels of resilience. An example items was, "I usually manage one way or another." - -### Data Simulation {-} - -Below is the code I used to simulate data. The following code assumes 8 participants who each participated in 3 waves (pre, post, followup). The sript produces "long" and "wide" forms are created. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -set.seed(2022) -#gives me 8 numbers, assigning each number 3 consecutive spots, in sequence -ID<-factor(c(rep(seq(1,8),each=3))) -#gives me a column of 24 numbers with the specified Ms and SD -Resilience<-rnorm(24,mean=c(5.7,6.21,6.26),sd=c(.88,.79,.37)) -#repeats pre, post, follow-up once each, 8 times -Wave<-rep(c("Pre","Post", "FollowUp"),each=1,8) -Amodeo_long<-data.frame(ID, Wave, Resilience) - -Amodeo_long$Wave <- factor(Amodeo_long$Wave, levels = c("Pre", "Post", "FollowUp")) - -# Create a new df (Amodeo_wide) -# Identify the original df -# We are telling it to connect the values of the Resilience variable its respective Wave designation -Amodeo_wide <- reshape2::dcast(data = Amodeo_long, formula =ID~Wave, value.var = "Resilience") -#doublecheck to see if they did what you think -str(Amodeo_wide) -Amodeo_wide$ID <- factor(Amodeo_wide$ID) -``` - -## Computing the Omnibus F {-} - -Without the *rstatix* helper package, here is how the analysis would be run in the package, *car.* Although this package is less intuitive to use, it results in both univariate output (both sphericity assumed and sphericity violated) and multivariate output (which does not require the sphericity assumption). - -Evaluating the data requires that we create some objects that will be fed into function. We can name these objects anything we like. - -In ths script below I define the objects that are required. - -* waveLevels is an object that will specify three levels of the independent variable (pre, post, follow-up), -* waveFactor simply makes "waveLevels" a factor -* waveBind column-binds (i.e., cbind) the pre, post, and follow-up variables from the wide form of the Amodeo dataset -* waveModel calculates the intercept (i.e., the means) of the pre, post, and follow-up levels - - -```{r message=FALSE, warning=FALSE, tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#library(car) -waveLevels <- c(1,2,3) -waveFactor <- as.factor(waveLevels) -waveFrame <- data.frame(waveFactor) -waveBind <-cbind(Amodeo_wide$Pre, Amodeo_wide$Post, Amodeo_wide$FollowUp) -waveModel<- lm(waveBind~1) -waveModel - -``` -To run the analysis, we insert these objects into arguments: - -* waveModel is the first argument, -* waveFrame is assigned to the *idata* command, -* waveFactor is assigned to the *idesign* command - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -analysis <-car::Anova(waveModel, idata=waveFrame, idesign=~waveFactor) -summary(analysis) -``` -The *car::Anova()* function produces both univariate and multivariate results. To begin to understand this data, let's start with what we learned in the [one-way repeated measures ANOVA lesson](#Repeated). - -### Univariate Results {-} - -When we ran the univariate approach in the lesson, we first checked the sphericity assumption. Our results here are identical to those from *rstatix::anova_test*. That is, we did not violate the sphericity assumption: Mauchley's test $= .566 p = 0.182$. The *F* test with univariate results was $F(2, 14) = 3.910, p = 0.045$. - ->The Greenhouse Geiser estimate was 0.698 the corrected *p* = .068. ->The Huyhn Feldt estimate was 0.817 and the corrected *p* = .057. - -The univariate ANOVA results are under the "Univariate Type III Repeated-Measures ANOVA Assuming Sphericity" heading. We find the ANOVA output on the row titled, "waveFactor." The results are identical to what we found in the lesson: $F(2,14) = 3.91, p = 0.045$. I do not see that an effect size is reported. - -### Multivariate Results {-} - -Researchers may prefer the multivariate approach because it does not require the sphericity assumption. Stated another way, if the sphericity assumption is violated, researchers can report the results of the multivariate analysis. - -We find the multivariate results in the middle of the output, under the heading, "Multivariate Tests: waveFactor." There are four choices: Pillai, Wilks, Hotelling-Lawley, and Roy. Green and Salkind [-@green_one-way_2017-1] have noted that in the one-way within-subjects ANOVA, all four will yield the same *F* and *p* values. They recommended reporting Wilks' lambda because researchers will have greatest familiarity with it. Thus, I would write up the result of this omnibus test like this: - ->Results of the one-way repeated measures ANOVA indicated a significant wave effect, $Wilks' \lambda = .597, F(2,6) = 2.022, p = 0.213$. - -Because follow-up testing is *pairwise* (i.e., there are only two levels being compared), the sphericity assumption is not required and those could proceed in the manner demonstrated in the [one-way repeated measures ANOVA lesson](#Repeated). - -### A Brief Commentary on Wrappers {-} - -As noted several times, because of its relative ease-of-use, the relevance of information included in the results, and its integration with the *ggpubr* package, I chose to use *rstatix* package in all of the ANOVA lessons. As I worked through this example, I spent several hours creating and interpreting the code. For me, there was value in this exercise: - -* I am encouraged and reassured with the consistency of results between the two approaches, -* I am in awe of the power of these programs and a little intimidated by all the options that are available within a given package, and -* I am deeply grateful to package developers who take the time to create packages for discipline-specific use-cases and then freely share their work with others. Thank you [Alboukadel Kassambara](https://github.com/kassambara/rstatix)! \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/750143CA-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/750143CA-contents deleted file mode 100644 index 1d18e6dc..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/750143CA-contents +++ /dev/null @@ -1,93 +0,0 @@ ---- -title: "ReCentering Psych Stats" -author: "Lynette H. Bikos, PhD, ABPP (she/her)" -date: "Last updated `r format (Sys.Date(), '%d %b %Y')`" -documentclass: book -site: bookdown::bookdown_site -bibliography: STATSnMETH.bib #This is my own bibtex file from my Zotero account. If this file is not in the project folder there will be an error and the book will not build. -citation-style: apa-single-spaced.csl #if you want APA style -link-citations: yes -urlcolor: blue #without this the links in the PDF do not show -fontsize: 11pt -geometry: margin=1in -highlight: tango -#DID NOT WORK, BUT DID NOT HURT EITHER I THINK IT NEEDS TO BE CONNECTED TO A PKG -#line-wrapping-in-code: true #wrap overflowing lines in code blocks? -url: https://lhbikos.github.io/ReCenterPsychStats/ #a link to the GitHub pages where it is rendered -cover-image: images/ReCenterPsychStats-bookcover2.jpg #link to the image for the book which will show up in any previews -description: | - ReCentering Psych Stats is an open education resource for teaching statistics with the open-source program, R, in a socially and culturally responsive manner. The series provides workflows and worked examples in R and each statistic is accompanied by an example APA style presentation of results. A core focus of the ReCentering series is simulated data from published articles that focus on issues of social justice and are, themselves, conducted in a socially responsive manner. -github-repo: lhbikos/ReCenterPsychStats - ---- - -```{r, include=FALSE} -options(tinytex.verbose = TRUE) -``` - - -# BOOK COVER {-} - -![An image of the book cover. It includes four quadrants of non-normal distributions representing gender, race/ethnicty, sustainability/global concerns, and journal articles](images/ReCenterPsychStats-bookcover2.jpg) -This open education resource is available in three formats: - -* Formatted as an [html book](https://lhbikos.github.io/ReCenterPsychStats/) via GitHub Pages -* As a [PDF](https://github.com/lhbikos/ReCenterPsychStats/blob/main/docs/ReCenterPsychStats.pdf) available in the [docs](https://github.com/lhbikos/ReCenterPsychStats/tree/main/docs) folder at the GitHub repository -* As an [ebook](https://github.com/lhbikos/ReCenterPsychStats/blob/main/docs/ReCenterPsychStats.epub) available in the [docs](https://github.com/lhbikos/ReCenterPsychStats/tree/main/docs) folder at the GitHub repository -* As a [Word document](https://github.com/lhbikos/ReCenterPsychStats/blob/main/docs/ReCenterPsychStats.docx) available in the [docs](https://github.com/lhbikos/ReCenterPsychStats/tree/main/docs) folder at the GitHub repository - -All materials used in creating this OER are available at its [GitHub repo](https://github.com/lhbikos/ReCenterPsychStats). - -As a perpetually-in-progress, open education resource, feedback is always welcome. This IRB-approved (SPU IRB #202102010R, no expiration) [Qualtrics-hosted survey](https://spupsych.az1.qualtrics.com/jfe/form/SV_0OnBLfut3VIOIS2) includes formal rating scales, open-ended text boxes, and a portal for uploading attachments (e.g., marked up PDFs). You are welcome to complete only the portions that are relevant to you. - -# PREFACE {-} - -**If you are viewing this document, you should know that this is a book-in-progress. Early drafts are released for the purpose teaching my classes and gaining formative feedback from a host of stakeholders. The document was last updated on `r format (Sys.Date(), '%d %b %Y')`**. Emerging volumes on other statistics are posted on the [ReCentering Psych Stats](https://lhbikos.github.io/BikosRVT/ReCenter.html) page at my research team's website. - -[Screencasted Lecture Link](https://youtu.be/yy0z85Wla7o) - -To *center* a variable in regression means to set its value at zero and interpret all other values in relation to this reference point. Regarding race and gender, researchers often center male and White at zero. Further, it is typical that research vignettes in statistics textbooks are similarly seated in a White, Western (frequently U.S.), heteronormative, framework. The purpose of this project is to create a set of open educational resources (OER) appropriate for doctoral and post-doctoral training that contribute to a socially responsive pedagogy -- that is, it contributes to justice, equity, diversity, and inclusion. - -Statistics training in doctoral programs are frequently taught with fee-for-use programs (e.g., SPSS/AMOS, SAS, MPlus) that may not be readily available to the post-doctoral professional. In recent years, there has been an increase and improvement in R packages (e.g., *psych*, *lavaan*) used for analyses common to psychological research. Correspondingly, many graduate programs are transitioning to statistics training in R (free and open source). This is a challenge for post-doctoral psychologists who were trained with other software. This OER will offer statistics training with R and be freely available (specifically in a GitHub repository and posted through GitHub Pages) under a Creative Commons Attribution - Non Commercial - Share Alike license [CC BY-NC-SA 4.0]. - -Training models for doctoral programs in health service psychology are commonly scholar-practitioner, scientist-practitioner, or clinical-scientist. An emerging model, the *scientist-practitioner-advocacy* training model, incorporates social justice advocacy so that graduates are equipped to recognize and address the sociocultural context of oppression and unjust distribution of resources and opportunities [@mallinckrodt_scientist-practitioner-advocate_2014]. In statistics textbooks, the use of research vignettes engages the learner around a tangible scenario for identifying independent variables, dependent variables, covariates, and potential mechanisms of change. Many students recall examples in Field's [-@field_discovering_2012] popular statistics text: Viagra to teach one-way ANOVA, beer goggles for two-way ANOVA, and bushtucker for repeated measures. What if the research vignettes were more socially responsive? - -In this OER, research vignettes will be from recently published articles where: - -* the author’s identity is from a group where scholarship is historically marginalized (e.g., BIPOC, LGBTQ+, LMIC[low-middle income countries]), -* the research is responsive to issues of justice, equity, inclusion, diversity, -* the lesson’s statistic is used in the article, and -* there is sufficient information in the article to simulate the data for the chapter example(s) and practice problem(s); or it is publicly available. - -In training for multicultural competence, the saying, "A fish doesn't know that it's wet" is often used to convey the notion that we are often unaware of our own cultural characteristics. In recent months and years, there has been an increased awakening to institutional and systemic factors that contribute to discrimination as a function of race, gender, nationality, class, and so forth. Queuing from the water metaphor, I am hopeful that a text that is recentered in the ways I have described can contribute to *changing the water* in higher education and in the profession of psychology. - - -## Copyright with Open Access {-} -Creative Commons License - -This book is published under a a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. This means that this book can be reused, remixed, retained, revised and redistributed (including commercially) as long as appropriate credit is given to the authors. If you remix, or modify the original version of this open textbook, you must redistribute all versions of this open textbook under the same license: CC BY-SA 4.0. - -A [GitHub open-source repository](https://github.com/lhbikos/ReCenterPsychStats) contains all of the text and source code for the book, including data and images. - -# ACKNOWLEDGEMENTS {-} - -As a doctoral student at the University of Kansas (1992-1996), I learned that "a foreign language" was a graduation requirement. *Please note that as one who studies the intersections of global, vocational, and sustainable psychology, I regret that I do not have language skills beyond English.* This could have been met with credit from high school, but my rural, mid-Missouri high school did not offer such classes. This requirement would have typically been met with courses taken during an undergraduate program -- but my non-teaching degree in the University of Missouri's School of Education was exempt from this. The requirement could have also been met with a computer language (FORTRAN, C++) -- but I did not have any of those either. There was a tiny footnote on my doctoral degree plan that indicated that a 2-credit course, "SPSS for Windows" would substitute for the language requirement. Given that it was taught by my one of my favorite professors, I readily signed up. As it turns out, Samuel B. Green, PhD, was using the course to draft chapters in the textbook [@green_using_2017] that has been so helpful for so many. Unfortunately, Drs. Green (1947 - 2018) and Salkind (1947 - 2017) are no longer with us. I have worn out numerous versions of their text. Another favorite text of mine has been Dr. Barbara Byrne's [-@byrne_structural_2016], "Structural Equation Modeling with AMOS." I loved the way she worked through each problem and paired it with a published journal article, so that the user could see how the statistical evaluation fit within the larger project/article. I took my tea-stained text with me to a workshop she taught at APA and was proud of the signature she added to it. Dr. Byrne created SEM texts for a number of statistical programs (e.g., LISREL, EQS, MPlus). As I was learning R, I wrote Dr. Byrne, asking if she had an edition teaching SEM/CFA with R. She promptly wrote back, saying that she did not have the bandwidth to learn a new statistics package. We lost Dr. Byrne in December 2020. I am so grateful to these role models for their contributions to my statistical training. I am also grateful for the doctoral students who have taken my courses and are continuing to provide input for how to improve the materials. - -The inspiration for training materials that re*center statistics and research methods came from the [Academics for Black Survival and Wellness Initiative](https://www.academics4blacklives.com/). This project, co-founded by Della V. Mosley, Ph.D., and Pearis L. Bellamy, M.S., made clear the necessity and urgency for change in higher education and the profession of psychology. - -At very practical levels, I am indebted to SPU's Library, and more specifically, SPU's Education, Technology, and Media Department. Assistant Dean for Instructional Design and Emerging Technologies, R. John Robertson, MSc, MCS, has offered unlimited consultation, support, and connection. Senior Instructional Designer in Graphics & Illustrations, Dominic Wilkinson, designed the logo and bookcover. Psychology and Scholarly Communications Librarian, Kristin Hoffman, MLIS, has provided consultation on topics ranging from OERS to citations. I am alo indebted to Associate Vice President, Teaching and Learning at Kwantlen Polytechnic University, Rajiv Jhangiani, PhD. Dr. Jhangiani's text [-@jhangiani_research_2019] was the first OER I ever used and I was grateful for his encouraging conversation. - -The creation of this OER has relied on strong peer and student support. Many thanks to Thane Erickson, PhD for being the first to pilot the resource (and approach to teaching) in his class. Students (both paid and unpaid) have served as editorial assistants in copyediting the text and correcting the text captions. Students who have held the Editorial Assistant role include Sarah Day, Ellie Smith, Tara Shelby, Keyera Gaulden, Kiana Clay, Lexa Gambrill, Ashley Righetti, and Jaylee York. - -Financial support for this project has been provided the following: - -* *Call to Action on Equity, Inclusion, Diversity, Justice, and Social Responsivity Request for Proposals* grant from the Association of Psychology Postdoctoral and Internship Centers (2021-2022). -* *Diversity Seed Grant*, Office of Inclusive Excellence and Advisory Council for Diversity and Reconciliation (ACDR), Seattle Pacific University. -* *ETM Open Textbook & OER Development Funding*, Office of Education, Technology, & Media, Seattle Pacific University. - -```{r include=FALSE} -# automatically create a bib database for R packages -knitr::write_bib(c( - .packages(), 'bookdown', 'knitr', 'rmarkdown' -), 'packages.bib') -``` diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/77EDB187-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/77EDB187-contents deleted file mode 100644 index cb9d8e84..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/77EDB187-contents +++ /dev/null @@ -1,272 +0,0 @@ -```{r include = FALSE} -options(scipen=999) -``` - -## Homeworked Example - -[Screencast Link](https://youtu.be/slmvZaXXEU8) - -For more information about the data used in this homeworked example, please refer to the description and codebook located at the end of the [introduction](ReCintro). - -The independent-samples t-test is useful when you want to compare means across two different groups. That is, the people in the comparison groups must be different from each other. - -### Working the Problem with R and R Packages - -#### Narrate the research vignette, describing the variables and their role in the analysis {-} - -I want to ask the question, "Do the course evaluation ratings for the traditional pedagogy subscale differ for CPY and ORG students in the ANOVA class?" - -I will use the mean rating for the traditional pedagogy subscale. As a mean, it retains its continuous, Likert scaling, ranging from 1 to 5 (with higher scores being more positive). - -My predictor variable will be department. It has two levels: CPY and ORG. - -*If you wanted to use this example and dataset as a basis for a homework assignment, you could change the course (i.e., Multivariate or Psychometrics) and/or change the dependent variable to one of the other scales*. - -#### Simulate (or import) and format data {-} - -First, bring in the dataset. - -```{r} -big <- readRDS("ReC.rds") -``` - -To avoid "dependency" in the data, I will just use data from the ANOVA course. Let's first trim it to just students who took ANOVA - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -JustANOVA <- subset(big, Course == "ANOVA") -``` - -I will create a mean score of completed items from the traditional pedagogy scale. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Creates a list of the variables that belong to that scale -TradPed_vars <- c('ClearResponsibilities', 'EffectiveAnswers','Feedback', 'ClearOrganization','ClearPresentation') - -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -JustANOVA$TradPed <- sjstats::mean_n(JustANOVA[, TradPed_vars], .75) - -``` - -To make it easier for teaching, I will make a super tiny df with just the predictor and continuous variable. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -IndT_df <-(dplyr::select(JustANOVA, Dept, TradPed)) -``` - -And further trim to non-missing data -```{r} -IndT_df <- na.omit(IndT_df) -``` - -Are the structures of the variables as follows: -* Grouping variable: factor -* Dependent variable: numerical or integer - -In our case we want Department to be a factor with two levels and the SCRPed variable to be integer or numerical. -```{r} -str(IndT_df) -``` - -Since the Department is a character variable, we need to change it to be a factor. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -IndT_df$Dept <- factor(IndT_df$Dept) -str(IndT_df$Dept) -``` - -Without further coding, R will order the factors alphabetically. This is fine. CPY will be the base/intercept and ORG will be the comparison (this becomes more important in regression). - -#### Evaluate statistical assumptions {-} - -* Evaluate and report skew and kurtosis -* Evaluate and correctly interpret homogeneity of variance (if Levene's < .05; use Welch's formulation) - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describeBy(IndT_df ~ Dept, type =1, mat=TRUE) -``` -Although I included Dept in the descriptives, it is a factor and therefore the values around distribution are rather senseless. - -TradPed, though, is a continuously scored variable: - -Skew = -0.763 (CPY) and -1.183 (ORG) falls below the |3.0| threshold of concern (Klein, 2016) -Kurtosis = 0.156 (CPY) and 0.583 (ORG) falls below the |10.0| threshold of concern (Klein, 2016) - -We can use the Shapiro Wilk test for a formal test of normality -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse)#opening this package so I can use the pipes -shapiro <- IndT_df%>% - group_by(Dept) %>% - rstatix::shapiro_test(TradPed) -shapiro -``` - -The Shapiro-Wilk test of normality indicated that the dependent variable, traditional pedagogy, differed significantly from a normal distribution for both CPY students $(W = 0.918, p < 0.001)$ and ORG students$(W = 0.851, p < 0.001)$. - -Should we be concerned? A general rule of thumb is that when cell sizes are larger than 15 the independent *t*-test should be relatively robust to violations of normality [@green_using_2017]. Although there are more CPY than ORG students, we are well-powered. - -For fun (not required), let's produce a pairs.panels. - -```{r} -psych::pairs.panels(IndT_df) -``` - -We can see that we'll have more CPY students than ORG students. Although our kurtosis was below |10| our distribution looks negatively skewed, with the majority of the scores being on the high end of the scale. - -And now for homogeneity of variance: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::levene_test(IndT_df, TradPed ~ Dept, center=median) -``` - -Levene's test for homogeneity of variance indicated that we did not violate the assumption of homogeneity of variance $(F[1, 110] = 2.460, p = 0.120)$. That is to say, the variance in each of the departments is not statistically significantly different from each other. We can use the regular (Student's) formulation of the *t*-test for independent samples. - - -#### Conduct an independent samples *t*-test (with an effect size and 95%CIs) {-} - -Conduct the independent samples *t*-test (with an effect size) - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -indT.test <- rstatix::t_test(IndT_df, TradPed~Dept, var.equal=TRUE, detailed=TRUE) %>% - rstatix::add_significance() -indT.test -``` - -From this output we learn that the value of the *t*-test is 1.423 and is non-significant *p = 0.148*. We are 95% confident that the mean diference falls between -0.102 and 0.618. Because this threshold crosses zero, we cannot be certain that the true difference in means is not zero. Here's how I would represent these results in a statistical string: $t(110) = 1.423, p = 0.158, CI95(0.102, 0.619)$. - -Calculating the Cohen's *d* as the effect size. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::cohens_d(IndT_df, TradPed ~ Dept, var.equal = TRUE) -``` -The value of Cohen's *d* statistic (interpreted in standard deviation units) is 0.300 and is small. We can add this value to the statistical string: $t(110) = 1.423, p = 0.158, CI95 (0.102, 0.619), d = 0.300$. - -#### APA style results with table(s) and figure {-} - -* Complete content of results (including t, df, p, d-or-eta, CI95%) -* Table -* Figure -* Grammar/formatting - ->An independent samples *t*-test was conducted to evaluate the hypothesis that there would be differences in course evaluation ratings of traditional pedagogy between academic departments (CPY, ORG). - ->We began by analyzing the data to see if it met the statistical assumptions for analysis with an independent samples *t*-test. One assumption is that the dependent variable be normally distributed within the both levels of the grouping variable. We evaluated skew and kurtosis using Kline's [-@kline_data_2016] guidelines of the absolute values of 3 (skew) and 10 (kurtosis). Our results were well-within these boundary conditions. Specifically, the traditional pedagogy ratings for CPY were -0.763 and 0.156 for skew and kurtosis, respectively; they were -1.183 and 0.583 for ORG. The Shapiro-Wilk test of normality indicated that the dependent variable, traditional pedagogy, differed significantly from a normal distribution for both CPY students $(W = 0.918, p < 0.001)$ and ORG students $(W = 0.851, p < 0.001)$. Levene's test for homogeneity of variance indicated that we did not violate the assumption of homogeneity of variance $(F[1, 110] = 2.460, p = 0.120)$. That is to say, the variance in each of the departments is not statistically significantly different from each other. Because the independent samples *t*-test is relatively robust to violations of normality when samples sizes have at least 15 participants per cell [@green_using_2017] and there was no violation of the homogeneity of variance assumption we proceded with the Student's formulation of the *t*-test for independent samples. - ->The independent samples *t*-test was nonsignificant, $t(110) = 1.423, p = 0.158$, the effect size (d = 0.300) was small. The 95% confidence interval for the difference in means ranged from -0.102 to 0.619. Means and standard deviations are presented in Table 1; the results are illustrated in Figure 1. - -We can use the *apaTables* package to create a table of means and standard deviations. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -apaTables::apa.1way.table(Dept, TradPed, IndT_df) -``` -And now a figure. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -indT.box <- ggpubr::ggboxplot(IndT_df, x = "Dept", y = "TradPed", color = "Dept", palette=c("#00AFBB", "#FC4E07"), add = "jitter", title = "Figure 1. Traditional Pedagogy as a Function of Academic Department") -ind.testT <- indT.test %>% rstatix::add_xy_position(x = "Dept") #autocomputes p-value labels positions -indT.box <- indT.box + - ggpubr::stat_pvalue_manual(ind.testT, label = "p.signif", tip.length=.02, hide.ns = FALSE, y.position = c(5.5)) + - labs(subtitle = rstatix::get_test_label(indT.test, detailed=TRUE)) #adds t-test results - -indT.box -``` - -#### Conduct power analyses to determine the power of the current study and a recommended sample size {-} - -We can use Cohen's d in this specification of *d*. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.t.test(d = 0.30, n = 112, power = NULL, sig.level = 0.05,type = "two.sample", alternative = "two.sided") -``` - -We were at 61% power. That is, given the value of the mean difference (), we had a 61% chance of detecting a statistically significant effect if there was one. How big of a sample would it take? - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.t.test(d = 0.3, n = NULL, power = 0.8, sig.level = 0.05, type = "two.sample", alternative = "two.sided") -``` - -To find a statistically significant difference, we would need 175 per group. This large size is consistent with the small effect -- that there isn't really a difference between the two groups. - -### Hand Calculations - -I will use the same example (and same dataset) for hand calculations. Before we continue: - ->You may notice that the results from the hand calculation are slightly different from the results I will obtain with the R packages. This is because the formula we have used for the hand-calculations presumes that we have a balanced design (i.e., that the cell sizes are equal). When cell sizes are unequal (i.e., an unbalanced design) the *rstatix::t_test* will produce different results. - -> Should we be concerned? No (and yes). My purpose in teaching hand calculations is for creating a conceptual overview of what is occurring in these statistics. If this lesson was a deeper exploration into the inner workings of *t*-tests, we would take more time to understand what is occurring. - -#### Using traditional NHST (null hypothesis testing language), state your null and alternative hypotheses {-} - -$$H_0: \mu_1 = \mu_2$$ -$$H_A: \mu_1 \neq \mu_2$$ - -#### Using an R package or functions in base R, calculate the means and standard deviations for both levels of the dependent variable {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describeBy(IndT_df ~ Dept, type =1, mat=TRUE) -``` - -CPY: *M* = 4.130, *SD* = 0.755 -ORG: *M* = 3.871, *SD* = 1.095 - -#### Calulate the SE used in the denominator of the *t*-test {-} - -Just as a reminder, the SE is the denominator in the *t*-test formula: - -$$t = \frac{\bar{X_{1}} -\bar{X_{2}}}{\sqrt{\frac{s_{1}^{2}}{N_{1}}+\frac{s_{2}^{2}}{N_{2}}}}$$ -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -sqrt((0.7547259^2/81) + (1.0948953^2/31)) -``` -The *SE* = 0.214 - -#### Calculate the independent samples *t*-test {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -(4.129630 - 3.870968)/0.2137828 -``` -*I note that this hand calculation differs from the worked in R. I believe this is likely due to an unbalanced design with unequal cell sizes (81 and 31).* - - -#### Identify the degrees of freedom associated with your *t*-test {-} - -$N - 2$ is the degrees of freedom: 112-2, df = 110 - -#### Locate the test critical value for your test {-} - -We can look at a [table of critical values](https://www.statology.org/t-distribution-table/) - -For a two-tailed test, with alpha of 0.05, and a sample size of 120 (close enough), the *t*-statistic must be greater than 1.98. - -We could also obtain a *t* critical value with this code: - -```{r} -qt(0.05/2, 112, lower.tail = TRUE) -qt(0.05/2, 112, lower.tail = FALSE) -``` -#### Is the *t*-test statistically significant? Why or why not? {-} - -In a two-tailed test, if the *t*-statistic falls outside the boundaries of -1.98 and 1.98 the means of the two groups are statistically significantly different from each other. - -My *t* value of 1.209929 does not exceed these boundaries and therefore is not statistically significant. - - -#### Calculate the confidence interval around the difference in sample means {-} - -Calculating a confidence interval around the difference in sample means requires the two-tailed test critical values. We can insert them into this formula: - -$$(\bar{X_{1}} -\bar{X_{2})} \pm t_{cv}(SE)$$ - -```{r} -(4.129630 - 3.870968) - (1.209929 * 0.2137828) -(4.129630 - 3.870968) + (1.209929 * 0.2137828) -``` -We are 95% confident that the mean difference falls between -0.000 and 0.517. Because this interval passes through zero, we cannot be certain that the difference is 0. This is consistent with the non-significant *p* value. - -#### Calculate the effect size (i.e., Cohen’s d associated with your *t*-test {-} - -Here is the formula for Cohen's *d*: - -$$d = t\sqrt{\frac{N_{1}+N_{2}}{N_{1}N_{2}}}$$ - -```{r} -1.209929 * (sqrt((81 + 31)/(81 * 31))) -``` - -#### Assemble the results into a statistical string {-} - -$t(110) = 1.210, p > 0.05, CI95(-0.000, 0.517), d = 0.256$ - diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/792F6C03-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/792F6C03-contents deleted file mode 100644 index e69de29b..00000000 diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/805AEC1C-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/805AEC1C-contents deleted file mode 100644 index edfc655b..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/805AEC1C-contents +++ /dev/null @@ -1,117 +0,0 @@ -# One-Way Repeated Measures with a Multivariate Approach {-} - -```{r include=FALSE} -knitr::opts_chunk$set(echo = TRUE) -knitr::opts_chunk$set(comment = NA) #keeps out the hashtags in the knits -options(scipen=999)#eliminates scientific notation -``` - -[Screencasted Lecture Link](https://youtu.be/1c3N733nSM0) - -As noted in the lesson on [one-way repeated measures ANOVA](#Repeated), the researcher can use a univariate or multivariate approach to analyzing the data. The *rstatix::anova_test()* is limited to the univariate approach. In order to maintain a streamlined chapter with minimal distractions to student learning I have chosen to provide a quick and separate demonstration of the multivariate approach in this appendix. In-so-doing, I will use the *car* package. - -As a quick reminder, I will describe and resimulate the data. The narration will presume familiarity with the [one-way repeated measures ANOVA](#Repeated) lesson. - -## Research Vignette {-} - -Amodeo [@amodeo_empowering_2018] and colleagues conducted a mixed methods study (qualitative and quantitative) to evaluate the effectiveness of an empowerment, peer-group-based, intervention with participants (*N* = 8) who experienced transphobic episodes. Focus groups used qualitative methods to summarize emergent themes from the program (identity affirmation, self-acceptance, group as support) and a one-way, repeated measures ANOVA provided evidence of increased resilience from pre to three-month followup. - -Eight participants (seven transgender women and one genderqueer person) participated in the intervention. The mean age was 28.5 (*SD* = 5.85). All participants were located in Italy. - -The within-subjects condition was wave, represented by T1, T2, and T3: - -* T1, beginning of training -* Training, three 8-hour days, - - content included identity and heterosexism, sociopolitical issues and minority stress, resilience, and empowerment -* T2, at the conclusion of the 3-day training -* Follow-up session 3 months later -* T3, at the conclusion of the +3 month follow-up session - -The dependent variable (assessed at each wave) was a 14-item resilience scale [@wagnild_development_1993]. Items were assessed on a 7-point scale ranging from *strongly disagree* to *strongly agree* with higher scores indicating higher levels of resilience. An example items was, "I usually manage one way or another." - -### Data Simulation {-} - -Below is the code I used to simulate data. The following code assumes 8 participants who each participated in 3 waves (pre, post, followup). The sript produces "long" and "wide" forms are created. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -set.seed(2022) -#gives me 8 numbers, assigning each number 3 consecutive spots, in sequence -ID<-factor(c(rep(seq(1,8),each=3))) -#gives me a column of 24 numbers with the specified Ms and SD -Resilience<-rnorm(24,mean=c(5.7,6.21,6.26),sd=c(.88,.79,.37)) -#repeats pre, post, follow-up once each, 8 times -Wave<-rep(c("Pre","Post", "FollowUp"),each=1,8) -Amodeo_long<-data.frame(ID, Wave, Resilience) - -Amodeo_long$Wave <- factor(Amodeo_long$Wave, levels = c("Pre", "Post", "FollowUp")) - -# Create a new df (Amodeo_wide) -# Identify the original df -# We are telling it to connect the values of the Resilience variable its respective Wave designation -Amodeo_wide <- reshape2::dcast(data = Amodeo_long, formula =ID~Wave, value.var = "Resilience") -#doublecheck to see if they did what you think -str(Amodeo_wide) -Amodeo_wide$ID <- factor(Amodeo_wide$ID) -``` - -## Computing the Omnibus F {-} - -Without the *rstatix* helper package, here is how the analysis would be run in the package, *car.* Although this package is less intuitive to use, it results in both univariate output (both sphericity assumed and sphericity violated) and multivariate output (which does not require the sphericity assumption). - -Evaluating the data requires that we create some objects that will be fed into function. We can name these objects anything we like. - -In ths script below I define the objects that are required. - -* waveLevels is an object that will specify three levels of the independent variable (pre, post, follow-up), -* waveFactor simply makes "waveLevels" a factor -* waveBind column-binds (i.e., cbind) the pre, post, and follow-up variables from the wide form of the Amodeo dataset -* waveModel calculates the intercept (i.e., the means) of the pre, post, and follow-up levels - - -```{r message=FALSE, warning=FALSE, tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#library(car) -waveLevels <- c(1,2,3) -waveFactor <- as.factor(waveLevels) -waveFrame <- data.frame(waveFactor) -waveBind <-cbind(Amodeo_wide$Pre, Amodeo_wide$Post, Amodeo_wide$FollowUp) -waveModel<- lm(waveBind~1) -waveModel - -``` -To run the analysis, we insert these objects into arguments: - -* waveModel is the first argument, -* waveFrame is assigned to the *idata* command, -* waveFactor is assigned to the *idesign* command - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -analysis <-car::Anova(waveModel, idata=waveFrame, idesign=~waveFactor) -summary(analysis) -``` -The *car::Anova()* function produces both univariate and multivariate results. To begin to understand this data, let's start with what we learned in the [one-way repeated measures ANOVA lesson](#Repeated). - -### Univariate Results {-} - -When we ran the univariate approach in the lesson, we first checked the sphericity assumption. Our results here are identical to those from *rstatix::anova_test*. That is, we did not violate the sphericity assumption: Mauchley's test $= .566 p = 0.182$. The *F* test with univariate results was $F(2, 14) = 3.910, p = 0.045$. - ->The Greenhouse Geiser estimate was 0.698 the corrected *p* = .068. ->The Huyhn Feldt estimate was 0.817 and the corrected *p* = .057. - -The univariate ANOVA results are under the "Univariate Type III Repeated-Measures ANOVA Assuming Sphericity" heading. We find the ANOVA output on the row titled, "waveFactor." The results are identical to what we found in the lesson: $F(2,14) = 3.91, p = 0.045$. I do not see that an effect size is reported. - -### Multivariate Results {-} - -Researchers may prefer the multivariate approach because it does not require the sphericity assumption. Stated another way, if the sphericity assumption is violated, researchers can report the results of the multivariate analysis. - -We find the multivariate results in the middle of the output, under the heading, "Multivariate Tests: waveFactor." There are four choices: Pillai, Wilks, Hotelling-Lawley, and Roy. Green and Salkind [-@green_one-way_2017-1] have noted that in the one-way within-subjects ANOVA, all four will yield the same *F* and *p* values. They recommended reporting Wilks' lambda because researchers will have greatest familiarity with it. Thus, I would write up the result of this omnibus test like this: - ->Results of the one-way repeated measures ANOVA indicated a significant wave effect, $Wilks' \lambda = .597, F(2,6) = 2.022, p = 0.213$. - -Because follow-up testing is *pairwise* (i.e., there are only two levels being compared), the sphericity assumption is not required and those could proceed in the manner demonstrated in the [one-way repeated measures ANOVA lesson](#Repeated). - -### A Brief Commentary on Wrappers - -As noted several times, because of its relative ease-of-use, the relevance of information included in the results, and its integration with the *ggpubr* package, I chose to use *rstatix* package in all of the ANOVA lessons. As I worked through this example, I spent several hours creating and interpreting the code. For me, there was value in this exercise: - -* I am encouraged and reassured with the consistency of results between the two approaches, -* I am in awe of the power of these programs and a little intimidated by all the options that are available within a given package, and -* I am deeply grateful to package developers who take the time to create packages for discipline-specific use-cases and then freely share their work with others. Thank you [Alboukadel Kassambara](https://github.com/kassambara/rstatix)! \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/8373033C-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/8373033C-contents deleted file mode 100644 index 2e0debfd..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/8373033C-contents +++ /dev/null @@ -1,228 +0,0 @@ -```{r include=FALSE} -options(scipen=999)#eliminates scientific notation -``` -## Homeworked Example - -[Screencast Link](https://youtu.be/eRCDNibARtg) - -For more information about the data used in this homeworked example, please refer to the description and codebook located at the end of the [introduction](ReCintro). - -### Working the Problem with R and R Packages - -#### Narrate the research vignette, describing the IV, DV, and COV {-} - -I want to ask the question, what are the effects of intentional recentering on students' evaluations of socially responsive pedagogy in the multivariate (last) course as a function of centering status (i.e., pre versus re), controlling for the socially responsive evaluations in the ANOVA (first) course: - -* Continuous DV: SRPed (socially responsive pedagogy) in the multivariate (last) class -* Between-subjects factor: recentering status of the class (Pre, Re) -* Covariate: SRPed in the ANOVA (first) class - - -*If you wanted to use this example and dataset as a basis for a homework assignment, you could choose a different dependent variable. I chose the socially responsive pedagogy subscale. Two other subscales include traditional pedagogy and valued by the student.* - -#### Simulate (or import) and format data {-} - -First I import the larger dataset. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -big <- readRDS("ReC.rds") -``` - -The SRPed (socially responsive pedagogy) variable is an average of the items on that scale. I will first create that variable. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Creates a list of the variables that belong to that scale -SRPed_vars <- c('InclusvClassrm', 'EquitableEval','MultPerspectives', 'DEIintegration') - -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -big$SRPed <- sjstats::mean_n(big[, SRPed_vars], .75) - -#if the scoring script won't run, try this one: -#big$SRPed <- sjstats::mean_n(big[, ..SRPed_vars], .75) -``` - -Let's trim it to just the variables of interest. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ANCOVA_df <- (dplyr::select (big, deID, Course, Centering, SRPed)) -``` - -And further filter so that there are just evaluations of ANOVA and multivariate courses. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ANCOVA_df <- subset(ANCOVA_df, Course == "ANOVA" | Course == "Multivariate") #multiple conditions -``` - -I want the course variable to be factor that is ordered by its sequence: ANOVA, multivariate. - -I want the centering variable to be ordered: Pre, Re - -```{r } -str(ANCOVA_df) -``` -Because R's default is to order alphabetically, the centering variable is correct. I just need to change the course variable. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ANCOVA_df$Course <- factor(ANCOVA_df$Course, levels = c("ANOVA", "Multivariate")) -str(ANCOVA_df) -``` -After checking the structure again, both are correct. - -My data is in the long (person-period) form. For this particular ANOVA I need it to be in the wide (person level) form. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ANCOVA_wide<- reshape2::dcast(data = ANCOVA_df, formula = deID + Centering ~ Course, value.var = "SRPed") -# before restructuring a second variable, rename the first variable -ANCOVA_wide <- dplyr::rename(ANCOVA_wide, SRPed_ANV = "ANOVA", SRPed_MLTV = "Multivariate") - -str(ANCOVA_wide) -head(ANCOVA_wide) -``` -The *head* function shows that the multivariate scores are missing. This design still has missingness for (a) some students who took ANOVA but haven't yet had multivariate and (b) others who may have skipped completing course evaluations. I'll take care of that next by requiring rows to have non-missing data. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ANCOVA_wide <- na.omit(ANCOVA_wide) -``` - - -#### Evaluate statistical assumptions {-} - -**Is there a linear relationship between the covariate and outcome at each level of the grouping variable?"** - -This would mean that there is linearity between the evaluation in the first course (covariate/ANOVA) and last course (outcome/Multivariate) at each level of the independent variable (Centering status). - -We can get a visual of this with a scatterplot (with regression lines) between the covariae and outcome. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(ggplot2) -ggpubr::ggscatter(ANCOVA_wide, x = "SRPed_ANV", y = "SRPed_MLTV", color = "Centering", add = "reg.line") + ggpubr::stat_regline_equation(aes(label = paste(..eq.label.., ..rr.label.., sep = "~~~~"), color = Centering)) -``` - -The plot looks a little funny. This is likely because there are no values below 3(ish) for ANOVA when courses were re-centered. Although we are looking for a linear relationship, the angled lines suggest there could be an interaction effect. The previous lesson (when we included all three courses [ANOVA, psychometrics, multivariate]) showed that there was. Spoiler alert -- mixed design ANOVA is a better analysis for this question, but the data does allow me (statistically) to use it for a homework demonstration. - -**Are the regression lines formed by the covariate and the outcome variable the same for each group?** - -This would mean that there is no interaction between the outcome and covariate. We can test this with an ANOVA model that specifies an interaction. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -ANCOVA_wide %>% - rstatix::anova_test(SRPed_MLTV ~Centering*SRPed_ANV) -``` -Curiously, the interaction term was not statistically significant $(F[1, 71] = 1.975, p = 0.164)$. This non-violation of the homogeneity of slopes assumption supports the use of ANCOVA. - -**Are the model residuals normally distributed and equal across groups?** - -First, I create a linear regression model -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SRPed_mod <- lm(SRPed_MLTV ~ SRPed_ANV + Centering, data = ANCOVA_wide) -``` - -I will use *broom::augment()* to add fitted values and residuals to the model I just created. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SRPed_mod_metrics <- broom::augment(SRPed_mod) -head(SRPed_mod_metrics) -``` - -I can now assess the normality of residuals with the Shapiro-Wilk test. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::shapiro_test(SRPed_mod_metrics$.resid) -``` - -The Shapiro-Wilk test suggested that our residuals are not statistically significantly different from a normal distribution $(W = 0.972, p = 0.101)$. - -ANCOVA further presumes that the variances of the residuals is equal for all groups. I can check this with the Levene's test. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SRPed_mod_metrics%>% - rstatix::levene_test(.resid ~ Centering) -``` -A non-significant Levene's test indicated no violation of the homogeneity of the residual variances for the groups $(F[1, 73] = 2.675, p = 0.106)$. - - -**Is there evidence of outliers? Are they extreme?** - -I can identify outliers by examining the standardized (or studentized) residuals. These are interpreted as the number of standard errors away from the regression line. - -```{r} -SRPed_mod_metrics %>% - filter(abs(.std.resid) > 3) %>% - as.data.frame() -``` - -No outliers were identified. - -Here's write-up of what I've done so far: - ->A one-way analysis of covariance (ANCOVA) was conducted. The independent variable, centering stage, had two levels: pre-centered, re-centered. The dependent variable was students' evaluation of socially responsive pedagogy during the last statistics course (multivariate) and the covariate was the students' evaluation of the same variable during the first statistics class (ANOVA). - ->A preliminary analysis evaluating the homogeneity-of-slopes assumption indicated that the relationship between the covariate and the dependent variable did not differ significantly as a function of the independent variable, $(F[1, 71] = 1.975, p = 0.164)$. Further, the non-significant Shapiro-Wilk test of normality on the model residuals $(W = 0.972, p = 0.101)$ indicated that the dependent variable was not statistically significantly different from a normal distribution and no outliers were identified. A non-significant Levene’s test indicated no violation of the homogeneity of the residual variances for all groups $(F[1, 73] = 2.675, p = 0.106)$. - - -#### Conduct omnibus ANOVA (w effect size) {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ANCOVA_mod <- ANCOVA_wide %>% - rstatix::anova_test(SRPed_MLTV ~ SRPed_ANV + Centering) -rstatix::get_anova_table(ANCOVA_mod) -``` ->There was a significant effect of the evaluation of socially responsive pedagogy at the first course (ANOVA) on the same rating at the last course $(F [1,72] = 39.696, p < .001, \eta^2 = 0.355)$ as well as a statistically significant effect of recentering on evaluations of socially responsive pedagogy during the last class $(F [1,72]) = 10.304, p = 0.002, \eta^2 = 0.125)$. Considering that we interpret values $eta^2$ values of .01, .06, and .14 to be small, medium, and large it appears that both the covariate and independent variable had substantial effects on the results. - -#### Conduct one set of follow-up tests; narrate your choice {-} - -Because this design has only two levels (pre-centered, re-centered), follow-up tests will not tell us any more information. However, investigating the covariate-adjusted mean is useful. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -emmeans_MLTV <- ANCOVA_wide%>% - rstatix::emmeans_test(SRPed_MLTV ~ Centering, covariate = SRPed_ANV, p.adjust.method = "none") -emmeans_MLTV -``` -Not surprisingly (since this single pairwise comparison is redundant with the omnibus ANCOVA), results suggest a statistically significant difference between the pre- and re-centered stages in the multivariate class. - -With this script I can obtain the covariate-adjusted (i.e., estimated marginal) means. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -emmeans_list <- rstatix::get_emmeans(emmeans_MLTV) -emmeans_list -``` -We can compare these to the unadjusted means: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -descripts_means <- psych::describeBy(SRPed_MLTV ~ Centering, data = ANCOVA_wide, mat=TRUE, digits=6) -descripts_means -``` - -While the differences are minor, they do exist. - -#### Describe approach for managing Type I error {-} - -Because we only needed to conduct the omnibus, there was no additional control of Type I error. - -#### APA style results with table(s) and figure {-} - ->A one-way analysis of covariance (ANCOVA) was conducted. The independent variable, centering stage, had two levels: pre-centered, re-centered. The dependent variable was students' evaluation of socially responsive pedagogy during the last statistics course (multivariate) and the covariate was the students' evaluation of the same variable during the first statistics class (ANOVA). - ->A preliminary analysis evaluating the homogeneity-of-slopes assumption indicated that the relationship between the covariate and the dependent variable did not differ significantly as a function of the independent variable, $(F[1, 71] = 1.975, p = 0.100)$. Further, the non-significant Shapiro-Wilk test of normality on the model residuals $(W = 0.972, p = 0.101)$ indicated that the dependent variable was not statistically significantly different from a normal distribution and no outliers were identified. A non-significant Levene’s test indicated no violation of the homogeneity of the residual variances for all groups $(F[1, 73] = 2.675, p = 0.106)$. - ->There was a significant effect of the evaluation of socially responsive pedagogy at the first course (ANOVA) on the same rating at the last course $(F [1,72] = 39.696, p < .001, \eta^2 = 0.355)$ as well as a statistically significant effect of recentering on evaluations of socially responsive pedagogy during the last class $(F]1,72) = 10.304, p = 0.002, \eta^2 = 0.125)$. Considering that we interpret values $eta^2$ values of .01, .06, and .14 to be small, medium, and large it appears that both the covariate and independent variable had substantial effects on the results. As illustrated in Figure 1, results suggested that those in the multivariate condition had more favorable ratings of socially responsive pedagogy than those in the ANOVA class. Table 1 provides unadjusted and covariate-adjusted means for the dependent variable. - - -In the case of ANCOVA, a table that compares unadjusted and covariate-adjusted means can be helpful. The lesson contains some script to export data. I will create a table to demonstrate how this might work: - -|Table 1 -|:--------------------------------------------------| -|Unadjusted and Covariate-Adjusted Descriptive Statistics - -|Centering |Unadjusted |Covariate-Adjusted -|:--------------|:-------------:|:-----------------:| - -| |*M* |*SD* |*EMM* |*SE* -|:--------------|:-------:|:----:|:---------:|:----:| -|Pre-centered |4.381277 |0.633 |4.381639 |0.067 | -|Re-centered |4.732143 |0.425 |4.731534 |0.086 | - - -And now a figure: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -emmeans_MLTV <- emmeans_MLTV %>% - rstatix::add_xy_position(x = "Centering", fun = "mean_se") -ggpubr::ggline(rstatix::get_emmeans(emmeans_MLTV), x = "Centering", y = "emmean", title = "Figure 1. SRPed Ratings as a Function of Centering, Controlling for Earlier Ratings") + - geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0.2) + - ggpubr::stat_pvalue_manual(emmeans_MLTV, hide.ns = TRUE, tip.length = 0.02, , y.position = c(5.0)) -``` diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/8434BF25-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/8434BF25-contents deleted file mode 100644 index 92b3632b..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/8434BF25-contents +++ /dev/null @@ -1,368 +0,0 @@ -```{r include=FALSE} -options(scipen=999)#eliminates scientific notation -``` - -## Homeworked Example - -[Screencast Link](https://youtu.be/3UhTJXp8uNI) - -For more information about the data used in this homeworked example, please refer to the description and codebook located at the end of the [introduction](ReCintro). - -### Working the Problem with R and R Packages - -#### Narrate the research vignette, describing the IV and DV. The data you analyze should have at least 3 levels in the independent variable; at least one of the attempted problems should have a significant omnibus test so that follow-up is required) {-} - -I want to ask the question, do course evaluation ratings for the traditional pedagogy dimension differ for students across the ANOVA, multivariate, and psychometrics courses (in that order, because that's the order in which the students take the class.) - -The dependent variable is the evaluation of traditional pedagogy. The independent variable is course/time (i.e., each student offers course evaluations in each of the three classes). - -*If you wanted to use this example and dataset as a basis for a homework assignment, the three different classes are the only repeated measures variable. Rather, you could choose a different dependent variable. I chose the traditional pedagogy subscale. Two other subscales include socially responsive pedagogy and valued by the student.* - -#### Check and, if needed, format data {-} - -```{r} -big <- readRDS("ReC.rds") -``` - -The TradPed (traditional pedagogy) variable is an average of the items on that scale. I will first create that variable. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Creates a list of the variables that belong to that scale -TradPed_vars <- c('ClearResponsibilities', 'EffectiveAnswers','Feedback', 'ClearOrganization','ClearPresentation') - -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -big$TradPed <- sjstats::mean_n(big[, TradPed_vars], .75) - -#if the scoring script won't run, try this one: -#big$TradPed <- sjstats::mean_n(big[, ..TradPed_vars], .75) -``` - -Let's trim to just the variables we need. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rm1wLONG_df <- (dplyr::select (big, deID, Course, TradPed)) -head(rm1wLONG_df) -``` - -* Grouping variables: factors -* Dependent variable: numerical or integer - -```{r} -str(rm1wLONG_df) -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rm1wLONG_df$Course <- factor(rm1wLONG_df$Course, levels = c("ANOVA", "Multivariate", "Psychometrics")) -str(rm1wLONG_df) -``` -Let's update the df to have only complete cases. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rm1wLONG_df <- na.omit(rm1wLONG_df) -nrow(rm1wLONG_df)#counts number of rows (cases) -``` -This took us to 307 cases. - -These analyses require that students have completed evaluations for all three courses. In the lesson, I restructured the data from long, to wide, back to long again. While this was useful pedagogy in understanding the difference between the two data structures, there is also super quick code that will simply retain data that has at least three observations per student. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -rm1wLONG_df <- rm1wLONG_df%>% - dplyr::group_by(deID)%>% - dplyr::filter(n()==3) -``` - -This took the data to 210 observations. Since each student contributed 3 observations, we know $N = 70$. - -```{r} -210/3 -``` -Before we start, let's get a plot of what's happening: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -bxp <- ggpubr::ggboxplot(rm1wLONG_df, x = "Course", y = "TradPed", add = "point", color = "Course", - xlab = "Statistics Course", ylab = "Traditional Pedagogy Course Eval Ratings", title = "Course Evaluations across Doctoral Statistics Courses") -bxp -``` - -#### Evaluate statistical assumptions {-} - -**Is the dependent variable normally distributed?** - -Given that this is a one-way repeated measures ANOVA model, the dependent variable must be normally distributed within each of the cells of the factor. - -We can examine skew and kurtosis in each of the levels of the TradPed variable with *psych::describeBy()*. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#R wasn't recognizing the data, so I quickly applied the as.data.frame function -rm1wLONG_df <- as.data.frame(rm1wLONG_df) -psych::describeBy(TradPed ~ Course, mat = TRUE, type = 1, data = rm1wLONG_df) -``` - -Although we note some skew and kurtosis, particularly for the multivariate class, none exceed the critical thresholds of |3| for skew and |10| identified by Kline [-@kline_data_2016]. - -I can formally test for normality with the Shapiro-Wilk test. If I use the residuals from an evaluated model, with one test, I can determine if TradPed is distributed normally within each of the courses. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#running the model -RMres_TradPed <- lm(TradPed ~ Course, data = rm1wLONG_df) -summary(RMres_TradPed) -``` -We will ignore this for now, but use the residuals in the formal Shapiro-Wilk test. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::shapiro_test(residuals(RMres_TradPed)) -``` -The distribution of model residuals is statistically significantly different than a normal distribution $(W = 0.876, p < .001)$. Although we have violated the assumption of normality, ANOVA models are relatively robust to such a violation when cell sizes are roughly equal and greater than 15 each [@green_one-way_2017-1]. - -Creating a QQ plot can let us know how badly the distribution departs from a normal one. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ggpubr::ggqqplot(residuals(RMres_TradPed)) -``` - -We can identify outliers and see if they are reasonable or should be removed. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -rm1wLONG_df %>% - group_by(Course)%>% - rstatix::identify_outliers(TradPed) -``` -Outliers for the TradPed variable are among the lowest evaluations (these can be seen on the boxplot). Although there are six outliers identified, none are extreme. Although they contribute to non-normality, I think it's important that this sentiment be retained in the dataset. - -**Assumption of sphericity** - -We will need to evaluate and include information about violations related to sphericity. Because these are calculated at the same time as the ANOVA, itself, I will simply leave this here as a placeholder. - -Here's how I would write up the evaluation of assumptions so far: - ->We utilized one-way repeated measures ANOVA to determine if there were differences in students' evaluation of traditional pedagogy across three courses -- ANOVA, multivariate, and psychometrics -- taught in that order. - ->Repeated measures ANOVA has several assumptions regarding normality, outliers, and sphericity. Although we note some skew and kurtosis, particularly for the multivariate class, none exceed the critical thresholds of |3| for skew and |10| identified by Kline [-@kline_data_2016]. We formally evaluated the normality assumption with the Shapiro-Wilk test. The distribution of model residuals was statistically significantly different than a normal distribution $(W = 0.876, p < .001)$. Although we violated the assumption of normality, ANOVA models are relatively robust to such a violation when cell sizes are roughly equal and greater than 15 each [@green_one-way_2017-1]. Although our data included six outliers, none were classified as extreme. Because they represented lower course evaluations, we believed it important to retain them in the dataset. PLACEHOLDER FOR SPHERICITY. - -#### Conduct omnibus ANOVA (w effect size) {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rmAOV <- rstatix::anova_test(data = rm1wLONG_df, dv = TradPed, wid = deID, within = Course) -rmAOV -``` -Let's start first with the sphericity test. Mauchly's test for sphericity was statistically significant, $(W = 0.878, p = 0.012)$. Had we not violated the assumption, our *F* string would have been created from the data in the ANOVA section of the output : $F(2, 138) = 2.838, p = 0.062, \eta^2 = 0.14$ However, because we violated the assumption, we need to use the degrees-of-freedom adjusted output under the "Sphericity Corrections" section; $F(1.78, 122.98) = 2.838, p = 0.068, ges = 0.014$. - -While the ANOVA is non-significant, because this is a homework demonstration, I will behave *as if* the test is significant and continue with the pairwise comparisons. - -#### Conduct all possible pairwise comparisons (like in the lecture) {-} - -I will follow up with a test of all possible pairwise comparisons and adjust with the bonferroni. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwc <- rstatix::pairwise_t_test(TradPed ~ Course, paired = TRUE, p.adjust.method = "bonf", data = rm1wLONG_df) -pwc -``` - -Consistent with the non-significant omnibus, there were non-significant differences between the pairs. This included, ANOVA and multivariate $(t[69] = -1.215, p = 0.687)$; ANOVA and psychometrics courses $(t[69] = -2.065, p = 0.128)$; and multivariate and psychometrics $(t[69] = -0.772, p = 1.000)$. - -#### Describe approach for managing Type I error {-} - -I used a traditional Bonferroni for the three, follow-up, pairwise comparisons. - -#### APA style results with figure {-} - ->We utilized one-way repeated measures ANOVA to determine if there were differences in students' evaluation of traditional pedagogy across three courses -- ANOVA, multivariate, and psychometrics -- taught in that order. - ->Repeated measures ANOVA has several assumptions regarding normality, outliers, and sphericity. Although we note some skew and kurtosis, particularly for the multivariate class, none exceed the critical thresholds of |3| for skew and |10| identified by Kline [-@kline_data_2016]. We formally evaluated the normality assumption with the Shapiro-Wilk test. The distribution of model residuals was statistically significantly different than a normal distribution $(W = 0.876, p < .001)$. Although we violated the assumption of normality, ANOVA models are relatively robust to such a violation when cell sizes are roughly equal and greater than 15 each [@green_one-way_2017-1]. Although our data included six outliers, none were classified as extreme. Because they represented lower course evaluations, we believed it important to retain them in the dataset. Mauchly's test indicated a violation of the sphericity assumption $(W = 0.878, p = 0.012)$. - ->Given the violation of the homogeneity of sphericity assumption, we are reporting the Greenhouse-Geyser adjusted values. Results of the omnibus ANOVA were not statistically significant $F(1.78, 122.98) = 2.838, p = 0.068, ges = 0.014$. - ->Although we would normally not follow-up a non-significant omnibus ANOVA with more testing, because this is a homework demonstration, we will follow-up the ANOVA with pairwise comparisons and manage Type I error with the traditional Bonferroni approach. Consistent with the non-significant omnibus, there were non-significant differences between the pairs. This included, ANOVA and multivariate $(t[69] = -1.215, p = 0.687)$; ANOVA and psychometrics courses $(t[69] = -2.065, p = 0.128)$; and multivariate and psychometrics $(t[69] = -0.772, p = 1.000)$. - -I can update the figure to include star bars. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -pwc <- pwc %>% - rstatix::add_xy_position(x = "Course") -bxp <- bxp + ggpubr::stat_pvalue_manual(pwc, label = "p.adj.signif", tip.length = 0.01, hide.ns = FALSE, y.position = c(5.25, 5.5, 5.75)) -bxp -``` - -#### Conduct power analyses to determine the power of the current study and a recommended sample size {-} - -In the *WebPower* package, we specify 6 of 7 interrelated elements; the package computes the missing one. - -* *n* = sample size (number of individuals in the whole study). -* *ng* = number of groups. -* *nm* = number of measurements/conditions/waves. -* *f* = Cohen's *f* (an effect size; we can use an effect size converter to obtain this value) - - Cohen suggests that f values of 0.1, 0.25, and 0.4 represent small, medium, and large effect sizes, respectively. -* *nscor* = the Greenhouse Geiser correction from our ouput; 1.0 means no correction was needed and is the package's default; < 1 means some correction was applied. -* *alpha* = is the probability of Type I error; we traditionally set this at .05 -* *power* = 1 - P(Type II error) we traditionally set this at .80 (so anything less is less than what we want). -* *type* = 0 is for between-subjects, 1 is for repeated measures, 2 is for interaction effect. - -I used *effectsize::eta2_to_f* packages convert our $\eta^2$ to Cohen's *f*. - -```{r message=FALSE, warning=FALSE} -effectsize::eta2_to_f(.014) -``` - -Retrieving the information about our study, we add it to all the arguments except the one we wish to calculate. For power analysis, we write "power = NULL." - -```{r message=FALSE, warning=FALSE, tidy=TRUE, tidy.opts=list(width.cutoff=70)} -WebPower::wp.rmanova(n=70, ng=1, nm=3, f = .1192, nscor = .891, alpha = .05, power = NULL, type = 1) -``` -The study had a power of 13%. That is, we had a 13% probability of finding a statistically significant result if one existed. - -In reverse, setting *power* at .80 (the traditional value) and changing *n* to *NULL* yields a recommended sample size. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -WebPower::wp.rmanova(n=NULL, ng=1, nm=3, f = .1192, nscor = .891, alpha = .05, power = .80, type = 1) -``` -With these new values, we learn that we would need 737 individuals in order to obtain a statistically significant result 80% of the time. - -### Hand Calculations - -For hand calculations, I will use the same dataframe (rm1wLONG_df) as I did for the calculations with R and R packages.Before we continue: - ->You may notice that the results from the hand calculation are slightly different from the results I will obtain with the R packages. This was true in the lesson as well. Hand calculations and those used in the R packages likely differ on how the sums of squares is calculated. While the results are "close-ish" they are not always identical. - -> Should we be concerned? No (and yes). My purpose in teaching hand calculations is for creating a conceptual overview of what is occurring in ANOVA models. If this lesson was a deeper exploration into the inner workings of ANOVA, we would take more time to understand what is occurring. My goal is to provide you with enough of an introduction to ANOVA that you would be able to explore further which sums of squares type would be most appropriate for your unique ANOVA model. - -#### Calculate sums of squares total (SST) for the omnibus ANOVA. Steps in this calculation must include calculating a grand mean and creating variables representing the mean deviation and mean deviation squared {-} - -The formula for sums of squares total: $$SS_{T}= \sum (x_{i}-\bar{x}_{grand})^{2}$$. - -We can use the mean function from base R to calculate the grand mean: - -```{r} -mean(rm1wLONG_df$TradPed) -``` -I will create a mean deviation variable by subtracting the mean from each score: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rm1wLONG_df$mDev <- rm1wLONG_df$TradPed - 4.319286 -head(rm1wLONG_df)#shows first six rows of dataset -``` - -Now I will square the mean deviation: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rm1wLONG_df$mDev2 <- rm1wLONG_df$mDev * rm1wLONG_df$mDev -head(rm1wLONG_df)#shows first six rows of dataset -``` - -Sums of squares total is the sum of the mean deviation squared scores. - -```{r} -SST <- sum(rm1wLONG_df$mDev2) -SST -``` -The sums of squares total is 103.9144. - -#### Calculate the sums of squares within (SSW) for the omnibus ANOVA. A necessary step in this equation is to calculate the variance for each student {-} - -Here is the formula for sums of squares within: - -$$SS_W = s_{person1}^{2}(n_{1}-1)+s_{person2}^{2}(n_{2}-1)+s_{person3}^{2}(n_{3}-1)+...+s_{personk}^{2}(n_{k}-1)$$ - -I can get the use the *psych::describeBy()* to obtain the standard deviations for each student's three ratings. I can square each of those for the variance to enter into the formula. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describeBy(TradPed ~ deID, mat=TRUE, type = 1, data = rm1wLONG_df) -``` - -Someone who codes in R could probably write a quick formula to do this -- in this case, I will take the time (and space) to copy each student's standard deviation into a formula that squares it, multiplies it by $n-1$ and then sums all 70 of those calculations. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SSW <- (0.8717798^2 * (3 - 1)) + (0.4163332 ^2 * (3 - 1)) + (0.6928203 ^2 * (3 - 1)) + (0.4000000 ^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.5291503^2 * (3 - 1)) + (0.5291503^2 * (3 - 1)) + (0.7023769^2 * (3 - 1)) + (0.4618802^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (1.2220202^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.9018500^2 * (3 - 1)) + (0.5033223^2 * (3 - 1)) + (0.0000000^2 * (3 - 1)) + (0.9451631^2 * (3 - 1)) + -(1.0066446^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.5484828^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (1.6165808^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.9165151^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.6429101^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.5291503^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.2309401^2 * (3 - 1)) + -(0.1154701^2 * (3 - 1)) + (0.9165151^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.5291503^2 * (3 - 1)) + -(0.5291503^2 * (3 - 1)) + (0.5291503^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + -(0.2309401^2 * (3 - 1)) + (0.2309401^2 * (3 - 1)) + (0.0000000^2 * (3 - 1)) + (0.2000000^2 * (3 - 1)) + (0.1154701^2 * (3 - 1)) + (0.5033223^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.0000000^2 * (3 - 1)) + (0.2309401^2 * (3 - 1)) + (0.4618802^2 * (3 - 1)) + (0.4163332^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.4000000^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + (0.8326664^2 * (3 - 1)) + (0.5773503^2 * (3 - 1)) + -(0.0000000^2 * (3 - 1)) + (0.2000000^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) + (0.3464102^2 * (3 - 1)) + -(0.4618802^2 * (3 - 1)) + (0.3055050^2 * (3 - 1)) - -SSW -``` -Our sums of squares within is 36.895. - -#### Calculate sums of squares model (SSM) for for the effect of time (or repeated measures) {-} - -The formula for the sums of squares model in repeated measures captures the effect of time (or the repeated measures nature of the design): $$SS_{M}= \sum n_{k}(\bar{x}_{k}-\bar{x}_{grand})^{2}$$ - -Earlier we learned that the grand mean is 4.319286. - -I can obtain the means for each course with *psych::describeBy()*. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describeBy(TradPed ~ Course, mat = TRUE, digits = 3, type = 1, data = rm1wLONG_df) -``` - -I can put it in the formula: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -(70 * (4.211 - 4.319286)^2) + (70 * (4.332 - 4.319286)^2) + (70 * (4.414 - 4.319286)^2) -``` -Sums of squares model is 1.4601 - - -#### Calculate sums of squares residual (SSR) {-} - -In repeated measures ANOVA $SS_W = SS_M + SS_R$. Knowing SSW (34.255) and SSM (1.460), we can do simple arithmetic to obtain SSR. - -```{r} -SSR <- 36.895 - 1.460 -SSR -``` -Sums of squares residual is 35.435. - - -#### Calculate the sums of squares between (SSB) {-} -In repeated measures ANOVA $SS_T = SS_W + SS_B$. Knowing SST (103.9144) and SSW (34.255), we can do simple arithmetic to obtain SSB. - -```{r} -SSB <- 103.9144 - 35.435 -SSB -``` -Sums of squares between is 68.4794. - - -#### Create a source table that includes the sums of squares, degrees of freedom, mean squares, *F* values, and *F* critical values {-} - -|One Way Repeated Measures ANOVA Source Table -|:--------------------------------------------------------------| - -|Source |SS |df |$MS = \frac{SS}{df}$ |$F = \frac{MS_{source}}{MS_{resid}}$ |$F_{CV}$| -|:---------|:--------|:-----------------|:------|:------|:------| -|Within |36.895 |(N-k) = 67 | | | | -|Model |1.4601 |(k-1) = 2 |0.7301 |1.3391 |3.138 | -|Residual |35.435 |(dfw - dfm) = 65 |0.5452 | | | -|Between |68.4794 |(N-1) = 69 | | | | -|Total |103.9144 |(cells-1) = 209 | | | | - -```{r} -#calculating degrees of freedom for the residual -67-2 -``` -Calculating mean square model and residual. -```{r} -1.4601/2#MSM -35.435/65#MSR -``` -Calculating the F ratio -```{r} -.7301/.5452 -``` - -Obtaining the F critical value: - -```{r} -qf(.05, 2, 65, lower.tail = FALSE) -``` - -We can see the same in an [F distribution table](https://www.statology.org/f-distribution-table/). - -#### Is the *F*-tests statistically significant? Why or why not? {-} - -No. The *F* value did not exceed the *F* critical value. To achieve statistical significance, my F value has to exceed 3.138. - -#### Assemble the results into a statistical string {-} - -$F(2, 65) = 1.339, p > 0.05$ - diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/86D23E19-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/86D23E19-contents deleted file mode 100644 index f204781e..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/86D23E19-contents +++ /dev/null @@ -1,387 +0,0 @@ -```{r include = FALSE} -options(scipen=999) -``` - - -## Homeworked Example -[Screencast Link](https://youtu.be/rLyN9GspdWU) - -For more information about the data used in this homeworked example, please refer to the description and codebook located at the end of the [introduction](ReCintro). - -### Working the Problem with R and R Packages - -#### Narrate the research vignette, describing the IV and DV. The data you analyze should have at least 3 levels in the independent variable; at least one of the attempted problems should have a significant omnibus test so that follow-up is required) {-} - -I want to ask the question, do course evaluation ratings for traditional pedagogy differ for students as we enacted a substantive revision to our statistics series. The evaluative focus is on the ANOVA course and we will compare ratings from the stable, transition, and resettled stages of the transitional period. The variable (Stage) of interest will have three levels: - -* STABLE: 2017 represents the last year of "stability during the old way" when we taught with SPSS and during the 2nd year of the doctoral programs. -* TRANSITION: 2018 & 2019 represent the transition to R, when the classes were 30% larger because each of the IOP and CPY departments were transitioning to the 1st year (they did it separately, so as not to double the classes) -* RESETTLED: 2020 & 2021 represent the "resettled" phase where the transition to R was fairly complete and the class size returned to normal because the classes were offered in the first year. - -This is not a variable that was included in the dataset posted to the OSF repository, so we will need to create it. - -*If you wanted to use this example and dataset as a basis for a homework assignment, you could create a different subset of data. I worked the example for students taking the ANOVA class. You could choose multivariate or psychometrics. You could also choose a different dependent variable. I chose the traditional pedagogy subscale. Two other subscales include socially responsive pedagogy and valued by the student.* - -#### Simulate (or import) and format data {-} - -```{r} -big <- readRDS("ReC.rds") -``` - -This df includes course evaluations from ANOVA, multivariate, and psychometrics. To include up to three evaluations per student would violate the assumption of independence, therefore, I will only select the students in ANOVA course. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -big <- subset(big, Course == "ANOVA") -``` - -Let's first create the "Stage" variable that represents the three levels of transition. - -The ProgramYear variable contains the information I need, but the factor labels are not intuitive. Let me remap them. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -big$Stage <- plyr::mapvalues(big$ProgramYear, from = c("Second", "Transition", "First"), to = c("Stable", "Transition", "Resettled")) -``` - -Let's check the structure: - -```{r} -str(big$Stage) -``` - -The TradPed (traditional pedagogy) variable is an average of the items on that scale. I will first create that variable. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Creates a list of the variables that belong to that scale -TradPed_vars <- c('ClearResponsibilities', 'EffectiveAnswers','Feedback', 'ClearOrganization','ClearPresentation') - -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -#big$TradPed <- sjstats::mean_n(big[, ..TradPed_vars], .75) -big$TradPed <- sjstats::mean_n(big[, TradPed_vars], .75) -``` - -With our variables properly formatted, let's trim it to just the variables we need. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -OneWay_df <-(dplyr::select (big, Stage, TradPed)) -``` - -Although we would handle missing data more carefully in a "real study," I will delete all cases with any missingness. This will prevent problems in the hand-calculations section, later (and keep the two sets of results more similar). - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -OneWay_df <- na.omit(OneWay_df) -``` - -Although the assignment doesn't require it, I will make a quick plot to provide a visualizaiton of our analysis. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ggpubr::ggboxplot(OneWay_df, x = "Stage", y = "TradPed", add = "jitter", - color = "Stage", title = "Figure 1. Evaluations of Traditional Pedagogy as a Result of Transition") # -``` - - -#### Evaluate statistical assumptions {-} - -**Is the dependent variable normally distributed across levels of the factor?** - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describeBy(TradPed ~ Stage, mat = TRUE, digits = 3, data = OneWay_df, type = 1) -``` - -We'll use Kline's (2016) threshholds of the absolute values of 3 (skew) and 10 (kurtosis). The highest absolute value of skew is -0.881; the highest absolute value of kurtosis is -0.629. These are well below the areas of concern. - -the Shapiro-wilk test is a formal assessment of normality. It is a 2-part test that begins with creating an ANOVA model from which we can extract residuals, then testing the residuals. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -TradPed_res <- lm(TradPed ~ Stage, data = OneWay_df) -#TradPed_res -rstatix::shapiro_test(residuals(TradPed_res)) -``` -The Shapiro-Wilk test suggests that the our distribution of residuals is statistically significantly different from a normal distribution $(W = 0.941, p < .001)$. - -It is possible to plot the residuals to see how and where they deviate from the line. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ggpubr::ggqqplot(residuals(TradPed_res)) -``` -Ooof! at the ends of the distribution they really deviate. - -**Should we remove outliers?** - -The *rstatix::identify_outliers()* function identifies outliers and extreme outliers. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -OneWay_df %>% - rstatix::identify_outliers(TradPed) -``` - -There are 4 cases identified with outliers; none of those is extreme. I also notice that these outliers are low course evaluations. It seems only fair to retain the data from individuals who were not satisfied with the course. - -**Are the variances of the dependent variable similar across the levels of the grouping factor?** - -We want the results of the Levene's homogeneity of variance test to be non-significant. This would support the notion that the TradPed variance is equivalent across the three stages of the transition. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::levene_test(OneWay_df, TradPed ~ Stage) -``` -The non-significant *p* value suggests that the variances across the three stages are not statistically significantly different: $F(2, 109) = 4.523, p = 0.013$. - - -Before moving on, I will capture our findings in an APA style write-up of the testing of assumptions: - ->Regarding the assumption of normality, skew and kurtosis values at each of the levels of program year fell well below the thresholds that Kline (2016a) identified as concerning (i.e., below |3| for skew and |10| for kurtosis). In contrast, results of a model-based Shapiro-Wilk test of normality, indicated that the model residuals differed from a normal distribution $(W = 0.941, p < .001)$. Although 4 outliers were identified none were extreme, thus we retained all cases. Finally, Levene’s homogeneity of variance test indicated a violation of the homogeneity of variance assumption $F(2, 109) = 4.523, p = 0.013$. ANOVA is relatively robust to this violation when there are at least 15 cases per cell and the design is balanced (i.e., equivalent cell sizes). While we have at least 15 cases per cell, we have a rather unbalanced design. We will need to keep this limitation in mind as we interpret the results. - -#### Conduct omnibus ANOVA (w effect size) {-} - -The *rstatix::anova_test()* function calculates the one-way ANOVA and includes the effect size, $\eta^2$ in the column, *ges*. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -omnibus1w <- rstatix::anova_test(OneWay_df, TradPed ~ Stage, detailed = FALSE) -omnibus1w -``` -The one-way ANOVA is statistically significant. This means that there should be at least one statistically significant difference between levels of the design. Before moving on, I will capture the *F* string: $F(2, 109) = 7.199, p = 0.001, \eta^2 = 0.117$. Regarding the effect size, values of .01, .07, and .14 are considered to be small, medium, and large. The value of .11 would be medium-to-large. - -#### Conduct one set of follow-up tests; narrate your choice {-} - -I will simply calculate post-hoc comparisons. That is, all possible pairwise comparisons. I will specify the traditional Bonferroni as the approach to managing Type I error. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -phoc <- rstatix::t_test(OneWay_df, TradPed ~ Stage, p.adjust.method = "bonferroni", detailed = TRUE) -phoc -``` - -The post hoc tests suggested statistically significant differences between the stable transition resettled stages, favoring the stable period of time (i.e., using SPSS and taught in the second year). - -#### Describe approach for managing Type I error {-} - -We used the Bonferroni. The Bonferroni divides the overall alpha (.05) by the number of comparisons (3). In this case, a *p* value woul dhave to be lower than 0.017 to be statistically significant. The calulation reverse-engineers this so that we can interpret the *p* values by the traditional. 0.05. In the output, it is possible to see the higher threshholds necessary to claim statistical significance. - -#### APA style results with table(s) and figure {-} - ->A one-way analysis of variance was conducted to evaluate the effects of significant transitions (e.g., from SPSS to R; to the second to the first year in a doctoral program) on students ratings of traditional pedagogy. The independent variable, stage, included three levels: stable (with SPSS and taught in the second year of a doctoral program), transitioning (with R and students moving from second to first year), and resettled (with R and in the first year of the program). - ->Regarding the assumption of normality, skew and kurtosis values at each of the levels of program year fell well below the thresholds that Kline (2016a) identified as concerning (i.e., below |3| for skew and |10| for kurtosis). In contrast, results of a model-based Shapiro-Wilk test of normality, indicated that the model residuals differed from a normal distribution $(W = 0.941, p < .001)$. Although 4 outliers were identified none were extreme, thus we retained all cases. Finally, Levene’s homogeneity of variance test indicated a violation of the homogeneity of variance assumption $F(2, 109) = 4.523, p = 0.013$. ANOVA is relatively robust to this violation when there are at least 15 cases per cell and the design is balanced (i.e., equivalent cell sizes). While we have at least 15 cases per cell, we have a rather unbalanced design. We will need to keep this limitation in mind as we interpret the results. - ->Results of the omnibus ANOVA indicated a statistically significant effect of stage on students assessments of traditional pedagogy, $F(2, 109) = 7.199, p = 0.001, \eta^2 = 0.117$. The effect size was medium-to-large. We followed up the significant omnibus with all possible pairwise comparisons. We controlled for Type I error with the traditional Bonferroni adjustment. Results suggested that there were statistically significant differences between the stable and transition stages $(Mdiff = 0.655, p = 0.003)$, but not between stable and resettled $(Mdiff = 0.267,p = 0.324)$ or transition and resettled $(Mdiff= -0.388,p = 0.217)$ stages. Given that the doctoral programs are unlikely to transition back to SPSS or into the second year, the instructor(s) are advised to consider ways that could result in greater student satisfaction. Means and standard deviations are presented in Table 1 and complete ANOVA results are presented in Table 2. Figure 1 provides an illustration of the results. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -apaTables::apa.1way.table(iv = Stage, dv = TradPed, show.conf.interval = TRUE, data = OneWay_df, table.number = 1, filename = "1wayHWTable.doc") -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -omnibus1wHW_b <- aov(TradPed ~ Stage, data = OneWay_df) -apaTables::apa.aov.table(omnibus1wHW_b, table.number = 2, filename = "1wayHWTable2.doc") -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -phoc <- phoc %>% - rstatix::add_xy_position(x = "Stage") - -ggpubr::ggboxplot(OneWay_df, x = "Stage", y = "TradPed", add = "jitter", - color = "Stage", title = "Figure 1. Evaluations of Traditional Pedagogy as a Result of Transition") + - ggpubr::stat_pvalue_manual(phoc, label = "p.adj.signif", tip.length = 0.02, - hide.ns = TRUE, y.position = c(5.5)) -``` - -#### Conduct power analyses to determine the power of the current study and a recommended sample size {-} - -The *pwr.anova.test()* has five parameters: - -* *k* = # groups -* *n* = sample size per group -* *f* = effect sizes, where 0.1/small, 0.25/medium, and 0.4/large - - In the absence from an estimate from our own data, we make a guess about the expected effect size value based on our knowledge of the literature -* *sig.level* = *p* value that you will use -* *power* = .80 is the standard value - -In the script below, we simply add our values. So long as we have four values, the fifth will be calculated for us. - -Because this calculator requires the effect size in the metric of Cohen's *f* (this is not the same as the *F* ratio), we need to convert it. The *effectsize* package has a series of converters. We can use the *eta2_to_f()* function. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -effectsize::eta2_to_f(.117) -``` -We simply plug this value into the "f =". - -First let's ask what our level of power was? Our goal would be 80%. - -Given that our design was unbalanced (21, 44, 47 across the three stages), I used 38 (114/3). - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.anova.test (k = 3, f = .3640094, sig.level = .05, n = 38) -``` -Our power was 0.94. That is, we had 94% chance to find a statistically significant result if one existed. In the next power analysis, let's see what sample size is recommended. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.anova.test (k = 3, f = .3640094, sig.level = .05, power = .80) -``` -In order to be at 80% power to find a statistically significant result if there is one, we would need only 25 people per group. We currently had an unbalanced design of 50, 41, 21. - -### Hand Calculations - -Before we continue: - ->You may notice that the results from the hand calculation are slightly different from the results I will obtain with the R packages. This is because the formula we have used for the hand-calculations utilizes an approach to calculating the sums of squares that presumes that we have a balanced design (i.e., that the cell sizes are equal). When cell sizes are unequal (i.e., an unbalanced design) the Type II package in *rstatix::anova_test* may produce different result. - -> Should we be concerned? No (and yes). My purpose in teaching hand calculations is for creating a conceptual overview of what is occurring in ANOVA models. If this lesson was a deeper exploration into the inner workings of ANOVA, we would take more time to understand what is occurring. My goal is to provide you with enough of an introduction to ANOVA that you would be able to explore further which sums of squares type would be most appropriate for your unique ANOVA model. - -#### Using traditional NHST (null hypothesis testing language), state your null and alternative hypotheses {-} - -Regarding the evaluation of traditional pedgagoy across three stages of transitions to a doctoral ANOVA course, the null hypothesis predicts no differences between the three levels of the dependent variable: - -$$H_{O}: \mu _{1} = \mu _{2} = \mu _{3}$$ - -In contrast, the alternative hypothesis suggests there will be differences. Apriorily, I did not make any specific predictions. - -$$H_{a1}: \mu _{1} \neq \mu _{2} \neq \mu _{3}$$ - -#### Calculate sums of squares total (SST). Steps in this calculation must include calculating a grand mean and creating variables representing the mean deviation and mean deviation squared {-} - -I will use this approach to calculating sums of squares total: - -$$SS_{T}= \sum (x_{i}-\bar{x}_{grand})^{2}$$ - -I will use the *psych::describe()* function to obtain the overall mean: - -```{r} -psych::describe(OneWay_df) -``` - -Next, I will subtract this value from each person's TradPed value. This will create a mean deviation. - - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -OneWay_df$mdevTP <- OneWay_df$TradPed - 4.06 -#I could also calculate it by using the "mean" function -#I had to include an na.rm=TRUE; this appears to be connected to missingness -OneWay_df$mdevTPb <- OneWay_df$TradPed - mean(OneWay_df$TradPed, na.rm=TRUE) -head(OneWay_df) -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -OneWay_df <- OneWay_df %>% - dplyr::mutate(m_devSQTP = mdevTP^2) - -#so we can see this in the textbook -head(OneWay_df) -``` - -I will ask for a sum of the mean deviation squared column. The function was not running, sometimes this occurs when there is missing data. While I didn't think that was true, adding "na.rm = TRUE" solved the problem. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SST <- sum(OneWay_df$m_devSQTP, na.rm = TRUE) -SST -``` -SST = 83.0332 - -#### Calculate the sums of squares for the model (SSM). A necessary step in this equation is to calculate group means {-} - -The formula for SSM is $$SS_{M}= \sum n_{k}(\bar{x}_{k}-\bar{x}_{grand})^{2}$$ - -We will need: - -* *n* for each group, -* Grand mean (earlier we learned it was 4.06), -* Group means - -We can obtain the group means several ways. I think the *psych::describeBy()* function is one of the easiest. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describeBy(TradPed ~ Stage, mat = TRUE, digits = 3, data = OneWay_df, type = 1) -``` - -Now we can pop these values into the formula. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SSM <- 50 * (4.348 -4.06)^2 + 41 * (3.693 - 4.06)^2 + 21 * (4.081 - 4.06)^2 -SSM -``` -SSM = 9.67871 - - -#### Calculate the sums of squares residual (SSR). A necessary step in this equation is to calculate the variance for each group {-} - -The formula for I will use to calculate SSR is $$SS_{R}= s_{group1}^{2}(n-1) + s_{group2}^{2}(n-1) + s_{group3}^{2}(n-1))$$ - -We will need: - -* *n* for each group, -* variance (standard deviation, squared) for each group - -We can obtain these values from the previous run of the *psych::describeBy()* function. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SSR <- (0.658^2)*(50 - 1) + (1.057^2)*(41 - 1) + (0.610^2)*(21-1) -SSR -``` -SSR = 73.3472 - - -#### Calculate the mean square model, mean square residual, and *F*-test {-} - -The formula for mean square model is $$MS_M = \frac{SS_{M}}{df{_{M}}}$$ - -* $SS_M$ was 9.67871 -* $df_M$ is *k* - 1 (where *k* is number of groups/levels) - -```{r} -MSM <- 9.67871/2 -MSM -``` -MSM is 4.839 - -The formula for mean square residual is $$MS_R = \frac{SS_{R}}{df{_{R}}}$$ - -* $SS_R$ was 79.292 -* $df_R$ is $N - k$ (112 - 3 = 109) - -```{r} -MSR = 73.3472/109 -MSR -``` - -The formula for the *F* ratio is $$F = \frac{MS_{M}}{MS_{R}}$$ - -```{r} -F <- 4.839/0.6729101 -F -``` -*F* = 7.191154 - - -#### What are the degrees of freedom for your numerator and denominator? {-} - -Numerator or $df_M$: 2 -Denominator or $df_R$: 109 - -#### Locate the test critical value for your one-way ANOVA {-} - -We could use use a [table of critical values](https://www.statology.org/how-to-read-the-f-distribution-table/) for the *F* distribution. - -The closest *N* in the table I am using is 120. If we set alpha at 0.05, our test value would need to exceed the absolute value of 3.0718. - -We can also use a look-up function, which follows this general form: qf(p, df1, df2. lower.tail=FALSE) -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -qf(.05, 2, 109, lower.tail=FALSE) -``` -Not surprisingly the values are quite similar. - -#### Is the *F*-test statistically significant? Why or why not? {-} - -Because the value of the *F* test (7.191) exceeded the absolute value of the critical value (3.080), the *F* test is statistically significant. - -#### Calculate and interpret the $\eta^2$ effect size {-} - -The formula to calculate the effect size is $$\eta ^{2}=\frac{SS_{M}}{SS_{T}}$$ - -* $SS_M$ was 9.679 -* $SS_T$ was 83.0332 - -```{r} -etaSQ <- 9.679/83.0332 -etaSQ -``` -Eta square is 0.117. Values of .01, .06, and .14 are interpreted as small, medium, and large. Our value of 0.12 is medium-to-large. - - -#### Assemble the results into a statistical string {-} - -$$F(2, 109) = 7.191, p < .05, \eta^2 = 0.117$$ \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/9008AEF5-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/9008AEF5-contents deleted file mode 100644 index 2e0debfd..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/9008AEF5-contents +++ /dev/null @@ -1,228 +0,0 @@ -```{r include=FALSE} -options(scipen=999)#eliminates scientific notation -``` -## Homeworked Example - -[Screencast Link](https://youtu.be/eRCDNibARtg) - -For more information about the data used in this homeworked example, please refer to the description and codebook located at the end of the [introduction](ReCintro). - -### Working the Problem with R and R Packages - -#### Narrate the research vignette, describing the IV, DV, and COV {-} - -I want to ask the question, what are the effects of intentional recentering on students' evaluations of socially responsive pedagogy in the multivariate (last) course as a function of centering status (i.e., pre versus re), controlling for the socially responsive evaluations in the ANOVA (first) course: - -* Continuous DV: SRPed (socially responsive pedagogy) in the multivariate (last) class -* Between-subjects factor: recentering status of the class (Pre, Re) -* Covariate: SRPed in the ANOVA (first) class - - -*If you wanted to use this example and dataset as a basis for a homework assignment, you could choose a different dependent variable. I chose the socially responsive pedagogy subscale. Two other subscales include traditional pedagogy and valued by the student.* - -#### Simulate (or import) and format data {-} - -First I import the larger dataset. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -big <- readRDS("ReC.rds") -``` - -The SRPed (socially responsive pedagogy) variable is an average of the items on that scale. I will first create that variable. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Creates a list of the variables that belong to that scale -SRPed_vars <- c('InclusvClassrm', 'EquitableEval','MultPerspectives', 'DEIintegration') - -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -big$SRPed <- sjstats::mean_n(big[, SRPed_vars], .75) - -#if the scoring script won't run, try this one: -#big$SRPed <- sjstats::mean_n(big[, ..SRPed_vars], .75) -``` - -Let's trim it to just the variables of interest. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ANCOVA_df <- (dplyr::select (big, deID, Course, Centering, SRPed)) -``` - -And further filter so that there are just evaluations of ANOVA and multivariate courses. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ANCOVA_df <- subset(ANCOVA_df, Course == "ANOVA" | Course == "Multivariate") #multiple conditions -``` - -I want the course variable to be factor that is ordered by its sequence: ANOVA, multivariate. - -I want the centering variable to be ordered: Pre, Re - -```{r } -str(ANCOVA_df) -``` -Because R's default is to order alphabetically, the centering variable is correct. I just need to change the course variable. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ANCOVA_df$Course <- factor(ANCOVA_df$Course, levels = c("ANOVA", "Multivariate")) -str(ANCOVA_df) -``` -After checking the structure again, both are correct. - -My data is in the long (person-period) form. For this particular ANOVA I need it to be in the wide (person level) form. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ANCOVA_wide<- reshape2::dcast(data = ANCOVA_df, formula = deID + Centering ~ Course, value.var = "SRPed") -# before restructuring a second variable, rename the first variable -ANCOVA_wide <- dplyr::rename(ANCOVA_wide, SRPed_ANV = "ANOVA", SRPed_MLTV = "Multivariate") - -str(ANCOVA_wide) -head(ANCOVA_wide) -``` -The *head* function shows that the multivariate scores are missing. This design still has missingness for (a) some students who took ANOVA but haven't yet had multivariate and (b) others who may have skipped completing course evaluations. I'll take care of that next by requiring rows to have non-missing data. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ANCOVA_wide <- na.omit(ANCOVA_wide) -``` - - -#### Evaluate statistical assumptions {-} - -**Is there a linear relationship between the covariate and outcome at each level of the grouping variable?"** - -This would mean that there is linearity between the evaluation in the first course (covariate/ANOVA) and last course (outcome/Multivariate) at each level of the independent variable (Centering status). - -We can get a visual of this with a scatterplot (with regression lines) between the covariae and outcome. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(ggplot2) -ggpubr::ggscatter(ANCOVA_wide, x = "SRPed_ANV", y = "SRPed_MLTV", color = "Centering", add = "reg.line") + ggpubr::stat_regline_equation(aes(label = paste(..eq.label.., ..rr.label.., sep = "~~~~"), color = Centering)) -``` - -The plot looks a little funny. This is likely because there are no values below 3(ish) for ANOVA when courses were re-centered. Although we are looking for a linear relationship, the angled lines suggest there could be an interaction effect. The previous lesson (when we included all three courses [ANOVA, psychometrics, multivariate]) showed that there was. Spoiler alert -- mixed design ANOVA is a better analysis for this question, but the data does allow me (statistically) to use it for a homework demonstration. - -**Are the regression lines formed by the covariate and the outcome variable the same for each group?** - -This would mean that there is no interaction between the outcome and covariate. We can test this with an ANOVA model that specifies an interaction. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -ANCOVA_wide %>% - rstatix::anova_test(SRPed_MLTV ~Centering*SRPed_ANV) -``` -Curiously, the interaction term was not statistically significant $(F[1, 71] = 1.975, p = 0.164)$. This non-violation of the homogeneity of slopes assumption supports the use of ANCOVA. - -**Are the model residuals normally distributed and equal across groups?** - -First, I create a linear regression model -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SRPed_mod <- lm(SRPed_MLTV ~ SRPed_ANV + Centering, data = ANCOVA_wide) -``` - -I will use *broom::augment()* to add fitted values and residuals to the model I just created. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SRPed_mod_metrics <- broom::augment(SRPed_mod) -head(SRPed_mod_metrics) -``` - -I can now assess the normality of residuals with the Shapiro-Wilk test. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::shapiro_test(SRPed_mod_metrics$.resid) -``` - -The Shapiro-Wilk test suggested that our residuals are not statistically significantly different from a normal distribution $(W = 0.972, p = 0.101)$. - -ANCOVA further presumes that the variances of the residuals is equal for all groups. I can check this with the Levene's test. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SRPed_mod_metrics%>% - rstatix::levene_test(.resid ~ Centering) -``` -A non-significant Levene's test indicated no violation of the homogeneity of the residual variances for the groups $(F[1, 73] = 2.675, p = 0.106)$. - - -**Is there evidence of outliers? Are they extreme?** - -I can identify outliers by examining the standardized (or studentized) residuals. These are interpreted as the number of standard errors away from the regression line. - -```{r} -SRPed_mod_metrics %>% - filter(abs(.std.resid) > 3) %>% - as.data.frame() -``` - -No outliers were identified. - -Here's write-up of what I've done so far: - ->A one-way analysis of covariance (ANCOVA) was conducted. The independent variable, centering stage, had two levels: pre-centered, re-centered. The dependent variable was students' evaluation of socially responsive pedagogy during the last statistics course (multivariate) and the covariate was the students' evaluation of the same variable during the first statistics class (ANOVA). - ->A preliminary analysis evaluating the homogeneity-of-slopes assumption indicated that the relationship between the covariate and the dependent variable did not differ significantly as a function of the independent variable, $(F[1, 71] = 1.975, p = 0.164)$. Further, the non-significant Shapiro-Wilk test of normality on the model residuals $(W = 0.972, p = 0.101)$ indicated that the dependent variable was not statistically significantly different from a normal distribution and no outliers were identified. A non-significant Levene’s test indicated no violation of the homogeneity of the residual variances for all groups $(F[1, 73] = 2.675, p = 0.106)$. - - -#### Conduct omnibus ANOVA (w effect size) {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ANCOVA_mod <- ANCOVA_wide %>% - rstatix::anova_test(SRPed_MLTV ~ SRPed_ANV + Centering) -rstatix::get_anova_table(ANCOVA_mod) -``` ->There was a significant effect of the evaluation of socially responsive pedagogy at the first course (ANOVA) on the same rating at the last course $(F [1,72] = 39.696, p < .001, \eta^2 = 0.355)$ as well as a statistically significant effect of recentering on evaluations of socially responsive pedagogy during the last class $(F [1,72]) = 10.304, p = 0.002, \eta^2 = 0.125)$. Considering that we interpret values $eta^2$ values of .01, .06, and .14 to be small, medium, and large it appears that both the covariate and independent variable had substantial effects on the results. - -#### Conduct one set of follow-up tests; narrate your choice {-} - -Because this design has only two levels (pre-centered, re-centered), follow-up tests will not tell us any more information. However, investigating the covariate-adjusted mean is useful. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -emmeans_MLTV <- ANCOVA_wide%>% - rstatix::emmeans_test(SRPed_MLTV ~ Centering, covariate = SRPed_ANV, p.adjust.method = "none") -emmeans_MLTV -``` -Not surprisingly (since this single pairwise comparison is redundant with the omnibus ANCOVA), results suggest a statistically significant difference between the pre- and re-centered stages in the multivariate class. - -With this script I can obtain the covariate-adjusted (i.e., estimated marginal) means. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -emmeans_list <- rstatix::get_emmeans(emmeans_MLTV) -emmeans_list -``` -We can compare these to the unadjusted means: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -descripts_means <- psych::describeBy(SRPed_MLTV ~ Centering, data = ANCOVA_wide, mat=TRUE, digits=6) -descripts_means -``` - -While the differences are minor, they do exist. - -#### Describe approach for managing Type I error {-} - -Because we only needed to conduct the omnibus, there was no additional control of Type I error. - -#### APA style results with table(s) and figure {-} - ->A one-way analysis of covariance (ANCOVA) was conducted. The independent variable, centering stage, had two levels: pre-centered, re-centered. The dependent variable was students' evaluation of socially responsive pedagogy during the last statistics course (multivariate) and the covariate was the students' evaluation of the same variable during the first statistics class (ANOVA). - ->A preliminary analysis evaluating the homogeneity-of-slopes assumption indicated that the relationship between the covariate and the dependent variable did not differ significantly as a function of the independent variable, $(F[1, 71] = 1.975, p = 0.100)$. Further, the non-significant Shapiro-Wilk test of normality on the model residuals $(W = 0.972, p = 0.101)$ indicated that the dependent variable was not statistically significantly different from a normal distribution and no outliers were identified. A non-significant Levene’s test indicated no violation of the homogeneity of the residual variances for all groups $(F[1, 73] = 2.675, p = 0.106)$. - ->There was a significant effect of the evaluation of socially responsive pedagogy at the first course (ANOVA) on the same rating at the last course $(F [1,72] = 39.696, p < .001, \eta^2 = 0.355)$ as well as a statistically significant effect of recentering on evaluations of socially responsive pedagogy during the last class $(F]1,72) = 10.304, p = 0.002, \eta^2 = 0.125)$. Considering that we interpret values $eta^2$ values of .01, .06, and .14 to be small, medium, and large it appears that both the covariate and independent variable had substantial effects on the results. As illustrated in Figure 1, results suggested that those in the multivariate condition had more favorable ratings of socially responsive pedagogy than those in the ANOVA class. Table 1 provides unadjusted and covariate-adjusted means for the dependent variable. - - -In the case of ANCOVA, a table that compares unadjusted and covariate-adjusted means can be helpful. The lesson contains some script to export data. I will create a table to demonstrate how this might work: - -|Table 1 -|:--------------------------------------------------| -|Unadjusted and Covariate-Adjusted Descriptive Statistics - -|Centering |Unadjusted |Covariate-Adjusted -|:--------------|:-------------:|:-----------------:| - -| |*M* |*SD* |*EMM* |*SE* -|:--------------|:-------:|:----:|:---------:|:----:| -|Pre-centered |4.381277 |0.633 |4.381639 |0.067 | -|Re-centered |4.732143 |0.425 |4.731534 |0.086 | - - -And now a figure: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -emmeans_MLTV <- emmeans_MLTV %>% - rstatix::add_xy_position(x = "Centering", fun = "mean_se") -ggpubr::ggline(rstatix::get_emmeans(emmeans_MLTV), x = "Centering", y = "emmean", title = "Figure 1. SRPed Ratings as a Function of Centering, Controlling for Earlier Ratings") + - geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0.2) + - ggpubr::stat_pvalue_manual(emmeans_MLTV, hide.ns = TRUE, tip.length = 0.02, , y.position = c(5.0)) -``` diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/977E6DF0-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/977E6DF0-contents deleted file mode 100644 index e69de29b..00000000 diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/A0A91E67-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/A0A91E67-contents deleted file mode 100644 index cd3469fe..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/A0A91E67-contents +++ /dev/null @@ -1,598 +0,0 @@ -# Paired Samples *t*-test {#tPaired} - -[Screencasted Lecture Link](https://youtube.com/playlist?list=PLtz5cFLQl4KNYvBQJnO_VFpoS5gJJOTJ8) - -```{r include=FALSE} -knitr::opts_chunk$set(echo = TRUE) -knitr::opts_chunk$set(comment = NA) #keeps out the hashtags in the knits -options(scipen=999)#eliminates scientific notation -``` - -Researchers are often interested in knowing if participants score differently on some outcome variable (like affective well-being) across two conditions. These conditions could be before and after an intervention; they could also be interventionless exposures such as scary versus funny movies. In these simple designs, the paired *t*-test can be used to test the researchers' hypotheses. - -## Navigating this Lesson - -There is about 45 minutes of lecture. If you work through the materials with me it would be plan for an additional hour - -While the majority of R objects and data you will need are created within the R script that sources the chapter, occasionally there are some that cannot be created from within the R framework. Additionally, sometimes links fail. All original materials are provided at the [Github site](https://github.com/lhbikos/ReCenterPsychStats) that hosts the book. More detailed guidelines for ways to access all these materials are provided in the OER's [introduction](#ReCintro) - -### Learning Objectives - -Learning objectives from this lecture include the following: - -* Recognize the research questions for which utilization of paired sample *t*-tests would be appropriate. -* Narrate the steps in conducting a paired samples *t*-test, beginning with testing the statistical assumptions through writing up an APA style results section. -* Calculate a paired samples *t*-test in R (including effect sizes). -* Interpret a 95% confidence interval around a mean difference score. -* Produce an APA style results for a paired-samples *t*-test. -* Determine a sample size that (given a set of parameters) would likely result in a statistically significant effect, if there was one. - -### Planning for Practice - -The suggestions for homework vary in degree of complexity. The more complete descriptions at the end of the chapter follow these suggestions. - -* Rework the paired samples *t*-test in the lesson by changing the random seed in the code that simulates the data. This should provide minor changes to the data, but the results will likely be very similar. -* Rework the paired samples *t*-test in the lesson by changing something else about the simulation. For example, if you are interested in power, consider changing the sample size. -* Use the simulated data that is provided, but use the nonverbal variable, instead. -* Conduct paired *t*-test with data to which you have access and permission to use. This could include data you simulate on your own or from a published article. - -### Readings & Resources - -In preparing this chapter, I drew heavily from the following resource(s). Other resources are cited (when possible, linked) in the text with complete citations in the reference list. - -* How to Do Paired T-test in R: The Best Tutorial You Will Love. (n.d.). Datanovia. Retrieved May 25, 2023, from https://www.datanovia.com/en/lessons/how-to-do-a-t-test-in-r-calculation-and-reporting/how-to-do-paired-t-test-in-r/ - - This tutorial provides a demonstration of the paired sampes t-test using the *rstatix* package. -* Navarro, D. (2020). Chapter 13: Comparing two means. In [Learning Statistics with R - A tutorial for Psychology Students and other Beginners](https://learningstatisticswithr.com/). Retrieved from https://stats.libretexts.org/Bookshelves/Applied_Statistics/Book%3A_Learning_Statistics_with_R_-_A_tutorial_for_Psychology_Students_and_other_Beginners_(Navarro) - - Navarro's OER includes a good mix of conceptual information about *t*-tests as well as R code. My lesson integrates her approach as well as considering information from Field's [-@field_discovering_2012] and Green and Salkind's [@green_using_2017] texts (as well as searching around on the internet). -* Elliott, A. M., Alexander, S. C., Mescher, C. A., Mohan, D., & Barnato, A. E. (2016). Differences in Physicians’ Verbal and Nonverbal Communication With Black and White Patients at the End of Life. *Journal of Pain and Symptom Management, 51*(1), 1–8. https://doi.org/10.1016/j.jpainsymman.2015.07.008 - - The source of our research vignette. - -### Packages - -The script below will (a) check to see if the following packages are installed on your computer and, if not (b) install them. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#will install the package if not already installed -#if(!require(psych)){install.packages("psych")} -#if(!require(faux)){install.packages("faux")} -#if(!require(tidyverse)){install.packages("tidyverse")} -#if(!require(dplyr)){install.packages("dplyr")} -#if(!require(ggpubr)){install.packages("ggpubr")} -#if(!require(pwr)){install.packages("pwr")} -#if(!require(apaTables)){install.packages("apaTables")} -#if(!require(knitr)){install.packages("knitr")} -#if(!require(rstatix)){install.packages("rstatix")} -``` - -## Introducing the Paired Samples *t*-test - -There are a couple of typical use cases for the paired samples *t*-test. Repeated measures or change-over-time is a very common use. In this case, the research participant may take a pre-test, be exposed to an intervention or other type of stimulus, then take a post-test. Owing to the limitations of the statistics, all participants must be exposed to the same intervention/stimulus. - -![An image of a row with three boxes: pre-test (in blue), intervention or exposure to stimulus (in light red), post-test (in blue) representing the use of a paired samples *t*-test in a repeated measures design](images/ttests/prepost_paired.jpg) - -A second common use is the assessment of a research participant in two competing conditions. An example might be the galvanic skin response ratings when a participant's hand is submerged in ice versus the GSR ratings when the hand is not exposed in ice. A strength of this design is the within-subjects' control of the participant. - -![An image of a row with two boxes labeled Condition A in light blue) and Condition B (in dark blue). This represents the use of a paired samples *t*-test to compare across conditions](images/ttests/conditions_paired.jpg) - -In the formula for the paired samples *t*-test we see a $\bar{D}$ in the numerator. This represents the *difference* between the continuously scaled scores in the two conditions. The denominator involves a standard deviation of the difference scores ($\hat\sigma_D$) and the square root of the sample size. - -$$t = \frac{\bar{D}}{\hat\sigma_D / \sqrt{N}}$$ -Although these types of research design and analyses are quite handy, they have some limitations. First, the paired samples *t*-test cannot establish causality because it lacks elements such as comparing conditions (e.g., treatment vs. control) and random assignment to those conditions. If a research wants to compare pre-post change as a result of participating in more-than-one condition, a [mixed design ANOVA](#Mixed) would be a better option. Second, the paired samples *t*-test cannot accommodate more than two comparison conditions. If the researcher wants to compare three or or more time periods or conditions, they will want to consider [repeated measures ANOVA](#Repeated) or [multilevel/hierarchical linear modeling](https://lhbikos.github.io/MultilevelModeling/). - -### Workflow for Paired Samples *t*-test - -The following is a proposed workflow for conducting the paired samples *t*-test. - -![A colorful image of a workflow for the paired samples *t*-test](images/ttests/PairedSampleWrkFlw.jpg) - -If the data meets the assumptions associated with the research design (e.g., independence of difference scores and a continuously scaled metric for that difference score), these are the steps for the analysis of an independent samples *t*-test: - -1. Prepare (upload) data. -2. Explore data with - - graphs - - descriptive statistics -3. Assess normality of the difference scores via skew and kurtosis -4. Compute the paired samples *t*-test -5. Compute an effect size (frequently the *d* or *eta* statistic) -6. Manage Type I error -7. Sample size/power analysis (which you should think about first, but in the context of teaching statistics, it's more pedagogically sensible, here). - -## Research Vignette - -Empirically published articles where *t*-tests are the primary statistic are difficult to locate. Having exhausted the psychology archives, I located this article in an interdisciplinary journal focused on palliative medicine. The research vignette for this lesson examined differences in physician's verbal and nonverbal communication with Black and White patients at the end of life [@elliott_differences_2016]. - -Elliott and colleagues [-@elliott_differences_2016] were curious to know if hospital-based physicians (56% White, 26% Asian, 7.4% each Black and Hispanic) engaged in verbal and nonverbal communication differently with Black and White patients. Black and White patient participants were matched on characteristics deemed important to the researchers (e.g., critically and terminally ill, prognostically similar). Interactions in the intensive care unit were audio and video recorded and then coded on dimensions of verbal and nonverbal communication. - -Because each physician saw a pair of patients (i.e., one Black patient and one White patient), the researchers utilized a paired samples, or dependent *t*-test. This statistical choice was consistent with the element of the research design that controlled for physician effects through matching patients on critical characteristics. Below are the primary findings of the study. - - -| |Black Patients |White Patients | | -|:---------------|:--------------|:--------------|:--------| -|Category |*Mean*(*SD*) |*Mean*(*SD*) |*p*-value| -|Verbal skill score (range 0 - 27)|8.37(3.36) | 8.41(3.21) |0.958| -|Nonverbal skill score (range 0 - 5) |2.68(.84) | 2.93(.77)|0.014| - -The primary analysis utilized by Elliott and colleagues [-@elliott_differences_2016] was the paired samples *t*-test. We will replicate that exact analysis with simulated data. - -### Simulating Data for the Paired Samples *t*-test - -Below is the code I used to simulate the data. The following code assumes 33 physician participants who had separate interactions with critically ill, end-of-life stage patients, who were identified as Black and White. The Elliott et al. [-@elliott_differences_2016] manuscript describe the process for coding verbal and nonverbal communication for video/audio recordings of the physician/patient interactions. Using that data, I simulate verbal and nonverbal communication scores for 33 physicians who rate patients who identify as Black and White, respectively. This creates four variables. - -In the lesson, we will compare verbal communication scores. The nonverbal communication score is available as an option for practice. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -#Setting the seed. If you choose this practice option, change the number below to something different. -set.seed(220817) -#These define the characteristics of the verbal variable. It is essential that the object names (e.g., A_mean) are not changed because they will be fed to the function in the faux package. -sub_n <- 33 -A_mean <- 8.37 -B_mean <- 8.41 -A_sd <- 3.36 -B_sd <- 3.21 -AB_r <- 0.3 - -#the faux package can simulate a variety of data. This function within the faux package will use the objects above to simulate paired samples data -paired_V <- faux::rnorm_multi( - n = sub_n, - vars = 2, - r = AB_r, - mu = c(A_mean, B_mean), - sd = c(A_sd, B_sd), - varnames = c("Verbal_BL", "Verbal_WH") - ) - -paired_V <- paired_V %>% dplyr::mutate(PhysID = row_number()) - -#Here, I repeated the process for the nonverbal variable. -sub_n <- 33 -A_mean <- 2.68 -B_mean <- 2.93 -A_sd <- .84 -B_sd <- .77 -AB_r <- 0.9 - -paired_NV <- faux::rnorm_multi( - n = sub_n, - vars = 2, - r = AB_r, - mu = c(A_mean, B_mean), - sd = c(A_sd, B_sd), - varnames = c("NVerb_BL", "NVerb_WH") - ) - -#This code produced an ID number for each physician -paired_NV <- paired_NV %>% dplyr::mutate(PhysID = row_number()) - -#This data joined the two sets of data. -#Note, I did not write any code that assumed tha the verbal and nonverbal data came from the same physician. Full confession: I'm not quite sure how to do that just yet. -dfPairedSamples <- dplyr::full_join(paired_V, paired_NV, by = c("PhysID")) -dfPairedSamples <- dfPairedSamples%>%dplyr::select(PhysID, everything()) -``` - -Before beginning our analysis, let's check the format of the variables to see if they are consistent with the scale of measurement of the variables. In our case, we expect to see four variables representing the verbal and nonverbal communication of the physicians with the patients who are identified as Black and White. Each of the variables should be continuously scaled and, therefore, should be formatted as *num* (numerical). - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -str(dfPairedSamples) -``` -The four variables of interest are correctly formatted as *num*. Because PhysID (physician ID) will not be used in our analysis, its structure is irrelevant. - -Below is code for saving (and then importing) the data in .csv or .rds files. I make choices about saving data based on what I wish to do with the data. If I want to manipulate the data outside of R, I will save it as a .csv file. It is easy to open .csv files in Excel. A limitation of the .csv format is that it does not save any restructuring or reformatting of variables. For this lesson, this is not an issue. - -Here is code for saving the data as a .csv and then reading it back into R. I have hashtagged these out, so you will need to remove the hashtags if you wish to run any of these operations. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#writing the simulated data as a .csv -#write.table(dfPairedSamples, file = "dfPairedSamples.csv", sep = ',', col.names=TRUE, row.names=FALSE) -#at this point you could clear your environment and then bring the data back in as a .csv -#reading the data back in as a .csv file -#dfPairedSamples<- read.csv ('dfPairedSamples.csv', header = TRUE) -``` - -The .rds form of saving variables preserves any formatting (e.g., creating ordered factors) of the data. A limitation is that these files are not easily opened in Excel. Here is the hashtagged code (remove hashtags if you wish to do this) for writing (and then reading) this data as an .rds file. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#saveRDS(dfPairedSamples, 'dfPairedSamples.rds') -#dfPairedSamples <- readRDS('dfPairedSamples.rds') -``` -### Quick Peek at the Data - -Plotting the data is a helpful early step in any data analysis. Further, visualizing the data can help us with a conceptual notion of the statistic we are utilizing. The *ggpubr* package is one of my go-to-tools for quick and easy plots of data. The *ggpaired()* function is especially appropriate for paired data. A [tutorial](https://rpkgs.datanovia.com/ggpubr/reference/ggpaired.html) is available at datanovia. - -Especially unique about this function is that the lines connect the scores of each person across time or conditions. In this research scenario, the lines present the amount of time the physicians spent with each of the two patients they treated. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ggpubr::ggpaired(dfPairedSamples, cond1 = "Verbal_BL", cond2 ="Verbal_WH", color = "condition", line.color = "gray", palette =c("npg"), xlab = "Patient Race", ylab = "Verbal Communication Rating") -``` -The box of the boxplot covers the middle 50% (the interquartile range). The horizontal line is the median. The whiskers represent three standard deviations above and below the mean. Any dots beyond the whiskers are outliers. - - -## Working the Paired Samples *t*-Test (by hand) - -### Stating the Hypothesis - -In this lesson, I will focus on differences in the verbal communication variable. Specifically, I hypothesize that physician verbal communication scores for Black and White patients will differ. In the hypotheses below, the null hypothesis ($\mu_D$) states that the difference score is zero; the alternative hypothesis ($\mu_D$) states that the difference score is different from zero. - -$$H_{O}: \mu _{D} = 0$$ -$$H_{A}: \mu _{D} \neq 0$$ - -Notice the focus on a *difference* score. Even though the R package we will use does not require one for calculation, creating one in our df will be useful for preliminary exploration. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Creating the Verbal_D variable within the dfPairedSamples df -#Doing the "math" that informs that variable -dfPairedSamples$Verbal_D <- (dfPairedSamples$Verbal_BL - dfPairedSamples$Verbal_WH) -#Displaying the first six rows of the df to show that the difference score now exists -head(dfPairedSamples) -``` -Examining this new variable, because we subtracted the verbal communication ratings of physicians with White patients from those of Black patients a negative score means that physicians had lower verbal engagement with Black patients; a positive score means that physicians had more verbal engagement with White patients. - -### Calculating the Paired Samples *t*-Test - -Let's take another look at the formula for calculating paired samples *t*-test. - -$$t = \frac{\bar{D}}{\hat\sigma_D / \sqrt{N}}$$ -We can use the data from our preliminary exploration in the calculation. - -* The mean difference was .08 -* The standard deviation of that difference was 4.14 -* The sample size is 33 - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -.08/(4.14/sqrt(33)) -``` -The resultant *t* value is 0.111 - -Hopefully, this hand-calculation provided an indication of how the means, standard deviation, and sample sizes contribute to the estimate of this *t*-test value. Now we ask, "But it is statistically significant?" - -#### Statistical Significance - -Our *t*-value was 0.111. We compare this value to the test critical value in a table of *t* critical values. In-so-doing we must know our degrees of freedom. Because the numerator in a paired samples *t*-test is a single difference score $\bar{D}$, the associated degrees of freedom is $N-1$. We must also specify the *p* value (in our case .05) and whether-or-not our hypothesis is unidirectional or bi-directional. Our question only asked, "Are the verbal communication levels different?" In this case, the test is two-tailed, or bi-directional. - -Let's return to the [table of critical values](https://www.statology.org/t-distribution-table/) for the *t* distribution to compare our *t*-value (0.111) to the column that is appropriate for our: - -* Degrees of freedom (in this case $N-1$ or 32) -* Alpha, as represented by $p < .05$ -* Specification as a one-tailed or two-tailed test - - Our alternative hypothesis made no prediction about the direction of the difference; therefore we will use a two-tailed test - -In the linked table, when the degrees of freedom reaches 30, there larger intervals. We will use the row representing degrees of freedom of 30. If our *t*-test value is lower than an absolute value of -2.042 or greater than the absolute value of 2.042, then our means are statistically significantly different from each other. In our case, we have not achieved statistical significance and we cannot say that the means are different. The *t* string would look like this: $t(32) = 0.111, p > .05$ - -We can also use the *qt()* function in base R. In the script below, I have indicated an alpha of .05. The "2" that follows indicates I want a two-tailed test. The 32 represents my degrees of freedom ($N-1$). In a two-tailed test, the regions of rejection will be below the lowerbound (lower.tail=TRUE) and above the upperbound (lower.tail=FALSE). - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -qt(.05/2, 32, lower.tail=TRUE) -qt(.05/2, 32, lower.tail=FALSE) -``` -If our *t* value is below the lowerbound (-2.04) or above the upper bound (2.04), then we have rejected the null hypothesis in favor of the alternative. As we demonstrated in the hand-calculations, we have not. The ratings of physicians' verbal engagement with patients who are racially identified as Black and White are not statistically significant. - -#### Confidence Intervals - -How confident are we in our result? With paired samples *t*-tests, it is common to report an interval in which we are 95% confident that our true mean difference exists. Below is the formula, which involves: - -* $\bar{D}$ the mean difference score -* $t_{cv}$ the test critical value for a two-tailed model (even if the hypothesis was one-tailed) where $\alpha = .05$ and the degrees of freedom are $N-1$ -* $s_{d}$ the standard deviation of $\bar{D}$ -* $N$ sample size - -$$\bar{D}\pm t_{cv}(s_{d}/\sqrt{n})$$ -Let's calculate it: - -First, let's get the proper *t* critical value: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -qt(.05/2, 32, lower.tail=TRUE) -qt(.05/2, 32, lower.tail=FALSE) -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -.08-(2.037*((4.14/(sqrt(33))))) -.08+(2.037*((4.14/sqrt(33)))) -``` -These values indicate the range of scores in which we are 95% confident that our true $\bar{D}$ lies. Stated another way, we are 95% confident that the true mean difference lies between -1.39 and 1.55. Because this interval crosses zero, we cannot rule out that the true mean difference is 0.00. This result is consistent with our non-significant *p* value. For these types of statistics, the 95% confidence interval and *p* value will always be yoked together. - -#### Effect Size - -Effect sizes address the magnitude of difference. There are two common effect sizes that are used with the paired samples *t*-test. The first is the *d* statistic, which measures, in standard deviation units, the distance between the two means. Regardless of sign, values of .2, .5, and .8 are considered to be small, medium, and large, respectively. - -Because the paired samples *t*-test used the difference score in the numerator, there are two easy options for calculating this effect: - -$$d=\frac{\bar{D}}{\hat\sigma_D}=\frac{t}{\sqrt{N}}$$ - -The first is to use the mean and standard deviation associated with the difference score: -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -.08/4.14 -``` -The formula uses the *t* value and *N*. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -0.111/(sqrt(33)) -``` -Within rounding error, both calculations result in a value ($d = 0.02$) that is quite small. - -Eta squared, $\eta^2$ is the proportion of variance of a test variable that is a function of the grouping variable. A value of 0 indicates that mean of the difference scores is equal to 0, where a value of 1 indicates that the difference scores in the sample are all the same nonzero value, and the test scores do not differ within each group. The following equation can be used to compute $\eta^2$. Conventionally, values of .01, .06, and .14 are considered to be small, medium, and large effect sizes, respectively. - -$$\eta^{2} =\frac{N(\bar{D}^{2})}{N(\bar{D}^{2}+(N-1)(\hat\sigma_D^{^{2}})}=\frac{t^{2}}{t^{2}+(N_{1}-1)}$$ -The first calculation option uses the N and the mean difference score: -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -(33*(.08^2))/((33*(.08^2)) + ((33-1)*(4.14^2))) -``` -The second calculation option uses the *t* values and sample size: -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -(0.111^2)/((0.111^2)+(33-1)) -``` -Within rounding errors, and similar to our *d* statistic, the $\eta^2$ value (0.0004) is quite small. - -## Working the Paired Samples *t*-Test with R Packages - -Let's rework the problem in R. We start at the top of the flowchart, evaluating the statistical assumptions. - -### Evaluating the Statistical Assumptions - -With an eye on our data, we can begin to explore the statistical assumptions associated with the paired samples *t*-test. Here's where we are in the workflow: - -![A colorful image of a workflow for the paired samples *t*-test highlighting the portion focused on assumptions](images/ttests/PairedAssmptns.jpg) -All statistical tests have some assumptions about the data. The paired-samples *t*-test has three: - -* The difference scores (i.e., the difference on the outcome across time or conditions) on the test variable are independent of each other. This is a matter of research design and no further statistical evaluation is required. -* The test variable should be continuously scaled. This is also a matter of research design and no statistical analysis is required. - - Our test variable is measured in minutes; this is continuously scaled and has the properties of *interval*-level data. -* The *difference scores* of the test variable are normally distributed. We can check this several ways: - - visually with histograms (perhaps with superimposed curves) and boxplots, - - calculation of skew and kurtosis values, - - calculation of the Shapiro-Wilk test of normality - -#### Are the difference scores of the test variable normally distributed? - -We can begin to evaluate normality by obtaining the descriptive statistics with the *describe()* function from the *psych* package. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describe(dfPairedSamples, type=1) -``` - -We observe that the skew and kurtosis values for Verbal_BL and Verbal_WH are well below the areas of concern (below the absolute value of 3 for skew; below the absolute values of 10 for kurtosis) identified by Kline [-@kline_data_2016]. - -Recall, though that the normality assumption for the paired samples *t*-test concerns the *difference score* (Verbal_D). We see that the mean difference is 0.08 (*SD* = 4.14). Its skew (-0.42) and kurtosis (-0.54) are also well-below the thresholds of concern. - -Beyond skew and kurtosis, we can formally test for deviations from normality with a Shapiro-Wilk. We want the results to be non-significant. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::shapiro_test(dfPairedSamples, Verbal_D) -``` -Results of the Shapiro-Wilk test of normality are not statistically significant $(W = 0.97, p = 0.57)$. This means that the distribution of difference scores is not statistically significantly different from a normal distribution. - -#### APA style write-up of testing the assumptions - -My practice is to create APA style drafts of the different sections of the analysis as I work along. Here's how I might capture our evaluation of the statistical assumptions: - ->We began by analyzing the data to see if it met the statistical assumptions for analysis with a paired samples *t*-test. One assumption is that the difference scores of dependent variable are normally distributed. We evaluated skew and kurtosis using Kline's [-@kline_data_2016] guidelines of the absolute values of 3 (skew) and 10 (kurtosis). Our results were well-within these boundary conditions. Further, a non-significant Shapiro-Wilk test of normality suggested that the distribution of difference scores was not statistically significant from a normal distribution $(W = 0.97, p = 0.57)$. - -### Computing the Paired Samples *t*-Test - -We are ready to compute the paired samples *t*-test. - -![A colorful image of a workflow for the paired samples *t*-test](images/ttests/PairedT.jpg) - -Calculating a paired samples *t*-test is possible through base R and a number of packages. Kassambara's [-@kassambara_pipe-friendly_nodate] *rstatix* package is one we can use for all of the *t*-test and ANOVA problems that we will work. - -A challenge in evaluating within-persons data is the *shape* of the data. The simulation resulted in a *wide* (also termed person-level or multivariate) format, where each of the 33 physicians has the verbal and non-verbal communication scores with Black and White patients. We need to reshape the data to a long (also termed person-period or univariate) format. Although it may seem a bit tricky at first, this is a skill you will return to in many longitudinal or repeated measures analyses. - -In the script below we are using the *melt()* and *setDT* functions from the *data.table* package. We put stable (i.e., time-invarient, "one-per-person") variables in a concatonated variable list of "id.vars." We create separate lists of the variables that change over time. In this case, each physician saw one Black patient and one White patient. Therefore, every physician will have two rows of data. For each variable collected at both points, we create concatonated lists. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -df_long <- data.table::melt(data.table::setDT(dfPairedSamples), id.vars=c("PhysID"), measure.vars=list(c("Verbal_BL", "Verbal_WH"), c("NVerb_BL", "NVerb_WH"))) -head(df_long) -``` -While that code performed the magic, it did not name the variables. We must provide that in separate code. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -df_long <- rename(df_long, PatientRace = variable, Verbal = value1, Nonverbal = value2 ) -``` - -After the reshaping, let's recheck the structure of our data: - -```{r} -str(df_long) -``` -The dependent variables Verbal and Nonverbal are continuously scaled, so the *num* designation is appropriate. Similarly, PatientRace is categorical, so *Factor* is appropriate. Because labels (instead of numbers) can minimize misinterpretation (or forgetting), I would prefer to use "Black" and "White" as opposed to "1" and "2". To further reduce the possibility of error, it is easy enough to create a second, parallel, variable. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -df_long$PtRace <- plyr::mapvalues(df_long$PatientRace, from = c(1, 2), to = c("Black", "White")) -``` - -We are now ready to perform the paired samples *t*-test. In the script below: - -* the first element points to the dataframe -* the second element provides a "formula" - - we are predicting "Verbal" from "PtRace" -* specifying "detailed = TRUE" will produce the 95% confidence interval around the difference - - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::t_test(df_long, Verbal ~ PtRace, paired=TRUE, detailed=TRUE) -``` - -This output provides information to get us started in drafting the APA style results. Identical to all the information we hand-calculated, we would write the *t* string this way: $t(32) = 0.113, p = .911, CI95(-1.39, 1.55)$. Our results show that the mean difference in physician verbal communication scores with Black and White patients was 0.081. Taking a look at the confidence interval, we are 95% confident that the true difference in means falls between the values of -1.386 and 1.549. What is critically important is that this confidence interval crosses zero. There is an important link between the CI95% and statistical significance. When the CI95% includes zero, *p* will not be lower than 0.05. - -We still need to calculate the effect size. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::cohens_d(df_long, Verbal ~ PtRace, paired=TRUE) -``` -Keeping in mind the interpretive criteria of .2, .5, and .8, as small, medium, and large effect sizes, we see that $d = 0.020$ is quite small. We can add it to our *t*-string and draft the results: $t(32) = 0.113, p = .911, d = 0.020, CI95(-1.39, 1.55)$. - - -## APA Style Results - -Putting it altogether we can assemble an APA style results section. Code for a table of means, standard deviations, and correlation follow the write-up of results. For inclusion in a manuscript, I would rework the export of the table to delete the difference score (i.e., Verbal_D). I might also exclude the rows of confidence intervals around the correlations. - ->We began by analyzing the data to see if it met the statistical assumptions for analysis with a paired samples *t*-test. One assumption is that the difference scores of dependent variable are normally distributed. We evaluated skew and kurtosis using Kline's [-@kline_data_2016] guidelines of the absolute values of 3 (skew) and 10 (kurtosis). Our results were well-within these boundary conditions. Further, a non-significant Shapiro-Wilk test of normality suggested that the distribution of difference scores was not statistically significant from a normal distribution $(W = 0.97, p = 0.57)$. - ->A paired samples *t*-test was conducted to evaluate the hypothesis that there would be differences in the degree of physicians' verbal engagement as a function of the patient's race (Black, White). The paired samples *t*-test was nonsignificant, *t*(32) = 0.133, *p* = .911. The small magnitude of the effect size (*d* = 0.02) was consistent with the nonsignificant result. The 95% confidence interval for the difference in means was quite wide and included the value of zero (95%CI[-1.386, 1.549]). Means and standard deviations are presented in Table 1; the results are illustrated in Figure 1. - - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse)#needed to use the pipe -#Creating a smaller df to include only the variables I want in the table -PairedDescripts <- dfPairedSamples%>% - select(Verbal_BL, Verbal_WH, Verbal_D) -#using the apa.cor.table function for means, standard deviations, and correlations -#the filename command will write the table as a word document to your file -apaTables::apa.cor.table(PairedDescripts, table.number=1, filename="Tab1_PairedV.doc") -``` -The figure we created earlier in the lesson would be sufficient for a journal article. However, using *rstatix* in combination with *ggpubbr* can be quite powerful. The result can be a figure that includes the *t*-test results and "significance bars." To do this, we first need to re-run the *rstatix::t_test*, but adding to it by - -* including "add_significance()" script after the pipe, and -* saving it as an object, which I'm naming "pair.test." - -We could have done this in the initial run (but I didn't want to make the test-statistic unnecessarily confusing). - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -pair.test <- rstatix::t_test(df_long, Verbal ~ PtRace, paired=TRUE, detailed=TRUE) %>% - rstatix::add_significance() -pair.test -``` - -Next, we create boxplot code with the long form of our data: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pair.box <- ggpubr::ggpaired(df_long, x = "PtRace", y = "Verbal", order = c("Black", "White"), line.color = "gray", palette =c("npg"), color = "PtRace", ylab = "Verbal Communication Rating", xlab = "Patient Race", title = "Figure 1. Physician Verbal Engagement as a Function of Patient Race") - -pair.test <- pair.test %>% rstatix::add_xy_position(x = "PtRace") #autocomputes p-value labels positions - -pair.box <- pair.box + - ggpubr::stat_pvalue_manual(pair.test, tip.length=.01, y.position = c(15) ) + - labs(subtitle = rstatix::get_test_label(pair.test, detailed=TRUE)) - -pair.box -``` -The tools available offer a great deal of flexibility. Determining which figure is best will likely depend on your outlet, your audience, and your personal preferences. For example, a print journal might prefer a black-and-white figure (with no fill in the boxes). This is accomplished easily enough by removing (or, hashtagging out) the "fill = PtRace" argument. - - -## Power in Paired Samples *t*-Tests - -Researchers often use power analysis packages to estimate the sample size needed to detect a statistically significant effect, if, in fact, there is one. Utilized another way, these tools allows us to determine the probability of detecting an effect of a given size with a given level of confidence. If the probability is unacceptably low, we may want to revise or stop. A helpful overview of power as well as guidelines for how to use the *pwr* package can be found at a [Quick-R website](https://www.statmethods.net/stats/power.html) [@kabacoff_power_2017]. - -In Champely's *pwr* package, we can conduct a power analysis for a variety of designs, including the paired *t*-test that we worked in this chapter. There are a number of interrelating elements of power: - -* Sample size, *n* refers to the number of pairs; our vignette had 33 -* *d* refers to the difference between means divided by the pooled standard deviation; we can use the value of Cohen's *d* for this -* *power* refers to the power of a statistical test; conventionally it is set at .80 -* *sig.level* refers to our desired alpha level; conventionally it is set at .05 -* *type* indicates the type of test we ran; ours was "paired" -* *alternative* refers to whether the hypothesis is non-directional/two-tailed ("two.sided") or directional/one-tailed("less" or "greater") - -In this script, we must specify *all-but-one* parameter; the remaining parameter must be defined as NULL. R will calculate the value for the missing parameter. - -When we conduct a "power analysis" (i.e., the likelihood of a hypothesis test detecting an effect if there is one), we specify, "power=NULL". Using the data from our results, we learn from this first run, that our statistical power was at 5%. That is, given the low value of the mean difference (.08) and the relatively large standard deviation (4.14), we had only a 5% chance of detecting a statistically significant effect if there was one. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.t.test(d=0.02,n = 33, power=NULL,sig.level=0.05,type="paired",alternative="two.sided") -``` -The results indicate that we were powered at 5%. That is, we had a 5% chance of finding a statistically significant difference, if in fact there was one. - -Researchers frequently use these tools to estimate the sample size required to obtain a statistically significant effect. In these scenarios we set *n* to *NULL*. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.t.test(d=0.02,n = NULL, power=0.8,sig.level=0.05,type="paired",alternative="two.sided") -``` -Using the results from the simulation of our research vignette, you can see that we would have needed 19624 individuals for the *p* value to be < .05, if, in fact there were a significant difference. - -Let's see if this is true. Below I will re-simulate the data for the verbal scores, changing only the sample size: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -set.seed(220820) -#These define the characteristics of the verbal variable. It is essential that the object names (e.g., A_mean) are not changed because they will be fed to the function in the faux package. -sub_n <- 19624 -A_mean <- 8.37 -B_mean <- 8.41 -A_sd <- 3.36 -B_sd <- 3.21 -AB_r <- 0.3 - -#the faux package can simulate a variety of data. This function within the faux package will use the objects above to simulate paired samples data -paired_V2 <- faux::rnorm_multi( - n = sub_n, - vars = 2, - r = AB_r, - mu = c(A_mean, B_mean), - sd = c(A_sd, B_sd), - varnames = c("Verbal_BL", "Verbal_WH") - ) - -paired_V2 <- paired_V2 %>% dplyr::mutate(PhysID = row_number()) - -#restructuring data to the long form -df_longV2 <- data.table::melt(data.table::setDT(paired_V2), id.vars=c("PhysID"), measure.vars=list(c("Verbal_BL", "Verbal_WH"))) -df_longV2 <- rename(df_longV2, PatientRace = variable, Verbal = value) -df_longV2$PtRace <- plyr::mapvalues(df_longV2$PatientRace, from = c("Verbal_BL", "Verbal_WH"), to = c("Black", "White")) -``` - -Now I will conduct the paired samples *t*-test and corresponding effect size. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::t_test(df_longV2, Verbal ~ PtRace, paired=TRUE, detailed=TRUE) -rstatix::cohens_d(df_longV2, Verbal ~ PtRace, paired=TRUE) -``` -The new results remain non-significant: $t(19623) = -1.243, p = 0.241, d = -0.009, 95CI (-0.088, 0.020)$. This tells me these means are quite similar and this is not a function of being under powered. - -Conducting power analyses requires that researchers speculate about their values. In this case, in order to estimate sample size, the researcher would need to make some guesses about the difference scores means and standard deviations. These values could be estimated from prior literature or a pilot study. - -## Practice Problems - -The suggestions for homework differ in degree of complexity. I encourage you to start with a problem that feels "do-able" and then try at least one more problem that challenges you in some way. Regardless, your choices should meet you where you are (e.g., in terms of your self-efficacy for statistics, your learning goals, and competing life demands). - -Additionally, please complete at least one set of *hand calculations*, that is use the code demonstrated in the chapter to work through the formulas that compute the paired samples *t*-test. At this stage in your learning, you may ignore any missingness in your dataset by excluding all rows with missing data in your variables of interest. - -### Problem #1: Rework the research vignette as demonstrated, but change the random seed - -If this topic feels a bit overwhelming, simply change the random seed in the data simulation of the research vignette, then rework the problem. This should provide minor changes to the data (maybe even in the second or third decimal point), but the results will likely be very similar. That said, don't be alarmed if what was non-significant in my working of the problem becomes significant. Our selection of *p* < .05 (and the corresponding 95% confidence interval) means that 5% of the time there could be a difference in statistical significance. - -### Problem #2: Rework the research vignette, but change something about the simulation - -Rework the paired samples *t*-test in the lesson by changing something else about the simulation. For example, if you are interested in understanding more about power, consider changing the sample size. Alternatively, you could specify different means and/or standard deviations. - -### Problem #3: Rework the research vignette, but swap one or more variables - -Use the simulated data, but select the nonverbal communication variables that were evaluated in the Elliott et al. [-@elliott_differences_2016] study. Compare your results to those reported in the mansucript. - -### Problem #4: Use other data that is available to you - -Using data for which you have permission and access (e.g., IRB approved data you have collected or from your lab; data you simulate from a published article; data from an open science repository; data from other chapters in this OER), complete a paired samples *t*-test. - -### Grading Rubric - -Regardless which option(s) you chose, use the elements in the grading rubric to guide you through the practice. - -|Assignment Component | Points Possible | Points Earned| -|:-------------------------------------- |:----------------: |:------------:| -|1. Narrate the research vignette, describing the variables and their role in the analysis | 5 |_____ | -|2. Simulate (or import) and format data | 5 |_____ | -|3. Evaluate statistical assumptions | 5 |_____ | -|4. Conduct a paired samples *t*-test (with an effect size & 95%CIs) |5 | _____ | -|5. APA style results with table(s) and figure | 5 |_____ | -|6. Conduct power analyses to determine the power of the current study and a recommended sample size | 5 |_____ | -|7. Explanation to grader | 5 |_____ | -|**Totals** | 35 |_____ | - - -|Hand Calculations | Points Poss | Points Earned -|:-----------------------------------------|:-------------:|:--------------| -|1. Using traditional NHST (null hypothesis testing language), state your null and alternative hypotheses| 2 | -|2. Using an R package or functions in base R (and with data in the "wide" format), calculate the *difference* score between the two observations of the dependent variable | 2 | | -|3. Obtain the mean and standard deviation of the *difference* score |2 | | -|4. Calculate the paired samples *t*-test | 4 || -|5. Identify the degrees of freedom associated with your paired samples *t*-test | 2 | -|6. Locate the test critical value for your paired samples *t*-test |2 | | -|7. Is the paired samples *t*-test statistically significant? Why or why not? | 2 | | -|8. What is the confidence interval around the mean difference? |4 | | -|9. Calculate the effect size (i.e., Cohen's *d* associated with your paired samples *t*-test |4 | | -|10. Assemble the results into a statistical string |4 | | -|**Totals* ** | 28 | | -```{r, child= 'Worked_Examples/15-5-woRked_tPaired.Rmd'} -``` - -```{r include=FALSE, tidy=TRUE, tidy.opts=list(width.cutoff=70)} -sessionInfo() -``` - - - - - diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/A0C1131E-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/A0C1131E-contents deleted file mode 100644 index 55b75016..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/A0C1131E-contents +++ /dev/null @@ -1,234 +0,0 @@ -```{r include = FALSE} -options(scipen=999) -``` - -## Homeworked Example - -[Screencast Link](https://youtu.be/_IiZ8MbtbVs) - -For more information about the data used in this homeworked example, please refer to the description and codebook located at the end of the [introduction](ReCintro). - -Preliminary analyses often consist of means, standard deviations, and correlations. These can be helpful in determining whether or not data are normally distribution. Correlations and pairs.panels also assess the relatedness of the variables. - -If you wanted to use this example and dataset as a basis for a homework assignment, you could (a) select a different course (i.e., Multivariate or Psychometrics) and/or (b) different variables. - -### Working the Problem with R and R Packages - -#### Create a df with 3 continuously scaled variables of interest {-} - -The ReC.rds is the entire dataset. Let's first open it. - -```{r} -ReCdf <- readRDS("ReC.rds") -``` - -Recall that students (represented by the *deID* variable) could contribute up to three course evaluations (i.e., ANOVA, psychometrics, multivariate) each. In many statistics, repeated observations creates dependencies that need to be accounted for statistically. - -To avoid this dependency and to practice an R skill, let's first filter the data, selecting only those students who took ANOVA. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -JustANOVA <- subset(ReCdf, Course == "ANOVA") -``` - -#### Create a df with 3 continuously scaled variables of interest {-} - -The assignment requires that we downsize to three variables. We could pick any three. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -tiny3 <- JustANOVA %>% - dplyr::select (OvInstructor, OvCourse, MyContribution) -``` - -#### Produce descriptive statistics {-} - -```{r} -psych::describe(tiny3) -``` - -#### Produce SPLOM/pairs.panels {-} - -```{r} -psych::pairs.panels(tiny3) -``` - -#### Produce an apaTables matrix {-} - -```{r} -apaTables::apa.cor.table(tiny3) -``` -#### Produce an APA Style write-up of the preliminary analyses {-} - ->Our sample included 113 doctoral students in Clinical and Industrial-Organizational psychology (PhD) programs who were completing a statistics class focused on analysis of variance. Visual inspection of three dimensions of course evaluation (overall instructor, overall course, my contributions) combined with formal evaluation of skewness and kurtosis suggested that their distributions did not violate the assumption of univariate normality. That is, skew values all fell below the absolute value of 3 and kurtosis values all fell below the absolute value of 10 [@kline_data_2016]. Means, standard deviations, and a correlation matrix are presented in Table 1. All three correlations were strong and statistically significant. We noted that the correlation between the overall instructor and overall course was especially high $(r = .83, p < .001)$ - -### Hand Calculations - -Although these are termed “hand calculations,” you may use the code demonstrated in the chapter to work these problems. - -I am going to continue with the *tiny3* dataset I used when I worked the problem with R and R packages. - -If you need to reimport data, here is a quick recap of the code explained earlier. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ReCdf <- readRDS("ReC.rds") -JustANOVA <- subset(ReCdf, Course == "ANOVA") - -library(tidyverse) -tiny3 <- JustANOVA %>% - dplyr::select (OvInstructor, OvCourse, MyContribution) -``` - -To avoid problems in the code we are used that is caused by missingness, we will eliminate any rows with missing data. -```{r} -tiny3 <- na.omit(tiny3) -``` - - -#### Create a variable that represents the mean {-} - -I will start with the OvInstructor variable. Inspect the dataframe to see that this new variable exists. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -tiny3$M_OvI <- mean(tiny3$OvInstructor, na.rm=TRUE) -``` - -#### Create a variable that represents the mean deviation {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -tiny3$Mdev_OvI <- (tiny3$OvInstructor-tiny3$M_OvI) -head(tiny3) -``` - -Inspect the dataframe to see that this new variable exists. Note that this functions to "center" the mean around zero. - - -#### What is the value of the sum of mean deviations? {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -round(sum(tiny3$Mdev_OvI, na.rm = TRUE), 3) -``` -Yes, zero! - -#### Create a variable that represents the absolute mean deviation {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -tiny3$abslt_mOvI <- abs(tiny3$Mdev_OvI) -head(tiny3) -``` - -Inspect the dataframe to see that this new variable no longer has negative values. - -**What is the value of the sum of the absolute mean deviation?** - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -round(sum(tiny3$abslt_mOvI, na.rm = TRUE), 3) -``` - - -**What is the value of the mean of the absolute mean deviation?** - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -round(mean(tiny3$abslt_mOvI, na.rm = TRUE), 3) -``` - -**What does this value tell you?** - -Average distance of each value from the mean. - -#### Create a variable that represents the mean deviation squared {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -tiny3$mdev2_OvI <- (tiny3$Mdev_OvI * tiny3$Mdev_OvI) -head(tiny3) -``` - -**What is the value of the sum of squared deviations around the mean (also known as sums of squares; sometimes abbreviated as $SS$)?** - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -sum(tiny3$mdev2_OvI, na.rm = TRUE) -``` - -**What is the value of the variance ($s^2$)?** - -There are at least two ways to do this with basic code (and then we can check our work). - -Here's how to do it with "more code." -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -var_OvI <- sum(tiny3$mdev2_OvI/((nrow(tiny3) - 1))) -var_OvI -``` - -Here's how to do it with the numbers that I calculated: -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -115.0973/(113-1) -``` - -Checking my work with the *var* function from base R. If it's wrong, I need to rework some of the previous steps. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -var(tiny3$OvInstructor, na.rm = TRUE) #checking my work -``` - -**What is the value of the standard deviation ($s$)?** - -There are two ways to calculate it with basic code; and then we can check it with more code from base R. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -sd_OvI <- sqrt(var_OvI)#calculating with the object I created -sd_OvI -sqrt (1.027655)#calculated with the actual numbers -sd(tiny3$OvInstructor)#checking my work with the code from baseR -``` - -#### Using the same general approach, calculate the mean deviation and standard deviation for a second, continuously scaled variable {-} - -My second variable is MyContribution -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#first the mean -tiny3$M_MyC <- mean(tiny3$MyContribution, na.rm=TRUE) -#second the mean deviation -tiny3$Mdev_MyC <- (tiny3$MyContribution-tiny3$M_MyC) -#third the mean deviation squared -tiny3$mdev2_MyC <- (tiny3$Mdev_MyC * tiny3$Mdev_MyC) -head(tiny3) - -#fourth the variance -var_MyC <- sum(tiny3$mdev2_MyC/((nrow(tiny3) - 1))) -var_MyC -#finally the standard deviation -sd_MyC <- sqrt(var_MyC) -sd_MyC#checking my work - -sd(tiny3$MyContribution)#checking my work -``` - -#### Create a variable that represents the *cross-product* (of the mean deviations). What is the sum of these cross-products? {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -tiny3$crossproduct <- (tiny3$Mdev_OvI * tiny3$Mdev_MyC) -head(tiny3) -``` - -The sum of the crossproduct is: - -```{r} -xp_sum <- sum(tiny3$crossproduct) -xp_sum -``` - -#### Calculate the value of their covariance {-} - -```{r} -cov <- (1/(113-1)) * 46.74336 -cov -``` - -#### Calculate value of correlation coefficient {-} - -```{r} -0.4173514/(1.013733*0.8338) - -``` -And now I can check my work with a function from base R. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -cor.test(tiny3$OvInstructor, tiny3$MyContribution) -``` -The correlation between ratings of overall instructor and my contribution is $0.493, p < .001$. diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/B3D99039-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/B3D99039-contents deleted file mode 100644 index af0675af..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/B3D99039-contents +++ /dev/null @@ -1,487 +0,0 @@ -```{r include = FALSE} -options(scipen=999) -``` - -## Homeworked Example - -[Screencast Link](https://youtu.be/gstP-tx4YUQ) - -For more information about the data used in this homeworked example, please refer to the description and codebook located at the end of the [introduction](ReCintro). - -### Working the Problem with R and R Packages - -#### Narrate the research vignette, describing the IV and DV. Miniminally, the data should allow the analysis of a 2 x 3 (or 3 X 2) design. At least one of the problems you work should have a significant interaction effect so that follow-up is required {-} - -I want to ask the question, do course evaluation ratings for the traditional pedagogy dimension differ for students in the ANOVA class as a function of: - -* **Stage** in the transition - - STABLE: 2017 represents the last year of "stability during the old way" when we taught with SPSS and during the 2nd year of the doctoral programs. - - TRANSITION: 2018 & 2019 represent the transition to R, when the classes were 30% larger because each of the IOP and CPY departments were transitioning to the 1st year (they did it separately, so as not to double the classes) - - RESETTLED: 2020 & 2021 represent the "resettled" phase where the transition to R was fairly complete and the class size returned to normal because the classes were offered in the first year. -* **Department** - - CPY: Clinical Psychology - - ORG: Industrial-Organizational Psychology - -*If you wanted to use this example and dataset as a basis for a homework assignment, you could create a different subset of data. I worked the example for students taking the ANOVA class. You could choose multivariate or psychometrics. You could also choose a different dependent variable. I chose the traditional pedagogy subscale. Two other subscales include socially responsive pedagogy and valued by the student.* - -#### Simulate (or import) and format data {-} - -```{r} -big <- readRDS("ReC.rds") -``` - -Let's first create the "Stage" variable that represents the three levels of transition. The ProgramYear variable contains the information I need, but the factor labels are not intuitive. Let me remap them. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -big$Stage <- plyr::mapvalues(big$ProgramYear, from = c("Second", "Transition", "First"), to = c("Stable", "Transition", "Resettled")) -``` - -Let's check the structure: -```{r} -str(big$Stage) -``` - -The TradPed (traditional pedagogy) variable is an average of the items on that scale. I will first create that variable. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Creates a list of the variables that belong to that scale -TradPed_vars <- c('ClearResponsibilities', 'EffectiveAnswers','Feedback', 'ClearOrganization','ClearPresentation') - -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -big$TradPed <- sjstats::mean_n(big[, TradPed_vars], .75) - -#if the scoring script won't run, try this one: -#big$TradPed <- sjstats::mean_n(big[, ..TradPed_vars], .75) -``` - -Each student in the dataset could contribute up to three course evaluations (i.e., one each for ANOVA, multivariate, psychometrics). Including all three would introduce *dependency* into the dataset and violate the assumption of independence. With our variables properly formatted let's create a subset with just the students who took ANOVA. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -TwoWay_df <- subset(big, Course == "ANOVA") -``` - -Next, let's trim it to just the variables we need. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -TwoWay_df <-(dplyr::select(TwoWay_df, Stage, Dept, TradPed)) -``` - -Although we would handle missing data more carefully in a "real study," I will delete all cases with any missingness. This will prevent problems in the hand-calculations section, later (and keep the two sets of results more similar). - -```{r} -df <- na.omit(TwoWay_df) -``` - -Before we continue, this data has a hiccup that makes it less than ideal for a 2 x 3 ANOVA. In 2017 everyone enrolled in the CPY section of the course. That is, there was no distinction between CPY and ORG students. In this dataset I do not have another variable with three levels. I will recode some data which MAKES THE STORY UNTRUE, but will allow me to demo 2-way ANOVA (sighhhh). For your homework, you are very welcome to engage in such practices (it's actually good for learning!) however, we would never do so in the analysis of real data. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -TwoWay_df <- na.omit(TwoWay_df) #the next operation required non-missing data -TwoWay_df[TwoWay_df$Stage == "Stable" & TwoWay_df$TradPed < 4.3, "Dept"]<- "ORG" -``` - -Although the homework assignment doesn't require it, I think it's useful to create a figure that shows what I intend to do. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -Box2way <- ggpubr::ggboxplot(TwoWay_df, x = "Dept", y = "TradPed", color = "Stage", xlab = "Academic Department", - ylab = "Students' Evaluations of Traditional Pedagogy", add = "jitter", - title = "Course Evaluations as a Function of Department and Stage in Transition") -Box2way -``` - -#### Evaluate statistical assumptions {-} - -**Is the dependent variable normally distributed at all levels of the combinations of the levels within the grouping variables?** - -I'll start with an inspection of skew and kurtosis for all combinations of the levels of the two grouping variables. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describeBy(TradPed ~ Stage + Dept, mat = TRUE, data = TwoWay_df, digits = 3, type = 1) -``` - -Following Kline's (2016) recommendations, skew for each combination of levels of the two IVs are < |3.0|. Kurtosis for each combination of levels of the two IVs are < |10.0|. - -The Shapiro-Wilk examines residuals from the ANOVA model. We can quickly/preliminarily run the two-way ANOVA. We do this to produce an object that holds the *model residuals.* -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -TwoWay_TradPed <- aov(TradPed ~ Stage * Dept, TwoWay_df) -summary(TwoWay_TradPed) -``` -The *residuals()* function serves to extract the residuals. We can apply the model-baesd *shapiro.test()* function from base R to see if the model residuals are non-normally distributed. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -resid_TradPed <- residuals(TwoWay_TradPed) -shapiro.test(resid_TradPed) -``` - -A statistically significant Shapiro-Wilks' test of normality suggests that we violated the assumption $W = 0.949, p < 0.001$. - -Let's plot the residuals -```{r} -hist(resid_TradPed) -``` -The histogram does look somewhat different (negatively skewed) from a normal distribution. -```{r} -qqnorm(resid_TradPed) -``` - -The dots stray from the expected diagonal; this also visualizes the non-normality of the data. - -Summary so far: - ->Factorial ANOVA assumes that the dependent variable is normally is distributed for all cells in the design. Although our analysis suggested skew and kurtosis were within the bounds considered to be normally distributed, the Shapiro-Wilk normality test (applied to the residuals from the factorial ANOVA model) suggested that the plotting of the residuals differed significantly from a normal distribution $W = 0.949, p < 0.001$. - -**Are there outliers?** - -Given the non-normality of the data, we can use the following procedure to see if there are outliers that could be transformed, truncated, or removed. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -TwoWay_df %>% - rstatix::identify_outliers(TradPed) -``` - -There are four outliers; none are extreme. Given that these are all on the low-side (of a negatively skewed distribution where most scores are higher), I feel it is important to retain them as they reflect more students' experiences. If this were for something other than a homework demonstration, I might also take a look at the case to see if there was evidence of inattention or something else. - -**Are the variances of the dependent variable similar across the all combinations of the levels within the grouping variables?** - -We can evaluate the homogeneity of variance test with Levene's test for the equality of error variances. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::levene_test(TwoWay_df, TradPed ~ Dept * Stage) -``` - -Levene’s test has indicated a violation of the homogeneity of variance assumption $(F[5, 106] = 6.412, p < .001)$. This is not surprising. The boxplots shows some widely varying variances. - -Do we have to stop? If cell sizes are reasonably large (e.g., at least 15) and balanced (equal), ANOVA is a relatively robust to violations of normality. Unfortunately, we don't have 15 in all cells AND our cells are unequal AND this was not an experiment. So.....this probably isn't the best approach (but it'll work for a class demo). - ->A 2 X 3 ANOVA was conducted to evaluate the effects of academic department (2 levels, CPY and ORG) and stage of transition (3 levels, stable, transitioning, resettled) on traditional pedagogy course evaluation ratings. - ->Factorial ANOVA assumes that the dependent variable is normally is distributed for all cells in the design. Although our analysis suggested skew and kurtosis were within the bounds considered to be normally distributed, the Shapiro-Wilk normality test (applied to the residuals from the factorial ANOVA model) suggested that the plotting of the residuals differed significantly from a normal distribution $W = 0.949, p < 0.001$. Further, Levene’s test has indicated a violation of the homogeneity of variance assumption $(F[5, 106] = 6.412, p < .001)$. Owing to a rather desperate need to provide a demonstration of the two-way ANOVA, I have decided to proceed and keep these violations in mind in the interpretation of results. - -#### Conduct omnibus ANOVA (w effect size) {-} - -We can use the *rstatix::anova_test()* function. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -omnibus2w <- rstatix::anova_test(TwoWay_df, TradPed ~ Dept * Stage, type = "2", detailed = TRUE) -omnibus2w -``` - -Let's write the F strings from the above table: - -* Department main effect: $F(1, 106) = 11.395, p = 0.001, \eta^2 = 0.097$ -* Stage main effect: $F(2, 106) = 10.070 , p < 0.001, \eta^2 = 0.160$ -* Interaction effect: $F(2, 106) = 4.904, p = 0.009, \eta^2 = 0.085$ - -So far we have statistically significant effects for the main and interaction effects. Here are the results so far: - ->Computing sums of squares with a Type II approach, the results for the omnibus ANOVA indicated a significant effects for the main effect of department, $F(1, 106) = 11.395, p = 0.001, \eta^2 = 0.097$; the main effect for stage in transition, $F(2, 106) = 10.070, p < 0.001, \eta^2 = 0.160$; and the interaction effect, $F(2, 106) = 4.904, p = 0.009, \eta^2 = 0.085$. - -#### Conduct one set of follow-up tests; narrate your choice {-} - -There are so many choices for following up a significant interaction effect. Regardless, we always follow a statistically significant interaction effect with an analysis of simple main effects. I think I am interested in the simple main effects for stage within department. This means I will conduct one-way ANOVAS for CPY and ORG, separately. And, if either is significant, I will look for differences across the stages. - -Although we could do something more complicated (like orthogonal contrast coding), given that those completing homework are often having early experiences with ANOVA, I will choose a more streamlined path by examining the the simple main effect of stage within department. - -Functionally, this computes two one-way ANOVAs, comparing the three stages within each of the departments. If the result is statistically significant, we will need to follow-up with more testing. - -The *rstatix::anova_test* does not allow me to specify a control for Type I error. Therefore, if I wanted to do so, I would need to monitor it outside of the R package. I *could* evaluate each of the *p* values for the two one-way ANOVAs at 0.025 (05/2). Rather than tracking Type I error at this level, I will wait and do so when I get to the pairwise comparisons that follow a statistically significant one-way ANOVA. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -TwoWay_df %>% - dplyr::group_by(Dept)%>% - rstatix::anova_test(TradPed ~ Stage) -``` -Results suggest statistically significant differences in department across the stages within the CPY department, but not the ORG department: - -* For CPY: $F(2, 58) = 18.497, p < 0.001, \eta^2 = 0.389$ -* For ORG: $F(2, 48) = 1.417, p = 0.252, \eta^2 = 0.056$ - -I would write up this stage of the analysis this way: - ->To explore the significant interaction effect, we followed with a test of simple main effect of the stage in transition within the academic department. We began with separate one-way ANOVAs. Results indicated significant differences within the CPY deparmtent $(F[2, 58] = 18.497, p < 0.001, \eta^2 = 0.389)$, but not for the ORG department $(F[2, 48] = 1.417, p = 0.252, \eta^2 = 0.056)$. - -Because there are three stages of transition, we need to followup with pairwise comparisons to see where the differences lie. Because I want to results from the significance tests to update the figure, I will save the output as an object. - -Although, technically, we only needed to compare 3 pairwise tests, this test (and figure) will compute them all. The Holm's Sequential Bonferroni is a very reasonable approach (balancing Type I error with sensibility) and so I will use it to evaluate the six pairwise comparisons that will be produced. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwTRwiDP <- TwoWay_df %>% - dplyr::group_by(Dept) %>% - rstatix::emmeans_test(TradPed ~ Stage, p.adjust.method = "holm") -pwTRwiDP -``` - - -Consistent with the significant one-way ANOVA for the ORG factor, there were non-significant differences between all pairs of stages. Within the CPY student evaluations, there were statistically significant differences between stable and transition and stabled and resettled comparisons. Both comparisons favored the stable level. - - -Here'w how I would assemble the entire APA style results: - ->A 2 X 3 ANOVA was conducted to evaluate the effects of academic department (2 levels, CPY and ORG) and stage of transition (3 levels, stable, transitioning, resettled) and on traditional pedagogy course evaluation ratings. - ->Factorial ANOVA assumes that the dependent variable is normally is distributed for all cells in the design. Although our analysis suggested skew and kurtosis were within the bounds considered to be normally distributed, the Shapiro-Wilk normality test (applied to the residuals from the factorial ANOVA model) suggested that the plotting of the residuals differed significantly from a normal distribution $W = 0.949, p < 0.001$. Further, Levene’s test has indicated a violation of the homogeneity of variance assumption $(F[5, 106] = 6.412, p < .001)$. Owing to a rather desperate need to provide a demonstration of the two-way ANOVA, I have decided to proceed and keep these violations in mind in the interpretation of results. - ->Computing sums of squares with a Type II approach, the results for the omnibus ANOVA indicated a significant effects for the main effect of department, $F(1, 106) = 11.395, p = 0.001, \eta^2 = 0.097$; the main effect for stage in transition, in transition $F(2, 106) = 10.07 , p < 0.001, \eta^2 = 0.160$, and the interaction effect, $F(2, 106) = 4.904, p = 0.009, \eta^2 = 0.085$. - -> To explore the significant interaction effect, we followed with a test of simple main effect of the stage in transition within the academic department. We began with separate one-way ANOVAs. Results indicated significant differences within the CPY deparmtent $(F[2, 58] = 18.497 , p < 0.001, \eta^2 = 0.389)$, but not for the ORG department $(F[2, 48] = 1.417, p = 0.252, \eta^2 = 0.056)$. - ->We followed the significant one-way ANOVAs with pairwise comparisons between the groups using the estimated marginal means. We specified the Holm's sequential Bonferroni for managing Type I error. For CPY students, comparisons between the stable and transition $(t[106] = 4.997, p < 0.001)$ and stable and resettled $(t[106] = 2.893, p = 0.005)$ stages were statistically significantly different. Cell means, marginal means, and standard deviations are presented in Table 1; results are illustrated in Figure 1. - -#### Describe approach for managing Type I error {-} - -I managed Type I error with the Holm's sequential Bonferroni. The Holm's is less conservative than the traditional Bonferroni because it adjusts the thresshold for statistical significance in a stepwise manner that takes into consideration the rank order of the *p* values and the number of comparisons made. - -#### APA style results with table(s) and figure {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -apaTables::apa.2way.table(Dept, Stage, TradPed, data = TwoWay_df, filename = "2Way.doc", table.number = 1, show.marginal.means = TRUE, landscape = TRUE) -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwTRwiDP <- pwTRwiDP %>% - rstatix::add_xy_position(x = "Dept") #x should be whatever the variable was used in the group_by argument -Box2way <- Box2way + ggpubr::stat_pvalue_manual(pwTRwiDP, label = "p.adj.signif", tip.length = 0.02, hide.ns = TRUE, y.position = c(5.3, 5.5)) -Box2way -``` -#### Conduct power analyses to determine the power of the current study and a recommended sample size {-} - -The *pwr.2way()* and *ss.2way()* functions require the following: - -* **a** number of groups in Factor A -* **b** number of groups in Factor B -* **alpha** significant level (Type I error probability) -* **beta** Type II error probability (Power = 1 - beta; traditionally set at .1 or .2) -* **f.A** the *f* effect size of Factor A -* **f.B** the *f* effect size of Factor B -* **B** Iteration times, default is 100 - -We need to convert our effect size ($\eta^2$) for the *interaction* to $f$ effect size (this is not the same as the *F* test). The *effectsize* package has a series of converters. We can use the *eta2_to_f()* function. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -effectsize::eta2_to_f(0.097) #FactorA -- Dept -effectsize::eta2_to_f(0.160) #Factor B -- Stage -effectsize::eta2_to_f(0.085) #interaction -``` - -The size.A and size.B are the sample size per group within the factor. Because ours differ, i divided the N by the number of groups. -```{r} -112/2 -112/3 -112/6 -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr2::pwr.2way(a = 2, b = 3, alpha = 0.05, size.A = 56, size.B = 37, f.A = 0.3277495, f.B = 0.4364358) -``` -At 100% (Dept), 100 (Stage), and 100% (interaction), our power to detect statistically significant main and interaction effects was strong - -I will use a different function to estimate what sample size would be sufficiently powerful. In this syntax: - -* beta is the Type II error probability (Power = 1-beta); usually set at 80 -* B is the iteration times, the default is 100 - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr2::ss.2way(a = 2, b = 3, alpha = 0.05, beta = 0.8, f.A = 0.3277495, f.B = 0.4364358, B = 100) -``` -```{r} -18*3 -``` -This recommends a sample size of 54; 18 in each group. - -### Hand Calculations - -Before we continue: - ->You may notice that the results from the hand calculation are slightly different from the results I will obtain with the R packages. This is because the formula we have used for the hand-calculations utilizes an approach to calculating the sums of squares that presumes that we have a balanced design (i.e., that the cell sizes are equal). When cell sizes are unequal (i.e., an unbalanced design) the Type II package in *rstatix::anova_test* will produce different result. - -> Should we be concerned? No (and yes). My purpose in teaching hand calculations is for creating a conceptual overview of what is occurring in ANOVA models. If this lesson was a deeper exploration into the inner workings of ANOVA, we would take more time to understand what is occurring. My goal is to provide you with enough of an introduction to ANOVA that you would be able to explore further which sums of squares type would be most appropriate for your unique ANOVA model. - -#### Calculate sums of squares total (SST) for the omnibus ANOVA. Steps in this calculation must include calculating a grand mean and creating variables representing the mean deviation and mean deviation squared {-} - -Here is the formula I will use for calculating the sums of squares total: $$SS_{T}= \sum (x_{i}-\bar{x}_{grand})^{2}$$ - -I will use *psych::describe()* to obtain the overall mean: - -```{r} -psych::describe(TwoWay_df) -``` - -The overall (grand) mean is 4.06. - -I will create a variable that represents the mean deviation: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -TwoWay_df <- TwoWay_df %>% - dplyr::mutate(m_dev = TradPed - 4.06) - -head(TwoWay_df) -``` - -Now I will square the mean deviation: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -TwoWay_df <- TwoWay_df %>% - mutate(m_devSQ = m_dev^2) -head(TwoWay_df) -``` - -SST is the sum of the mean deviation squared values: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SST <- sum(TwoWay_df$m_devSQ, na.rm=TRUE) -SST -``` -Our sums of squares total is 83.0332 - - -#### Calculate the sums of squares for the model (SSM) for the omnibus ANOVA. A necessary step in this equation is to calculate group means for all combinations of the levels in the factorial design {-} - -Here is the formula for calculating SSM: $$SS_{M}= \sum n_{k}(\bar{x}_{k}-\bar{x}_{grand})^{2}$$ - -The formula indicates that we need: - -* *n* (sample size for each group) -* Group means -* Grand mean (earlier we learned it was 4.06) - -I will obtain group means and $n$s with *psych::desribeBy*. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describeBy(TradPed ~ Dept + Stage, mat = TRUE, data = TwoWay_df, digits = 3) -``` - -To calculate it: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SSM <- 25 * (4.832 - 4.06)^2 + 25 * (3.864 - 4.06)^2 + 26 * (3.769 - 4.06)^2 + - 15 * (3.560 - 4.06)^2 + 10 * (4.010 - 4.06)^2 + 11 * (4.145 - 4.06)^2 -SSM -``` -Sums of squares for the model is 21.91618. - -#### Calculate the sums of squares residual (SSR) for the omnibus ANOVA. A necessary step in this equation is to calculate the variance for each group {-} - -I will use the following formula to calculate SSR: $$SS_{R}= s_{group1}^{2}(n-1) + s_{group2}^{2}(n-1) + s_{group3}^{2}(n-1) + s_{group4}^{2}(n-1) + s_{group5}^{2}(n-1) + s_{group6}^{2}(n-1))$$ - -This requires: - -* *n* (sample size for each group) -* group variance (I can square the standard deviation for each group) - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SSR <- ((0.236^2)*(25-1))+ ((0.582^2)*(25-1)) + ((0.878^2)*(26-1)) + ((1.338^2)*(15-1)) + ((0.578^2)*(10-1)) + ((0.658^2)*(11-1)) -SSR -``` -Our sums of squares for the residual is 61.13799. - -#### Calculate sums of squares model (SSM) for each of the factors in the model {-} - -**SSM for the Department main effect:** - -Reminder of the formula: $SS_{a:Dept}= \sum n_{k}(\bar{x}_{k}-\bar{x}_{grand})^{2}$ - -Earlier I learned the grand mean = 4.06 - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describeBy(TradPed ~ Dept, mat=TRUE, data = TwoWay_df, digits=3) -``` -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SSM_dept <- 61 * (4.244 - 4.06)^2 + 51 * (3.835 - 4.06)^2 -SSM_dept -``` -Sums of squares model for the department factor is 4.647091. - -**SSM for the Stage main effect:** - -Reminder of the formula: $SS_{a:Stage}= \sum n_{k}(\bar{x}_{k}-\bar{x}_{grand})^{2}$ - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describeBy(TradPed ~ Stage, mat=TRUE, data = TwoWay_df, digits=3) -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SSM_stage <- 50 * (4.348 - 4.06)^2 + 42 * (3.693 - 4.06)^2 + 32 * (4.081 - 4.06)^2 -SSM_stage -``` -Sums of squares model for the stage factor is 9.81825 - -**SSM for the Department x Stage interaction term:** - -I can calculate the SSM for the interaction term with this formula: $SS_{axb} = SS_M - (SS_a + SS_b)$ - - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SSM_int <- 21.91618 - (4.647091 + 9.81825) -SSM_int -``` - -#### Create a source table that includes the sums of squares, degrees of freedom, mean squares, *F* values, and *F* critical values {-} - -It is easiest for me when I put these in a table. - -|Summary ANOVA for TradPed as a Function of Dept & Stage -|:-------------------------------------------------------| - -|Source |SS |df |$MS = \frac{SS}{df}$ |$F = \frac{MS_{source}}{MS_{resid}}$ |$F_{CV}$| -|:---------|:--------|:----------|:------|:------|:------| -|Model |21.916 |5 |4.383 |7.596 |2.300 | -|a:Dept |4.647 |1 |4.647 |8.054 |3.931 | -|b:Stage |9.818 |2 |4.909 |8.508 |3.082 | -|aXb |7.451 |2 |3.726 |6.458 |3.082 | -|Residual |61.138 |106 |0.577 | | | -|Total |83.033 | | | | | - -Main effect for department: $F(1, 106) = 8.054, p < 0.05$ -Main effect for stage: $F(2, 106) = 8.508, p < 0.05$ -Interaction effect: $F(2, 106) = 6.458, p < 0.05$ - -You may notice that these calculations don't exactly follow the rules of the lecture. For example, The "model and "residual" should equal the total. I believe this is because there are different cell sizes which causes an unbalanced design and throws off the otherwise perfect calculations. This issue of unbalanced design is an important one in ANOVA. - -Checking to see if my sums of squares a, b, and axb equal the SSM; and that SSM + SSR = SST. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -21.916 + 61.138 -(4.647 + 9.818 + 7.451) + 61.138 -4.647 + 9.818 + 7.451 -``` -Below are the calculations for the mean square values: -```{r} -21.916 /5 -4.647/1 -9.818/2 -7.451/2 -61.138/106 -``` -Below are the calculations for the *F* tests: - -```{r} -4.383/0.577 -4.647/0.577 -4.909/0.577 -3.726/0.577 -``` -Looking up the *F* critical values (requires alpha level and degrees of freedom for the numerator and denominator [model and residual]): - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -qf(0.05, 5, 106, lower.tail = FALSE) #omnibus -qf(0.05, 1, 106, lower.tail = FALSE) #Dept main effect -qf(0.05, 2, 106, lower.tail = FALSE) #Stage main effect -qf(0.05, 2, 106, lower.tail = FALSE) #interaction term -``` - -#### Are the *F*-tests for the main and interaction effects statistically significant? Why or why not? {-} - -In the hand calculations, the main and interaction effects are significant when the *F* value exceeds the *F* critical value. All three are. - -#### Calculate and interpret the $\eta^2$ effect sizes for the main and interaction effects {-} - -The formula for eta squared is: - -$$\eta ^{2}=\frac{SS_{M}}{SS_{T}}$$ - -The values of .01, .06, and .14 are considered small, medium, and large in ANOVA models. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -4.647/83.033 #eta squared for department main effect -9.818/83.033 #eta squared for stage main effect -7.451/83.033 #eta squared for interaction effect -``` - -The $\eta ^{2}$ values are 0.056 (medium), 0.118 (medium-to-large), and 0.090 (medium-to-large) for the department, stage, and interaction effects, respectively. - -#### Assemble the results into their statistical strings {-} - -Main effect for department: $F(1, 106) = 8.054, p < 0.05, \eta ^{2} = 0.056$ -Main effect for stage: $F(2, 106) = 8.508, p < 0.05, \eta ^{2} = 0.118$ -Interaction effect: $FF(2, 106) = 6.458, p < 0.05, \eta ^{2} = 0.090$ \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/B52A1CC1-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/B52A1CC1-contents deleted file mode 100644 index bcfbd529..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/B52A1CC1-contents +++ /dev/null @@ -1,220 +0,0 @@ -```{r include = FALSE} -options(scipen=999) -``` - -## Homeworked Example - -[Screencast Link](https://youtu.be/qtA-tkDma3Q) - -For more information about the data used in this homeworked example, please refer to the description and codebook located at the end of the [introduction](ReCintro). - -The one-sample test comes in handy when you want to compare your dataset to an external benchmark or standard. It can be a real helper in program evaluation - -### Working the Problem with R and R Packages - -#### Narrate the research vignette, describing the variables and their role in the analysis {-} - -From my course evaluation data, I want to ask the question, "Are ratings for the Overall Instructor for the ANOVA course evals statistically significantly different from the overall departmental averages for that same item?" In CPY the overall average for that specific item is 4.4. - -*If you wanted to use this example and dataset as a basis for a homework assignment, you could select a different course (i.e., Multivariate or Psychometrics) and/or compare the mean for the ORG department ($M = 4.1$).* - -#### Simulate (or import) and format data {-} - -First I will open the entire dataset. -```{r} -ReCdf <- readRDS("ReC.rds") -``` - -Let's first trim it to just students who took ANOVA -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -JustANOVA <- subset(ReCdf, Course == "ANOVA") -``` - -And further trim to our variable of interest -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -tiny1 <- JustANOVA %>% - dplyr::select (OvInstructor) -``` - -And further trim to non-missing data -```{r} -tiny1 <- na.omit(tiny1) -``` - -* Is the sample variable on a continuous scale of measurement and formatted as *num* or *int* in R? -* Is the external score evaluated on the same continuous scale? -```{r} -str(tiny1$OvInstructor) -``` -Yes. The format for the OvInstructor variable is integer (which is numerical); the overall course evaluation is on an equivalent (1 to 5) scale. - - -#### Evaluate statistical assumptions {-} - -* Are the skew and kurtosis values within the range expected? -* Does the distribution of the variable differ significantly from a normal distribution? - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pastecs::stat.desc(tiny1$OvInstructor, norm=TRUE) -``` -The skew value is -9.84 and far exceeds the absolute value of 3. The skew.2SE is -2.164 (larger than the absolute value of 2.0) is consistent. Thus, we might have some concern about skew. - -The kurtosis value is -7.410 and is below the absolute value of 10. The kurt.2SE value is -8.212 which is substantially larger than the absolute value of 2.0. Thus, we are similarly concerned about kurtosis. - -The Shapiro Wilk test value is 7.728 (*p* < 0.001). This significant value suggests a distribution that is not normally distributed. - - -#### Conduct a one sample *t* test (with an effect size) {-} - -We will compare the overall instructor from the data to the CPY average of 4.4. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::t_test(tiny1, OvInstructor ~ 1, mu = 4.4, detailed = TRUE) -``` -We can begin to create our *t* string: - -$t(112) = -2.246, p = 0.027, CI95(3.997, 4.374)$ - -Let's interpret the results. With 112 degrees of freedom, our *t* value is -2.245. Because the *p* value is less than .05, this is statistically significant. This means that my course evaluations in ANOVA were statistically significantly lower than the average for CPY. We are 95% confident that the true course evaluation mean (for my courses) fell between 3.997 and 4.374. - -Let's calculate the effect size. We will use a Cohen's *d* which is interpreted in standard deviation units. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::cohens_d(tiny1, OvInstructor ~ 1, ref.group = NULL, mu = 4.4) -``` -Cohen's *d* was 0.211. This is a small effect. We can add it to the *t* string. - -$t(112) = -2.246, p = 0.027, CI95(3.997, 4.374), d = -0.211$ - - -#### APA style results with table(s) and figure {-} - -* t-test results should include t, df, p, d-or-eta, and CI95% -* Table -* Figure -* Grammar/style - ->A one-sample *t*-test was used to evaluate whether the *overall instructor* course evaluation ratings from the ANOVA courses were statistically significant different from the departmental averages for the Clinical (CPY; *M* = 4.4) department. The sample mean for the ANOVA course evaluations was 4.186 (*SD* = 1.013). Although this mean was statistically significantly different from the average CPY course evaluation ratings of the same item, $t(112) = -2.246, p = 0.027, CI95(3.997, 4.374)$, the effect size was quite small $(d = -0.211)$. A distribution of the ANOVA course ratings is found in Figure 1. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ggpubr::ggboxplot(tiny1$OvInstructor, ylab = "Course Evaluation Ratings", xlab = FALSE, add = "jitter", title = "Figure 1. Overall Instructor Ratings for ANOVA") -``` - -#### Conduct power analyses to determine the power of the current study and a recommended sample size {-} - -A quick reminder that the *d* in the power analysis is the difference between the means divided by the pooled standard deviation. This is the same as Cohen's d that we just calculated. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.t.test(d = -0.211 , n = 113, power = NULL, sig.level = 0.05, type = "one.sample", alternative = "two.sided") -``` - -For the comparison to the CPY departmental average, power was 60%. That is, given the value of the mean difference relative to the pooled standard deviation we had a 60% chance of detecting a statistically significant effect if there was one. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.t.test(d = -0.211, n = NULL, power = 0.8, sig.level = 0.05, type = "one.sample", alternative = "two.sided") -``` -For the CPY departmental comparison, the recommended sample size would be 178. This means there would need to be 178 individuals to find a statistically significant difference, if one existed (at a power of 80%). - -### Hand Calculations - -#### Using traditional NHST (null hypothesis testing language), state your null and alternative hypotheses {-} - -$$ -\begin{array}{ll} -H_0: & \mu = 4.4 \\ -H_A: & \mu \neq 4.4 -\end{array} -$$ - -#### Calculate the mean of your sample; identify the mean of your benchmarking sample {-} - -I will continue with the *tiny1* dataset and calculate the mean of the OvInstructor variable from my ANOVA course evaluations. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -mean(tiny1$OvInstructor, na.rm=TRUE) -``` - -The mean of my benchmarking sample is 4.4. This number is a "departmental standard" and did not need to be calculated by me for this purpose. - -#### Using the steps from the previous lesson, hand-calculate the standard deviation of your sample. This should involve variables representing the mean, mean deviation, and mean deviation squared {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#first the mean -tiny1$M_OvInst <- mean(tiny1$OvInstructor, na.rm=TRUE) -#second the mean deviation -tiny1$Mdev_OvInst <- (tiny1$OvInstructor-tiny1$M_OvInst) -#third the mean deviation squared -tiny1$mdev2_OvInst <- (tiny1$Mdev_OvInst * tiny1$Mdev_OvInst) -#fourth the variance -var_OvInst <- sum(tiny1$mdev2_OvInst /((nrow(tiny1) - 1))) -var_OvInst -#finally the standard deviation -sd_OvInst <- sqrt(var_OvInst) -sd_OvInst - -head(tiny1) -``` -The variance is 1.028; the standard deviation is 1.014. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -sd(tiny1$OvInstructor)#checking my work -``` - -#### Calculate the one-sample *t*-test {-} - -Here's the formula: - -$$ -t = \frac{\bar{X} - \mu}{\hat{\sigma}/\sqrt{N} } -$$ - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -(4.185841 - 4.4)/(1.013733/sqrt(113)) -``` - -#### Identify the degrees of freedom associated with your *t*-test {-} - -For the one-sample *t*-test, $df = N - 1$. In our case - -```{r} -113 - 1 -``` - -#### Locate the test critical value for your test {-} -We can use a table of critical values for the one sample *t*-test: https://www.statology.org/t-distribution-table/ - -A 2-tail test, when p - .05, with ~120 individuals is 1.98 - -Or, this code: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -qt(p = 0.05/2, df = 112, lower.tail = FALSE) -``` -#### Is the *t*-test statistically significant? Why or why not? {-} - -Yes *t* = -2.245701 exceeds the (absolute) test critical value of 1.98. - -#### What is the confidence interval around your sample mean? {-} - -Here is a reminder of the formula: - -$$\bar{X} \pm t_{cv}(\frac{s}{\sqrt{n}})$$ - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -(4.185841) - ((1.98118)*(1.013733/sqrt(113))) -(4.185841) + ((1.98118)*(1.013733/sqrt(113))) -``` - -We are 95% confident that the sample mean for the students in the ANOVA classes is between 3.997, 4.375. - -#### Calculate the effect size (i.e., Cohen's *d* associated with your *t*-test {-} - -A reminder of the two formula: - -$$d = \frac{Mean Difference}{SD}=\frac{t}{\sqrt{N}}$$ -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#First formula -(4.185841 - 4.4)/1.013733 -#Second formula --2.245701/sqrt(113) -``` diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/B561ADE4-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/B561ADE4-contents deleted file mode 100644 index 6e4eb905..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/B561ADE4-contents +++ /dev/null @@ -1,115 +0,0 @@ -# One-Way Repeated Measures with a Multivariate Approach {-} - -```{r include=FALSE} -knitr::opts_chunk$set(echo = TRUE) -knitr::opts_chunk$set(comment = NA) #keeps out the hashtags in the knits -options(scipen=999)#eliminates scientific notation -``` - -As noted in the lesson on [one-way repeated measures ANOVA](#Repeated), the researcher can use a univariate or multivariate approach to analyzing the data. The *rstatix::anova_test()* is limited to the univariate approach. In order to maintain a streamlined chapter with minimal distractions to student learning I have chosen to provide a quick and separate demonstration of the multivariate approach in this appendix. In-so-doing, I will use the *car* package. - -As a quick reminder, I will describe and resimulate the data. The narration will presume familiarity with the [one-way repeated measures ANOVA](#Repeated) lesson. - -## Research Vignette {-} - -Amodeo [@amodeo_empowering_2018] and colleagues conducted a mixed methods study (qualitative and quantitative) to evaluate the effectiveness of an empowerment, peer-group-based, intervention with participants (*N* = 8) who experienced transphobic episodes. Focus groups used qualitative methods to summarize emergent themes from the program (identity affirmation, self-acceptance, group as support) and a one-way, repeated measures ANOVA provided evidence of increased resilience from pre to three-month followup. - -Eight participants (seven transgender women and one genderqueer person) participated in the intervention. The mean age was 28.5 (*SD* = 5.85). All participants were located in Italy. - -The within-subjects condition was wave, represented by T1, T2, and T3: - -* T1, beginning of training -* Training, three 8-hour days, - - content included identity and heterosexism, sociopolitical issues and minority stress, resilience, and empowerment -* T2, at the conclusion of the 3-day training -* Follow-up session 3 months later -* T3, at the conclusion of the +3 month follow-up session - -The dependent variable (assessed at each wave) was a 14-item resilience scale [@wagnild_development_1993]. Items were assessed on a 7-point scale ranging from *strongly disagree* to *strongly agree* with higher scores indicating higher levels of resilience. An example items was, "I usually manage one way or another." - -### Data Simulation {-} - -Below is the code I used to simulate data. The following code assumes 8 participants who each participated in 3 waves (pre, post, followup). The sript produces "long" and "wide" forms are created. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -set.seed(2022) -#gives me 8 numbers, assigning each number 3 consecutive spots, in sequence -ID<-factor(c(rep(seq(1,8),each=3))) -#gives me a column of 24 numbers with the specified Ms and SD -Resilience<-rnorm(24,mean=c(5.7,6.21,6.26),sd=c(.88,.79,.37)) -#repeats pre, post, follow-up once each, 8 times -Wave<-rep(c("Pre","Post", "FollowUp"),each=1,8) -Amodeo_long<-data.frame(ID, Wave, Resilience) - -Amodeo_long$Wave <- factor(Amodeo_long$Wave, levels = c("Pre", "Post", "FollowUp")) - -# Create a new df (Amodeo_wide) -# Identify the original df -# We are telling it to connect the values of the Resilience variable its respective Wave designation -Amodeo_wide <- reshape2::dcast(data = Amodeo_long, formula =ID~Wave, value.var = "Resilience") -#doublecheck to see if they did what you think -str(Amodeo_wide) -Amodeo_wide$ID <- factor(Amodeo_wide$ID) -``` - -## Computing the Omnibus F {-} - -Without the *rstatix* helper package, here is how the analysis would be run in the package, *car.* Although this package is less intuitive to use, it results in both univariate output (both sphericity assumed and sphericity violated) and multivariate output (which does not require the sphericity assumption). - -Evaluating the data requires that we create some objects that will be fed into function. We can name these objects anything we like. - -In ths script below I define the objects that are required. - -* waveLevels is an object that will specify three levels of the independent variable (pre, post, follow-up), -* waveFactor simply makes "waveLevels" a factor -* waveBind column-binds (i.e., cbind) the pre, post, and follow-up variables from the wide form of the Amodeo dataset -* waveModel calculates the intercept (i.e., the means) of the pre, post, and follow-up levels - - -```{r message=FALSE, warning=FALSE, tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#library(car) -waveLevels <- c(1,2,3) -waveFactor <- as.factor(waveLevels) -waveFrame <- data.frame(waveFactor) -waveBind <-cbind(Amodeo_wide$Pre, Amodeo_wide$Post, Amodeo_wide$FollowUp) -waveModel<- lm(waveBind~1) -waveModel - -``` -To run the analysis, we insert these objects into arguments: - -* waveModel is the first argument, -* waveFrame is assigned to the *idata* command, -* waveFactor is assigned to the *idesign* command - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -analysis <-car::Anova(waveModel, idata=waveFrame, idesign=~waveFactor) -summary(analysis) -``` -The *car::Anova()* function produces both univariate and multivariate results. To begin to understand this data, let's start with what we learned in the [one-way repeated measures ANOVA lesson](#Repeated). - -### Univariate Results {-} - -When we ran the univariate approach in the lesson, we first checked the sphericity assumption. Our results here are identical to those from *rstatix::anova_test*. That is, we did not violate the sphericity assumption: Mauchley's test $= .566 p = 0.182$. The *F* test with univariate results was $F(2, 14) = 3.910, p = 0.045$. - ->The Greenhouse Geiser estimate was 0.698 the corrected *p* = .068. ->The Huyhn Feldt estimate was 0.817 and the corrected *p* = .057. - -The univariate ANOVA results are under the "Univariate Type III Repeated-Measures ANOVA Assuming Sphericity" heading. We find the ANOVA output on the row titled, "waveFactor." The results are identical to what we found in the lesson: $F(2,14) = 3.91, p = 0.045$. I do not see that an effect size is reported. - -### Multivariate Results {-} - -Researchers may prefer the multivariate approach because it does not require the sphericity assumption. Stated another way, if the sphericity assumption is violated, researchers can report the results of the multivariate analysis. - -We find the multivariate results in the middle of the output, under the heading, "Multivariate Tests: waveFactor." There are four choices: Pillai, Wilks, Hotelling-Lawley, and Roy. Green and Salkind [-@green_one-way_2017-1] have noted that in the one-way within-subjects ANOVA, all four will yield the same *F* and *p* values. They recommended reporting Wilks' lambda because researchers will have greatest familiarity with it. Thus, I would write up the result of this omnibus test like this: - ->Results of the one-way repeated measures ANOVA indicated a significant wave effect, $Wilks' \lambda = .597, F(2,6) = 2.022, p = 0.213$. - -Because follow-up testing is *pairwise* (i.e., there are only two levels being compared), the sphericity assumption is not required and those could proceed in the manner demonstrated in the [one-way repeated measures ANOVA lesson](#Repeated). - -### A Brief Commentary on Wrappers - -As noted several times, because of its relative ease-of-use, the relevance of information included in the results, and its integration with the *ggpubr* package, I chose to use *rstatix* package in all of the ANOVA lessons. As I worked through this example, I spent several hours creating and interpreting the code. For me, there was value in this exercise: - -* I am encouraged and reassured with the consistency of results between the two approaches, -* I am in awe of the power of these programs and a little intimidated by all the options that are available within a given package, and -* I am deeply grateful to package developers who take the time to create packages for discipline-specific use-cases and then freely share their work with others. Thank you [Alboukadel Kassambara](https://github.com/kassambara/rstatix)! \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/B59B3AD9-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/B59B3AD9-contents deleted file mode 100644 index 3268cc12..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/B59B3AD9-contents +++ /dev/null @@ -1,89 +0,0 @@ -```{r include = FALSE} -options(scipen=999) -``` - -## Introduction to the Data Set Used for Homeworked Examples - -[Screencast Link]() - -Each lesson concludes with streamlined example of working the primary statistic from each lesson. This section is intended to be helpful in two ways: - -* The worked example focuses on the operations and interpretations and more closely mimics "how you would work a problem in real life." -* The grading rubric from the end of each lesson serves as the outline for the process. -* This dataset could be used for the practice problems. For homework that you submit for grading, please choose *different variables* than the ones worked in the examples. - -### The Data Set - -The dataset used in the "homeworked" examples is from my own research. Along long with the pre-registration and codebooks, it is publicly available in a [pre-registered repository](https://osf.io/z84kh/) on the Open Science Framework (OSF). I have also provided a copy of it in the [GitHub repository](https://github.com/lhbikos/ReCenterPsychStats/blob/main/Worked_Examples/ReC.rds) that hosts the ReCentering Psych Stats OER. - -This data is from an IRB-approved study. The informed consent of the IRB specified that the data could be used in research as well as in teaching demonstrations and would be made available to the general public. You may notice there are student- and teacher- IDs. These numbers are *not** the institution's identification numbers. Rather, they have been further anonymized. - -The purpose of the research project was to evaluate efforts to recenter – in a socially responsive way – courses in the statistics and research methods sequence in scientist-practitioner psychology (PhD) programs. The recentering occurred in two phases: (a) a transition from SPSS to R and (b) an explicit recentering. Data were from end-of-course evaluations three courses I taught: Research Methods I: Analysis of Variance [ANOVA], Research Methods III: Multivariate Modeling [multivariate], and Research Methods IV: Psychometrics/Theory of Test Construction [psychometrics]) that were offered 2017 through 2022. - -Because students could contribute up to three course evaluations, each, multilevel modeling was used for the primary analyses. The nature of the data, though, allows me to demonstrate all of the statistics utilized the OER with this data. For each analysis, I have tried to derive a sensible question that *could be* answered by the data. In-so-doing, I try to point out when the alignment of research question and statistic is less than ideal. - -The data file is titled *ReC.rds* and can be retrieved with this code: - -```{r} -dfReC <- readRDS("ReC.rds") -``` - -The following can serve as a codebook: - -|Variable |Definition or Description |Scaling| -|:---------------|:----------------------------------------------------|:------------------------| -|deID |Anonymized identification for each student Each student could contribute up to three course evaluations |Nominal/factor | -|CourseID |Unique number for each course taught (i.e., ANOVA has unique numbers across department and year). |Nominal/factor| -|Dept |CPY (Clinical Psychology), ORG (Industrial Organizational Psychology)|Nominal/factor| -|Course |ANOVA (analysis of variance), Multivariate (multivariate modeling), Psychometrics (psychometrics/theory of test construction), taught in that order | Nominal/factor| -|StatsPkg |SPSS, R | Nominal/factor| -|Centering |Pre (before explicit recentering), Re (included explicit recentering) | Nominal/factor| -|Year |Calendar year in which the course was taught |Calendrical time| -|Quarter |Academic term in which course was taught (fall, winter, spring)| Nominal/factor| -|ProgramYear |A potential confound to the study. During the changes from SPSS to R and the explicit recentering, the program was also moving the stats sequence from the second to the first year of the doctoral program. First = course taken during first year; Second = course taken during second year; Transition = course taken during the transition period. | Nominal/factor| -|SPFC.Decolonize.Opt.Out|Students were given the opportunity to exclude their data from analysis. Such data was removed prior to any analysis and not included in this set. | Character| - -COURSE EVALUATION ITEMS; 5-point Likert scaling from 1(*strongly disagree*) to 5(*strongly agree*). Higher scores are more favorable evaluations. - -|Variable |Complete Item | -|:---------------|:-------------------------------------------------------------------| -|IncrInterest |My interest in the subject matter increased over the span of the course.| -|IncrUnderstanding |My understanding of the subject matter increased over the span of the course.| -|ValObjectives |This course has objectives that are valuable in furthering my education.| -|ApprAssignments |This course has had an appropriate workload, given the course objectives.| -|EffectiveAnswers|The instructor has effectively answered student questions.| -|Respectful |The instructor has shown respect to students.| -|ClearResponsibilities|The instructor has made student responsibilities clear.| -|Feedback |The instructor has provided feedback to me about my learning progress.| -|OvInstructor |My overall rating of this instructor for this course is:| -|MultPerspectives|The instructor has helped students consider issues from multiple perspectives, where applicable.| -|OvCourse |My overall rating of the course content is:| -|InclsvClssrm |The instructor has been intentional in fostering an inclusive classroom for students with diverse backgrounds and abilities.| -|DEIintegration |The instructor has, when appropriate, discussed the relationships between race/ethnicity/culture and course content.| -|ClearPresentation|The instructor has presented course material clearly.| -|ApprWorkload |This course has had an appropriate workload, given the course objectives.| -|MyContribution |My overall rating of my contribution in this course is:| -|InspiredInterest|The instructor has inspired student interest in the subject matter of this course.| -|Faith |The instructor has, when appropriate, discussed the relationship between the Christian faith and course content.| -|EquitableEval |The instructor used methods of evaluating student course work that were equitable.| -|ClearOrganization|This course has had a clear overall organization.| -|RegPrepare |I regularly read, reviewed, visited/logged on, or completed assigned readings and tasks.| -|EffectiveLearning|This course has consisted of course activities/tasks that were effective in helping me learn (e.g., discussions, readings, assignments, labs, or other activities).| -|AccessibleInstructor|The instructor has been accessible (e.g., discussion sessions, virtual office hours, phone, chat, email, online forum or conference, etc.).| - -From these variables, I created three scales to assess valued by the student (Valued), traditional pedagogy (TradPed), and socially responsive pedagogy (SRped). I will use these in the demonstrations. - -* **Valued by the student** includes the items: ValObjectives, IncrUnderstanding, IncrInterest - -* **Traditional pedagogy** includes the items: ClearResponsibilities, EffectiveAnswers, Feedback, ClearOrganization, ClearPresentation - -* **Socially responsive pedagogy** includes the items: InclusvClassrm, EquitableEval, MultPerspectives, DEIintegration - -In the examples where the scale scores are used, I provide code for calculating the means. - -Here's how to import the data: - -```{r} -ReCdf <- readRDS("ReC.rds") -``` - diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/CF49F9D1-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/CF49F9D1-contents deleted file mode 100644 index a2d96010..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/CF49F9D1-contents +++ /dev/null @@ -1,271 +0,0 @@ -```{r include=FALSE} -options(scipen=999)#eliminates scientific notation -``` -## Homeworked Example - -[Screencast Link](https://youtu.be/6pkF-tnmNuY) - -For more information about the data used in this homeworked example, please refer to the description and codebook located at the end of the [introduction](ReCintro). - -### Working the Problem with R and R Packages - -#### Narrate the research vignette, describing the IV and DV {-} - -**Minimally, the data should allow the analysis of a 2 x 3 (or 3 X 2) design. At least one of the problems you work should have a significant interaction effect so that follow-up is required.** - -I want to ask the question, what are the effects of intentional recentering on students evaluations of socially responsive pedagogy as they progress through three doctoral courses in statistics. My design is a 3 x 2 ANOVA: - -* Within-subjects factor: student as they progress through ANOVA, multivariate, psychometrics -* Between-subjects factor: recentering status of the class (Pre, Re) -* Continuous DV: SRPed (socially responsive pedagogy) - -*If you wanted to use this example and dataset as a basis for a homework assignment, you could choose a different dependent variable. I chose the socially responsive pedagogy subscale. Two other subscales include traditional pedagogy and valued by the student.* - -#### Simulate (or import) and format data {-} - -First I import the larger dataset. -```{r} -big <- readRDS("ReC.rds") -``` - -The SRPed (socially responsive pedagogy) variable is an average of the items on that scale. I will first create that variable. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Creates a list of the variables that belong to that scale -SRPed_vars <- c('InclusvClassrm', 'EquitableEval','MultPerspectives', 'DEIintegration') - -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -big$SRPed <- sjstats::mean_n(big[, SRPed_vars], .75) - -#if the scoring script won't run, try this one: -#big$SRPed <- sjstats::mean_n(big[, ..SRPed_vars], .75) -``` - -Let's trim it to just the variables of interest -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -mixt_df <- (dplyr::select (big, deID, Course, Centering, SRPed)) -``` - -I want the course variable to be factor that is ordered by its sequence: ANOVA, multivariate, psychometrics. - -I want the centering variable to be ordered: Pre, Re - -```{r} -str(mixt_df) -``` -Because R's default is to order alphabetically, the centering variable is correct. I just need to change the course variable. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -mixt_df$Course <- factor(mixt_df$Course, levels = c("ANOVA", "Multivariate", "Psychometrics")) -str(mixt_df) -``` -After checking the structure again, both are correct. - -I want all of my analyses (i.e., testing of assumptions, descriptives, omnibus F, follow-up) to be with the same dataset. Because each of these analyses will use listwise deletion (i.e., deleting cases, potentially differing numbers, when there is missing data), I will take care of this now. Because this is a longitudinal analysis, I will do it in two steps. - -The current dataset is is in *long* form. This means each student has up to three rows of data. I will first delete rows that have any missing data: - -```{r} -mixt_df <- na.omit(mixt_df) -``` - -This took me from 310 observations to 299. - -These analyses, though, require that students have completed evaluations for all three courses. In the chapter, I restructured the data from long, to wide, back to long again. While this was useful pedagogy in understanding the difference between the two datasets, there is also super quick code that will simply retain data that has at least three observations per student. - -```{r} -library(tidyverse) -mixt_df <- mixt_df%>% - dplyr::group_by(deID)%>% - dplyr::filter(n()==3) -``` - -This took the data to 198 observations. Since each student contributed 3 observations, we know $N = 66$. - -Let's get an a priori peek at what we're doing: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -mixt_box <- ggpubr::ggboxplot(mixt_df, x = "Course", y = "SRPed", color = "Centering", palette = "jco", xlab = "Statistics Sequence", ylab = "Socially Responsive Pedagogy", title = "Socially Responsive Course Evaluations as a Function of Centering and Time", add = "jitter") -mixt_box -``` - -#### Evaluate statistical assumptions {-} - -**Is the dependent variable normally distributed in all combinations of the factors?** - -I can examine skew and kurtosis at the cell level with *psych::describeBy()*. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -mixt_df <- as.data.frame(mixt_df)#my data was not reading as a df so I applied this function -psych::describeBy(SRPed ~ Course + Centering, data = mixt_df, type = 1, mat = TRUE, digits = 3) -``` -Across all 6 conditions: - -* No skew exceeds the threshholds of concern (>3; Kline [2016]) - - the most extreme skew is -1.909 -* No kurtosis exceeds the threshholds of concern (>10; Kline [2016]) - - the most extreme kurtosis is 3.680 - -**Are the model residuals normally distributed?** - -I can use the Shapiro-Wilk test to formally investigate the normality assumption. Examining the distribution of the model residuals is one of the most efficient ways to do this. First, I need to run the model and extract the residuals. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -mixt_mod <- aov(SRPed ~ Course*Centering, mixt_df) -summary(mixt_mod) -``` -We won't look at this yet, but simply focus on testing the assumption of normality. The next step is to extract the residuals. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -mixt_resid <- residuals(mixt_mod) -``` - -The formal test of normality is the Shapiro-Wilk test: - -```{r} -shapiro.test(mixt_resid) -``` -Our test result is $W = 0.859, p < .001.$. The significant *p* value indicates that we have violated the normality assumption. When cell sizes have at least 15 cases each and are roughly equivalent in size, ANOVA models are generally robust to this violation. None-the-less, we should keep it in mind. - -We can plot the residuals to "see" how bad it is: -```{r} -hist(mixt_resid) -``` -Like the data itself, the residuals have a negative skew with a pile-up of scores on the "high" side. - -```{r} -qqnorm(mixt_resid) -``` -Similarly, we see that the residuals sharply deviate from the diagonal at the top. - -**Is there evidence of outliers? Are they extreme?** - -The *rstatix::identify_outliers()* function identifies outliers and extreme outliers. - -```{r} -mixt_df%>% - group_by(Course, Centering)%>% - rstatix::identify_outliers(SRPed) -``` -There are 9 rows of outliers; none are extreme. Cross-referencing back to the boxplot, these are on the low side of evaluations. As an instructor, it seems important to retain the voices that rated socially responsive pedagogy lower than the other students. Although they contribute to non-normality, to exclude them would bias the data in a positive direction. - -**Are the variances of the dependent variable equivalent across all combinations of the factors?** - -I can use the Levene's test with *rstatix::levene_test()*. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -mixt_df %>% - group_by(Course)%>% - rstatix::levene_test(SRPed ~ Centering) -``` -Levene's test indicated a violation of this assumption between the Pre and Re centering conditions in the multivariate class $(F[1, 64] = 4.787, p = 0.032)$. There was no indication of assumption violation for the ANOVA class $(F[1, 64] = 0.176, p = 0.676)$ nor the psychometrics class $(F[1, 64] = 0.320, p = 0.573)$. - -Before moving on I will write up the portion of the APA results section that evaluates the assumptions: - ->We conducted a 2 X 3 mixed design ANOVA to evaluate students' evaluations of social responsive pedagogy as a function of centering stage (i.e., pre-centered and re-centered) across three doctoral statistics courses in professional psychology (i.e., ANOVA, multivariate, psychometrics; taught in that order). - ->Mixed design ANOVA has a numer of assumptions related to both the within-subjects and between-subjects elements. Data are expected to be normaly distributed at each level of the design. Relative to the thresholds identified by Kline [-@kline_data_2016] there was no evidence of skew (all values were at or below the absolute value of 1.909) and kurtosis (all values were below the absolute value of 3.680). The Shapiro-Wilk test applied to model residuals provided a formal test of normality. The test result was $W = 0.859, p < .001.$ and indicated a violation of the the normality assumption. Visual inspection of boxplots for each wave of the design, assisted by the rstatix::identify_outliers() function (which reports values above Q3 + 1.5xIQR or below Q1 - 1.5xIQR, where IQR is the interquartile range) indicated 9 outliers; none of these at the extreme level. All outliers were among the lowest student ratings of socially responsive pedagogy. We determined that it was important that the dataset retain these perspectives. - -> Regardin the homogeneity of variance assumption, Levene's test indicated a violation between the pre- and re- centering conditions in the multivariate class $(F[1, 64] = 4.787, p = 0.032)$. There was no indication of assumption violation for the ANOVA class $(F[1, 64] = 0.176, p = 0.676)$ nor the psychometrics class $(F[1, 64] = 0.320, p = 0.573)$. PLACEHOLDER FOR SPHERICITY ASSUMPTION. - -#### Conduct omnibus ANOVA (w effect size) {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::anova_test(data = mixt_df, dv = SRPed, wid = deID, between = Centering, within = Course) -``` -Because Course is a repeated measures factor, we evaluate Mauchly's test for the main $(W = 0.919, p = 0.098)$ and interaction $(W = 0.919, p = 0.098)$ effects. Neither was statistically significant, meaning we did not violate the sphericity assumption. - -Let's write the F strings from the above table: - -* Centering main effect: $F(1, 56) = 0.000, p = 0.988, \eta^2 = 0.000$ -* Course effect: $F(2, 112) = 0.550, p = 0.578, \eta^2 = 0.003$ -* Interaction effect: $F(2, 112) = 8.547, p = 0.001, \eta^2 = 0.039$ - ->Regarding the omnibus ANOVA, neither the main effect for centering stage $(F[1, 56] = 0.000, p = 0.988, \eta^2 = 0.000)$ nor course $(F[2, 112] = 0.550, p = 0.578, \eta^2 = 0.003)$. However there was a statistically significant centering x course interaction effect $(F[2, 112] = 8.547, p = 0.001, \eta^2 = 0.039)$. - -#### Conduct one set of follow-up tests; narrate your choice {-} - -With a significant interaction effect, we will want to follow-up with an analysis of simple main effects. I think I am interested in the simple main effects for centering within each of the courses. Because there are two levels of Centering (pre, re) within each of the courses, I can go straight to *t*-tests. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -Simple_Course <- mixt_df%>% - group_by(Course)%>% - rstatix::t_test(SRPed ~ Centering, detailed = TRUE, p.adjust.method = "none")%>% - rstatix::add_significance() -Simple_Course -``` - -I also want effect sizes (Cohen's *d*): - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -mixt_df%>% - group_by(Course)%>% - rstatix::cohens_d(SRPed ~ Centering) -``` - ->We followed the significant interaction effect with an evaluation of simple main effects of centering within course. Because there were only three comparisons following the omnibus evaluation, we used the LSD method (i.e., no additional control) to control for Type I error and left the alpha at .05 (Green & Salkind, 2014b). While there were non-statistically significant difference between pre- and re-centered conditions in the ANOVA $(MDiff = 0.095; t[56.04] = 0.652, p = 0.517, d = 0.162)$ and psychometrics $(MDiff = 0.136; t[60.23 = 0.944, p = 0.349, d = 0.233)$ courses, there was a statistically significant difference in the multivariate course $(MDiff = -0.311; t[61.53] = -2.294, p = 0.025, d = -0.558)$ which suggested an increase in ratings of socially responsive pedagogy. - -#### Describe approach for managing Type I error {-} - -Because there were only three comparisons following the omnibus evaluation, I used the LSD method to control for Type I error and retained the alpha at .05 (Green & Salkind, 2014b). - -#### APA style results with table(s) and figure {-} - ->We conducted a 2 X 3 mixed design ANOVA to evaluate students' evaluations of social responsive pedagogy as a function of centering stage (i.e., pre-centered and re-centered) across three doctoral statistics courses in professional psychology (i.e., ANOVA, multivariate, psychometrics; taught in that order). - ->Mixed design ANOVA has a numer of assumptions related to both the within-subjects and between-subjects elements. Data are expected to be normaly distributed at each level of the design. Relative to the thresholds identified by Kline [-@kline_data_2016] there was no evidence of skew (all values were at or below the absolute value of 1.909) and kurtosis (all values were below the absolute value of 3.680). The Shapiro-Wilk test applied to model residuals provided a formal test of normality. The test result was $W = 0.859, p < .001.$and indicated a violation of the the normality assumption. Visual inspection of boxplots for each wave of the design, assisted by the rstatix::identify_outliers() function (which reports values above Q3 + 1.5xIQR or below Q1 - 1.5xIQR, where IQR is the interquartile range) indicated 9 outliers; none of these at the extreme level. All outliers were among the lowest student ratings of socially responsive pedagogy. We determined that it was important that the dataset retain these perspectives. - -> Regardin the homogeneity of variance assumption, Levene's test indicated a violation between the pre- and re- centering conditions in the multivariate class $(F[1, 64] = 4.787, p = 0.032)$. There was no indication of assumption violation for the ANOVA class $(F[1, 64] = 0.176, p = 0.676)$ nor the psychometrics class $(F[1, 64] = 0.320, p = 0.573)$. Mauchly's test indicated no violation of the sphericity asssumption $(W = 0.919, p = 0.098)$, therefore we proceeded normally. - ->Regarding the omnibus ANOVA, neither the main effect for centering stage $(F[1, 56] = 0.000, p = 0.988, \eta^2 = 0.000)$ nor course $(F[2, 112] = 0.550, p = 0.578, \eta^2 = 0.003)$. However there was a statistically significant centering x course interaction effect $(F[2, 112] = 8.547, p = 0.001, \eta^2 = 0.039)$. - ->We followed the significant interaction effect with an evaluation of simple main effects of centering within course. Because there were only three comparisons following the omnibus evaluation, we used the LSD method (i.e., no additional control) to control for Type I error and left the alpha at .05 (Green & Salkind, 2014b). While there were non-statistically significant difference between pre- and re-centered conditions in the ANOVA $(MDiff = 0.095; t[56.04] = 0.652, p = 0.517, d = 0.162)$ and psychometrics $(MDiff = 0.136; t[60.23 = 0.944, p = 0.349, d = 0.233)$ courses, there was a statistically significant difference in the multivariate course $(MDiff = -0.311; t[61.53] = -2.294, p = 0.025, d = -0.558)$ . - -A quick way to produce a table of means and standard deviations for mixed design ANOVA is this: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -apaTables::apa.2way.table(iv1=Course, iv2=Centering, dv=SRPed, data=mixt_df, filename = "Mixed_Table.doc", table.number = 1) -``` - -I can update my figure with star bars: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -Simple_Course <- Simple_Course %>% - rstatix::add_xy_position(x = "Course") -mixt_box <- mixt_box + ggpubr::stat_pvalue_manual(Simple_Course, label = "p.signif", tip.length = 0.02, hide.ns = TRUE, y.position = c(5.3)) -mixt_box -``` - -#### Conduct power analyses to determine the power of the current study and a recommended sample size {-} - -In the *WebPower* package, we specify 6 of 7 interrelated elements; the package computes the missing element - -* *n* = sample size (number of individuals in the whole study) -* *ng* = number of groups -* *nm* = number of repeated measurements (i.e., waves) -* *f* = Cohen's *f* (an effect size; we can use a conversion calculator); Cohen suggests that f values of 0.1, 0.25, and 0.4 represent small, medium, and large effect sizes, respectively -* *nscor* = the Greenhouse Geiser correction from our ouput; 1.0 means no correction was needed and is the package's default; < 1 means some correction was applied -* *alpha* = is the probability of Type I error; we traditionally set this at .05 -* *power* = 1 - P(Type II error) we traditionally set this at .80 (so anything less is less than what we want) -* *type* = 0 is for between-subjects, 1 is for repeated measures, 2 is for interaction effect; in a mixed design ANOVA we will select "2" - -As in the prior lessons, we need to convert our effect size for the *interaction* to $f$ effect size (this is not the same as the *F* test). The *effectsize* package has a series of converters. We can use the *eta2_to_f()* function to translate the $\eta^{2}$ associated with the interaction effect to Cohen's *f*. - - -```{r message=FALSE, warning = FALSE, tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#include effect size from the interaction effect -effectsize::eta2_to_f(0.039) -``` -We can now retrieve information from our study (including the Cohen's *f* value we just calculated) and insert it into the script for the power analysis. -```{r message=FALSE, warning = FALSE, tidy=TRUE, tidy.opts=list(width.cutoff=70) } -WebPower::wp.rmanova(n=66, ng=2, nm=3, f = 0.2014515, nscor = .925, alpha = .05, power = NULL, type = 2) -``` -We are powered at .274 (we have a 27% of rejecting the null hypothesis, if it is true) - -In reverse, setting *power* at .80 (the traditional value) and changing *n* to *NULL* yields a recommended sample size. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -WebPower::wp.rmanova(n=NULL, ng=2, nm=3, f = 0.2014515, nscor = .925, alpha = .05, power = .80, type = 2) -``` -Given our desire for strong power and our weak effect size, this power analysis suggests a sample size of 252 participants is required to be adequately powered (80%) to detect a significant interaction effect. \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/CFEE46D1-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/CFEE46D1-contents deleted file mode 100644 index eff8a09d..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/CFEE46D1-contents +++ /dev/null @@ -1,304 +0,0 @@ -# Ready_Set_R {#Ready} - -[Screencasted Lecture Link](https://youtube.com/playlist?list=PLtz5cFLQl4KPVmAkrTNyX_3VuVlPP1cXB) - -```{r include=FALSE} -knitr::opts_chunk$set(echo = TRUE) -knitr::opts_chunk$set(comment = NA) #keeps out the hashtags in the knits -options(scipen=999)#eliminates scientific notation -``` - -With the goal of creating a common, system-wide approach to using the platform, this lesson was originally created for Clinical and Industrial-Organizational doctoral students who are entering the "stats sequence." I hope it will be useful for others (e.g., faculty, post-doctoral researchers, and practitioners) who are also making the transition to R. - -## Navigating this Lesson - -There is about 45 minutes of lecture. - -While the majority of R objects and data you will need are created within the R script that sources the chapter, occasionally there are some that cannot be created from within the R framework. Additionally, sometimes links fail. All original materials are provided at the [Github site](https://github.com/lhbikos/ReCenterPsychStats) that hosts the book. More detailed guidelines for ways to access all these materials are provided in the OER's [introduction](#ReCintro) - -### Learning Objectives - -Learning objectives from this lecture include the following: - -* Downloading/installing R's parts and pieces. -* Using R-Markdown as the interface for running R analyses and saving the script. -* Recognizing and adopting best practices for "R hygiene." -* Identifying effective strategies for troubleshooting R hiccups. - -## downloading and installing R - -### So many paRts and pieces - -Before we download R, it may be helpful to review some of R's many parts and pieces. - -The base software is free and is available [here](https://www.r-project.org/) - -Because R is already on my machine (and because the instructions are sufficient), I will not walk through the demo, but I will point out a few things. - -* The "cran" (I think "cranium") is the *Comprehensive R Archive Network.* In order for R to run on your computer, you have to choose a location -- and it should be geographically "close to you." - + Follow the instructions for your operating system (Mac, Windows, Linux) - + You will see the results of this download on your desktop (or elsewhere if you chose to not have it appear there) but you won't ever use R through this platform. -* [R Studio](https://www.rstudio.com/products/RStudio/) is the way in which we operate R. It's a separate download. Choose the free, desktop, option that is appropriate for your operating system: -* *R Markdown* is the way that many analysts write *script*, conduct analyses, and even write up results. These are saved as .rmd files. - + In R Studio, open an R Markdown document through File/New File/R Markdown - + Specify the details of your document (title, author, desired ouput) - + In a separate step, SAVE this document (File/Save] into a NEW FILE FOLDER that will contain anything else you need for your project (e.g., the data). - + *Packages* are at the heart of working in R. Installing and activating packages require writing script. - -**Note** If you are working on an *enterprise-owned machine* (e.g,. in my specific context, if you are a faculty/staff or have a lab with institution-issued laptops) there can be complications caused by how documents are stored. In recent years we have found that letting the computer choose where to load base R, R Studio, and the packages generally works. The trick is to save R projects (i.e., folder with .rmd files and data) into the OneDrive folder that syncs to your computer. If you have difficulty knitting that is unrelated to code/script (which you can evaluate by having a classmate or colleague successfully knit on their machine), it is likely because you have saved the files to the local hard drive and not OneDrive. If you continue to have problems I recommend consulting with your computer and technology support office. - -### oRienting to R Studio (focusing only on the things we will be using first and most often) - -R Studio is organized around four panes. These can be re-sized and rearranged to suit your personal preferences. - -* Upper right window - + Environment: lists the *objects* that are available to you (e.g., dataframes) -* Lower right window - + *Files*: Displays the file structure in your computer's environment. Make it a practice to (a) organize your work in small folders and (b) navigate to that small folder that is holding your project when you are working on it. - + *Packages*: Lists the packages that have been installed. If you navigate to a specific package, you will know if it is "on" because its box is checked. You can also access information about the package (e.g., available functions, examples of script used with the package) in this menu. This information opens in the "Help" window. - + The *Viewer* and *Plots* tabs will be useful, later, in some advanced statistics when we can simultaneously examine output and script in windows that are side-by-side. -* Upper left window - + If you are using R Markdown, that file lives here and is composed of open space and chunks. -* Lower left window - + R Studio runs in the Console (the background). Very occasionally, I can find useful troubleshooting information here. - + More commonly, I open my R Markdown document so that it takes up the whole screen. - -## best pRactices - -Many initial problems in R can be solved with good R hygiene. Here are some suggestions for basic practices. It can be tempting to "skip this." However, in the first few weeks of class, these are the solutions I am presenting (and repeating, ad nauseum) to my students. - -### Everything is documented in the .rmd file - -Although others do it differently, I put *everything* in my .rmd file. That is, my R script includes code for importing data and opening packages. Additionally, I make notes about the choices I am making. Relatedly, I keep a "bug log" -- noting what worked and what did not work. I will also begin my APA style results section directly in the .rmd file. - -Why do I do all this? Because when I return to my project hours or years later, I have a permanent record of very critical things like (a) where my data is located, (b) what version I was using, and (c) what package was associated with the functions. - -### Setting up the file - -File organization is a critical key to success. In your computing environment: - -* Create a project file folder. -* Put the data file in it. -* Open an R Markdown file. -* Save it in the same file folder as the data. -* When your data and .rmd files are in the same folder (not your desktop, but a specific folder) the data can be pulled into the .rmd file without creating a working directory. - - -### Script in chunks and everything else in the "inline text" sections - -The R Markdown document is an incredible tool for integrating text, tables, and analyses. This entire OER is written in R Markdown. A central feature of this is "chunks." - -The only thing in the chunks should be script for running R. You can also hashtag comments so they won't run (but you can also write anything you want between chunks without using hashtags). - -Syntax for simple formatting in the text (i.e., non-chunk) areas (e.g., using italics, making headings, bold) is found here: https://rmarkdown.rstudio.com/authoring_basics.html - -"Chunks" start and end with with three tic marks and will show up in a shaded box. Chunks have three symbols in their upper right. Those controls will disappear (and your script will not run) if you have replaced them with double or single quotation marks or one or more of the tics are missing. - -The easiest way to insert a chunk is to use the INSERT/R command at the top of this editor box. You can also insert a chunk with the keyboard shortcut: CTRL/ALT/i - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#hashtags let me write comments to remind myself what I did -#here I am simply demonstrating arithmetic (but I would normally be running code) -2021 - 1966 -``` - -### Managing packages - -As scientist-practitioners (and not coders), we will rely on *packages* to do much of the work. At first you may feel overwhelmed about the large number of packages that are available. Soon, though, you will become accustomed to the ones most applicable to our work (e.g., psych, tidyverse, rstatix, apaTables). - -Researchers treat packages differently. In these lectures, I list all the packages we will use in an opening chunk at the beginning of the lecture. When the hashtags are removed, the script will ask R to check to see if the package is installed on your machine. If it is, installation is skipped. If it is not, R installs it. Simply remove the hashtag to run the code the first time, then hashtag them back out so R is not always re-checking. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#will install the package if not already installed -#if(!require(psych)){install.packages("psych")} -``` - -To make a package operable, you need to open it. There are two primary ways to do this. The first is to use the library function. - -```{r message=FALSE, warning=FALSE} -#install.packages ("psych") -library (psych) -``` - -The second way is to place a double colon between the package and function. This second method has become my preferred practice because it helps me remember what package goes with each function. It can also prevent R hiccups when there are identical function names and R does not know which package to use. Below is an example where I might ask for descriptives from the psych package. Because I have not yet uploaded data, I have hashtagged it out, making the command inoperable. - -```{r} -#psych::describe(mydata) -``` - -There are exceptions. One is the *tidyverse* package. Some of my script uses pipes (%>%) and pipes require *tidyverse* to be activated. This is why you will often see me call the *tidyverse* package with the *library()* function (as demonstrated above.) - - -### Upload the data - -When imported (or simulated) properly, data will appear as an object in the global environment. - -In the context of this OER, I will be simulating data in each lesson for immediate use in the lesson. This makes this web-based OER more *portable.* This also means that when working the problems in the chapter we do notneed to (a) write the data to a file or (b) import data from files. Because these are essential skills, I will demonstrate this process here -- starting with simulating data. - -At this point, simulating data is beyond the learning goals I have established for the chapter. I do need to include the code so that we get some data. The data I am simulating is used in the [one-way ANOVA lesson](#oneway). The data is from the Tran and Lee [-@tran_you_2014] random clinical trial. - -In this simulation, I am simply creating an ID number, a condition (High, Low, Control), and a score on the dependent variable, "Accurate." More information about this study is included in the [one-way ANOVA chapter](#oneway). - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Note, this simulation results in a different datset than is in the OnewayANOVA lesson -#sets a random seed so that we get the same results each time -set.seed(2021) -#sample size, M and SD for each group -Accurate <- c(rnorm(30, mean=1.18, sd=0.80), rnorm(30, mean=1.83, sd = 0.58), rnorm(30, mean = 1.76, sd = 0.56)) -#set upper bound for DV -Accurate[Accurate>3]<-3 -#set lower bound for DV -Accurate[Accurate<0]<-0 -#IDs for participants -ID<-factor(seq(1,90)) -#name factors and identify how many in each group; should be in same order as first row of script -COND<-c(rep("High", 30), rep("Low", 30), rep("Control", 30)) -#groups the 3 variables into a single df: ID, DV, condition -Acc_sim30 <-data.frame(ID, COND, Accurate) -``` - -At this point, this data lives only in this .rmd file after the above code is run. Although there are numerous ways to export and import data, I have a preference for two. - -#### To and from .csv files - -The first is to write the data to a .csv file. In your computer's environment (outside of R), these files are easily manipulated in Excel. I think of them as being "Excel lite" because although Excel can operate them, they lack some of the more advanced features of an Excel spreadsheet. - -In the code below, I identify the R object "Acc_sim30" and give it a file name, "to_CSV.csv". This file name must have the .csv extension. I also indicate that it should preserve the column names (but ignore row names; since we don't have row names). - -This file will save in the same folder as wherever you are using this .rmd file. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#to write it to an outfile as a .csv -write.table(Acc_sim30, file="to_CSV.csv", sep=",", col.names=TRUE, row.names=FALSE) -``` - -Importing this object back into the R environment can be accomplished with some simple code. For the sake of demonstration, - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#to save the df as an .csv (think "Excel lite") file on your computer; it should save in the same file as the .rmd file you are working with -from_CSV <- read.csv ("to_CSV.csv", header = TRUE) -``` - -The advantage of working with .csv files is that it is then easy to inspect and manipulate them outside of the R environment. The disadvantage of .csv files is that each time they are imported they lose any formatting you may have meticulously assigned to them. - - -#### To and from .rds files - -While it is easy enough to rerun the code (or copy it from data prep .rmd and paste it into an .rmd you are using for advanced analysis), there is a better way! Saving the data as an R object preserves all of its characteristics. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#to save the df as an .rds file on your computer; it should save in the same file as the .rmd file you are working with -saveRDS(Acc_sim30, "to_Robject.rds") -``` - -This file will save to your computer (and you can send it to colleagues). However, it is not easy to "just open it" in Excel. To open an .rds file and use it (whether you created it or it is sent to you by a colleague), use the following code: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -from_rds <- readRDS("to_Robject.rds") -``` - -If you are the recipient of an R object, but want to view it as a .csv, simply import the .rds then use the above code to export it as a .csv. - -#### From SPSS files - -Your data may come to you in a variety of ways. One of the most common is SPSS. The *foreign* package is popular for importing SPSS data. Below is code which would import an SPSS file *if I had created one*. You'll see that this script is hashtagged out because I rarely use SPSS and do not have a handy file to demo. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#opening an SPSS file requires the foreign package which I opened earlier -#from_SPSS <- foreign::read.spss ("SPSSdata.sav", use.value.labels = TRUE, to.data.frame = TRUE) -``` - -## quick demonstRation - -Let's run some simple descriptives. In the script below, I am using the *psych* package. Descriptive statistics will appear for all the data in the dataframe and the output will be rounded to three spaces. Note that rather than opening the psych package with the library function, I have used the double colon convention. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -round(psych::describe(Acc_sim30),3) -``` -Because "ID" is the case ID and COND is the factor (high, low, control), the only variable for which this data is sensible is "Accurate." Nonetheless, this provides an example of how to apply a package's function to a dataset. As we progress through the text we will learn how to manage the data so that we get the specific output we are seeking. - -## the knitted file - -One of the coolest things about R Markdown is its capacity to *knit* to HTML, PPT, or WORD. - -* In this OER, I am writing the lessons in R markdown (.rmd files), with the package *bookdown* as a helper, and knitting the files to .html, .doc, .pdf, and .epub formats. -* The package *papaja* is designed to prepare APA manuscripts where the writing, statistics, and references are all accomplished in a single file. This process contributes to replicability and reproducibility. -* More detailed instructions for knitting to these formats are provided in the [extRas](https://lhbikos.github.io/extRas/) mini-volume of [ReCentering Psych Stats](https://lhbikos.github.io/BikosRVT/ReCenter.html). - -## tRoubleshooting in R maRkdown - -Hiccups are normal. Here are some ideas that I have found useful in getting unstuck. - -* In a given set of operations, you must run/execute each piece of code in order: every, single, time. That is, all the packages have to be in your library and activated. - + If you open an .rmd file, you cannot just scroll down to make a boxplot. You need to run any *prerequisite* script (like loading files, putting the data in the global environment, etc.) - + Lost? Clear your global environment (broom icon in the upper right) and start over. Fresh starts are good. -* Your .rmd file and your data need to be stored in the same file folder. Make unique folders for each project (even if each contains only a few files). -* If you have tried what seems apparent to you and cannot solve your challenge, do not wait long before typing warnings into a search engine. Odds are, you'll get some useful hints in a manner of seconds. Especially at first, these are common errors: - + The package isn't loaded. - + The .rmd file hasn't been saved yet, or isn't saved in the same folder as the data. - + There are errors in punctuation or spelling. -* Restart R (it's quick -- not like restarting your computer). I frequently restart and clear my output and environment so that I can better track my order of operations. -* If you receive an error indicating that a function isn't working or recognized, and you have loaded the package, type the name of the package in front of the function with two colons (e.g., psych::describe(df)). If multiple packages are loaded with functions that have the same name, R can get confused. - -## just *why* have we tRansitioned to R? - -* It is (or at least it appears to be) the futuRe. -* SPSS individual and site licenses are increasingly expensive and limited; that is, Mplus, AMOS, HLM, or R tools may also be needed. As package development for R is exploding, we have tools to "do just about anything." -* Most graduate psychology programs are scientist/practitioner in nature and include training in "high end" statistics. Yet, many of your employing organizations will not have SPSS. R is a free, universally accessible program, that our graduates can use anywhere. - -## stRategies for success - -* Engage with R, but don't let it overwhelm you. - + The *mechanical is also the conceptual*. Especially while it's *simpler*, do try to retype the script into your own .rmd file and run it. Track down the errors you are making and fix them. - + If this stresses you out, move to simply copying the code into the .rmd file and running it. If you continue to have errors, you may have violated one of the best practices above (ask, "Is the package activated?" "Are the data and .rmd files in the same place?" "Is all the prerequisite script run?"). - + Still overwhelmed? Keep moving forward by (retrieving the original .rmd file from the GitHub repository) opening a copy of the .rmd file and just "run it along" with the lecture. Spend your mental power trying to understand what each piece does so you can translate it for any homework assignments. My suggestions for practice are intended to be parallel to the lecture with no sneaky trix. -* Copy script that works elsewhere and replace it with your datafile, variables, and so forth. -* The leaRning curve is steep, but not impossible. Gladwell [-@gladwell_outliers_2008] taught us that it takes about 10,000 hours to get great at something (2,000 to get reasonably competent). Practice. Practice. Practice. -* Updates to R, R Studio, and the packages are necessary, but can also be problematic. Sometimes updates cause programs/script to fail (e.g., "X has been deprecated for version X.XX"). My personal practice is to update R, R Studio, and the packages a week or two before each academic term. I expect that - + prior scripts may need to be updated or revised with package updates, and - + there will be incongruencies between base R, R Studio, and the packages. -* Embrace your downward dog. And square breathing. Also, walk away, then come back. - - -## Resources for getting staRted - -R for Data Science: https://r4ds.had.co.nz/ - -R Cookbook: http://shop.oreilly.com/product/9780596809164.do - -R Markdown homepage with tutorials: https://rmarkdown.rstudio.com/index.html - -R has cheatsheets for everything, here's the one for R Markdown: https://www.rstudio.com/wp-content/uploads/2015/02/rmarkdown-cheatsheet.pdf - -R Markdown Reference guide: https://www.rstudio.com/wp-content/uploads/2015/03/rmarkdown-reference.pdf - -Using R Markdown for writing reproducible scientific papers: https://libscie.github.io/rmarkdown-workshop/handout.html - -Script for all of Field's text: https://studysites.uk.sagepub.com/dsur/study/scriptfi.htm - -LaTeX equation editor: https://www.codecogs.com/latex/eqneditor.php - -## Practice Problems - -The suggestions for practice in this lesson are foundational for starting work in R. If you struggle with any of these steps, I encourage you to get consultation from a peer, instructor, or a tutor. - -|Assignment Component | Points Possible | Points Earned| -|:-------------------------------------- |:----------------: |:------------:| -|1. Download base R and R Studio | 5 |_____ | -|2. Open and save an .rmd (R Markdown) file in a "sensible location" on your computer|5 |_____ | -|3. In the .rmd file, open a chunk and perform a simple mathematical operation of your choice (e.g., subtract your birth year from this year) |5 |_____ | -|4. Install at least three packages; we will commonly use *psych*, *tidyverse*, *dplyr*, *knitr*, *ggplot2*, *ggpubr*) |5 |_____ | -|5. Copy the simulation in this lesson to your .rmd file. Change the random seed and run the simulation. Save the resulting data as a .csv or .rds file *in the same file as you saved the .rmd file*. |5 | _____ | -|6. Clear your environment (broom in upper right). Open the simulated file that you saved. | 5 |_____ | -|7. Run the *describe()* function from the *psych* package with your simulated data that you imported from your local drive. | 5 |_____ | -|8. Demonstration/discussion with a grader. | 5 |_____ | -|**Totals** | 40 |_____ | - -```{r, child=c('Worked_Examples/15-1-woRked_ReadySetR.Rmd')} -``` - -```{r include=FALSE} -sessionInfo() -``` - - diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/DCBE97C0-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/DCBE97C0-contents deleted file mode 100644 index e69de29b..00000000 diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/E0D5A16E-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/E0D5A16E-contents deleted file mode 100644 index f204781e..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/E0D5A16E-contents +++ /dev/null @@ -1,387 +0,0 @@ -```{r include = FALSE} -options(scipen=999) -``` - - -## Homeworked Example -[Screencast Link](https://youtu.be/rLyN9GspdWU) - -For more information about the data used in this homeworked example, please refer to the description and codebook located at the end of the [introduction](ReCintro). - -### Working the Problem with R and R Packages - -#### Narrate the research vignette, describing the IV and DV. The data you analyze should have at least 3 levels in the independent variable; at least one of the attempted problems should have a significant omnibus test so that follow-up is required) {-} - -I want to ask the question, do course evaluation ratings for traditional pedagogy differ for students as we enacted a substantive revision to our statistics series. The evaluative focus is on the ANOVA course and we will compare ratings from the stable, transition, and resettled stages of the transitional period. The variable (Stage) of interest will have three levels: - -* STABLE: 2017 represents the last year of "stability during the old way" when we taught with SPSS and during the 2nd year of the doctoral programs. -* TRANSITION: 2018 & 2019 represent the transition to R, when the classes were 30% larger because each of the IOP and CPY departments were transitioning to the 1st year (they did it separately, so as not to double the classes) -* RESETTLED: 2020 & 2021 represent the "resettled" phase where the transition to R was fairly complete and the class size returned to normal because the classes were offered in the first year. - -This is not a variable that was included in the dataset posted to the OSF repository, so we will need to create it. - -*If you wanted to use this example and dataset as a basis for a homework assignment, you could create a different subset of data. I worked the example for students taking the ANOVA class. You could choose multivariate or psychometrics. You could also choose a different dependent variable. I chose the traditional pedagogy subscale. Two other subscales include socially responsive pedagogy and valued by the student.* - -#### Simulate (or import) and format data {-} - -```{r} -big <- readRDS("ReC.rds") -``` - -This df includes course evaluations from ANOVA, multivariate, and psychometrics. To include up to three evaluations per student would violate the assumption of independence, therefore, I will only select the students in ANOVA course. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -big <- subset(big, Course == "ANOVA") -``` - -Let's first create the "Stage" variable that represents the three levels of transition. - -The ProgramYear variable contains the information I need, but the factor labels are not intuitive. Let me remap them. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -big$Stage <- plyr::mapvalues(big$ProgramYear, from = c("Second", "Transition", "First"), to = c("Stable", "Transition", "Resettled")) -``` - -Let's check the structure: - -```{r} -str(big$Stage) -``` - -The TradPed (traditional pedagogy) variable is an average of the items on that scale. I will first create that variable. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Creates a list of the variables that belong to that scale -TradPed_vars <- c('ClearResponsibilities', 'EffectiveAnswers','Feedback', 'ClearOrganization','ClearPresentation') - -#Calculates a mean if at least 75% of the items are non-missing; adjusts the calculating when there is missingness -#big$TradPed <- sjstats::mean_n(big[, ..TradPed_vars], .75) -big$TradPed <- sjstats::mean_n(big[, TradPed_vars], .75) -``` - -With our variables properly formatted, let's trim it to just the variables we need. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -OneWay_df <-(dplyr::select (big, Stage, TradPed)) -``` - -Although we would handle missing data more carefully in a "real study," I will delete all cases with any missingness. This will prevent problems in the hand-calculations section, later (and keep the two sets of results more similar). - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -OneWay_df <- na.omit(OneWay_df) -``` - -Although the assignment doesn't require it, I will make a quick plot to provide a visualizaiton of our analysis. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ggpubr::ggboxplot(OneWay_df, x = "Stage", y = "TradPed", add = "jitter", - color = "Stage", title = "Figure 1. Evaluations of Traditional Pedagogy as a Result of Transition") # -``` - - -#### Evaluate statistical assumptions {-} - -**Is the dependent variable normally distributed across levels of the factor?** - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describeBy(TradPed ~ Stage, mat = TRUE, digits = 3, data = OneWay_df, type = 1) -``` - -We'll use Kline's (2016) threshholds of the absolute values of 3 (skew) and 10 (kurtosis). The highest absolute value of skew is -0.881; the highest absolute value of kurtosis is -0.629. These are well below the areas of concern. - -the Shapiro-wilk test is a formal assessment of normality. It is a 2-part test that begins with creating an ANOVA model from which we can extract residuals, then testing the residuals. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -TradPed_res <- lm(TradPed ~ Stage, data = OneWay_df) -#TradPed_res -rstatix::shapiro_test(residuals(TradPed_res)) -``` -The Shapiro-Wilk test suggests that the our distribution of residuals is statistically significantly different from a normal distribution $(W = 0.941, p < .001)$. - -It is possible to plot the residuals to see how and where they deviate from the line. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ggpubr::ggqqplot(residuals(TradPed_res)) -``` -Ooof! at the ends of the distribution they really deviate. - -**Should we remove outliers?** - -The *rstatix::identify_outliers()* function identifies outliers and extreme outliers. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -OneWay_df %>% - rstatix::identify_outliers(TradPed) -``` - -There are 4 cases identified with outliers; none of those is extreme. I also notice that these outliers are low course evaluations. It seems only fair to retain the data from individuals who were not satisfied with the course. - -**Are the variances of the dependent variable similar across the levels of the grouping factor?** - -We want the results of the Levene's homogeneity of variance test to be non-significant. This would support the notion that the TradPed variance is equivalent across the three stages of the transition. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::levene_test(OneWay_df, TradPed ~ Stage) -``` -The non-significant *p* value suggests that the variances across the three stages are not statistically significantly different: $F(2, 109) = 4.523, p = 0.013$. - - -Before moving on, I will capture our findings in an APA style write-up of the testing of assumptions: - ->Regarding the assumption of normality, skew and kurtosis values at each of the levels of program year fell well below the thresholds that Kline (2016a) identified as concerning (i.e., below |3| for skew and |10| for kurtosis). In contrast, results of a model-based Shapiro-Wilk test of normality, indicated that the model residuals differed from a normal distribution $(W = 0.941, p < .001)$. Although 4 outliers were identified none were extreme, thus we retained all cases. Finally, Levene’s homogeneity of variance test indicated a violation of the homogeneity of variance assumption $F(2, 109) = 4.523, p = 0.013$. ANOVA is relatively robust to this violation when there are at least 15 cases per cell and the design is balanced (i.e., equivalent cell sizes). While we have at least 15 cases per cell, we have a rather unbalanced design. We will need to keep this limitation in mind as we interpret the results. - -#### Conduct omnibus ANOVA (w effect size) {-} - -The *rstatix::anova_test()* function calculates the one-way ANOVA and includes the effect size, $\eta^2$ in the column, *ges*. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -omnibus1w <- rstatix::anova_test(OneWay_df, TradPed ~ Stage, detailed = FALSE) -omnibus1w -``` -The one-way ANOVA is statistically significant. This means that there should be at least one statistically significant difference between levels of the design. Before moving on, I will capture the *F* string: $F(2, 109) = 7.199, p = 0.001, \eta^2 = 0.117$. Regarding the effect size, values of .01, .07, and .14 are considered to be small, medium, and large. The value of .11 would be medium-to-large. - -#### Conduct one set of follow-up tests; narrate your choice {-} - -I will simply calculate post-hoc comparisons. That is, all possible pairwise comparisons. I will specify the traditional Bonferroni as the approach to managing Type I error. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -phoc <- rstatix::t_test(OneWay_df, TradPed ~ Stage, p.adjust.method = "bonferroni", detailed = TRUE) -phoc -``` - -The post hoc tests suggested statistically significant differences between the stable transition resettled stages, favoring the stable period of time (i.e., using SPSS and taught in the second year). - -#### Describe approach for managing Type I error {-} - -We used the Bonferroni. The Bonferroni divides the overall alpha (.05) by the number of comparisons (3). In this case, a *p* value woul dhave to be lower than 0.017 to be statistically significant. The calulation reverse-engineers this so that we can interpret the *p* values by the traditional. 0.05. In the output, it is possible to see the higher threshholds necessary to claim statistical significance. - -#### APA style results with table(s) and figure {-} - ->A one-way analysis of variance was conducted to evaluate the effects of significant transitions (e.g., from SPSS to R; to the second to the first year in a doctoral program) on students ratings of traditional pedagogy. The independent variable, stage, included three levels: stable (with SPSS and taught in the second year of a doctoral program), transitioning (with R and students moving from second to first year), and resettled (with R and in the first year of the program). - ->Regarding the assumption of normality, skew and kurtosis values at each of the levels of program year fell well below the thresholds that Kline (2016a) identified as concerning (i.e., below |3| for skew and |10| for kurtosis). In contrast, results of a model-based Shapiro-Wilk test of normality, indicated that the model residuals differed from a normal distribution $(W = 0.941, p < .001)$. Although 4 outliers were identified none were extreme, thus we retained all cases. Finally, Levene’s homogeneity of variance test indicated a violation of the homogeneity of variance assumption $F(2, 109) = 4.523, p = 0.013$. ANOVA is relatively robust to this violation when there are at least 15 cases per cell and the design is balanced (i.e., equivalent cell sizes). While we have at least 15 cases per cell, we have a rather unbalanced design. We will need to keep this limitation in mind as we interpret the results. - ->Results of the omnibus ANOVA indicated a statistically significant effect of stage on students assessments of traditional pedagogy, $F(2, 109) = 7.199, p = 0.001, \eta^2 = 0.117$. The effect size was medium-to-large. We followed up the significant omnibus with all possible pairwise comparisons. We controlled for Type I error with the traditional Bonferroni adjustment. Results suggested that there were statistically significant differences between the stable and transition stages $(Mdiff = 0.655, p = 0.003)$, but not between stable and resettled $(Mdiff = 0.267,p = 0.324)$ or transition and resettled $(Mdiff= -0.388,p = 0.217)$ stages. Given that the doctoral programs are unlikely to transition back to SPSS or into the second year, the instructor(s) are advised to consider ways that could result in greater student satisfaction. Means and standard deviations are presented in Table 1 and complete ANOVA results are presented in Table 2. Figure 1 provides an illustration of the results. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -apaTables::apa.1way.table(iv = Stage, dv = TradPed, show.conf.interval = TRUE, data = OneWay_df, table.number = 1, filename = "1wayHWTable.doc") -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -omnibus1wHW_b <- aov(TradPed ~ Stage, data = OneWay_df) -apaTables::apa.aov.table(omnibus1wHW_b, table.number = 2, filename = "1wayHWTable2.doc") -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -phoc <- phoc %>% - rstatix::add_xy_position(x = "Stage") - -ggpubr::ggboxplot(OneWay_df, x = "Stage", y = "TradPed", add = "jitter", - color = "Stage", title = "Figure 1. Evaluations of Traditional Pedagogy as a Result of Transition") + - ggpubr::stat_pvalue_manual(phoc, label = "p.adj.signif", tip.length = 0.02, - hide.ns = TRUE, y.position = c(5.5)) -``` - -#### Conduct power analyses to determine the power of the current study and a recommended sample size {-} - -The *pwr.anova.test()* has five parameters: - -* *k* = # groups -* *n* = sample size per group -* *f* = effect sizes, where 0.1/small, 0.25/medium, and 0.4/large - - In the absence from an estimate from our own data, we make a guess about the expected effect size value based on our knowledge of the literature -* *sig.level* = *p* value that you will use -* *power* = .80 is the standard value - -In the script below, we simply add our values. So long as we have four values, the fifth will be calculated for us. - -Because this calculator requires the effect size in the metric of Cohen's *f* (this is not the same as the *F* ratio), we need to convert it. The *effectsize* package has a series of converters. We can use the *eta2_to_f()* function. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -effectsize::eta2_to_f(.117) -``` -We simply plug this value into the "f =". - -First let's ask what our level of power was? Our goal would be 80%. - -Given that our design was unbalanced (21, 44, 47 across the three stages), I used 38 (114/3). - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.anova.test (k = 3, f = .3640094, sig.level = .05, n = 38) -``` -Our power was 0.94. That is, we had 94% chance to find a statistically significant result if one existed. In the next power analysis, let's see what sample size is recommended. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.anova.test (k = 3, f = .3640094, sig.level = .05, power = .80) -``` -In order to be at 80% power to find a statistically significant result if there is one, we would need only 25 people per group. We currently had an unbalanced design of 50, 41, 21. - -### Hand Calculations - -Before we continue: - ->You may notice that the results from the hand calculation are slightly different from the results I will obtain with the R packages. This is because the formula we have used for the hand-calculations utilizes an approach to calculating the sums of squares that presumes that we have a balanced design (i.e., that the cell sizes are equal). When cell sizes are unequal (i.e., an unbalanced design) the Type II package in *rstatix::anova_test* may produce different result. - -> Should we be concerned? No (and yes). My purpose in teaching hand calculations is for creating a conceptual overview of what is occurring in ANOVA models. If this lesson was a deeper exploration into the inner workings of ANOVA, we would take more time to understand what is occurring. My goal is to provide you with enough of an introduction to ANOVA that you would be able to explore further which sums of squares type would be most appropriate for your unique ANOVA model. - -#### Using traditional NHST (null hypothesis testing language), state your null and alternative hypotheses {-} - -Regarding the evaluation of traditional pedgagoy across three stages of transitions to a doctoral ANOVA course, the null hypothesis predicts no differences between the three levels of the dependent variable: - -$$H_{O}: \mu _{1} = \mu _{2} = \mu _{3}$$ - -In contrast, the alternative hypothesis suggests there will be differences. Apriorily, I did not make any specific predictions. - -$$H_{a1}: \mu _{1} \neq \mu _{2} \neq \mu _{3}$$ - -#### Calculate sums of squares total (SST). Steps in this calculation must include calculating a grand mean and creating variables representing the mean deviation and mean deviation squared {-} - -I will use this approach to calculating sums of squares total: - -$$SS_{T}= \sum (x_{i}-\bar{x}_{grand})^{2}$$ - -I will use the *psych::describe()* function to obtain the overall mean: - -```{r} -psych::describe(OneWay_df) -``` - -Next, I will subtract this value from each person's TradPed value. This will create a mean deviation. - - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -OneWay_df$mdevTP <- OneWay_df$TradPed - 4.06 -#I could also calculate it by using the "mean" function -#I had to include an na.rm=TRUE; this appears to be connected to missingness -OneWay_df$mdevTPb <- OneWay_df$TradPed - mean(OneWay_df$TradPed, na.rm=TRUE) -head(OneWay_df) -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -OneWay_df <- OneWay_df %>% - dplyr::mutate(m_devSQTP = mdevTP^2) - -#so we can see this in the textbook -head(OneWay_df) -``` - -I will ask for a sum of the mean deviation squared column. The function was not running, sometimes this occurs when there is missing data. While I didn't think that was true, adding "na.rm = TRUE" solved the problem. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SST <- sum(OneWay_df$m_devSQTP, na.rm = TRUE) -SST -``` -SST = 83.0332 - -#### Calculate the sums of squares for the model (SSM). A necessary step in this equation is to calculate group means {-} - -The formula for SSM is $$SS_{M}= \sum n_{k}(\bar{x}_{k}-\bar{x}_{grand})^{2}$$ - -We will need: - -* *n* for each group, -* Grand mean (earlier we learned it was 4.06), -* Group means - -We can obtain the group means several ways. I think the *psych::describeBy()* function is one of the easiest. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describeBy(TradPed ~ Stage, mat = TRUE, digits = 3, data = OneWay_df, type = 1) -``` - -Now we can pop these values into the formula. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SSM <- 50 * (4.348 -4.06)^2 + 41 * (3.693 - 4.06)^2 + 21 * (4.081 - 4.06)^2 -SSM -``` -SSM = 9.67871 - - -#### Calculate the sums of squares residual (SSR). A necessary step in this equation is to calculate the variance for each group {-} - -The formula for I will use to calculate SSR is $$SS_{R}= s_{group1}^{2}(n-1) + s_{group2}^{2}(n-1) + s_{group3}^{2}(n-1))$$ - -We will need: - -* *n* for each group, -* variance (standard deviation, squared) for each group - -We can obtain these values from the previous run of the *psych::describeBy()* function. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -SSR <- (0.658^2)*(50 - 1) + (1.057^2)*(41 - 1) + (0.610^2)*(21-1) -SSR -``` -SSR = 73.3472 - - -#### Calculate the mean square model, mean square residual, and *F*-test {-} - -The formula for mean square model is $$MS_M = \frac{SS_{M}}{df{_{M}}}$$ - -* $SS_M$ was 9.67871 -* $df_M$ is *k* - 1 (where *k* is number of groups/levels) - -```{r} -MSM <- 9.67871/2 -MSM -``` -MSM is 4.839 - -The formula for mean square residual is $$MS_R = \frac{SS_{R}}{df{_{R}}}$$ - -* $SS_R$ was 79.292 -* $df_R$ is $N - k$ (112 - 3 = 109) - -```{r} -MSR = 73.3472/109 -MSR -``` - -The formula for the *F* ratio is $$F = \frac{MS_{M}}{MS_{R}}$$ - -```{r} -F <- 4.839/0.6729101 -F -``` -*F* = 7.191154 - - -#### What are the degrees of freedom for your numerator and denominator? {-} - -Numerator or $df_M$: 2 -Denominator or $df_R$: 109 - -#### Locate the test critical value for your one-way ANOVA {-} - -We could use use a [table of critical values](https://www.statology.org/how-to-read-the-f-distribution-table/) for the *F* distribution. - -The closest *N* in the table I am using is 120. If we set alpha at 0.05, our test value would need to exceed the absolute value of 3.0718. - -We can also use a look-up function, which follows this general form: qf(p, df1, df2. lower.tail=FALSE) -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -qf(.05, 2, 109, lower.tail=FALSE) -``` -Not surprisingly the values are quite similar. - -#### Is the *F*-test statistically significant? Why or why not? {-} - -Because the value of the *F* test (7.191) exceeded the absolute value of the critical value (3.080), the *F* test is statistically significant. - -#### Calculate and interpret the $\eta^2$ effect size {-} - -The formula to calculate the effect size is $$\eta ^{2}=\frac{SS_{M}}{SS_{T}}$$ - -* $SS_M$ was 9.679 -* $SS_T$ was 83.0332 - -```{r} -etaSQ <- 9.679/83.0332 -etaSQ -``` -Eta square is 0.117. Values of .01, .06, and .14 are interpreted as small, medium, and large. Our value of 0.12 is medium-to-large. - - -#### Assemble the results into a statistical string {-} - -$$F(2, 109) = 7.191, p < .05, \eta^2 = 0.117$$ \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/E6AB49F9-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/E6AB49F9-contents deleted file mode 100644 index 59644e18..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/E6AB49F9-contents +++ /dev/null @@ -1,89 +0,0 @@ -```{r include = FALSE} -options(scipen=999) -``` - -## Homeworked Example - -[Screencast Link](https://youtu.be/ZrQUt9lidCM) - -Several elements of the practice problems (i.e., download base R and R studio) are not easily demonstrated and not replicated here. These are skipped. - -*If you wanted to use this example and dataset as a basis for a homework assignment, you could simply change the seed -- again. For a greater challenge, you could adjust the simulation to have different sample sizes, means, or standard deviations.* - -#### Perform a simple mathematical operation:{-} - -In the .rmd file, open a chunk and perform a simple mathematical operation of your choice (e.g., subtract your birth year from this year). - -```{r} -2023 - 1966 -``` - - -#### Install at least three packages we will commonly use {-} - -Below is code for installing three packages. Because continuous reinstallation can be problematic, I have hashtagged them so that they will not re-run. -```{r} -#install.packages("tidyverse") -#install.packages("ggpubr") -#install.packages("psych") -``` - -#### Copy the simulation in this lesson to your .rmd file. Change the random seed and run the simulation {-} - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -set.seed(2023) -# sample size, M and SD for each group -Accurate <- c(rnorm(30, mean = 1.18, sd = 0.8), rnorm(30, mean = 1.83, - sd = 0.58), rnorm(30, mean = 1.76, sd = 0.56)) -# set upper bound for DV -Accurate[Accurate > 3] <- 3 -# set lower bound for DV -Accurate[Accurate < 0] <- 0 -# IDs for participants -ID <- factor(seq(1, 90)) -# name factors and identify how many in each group; should be in same -# order as first row of script -COND <- c(rep("High", 30), rep("Low", 30), rep("Control", 30)) -# groups the 3 variables into a single df: ID, DV, condition -Acc_sim30B <- data.frame(ID, COND, Accurate) -``` - -#### Save the resulting data as a .csv or .rds file in the same file as you saved the .rmd file {-} - -You only need to save it as a .csv or .rds file. I have demonstrated both. - -Saving as a .csv file -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -write.table(Acc_sim30B, file = "to_CSVb.csv", sep = ",", col.names = TRUE, - row.names = FALSE) -``` - -Saving as an .rds file -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -saveRDS(Acc_sim30B, "to_RobjectB.rds") -``` - -#### Clear your environment (broom in upper right) {-} - -You only need to import the .csv or .rds file; I have demonstrated both. -Open the .csv file from my local drive. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -from_CSV <- read.csv("to_CSVb.csv", header = TRUE) -``` - -Open the .rds file from my local drive. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -from_rds <- readRDS("to_RobjectB.rds") -``` - -#### Run the describe() function from the psych package with your simulated data that you imported from your local drive {-} - -You only need to retrieve descriptives from the .csv or .rds file; I have demonstrated both. -```{r} -psych::describe(from_CSV) -``` - -```{r} -psych::describe(from_rds) -``` - diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/FA4219E5-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/FA4219E5-contents deleted file mode 100644 index 491284a5..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/FA4219E5-contents +++ /dev/null @@ -1,600 +0,0 @@ - -# Independent Samples *t*-test {#tIndSample} - -[Screencasted Lecture Link](https://youtube.com/playlist?list=PLtz5cFLQl4KPx0VxnBTx9Y3_K6VFwtM1I) - -```{r include=FALSE, tidy=TRUE, tidy.opts=list(width.cutoff=70)} -knitr::opts_chunk$set(echo = TRUE) -knitr::opts_chunk$set(comment = NA) #keeps out the hashtags in the knits -``` - - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -options(scipen=999)#eliminates scientific notation -``` - -Researchers may wish to know if there are differences on a given outcome variable as a result of a dichotomous grouping variable. For example, during the COVID-19 pandemic, my research team asked if there were differences in the percentage of time that individuals wore facemasks as a result of 2020 Presidential voting trends (Republican or Democratic) of their county of residence. In these simple designs, the independent samples *t*-test could be used to test the researchers' hypotheses. - -## Navigating this Lesson - -There is just less than one hour of lecture. If you work through the materials with me, plan for an additional hour - -While the majority of R objects and data you will need are created within the R script that sources the chapter, occasionally there are some that cannot be created from within the R framework. Additionally, sometimes links fail. All original materials are provided at the [Github site](https://github.com/lhbikos/ReCenterPsychStats) that hosts the book. More detailed guidelines for ways to access all these materials are provided in the OER's [introduction](#ReCintro) - -### Learning Objectives - -Learning objectives from this lecture include the following: - -* Recognize the research questions for which utilization of the independent samples *t*-test would be appropriate. -* Narrate the steps in conducting an independent samples *t*-test, beginning with testing the statistical assumptions through writing up an APA style results section. -* Calculate an independent samples *t*-test in R (including effect sizes and 95%CIs). -* Interpret a 95% confidence interval around a mean difference score. -* Produce an APA style results section for an independent samples *t*-test. -* Determine a sample size that (given a set of parameters) would likely result in a statistically significant effect, if there was one. - -### Planning for Practice - -The suggestions for homework vary in degree of complexity. The more complete descriptions at the end of the chapter follow these suggestions. - -* Rework the independent samples *t*-test in the lesson by changing the random seed in the code that simulates the data. This should provide minor changes to the data, but the results will likely be very similar. -* Rework the independent samples *t*-test in the lesson by changing something else about the simulation. For example, if you are interested in power, consider changing the sample size. -* Use the simulated data that is provided, but use the nonverbal variable, instead. -* Conduct an independent samples *t*-test with data to which you have access and permission to use. This could include data you simulate on your own or from a published article. - -### Readings & Resources - -In preparing this chapter, I drew heavily from the following resource(s). Other resources are cited (when possible, linked) in the text with complete citations in the reference list. - -* Navarro, D. (2020). Chapter 13: Comparing two means. In [Learning Statistics with R - A tutorial for Psychology Students and other Beginners](https://learningstatisticswithr.com/). Retrieved from https://stats.libretexts.org/Bookshelves/Applied_Statistics/Book%3A_Learning_Statistics_with_R_-_A_tutorial_for_Psychology_Students_and_other_Beginners_(Navarro) - - Navarro's OER includes a good mix of conceptual information about *t*-tests as well as R code. My lesson integrates her approach as well as considering information from Field's [-@field_discovering_2012] and Green and Salkind's [@green_using_2017] texts (as well as searching around on the internet). -* Elliott, A. M., Alexander, S. C., Mescher, C. A., Mohan, D., & Barnato, A. E. (2016). Differences in Physicians’ Verbal and Nonverbal Communication With Black and White Patients at the End of Life. *Journal of Pain and Symptom Management, 51*(1), 1–8. https://doi.org/10.1016/j.jpainsymman.2015.07.008 - - The source of our research vignette. - -### Packages - -The script below will (a) check to see if the following packages are installed on your computer and, if not (b) install them. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#will install the package if not already installed -#if(!require(psych)){install.packages("psych")} -#if(!require(tidyverse)){install.packages("tidyverse")} -#if(!require(dplyr)){install.packages("dplyr")} -#if(!require(ggpubr)){install.packages("ggpubr")} -#if(!require(pwr)){install.packages("pwr")} -#if(!require(apaTables)){install.packages("apaTables")} -#if(!require(knitr)){install.packages("knitr")} -#if(!require(rstatix)){install.packages("rstatix")} -``` - -## Introducing the Independent Samples *t*-Test - -The independent samples *t*-test assesses whether the population mean of the test variable for one group differs from the population mean of the test variable for a second group. This *t*-test can only accommodate two levels of a grouping variable (e.g., teachers/students, volunteers/employees, treatment/control) and the participants must be different in each group. - -![An image of a row with two boxes labeled Condition A (in light blue) and Condition B (in dark blue). This represents the use of an independent samples *t*-test to compare across conditions.](images/ttests/conditions_paired.jpg) - -The comparison of two means is especially evident in the numerator of the formula. In the denominator we can see that the mean difference is adjusted by the standard error. At the outset, you should know that the formula in the denominator gets messy, but the formula, alone, provides an important conceptual map. - -$$t = \frac{\bar{X}_1 - \bar{X}_2}{\mbox{SE}}$$ -If the researcher is interested in comparing the same participants' experiences across time or in different groups, they should consider using a [paired samples *t*-test](#tPaired). Further, the independent samples *t*-test is limited to a grouping variable with only two levels. If the researcher is interested in three or more levels, they should consider using a [one-way ANOVA](#oneway). - -### Workflow for Independent Samples *t*-Test - -The following is a proposed workflow for conducting a independent samples *t*-test. - -![A colorful image of a workflow for the one sample t-test](images/ttests/IndSampleWrkFlw.jpg) -If the data meets the assumptions associated with the research design (e.g., independence of observations and a continuously scaled metric), these are the steps for the analysis of an independent samples *t*-test: - -1. Prepare (upload) data. -2. Explore data with - - graphs - - descriptive statistics -3. Assess normality via skew, kurtosis, and the Shapiro-Wilk test of normality -4. Consider the homogeneity of variance assumption and decide whether to use the Student's or Welch's formulation. -5. Compute the independent samples *t*-test -6. Compute an effect size (frequently the *d* or *eta* statistic) -7. Manage Type I error -8. Sample size/power analysis (which you should think about first, but in the context of teaching statistics, it's more pedagogically sensible, here). - -## Research Vignette - -Empirically published articles where *t*-tests are the primary statistic are difficult to locate. Having exhausted the psychology archives, I located this article in an interdisciplinary journal focused on palliative medicine. The research vignette for this lesson examined differences in physician's verbal and nonverbal communication with Black and White patients at the end of life [@elliott_differences_2016]. - -Elliott and colleagues [-@elliott_differences_2016] were curious to know if hospital-based physicians (56% White, 26% Asian, 7.4% each Black and Hispanic) engaged in verbal and nonverbal communication differently with Black and White patients. Black and White patient participants were matched on characteristics deemed important to the researchers (e.g., critically and terminally ill, prognostically similar, expressed similar treatment preferences). Interactions in the intensive care unit were audio and video recorded and then coded on dimensions of verbal and nonverbal communication. - -Because each physician saw a pair of patients (i.e., one Black patient and one White patient), the researchers utilized a paired samples, or dependent *t*-test. This statistical choice was consistent with the element of the research design that controlled for physician effects through matching. Below are the primary findings of the study. - - -| |Black Patients |White Patients | | -|:---------------|:--------------|:--------------|:--------| -|Category |*Mean*(*SD*) |*Mean*(*SD*) |*p*-value| -|Verbal skill score (range 0 - 27)|8.37(3.36) | 8.41(3.21) |0.958| -|Nonverbal skill score (range 0 - 5) |2.68(.84) | 2.93(.77)|0.014| - - -Although their design was more sophisticated (and, therefore, required the paired samples *t*-test), Elliott et al. [-@elliott_differences_2016] could have simply compared the outcome variables (e.g., verbal and nonverbal communication) as a function of their dichotomous variable, patient race (Black, White). - -### Data Simulation - -In the data below, I have simulated the verbal and non-verbal communication variables using the means and standard deviations listed in the article. Further, I truncated them to fit within the assigned range. I created 33 sets each and assigned them to the Black or White level of the grouping variable. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -set.seed(220815) -#sample size, M, and SD for Black then White patients -Verbal <- c(rnorm(33, mean=8.37, sd=3.36), rnorm(33, mean = 8.41, sd=3.21)) -#set upper bound -Verbal[Verbal>27]<-27 -#set lower bound -Verbal[Verbal<0]<-0 -#sample size, M, and SD for Black then White patients -Nonverbal <- c(rnorm(33, mean=2.68, sd=.84), rnorm(33, mean = 2.93, sd=.77)) -#set upper bound -Nonverbal[Nonverbal>5]<-5 -#set lower bound -Nonverbal[Nonverbal<0]<-0 - -ID<-factor(seq(1,66)) -#name factors and identify how many in each group; should be in same order as first row of script -PatientRace<-c(rep("Black", 33), rep("White", 33)) -#groups the 3 variables into a single df: ID#, DV, condition -dfIndSamples <-data.frame(ID, PatientRace, Verbal, Nonverbal) -``` - -With our data in hand, let's inspect its structure (i.e., the measurement scales for the variables) to see if they are appropriate. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -str(dfIndSamples) -``` -The verbal and nonverbal variables are quasi-interval scale variables. Therefore, the numerical scale is correctly assigned by R. In contrast, patient race is a nominal variable and should be a factor. In their article, Elliot et al. [-@elliott_differences_2016] assigned Black as the baseline variable and White as the comparison variable. Because R orders factors alphabetically, and "Black" precedes "White", this would happen automatically. Because creating ordered factors is a useful skill, I will write out the full code. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -dfIndSamples$PatientRace <- factor(dfIndSamples$PatientRace, levels = c("Black", "White")) -``` - -Let's again check the formatting of the variables: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -str(dfIndSamples) -``` -The four variables of interest are now correctly formatted as *num* and *factor*. - -Below is code for saving (and then importing) the data in .csv or .rds files. I make choices about saving data based on what I wish to do with the data. If I want to manipulate the data outside of R, I will save it as a .csv file. It is easy to open .csv files in Excel. A limitation of the .csv format is that it does not save any restructuring or reformatting of variables. For this lesson, this is not an issue. - -Here is code for saving the data as a .csv and then reading it back into R. I have hashtagged these out, so you will need to remove the hashtags if you wish to run any of these operations. If you have simulated the data (above), you do not need to save and then re-import the data. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#writing the simulated data as a .csv -#write.table(dfIndSamples, file = "dfIndSamples.csv", sep = ',', col.names=TRUE, row.names=FALSE) -#at this point you could clear your environment and then bring the data back in as a .csv -#reading the data back in as a .csv file -#dfIndSamples<- read.csv ('dfIndSamples.csv', header = TRUE) -``` - -The .rds form of saving variables preserves any formatting (e.g., creating ordered factors) of the data. A limitation is that these files are not easily opened in Excel. Here is the hashtagged code (remove hashtags if you wish to do this) for writing (and then reading) this data as an .rds file. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#saveRDS(dfIndSamples, 'dfIndSamples.rds') -#dfIndSamples <- readRDS('dfIndSamples.rds') -#str(dfIndSamples) -``` - -### Quick Peek at the Data - -Plotting the data is a helpful early step in any data analysis. Further, visualizing the data can help us with a conceptual notion of the statistic we are utilizing. The *ggpubr* package is one of my go-to-tools for quick and easy plots of data. Boxplots are terrific for data that is grouped. A helpful [tutorial](https://rpkgs.datanovia.com/ggpubr/) for boxplots (and related plots) can be found at datanovia. - -In the code below I introduced the colors by identifying the grouping variable and assigning colors. Those color codes are the "Hex" codes you find in the custom color palette in your word processing program. - -I am also fond of plotting each case with the command, *add = "jitter"*. To increase your comfort and confidence in creating figures (and with other tools) try deleting and adding back in different commands. This is how to distinguish between the essential and the elective elements of the code. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ggpubr::ggboxplot(dfIndSamples, x = "PatientRace", y = "Verbal", color = "PatientRace", palette =c("#00AFBB", "#FC4E07"), add = "jitter") -``` -The box of the boxplot covers the middle 50% (the interquartile range). The horizontal line is the median. The whiskers represent three standard deviations above and below the mean. Any dots are outliers. - - -## Working the Independent Samples *t*-Test (by hand) - -### Stating the Hypothesis - -In this lesson, I will focus on differences in the verbal communication variable. Specifically, I hypothesize that physician verbal communication scores for Black and White patients will differ. In the hypotheses below, the null hypothesis ($H_0$) states that the two means are equal; the alternative hypothesis ($H_A$) states that the two means are not equal. - -$$ -\begin{array}{ll} -H_0: & \mu_1 = \mu_2 \\ -H_A: & \mu_1 \neq \mu_2 -\end{array} -$$ - - - - - - - - - - - -### Calculating the *t*-Test - -Earlier I presented a formula for the independent samples *t*-test. - -$$t = \frac{\bar{X}_1 - \bar{X}_2}{\mbox{SE}}$$ -There are actually two formulations of the *t*-test. Student's version can be used when there is no violation of the homogeneity of variance assumption; Welch's can be used when the homogeneity of variance assumption is violated. For the hand-calculation demonstration, I will only demonstrate the formula in the most ideal of circumstances, that is: there is no violation of the homogeneity of variance assumption and sample sizes are equal. - -Even so, while the formula seems straightforward enough, calculating the SE in the denominator gets a little spicy: - -$$t = \frac{\bar{X_{1}} -\bar{X_{2}}}{\sqrt{\frac{s_{1}^{2}}{N_{1}}+\frac{s_{2}^{2}}{N_{2}}}}$$ -Let's first calculate the SE -- the value of the denominator. For this, we need the standard deviations for the dependent variable (verbal) for both levels of patient race. We obtained these earlier when we used the *describeBy()* function in the *psych* package. - -The standard deviation of the verbal variable for the levels in the patient race group were 2.99 for Black patients and 3.20 for White patients; the *N* in both our groups is 33. We can do the denominator math right in an R chunk: -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -sqrt((2.985^2/33) + (3.203^2/33)) -``` -Our *SE* = 0.762 - -With the simplification of the denominator, we can easily calculate the independent sample *t*-test. - -$$t = \frac{\bar{X_{1}} -\bar{X_{2}}}{SE}$$ -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -(7.615 - 8.891)/0.762 -``` -Hopefully, this hand-calculation provided an indication of how the means, standard deviation, and sample sizes contribute to the estimate of this *t*-test value. Now we ask, "But it is statistically significant?" - -#### Statistical Significance - -The question of statistical significance testing invokes NHST (null hypothesis significance testing). In the case of the independent samples *t*-test, the null hypothesis is that the two means are equal; the alternative is that they are not equal. Our test is of the null hypothesis. When the probability (*p*) is less than the value we specify (usually .05), we are 95% certain that the two means are not equal. Thus, we reject the null hypothesis (the one we tested) in favor of the alternative (that the means are not equal). - -$$ -\begin{array}{ll} -H_0: & \mu_1 = \mu_2 \\ -H_A: & \mu_1 \neq \mu_2 -\end{array} -$$ -Although still used, NHST has its critiques. Among the critiques are the layers of logic and confusing language as we interpret the results. - -Our *t*-value was -1.675. We compare this value to the test critical value in a table of *t* critical values. In-so-doing we must know our degrees of freedom. In the test that involves two levels of a grouping value, we will use $N -1$ as the value for degrees of freedom. We must also specify the *p* value (in our case .05) and whether-or-not our hypothesis is unidirectional or bi-directional. Our question only asked, "Are the verbal communication levels different?" In this case, the test is two-tailed, or bi-directional. - -Let's return to the [table of critical values](https://www.statology.org/t-distribution-table/) for the *t* distribution to compare our *t*-value (-1.675) to the column that is appropriate for our: - -* Degrees of freedom (in this case $N-2$ or 64) - - We have two levels of a grouping value; for each our df is $N-1$ -* Alpha, as represented by $p < .05$ -* Specification as a one-tailed or two-tailed test - - Our alternative hypothesis made no prediction about the direction of the difference; therefore we will use a two-tailed test - -In the above linked table of critical values, when the degrees of freedom reaches 30, there larger intervals. We will use the row representing degrees of freedom of 60. If our *t*-test value is lower than an absolute value of -2 or greater than the absolute value of 2, then our means are statistically significantly different from each other. In our case, we have not achieved statistical significance and we cannot say that the means are different. The *t* string would look like this: $t(64) = -1.675, p > .05$ - -We can also use the *qt()* function in base R. In the script below, I have indicated an alpha of .05. The "2" that follows indicates I want a two-tailed test. The 64 represents my degrees of freedom ($N-2$). In a two-tailed test, the regions of rejection will be below the lowerbound (lower.tail=TRUE) and above the upperbound (lower.tail=FALSE). - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -qt(.05/2, 64, lower.tail=TRUE) -qt(.05/2, 64, lower.tail=FALSE) -``` -Given the large intervals, it makes sense that this test critical value is slightly different than the one from the table. - -#### Confidence Intervals - -How confident are we in our result? With independent samples *t*-tests, it is common to report an interval in which we are 95% confident that our true mean difference exists. Below is the formula, which involves: - -* $\bar{X_{1}}-\bar{X_{2}}$ the difference in the means -* $t_{cv}$ the test critical value for a two-tailed model (even if the hypothesis was one-tailed) where $\alpha = .05$ and the degrees of freedom are $N-2$ -* $SE$ the standard error used in the denominator of the test statistic - -$$(\bar{X_{1}} -\bar{X_{2})} \pm t_{cv}(SE)$$ -Let's calculate it: - -First, let's get the proper *t* critical value. Even though these are identical to the one above, I am including them again. Why? Because if the original hypothesis had been one-tailed, we would need to calculate a two-tailed confidence interval; this is a placeholder to remind us. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -qt(.05/2, 64, lower.tail=TRUE) -qt(.05/2, 64, lower.tail=FALSE) -``` -With this in hand, let's calculate the confidence intervals. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -(7.614-8.891)- (1.99773*0.762) -(7.614-8.891)+(1.99773*0.762) -``` -These values indicate the range of scores in which we are 95% confident that our true mean difference ($\bar{X_{1}}-\bar{X_{2}}$) lies. Stated another way, we are 95% confident that the true mean difference lies between -2.80 and 0.25 Because this interval crosses zero, we cannot rule out that the true mean difference is 0.00. This result is consistent with our non-significant *p* value. For these types of statistics, the 95% confidence interval and *p* value will always be yoked together. - -#### Effect Size - -Whereas *p* values address statistical significance, effect sizes address the magnitude of difference. There are two common effect sizes that are used with the independent samples *t*-test. The first is the *d* statistic, which measures, in standard deviation units, the distance between the two means. The simplest formula involves the *t* value and sample sizes: - -$$d = t\sqrt{\frac{N_{1}+N_{2}}{N_{1}N_{2}}}$$ - -With a *t* value of -1.675 and sample sizes at 33 each, we can easily calculate this. Small, medium, and large sizes for the *d* statistic are .2, .5, and .8, respectively (irrespective of sign). - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} --1.675*(sqrt((33+33)/(33*33))) -``` -Our value, -0.412 suggests a small-to-medium effect size. We might wonder why it wasn't statistically significant? Later we will discuss power and the relationship between sample size, one vs. two-tailed hypotheses, and effect sizes. - -Eta square, $\eta^2$ is the proportion of variance of a test variable that is a function of the grouping variable. A value of 0 indicates that the difference in the mean scores is equal to 0, where a value of 1 indicates that the sample means differ, and the test scores do not differ within each group. The following equation can be used to compute $\eta^2$. Conventionally, values of .01, .06, and .14 are considered to be small, medium, and large effect sizes, respectively. - -$$\eta^{2} =\frac{t^{2}}{t^{2}+(N_{1}+N_{2}-2)}$$ -Let's calculate it: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -(-1.6745*-1.6745)/((-1.6745*-1.6745)+(33 + 33 -2)) -``` -Similarly, the $\eta^2$ is small-to-medium. - - -## Working the Independent Samples *t*-Test with R Packages - -Let's rework the problem in R. We start at the top of the flowchart, evaluating the statistical assumptions. - -### Evaluating the Statistical Assumptions - -With an eye on our data, we can begin to explore the statistical assumptions associated with the independent samples *t*-test. Here's where we are in the workflow: - -![The workflow for the one sample *t*-test highlighting the evaluation of assumptions section](images/ttests/IndSampleAssmptns.jpg) - -All statistical tests have some assumptions about the data. The independent-samples *t*-test has four: - -* The scores on the test variable as independent of each other. This is a research design issue and the independent-samples *t*-test is not robust to violating this assumption. - - If physicians' verbal communication was evaluated and reported for more than one patient, this vignette would violate the assumption of the independent samples *t*-test. For the sake of simplicity, let's presume that each was evaluated on verbal communication for only one patient. If the research scenario was such that physicians contributed multiple datapoints a potential analytic choice that is robust to such a violation is [multilevel modeling](https://lhbikos.github.io/MultilevelModeling/). -* The test variable should be continuously scaled. This is also a matter of research design and no statistical analysis is required. - - Our test variable is an evaluation of verbal interactions; this is continuously scaled and has the properties of *interval*-level data. -* The test variable is normally distributed. We can check this several ways: - - visually with histograms (perhaps with superimposed curves) and boxplots, - - calculation of skew and kurtosis values, - - calculation of the Shapiro-Wilk test of normality -* The variances of the normally distributed test variable for both levels of the grouping factor are equal. This is called the homogeneity of variance test and is easily calculated with a Levene's test of homogeneity of variance. - -#### Is the dependent variable normally distributed at each level of the grouping variable? - -We can begin to evaluate the assumption of normality by obtaining the descriptive statistics with the *describe()* function from the *psych* package. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describe(dfIndSamples$Verbal, type=1) #type=1 produces the type of skew and kurtosis associated with Kline's interpretive guidelines -``` - -From this, we learn that the overall verbal mean is 8.25 with a standard deviation of 3.14. The values for skew (0.44) and kurtosis (1.34) fall below the areas of concern (below the absolute value of 3 for skew; below the absolute values of 10 for kurtosis) identified by Kline [-@kline_data_2016]. - -Recall that one of the assumptions for independent samples *t*-test is that the variable of interest is normally distributed within each level of the grouping variable. The *describeBy()* function in the *psych* package allows us to obtain these skew and kurtosis at both levels of the grouping variable. - -If we feed the function the entire df, it will give us results for each level of PatientRace for each variable, including variables for which such disaggregation is nonsensible (i.e., ID, PatientRace). If we had a large df, we might want to create a tiny df that only includes our variable(s) of interest. For now, it is not problematic to include all the variables. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -psych::describeBy(dfIndSamples ~ PatientRace, mat=TRUE, type=1) -``` -In this analysis we are interested in the verbal variable. We see that patients who are Black received verbal interactions from physicians that were quantified by a mean score of 7.61 (*SD* = 2.99); physicians' scores for White patients were 8.89 (*SD* = 3.20). Skew and kurtosis values for the verbal ratings with Black patients were -.37 and -.14, respectively. They were 1.07 and 1.54 for White patients. As before, these fall well below the absolute values of 3 (skew) and 10 (kurtosis) that are considered to be concerning. - -Beyond skew and kurtosis, we can formally test for deviations from normality with a Shapiro-Wilk. The script below first groups the data by PatientRace and then applies the *rstatix::shapiro_test()*. We want the results to be non-significant. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse)#opening this package so I can use the pipes -shapiro <- dfIndSamples %>% - group_by(PatientRace) %>% - rstatix::shapiro_test(Verbal) -shapiro -``` -The Shapiro-Wilk test of normality indicated that the dependent variable, evaluation of verbal interaction with the patient was normally distributed within Black patients $(W = 0.977, p = 0.677)$, but not within White patients $(W = 0.922, p = 0.020$. That is, the distribution of verbal communication scores for physicians attending to White patients was statistically significantly different from a normal distribution. - -Should we be concerned? A general rule of thumb is that when cell sizes are larger than 15 the independent *t*-test should be relatively robust to violations of normality [@green_using_2017]. - -#### Are the variances of the dependent variable similar across the levels of the grouping factor? - -One of the assumptions of the independent samples *t*-test is that the variances of the dependent variable (verbal communication) are similar for both levels of the PatientRace factor. We can use the Levene's test to do this. We want this value to be non-significant $(p > .05)$. If violated, we we can use the Welch's test because it is robust to the violation of the homogeneity of variance. - -Using *rstatix::levene_test()*, we simply need to point to the data, provide a "formula" in the form of "dependent variable by grouping variable," and specify about how to center the data. The median is a commonly used because it provides a more robust test. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::levene_test(dfIndSamples, Verbal ~ PatientRace, center=median) -``` - -The results of the Levene's test are presented as an *F* statistic. We'll get to *F* distributions in the next chapter. For now, it is just important to know how to report and interpret them: - -* Degrees of freedom are 1 and 64 -* The value of the *F* statistic is 0.039 -* The *p* value is 0.843 (i.e., greater than .05) - -Happily, our Levene's result is $(F[1, 64] = 0.039, p = 0.843)$ not significant. Because *p* is greater than .05, we have not violated the homogeneity of variance assumption. That is to say, the variance in the patient race groups is not statistically significantly different from each other. We can use the regular (Student's) formulation of the *t*-test for independent samples. - -#### APA style write-up of testing the assumptions - -My practice is to create APA style drafts of the different sections of the analysis as I work along. Here's how I might capture our evaluation of the statistical assumptions: - ->We began by analyzing the data to see if it met the statistical assumptions for analysis with an independent samples *t*-test. One assumption is that the dependent variable be normally distributed within the both levels of the grouping variable. We evaluated skew and kurtosis using Kline's [-@kline_data_2016] guidelines of the absolute values of 3 (skew) and 10 (kurtosis). Our results were well-within these boundary conditions. Specifically, the verbal ratings of physicians with Black patients were -.37 and -.14 for skew and kurtosis, respectively; they were 1.07 and 1.54 for White patients. The Shapiro-Wilk test of normality indicated that the dependent variable was normally distributed within Black patients $(W = 0.977, p = 0.677)$, but not within White patients $(W = 0.922, p = 0.020)$. That is, the distribution of verbal communication scores for physicians attending to White patients was statistically significantly different from a normal distribution. Results of Levene's homogeneity of variance test suggested that the variance in each of the patient race groups was not statistically significantly different from each other $(F[1, 64] = 0.039, p = 0.843)$. Because the independent samples *t*-test is relatively robust to violations of normality when samples sizes have at least 15 participants per cell [@green_using_2017] and there was no violation of the homogeneity of variance assumption we proceded with the Student's formulation of the *t*-test for independent samples. - -Odds are, owing to space limitations in journals, you would not provide this much detail about an independent samples *t*-test in an empirical manuscript. I am encouraging you to do so as you work through these chapters because it is good practice for thinking through the logic and sequencing of statistics as well as writing results in APA style. - -### Computing the Independent Samples *t*-Test - -We are ready to compute the independent samples *t*-test. - -![A colorful image of a workflow for the paired samples *t*-test focusing on the computation of the t-test](images/ttests/IntSampT.jpg) - -Calculating an independent samples *t*-test is possible through base R and a number of packages. Kassambara's [-@kassambara_pipe-friendly_nodate] *rstatix* package is one we can use for all of the *t*-test and ANOVA problems that we will work. I like it for several reasons. First, it was designed to be "pipe-friendly" in a manner that is consistent with the *tidyverse* approach to working in R and there are numerous tutorials. Additionally, *rstatix* objects work well with *ggpubr*, one of my favorite packages for graphing data and results. - -In the script below: - -* the first element points to the dataframe -* the second element provides a "formula" - - we are predicting "Verbal" from "PatientRace" -* the third element, "var.equal=TRUE" means that we are using Student's formulation (because we did not violate the homogeneity of variance assumption) -* specifying "detailed = TRUE" will produce the 95% confidence interval around the difference in the two means - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::t_test(dfIndSamples, Verbal~PatientRace, var.equal=TRUE, detailed=TRUE) -``` -From this output we can start to draft our *t* string: $t(64) = -1.675, p = 0.099, CI95(-2.80, 0.25)$. - -Separately, we must request the effect size. Earlier in the lesson we calculated both Cohen's *d* and eta-squared. Unfortunately, the *rstatix* package only offers the Cohen's *d* for *t*-tests. If you wanted an eta-squared, it would be easy enough to hand-calculate (or obtain from another R package). -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::cohens_d(dfIndSamples, Verbal ~ PatientRace, var.equal = TRUE) -``` -We can update our *t* string to include the effect size: $t(64) = -1.675, p = 0.099, CI95(-2.80, 0.25), d = -0.412$ - -What does this mean? Our result is not-significant. Our estimate of the difference in verbal communication ratings when physicians interacted with Black and White patients was -1.675. We are 95% confident that that true mean difference is as low as -2.80 or as high as 0.25. Because the confidence interval crosses zero, we cannot be certain that the true difference is zero. This is consistent with the non-significant *p* value and effect size. Our output even tells us that the *d* of -0.41 is small. - -### What if we had violated the homogeneity of variance assumption? - -Earlier we used the Levene's test to examine the homogeneity of variance assumption. If we had violated it, the Welch's formulation of the independent sample *t*-test is available to us. The *rstatix* package makes this easy. We simply change the *var.equal* to *FALSE*. This will produce the Welch's alternative, which takes into consideration violations of the homogeneity of variance assumption. Conveniently, "Student's" or "Welch's" will serve as the first row of the output. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::t_test(dfIndSamples, Verbal~PatientRace, var.equal=FALSE, detailed=TRUE) -``` -Likely because of the similarity of the standard deviations associated with each level of patient race and our equal cell sizes, this changes nothing about our conclusion. Note that the degrees of freedom in the Student's *t*-test analysis (the first one) was 64; in the Welch's version, the degrees of freedom is 63.685. It is this change that, when the homogeneity of variance assumption is violated, can make the Welch's results more conservative (i.e., less likely to have a statistically significant result). - -## APA Style Results - -Putting it altogether, here is an APA Style results section: - ->An independent samples *t*-test was conducted to evaluate the hypothesis that there would be differences between the quality of physicians' verbal communication depending on whether the patient's race (Black, White). - ->We began by analyzing the data to see if it met the statistical assumptions for analysis with an independent samples *t*-test. One assumption is that the dependent variable be normally distributed within the both levels of the grouping variable. We evaluated skew and kurtosis using Kline's [-@kline_data_2016] guidelines of the absolute values of 3 (skew) and 10 (kurtosis). Our results were well-within these boundary conditions. Specifically, the verbal ratings of physicians with Black patients were -.37 and -.14 for skew and kurtosis, respectively; they were 1.07 and 1.54 for White patients. The Shapiro-Wilk test of normality indicated that the dependent variable was normally distributed within Black patients $(W = 0.977, p = 0.677)$, but not within White patients $(W = 0.922, p = 0.020$. That is, the distribution of verbal communication scores for physicians attending to White patients was statistically significantly different from a normal distribution. Results of Levene's homogeneity of variance test suggested that the variance in each of the patient race groups was not statistically significantly different from each other $(F[1, 64] = 0.039, p = 0.843)$. Because the independent samples *t*-test is relatively robust to violations of normality when samples sizes have at least 15 participants per cell [@green_using_2017] and there was no violation of the homogeneity of variance assumption we proceded with the Student's formulation of the *t*-test for independent samples. - ->Results of the independent samples *t*-test was nonsignificant, $t(64) = -1.675, p = .099, d = 0.412$. The 95% confidence interval for the difference in means ranged from -2.799 to 0.246. Means and standard deviations are presented in Table 1; the results are illustrated in Figure 1. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -apaTables::apa.1way.table(PatientRace, Verbal, dfIndSamples) -``` - -The figure we created earlier in the lesson would be sufficient for a journal article. However, using *rstatix* in combination with *ggpubbr* can be quite powerful. The result can be a figure that includes the *t*-test results and "significance bars." To do this, we first need to re-run the *rstatix::t_test*, but adding to it by - -* including "add_significance()" script after the pipe, and -* saving it as an object, which I'm naming "pair.test." - -We could have done this in the initial run (but I didn't want to make the test-statistic unnecessarily confusing). - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ind.test <- rstatix::t_test(dfIndSamples, Verbal~PatientRace, var.equal=TRUE, detailed=TRUE) %>% - rstatix::add_significance() -ind.test -``` - -Next, we update the earlier boxplot code with the results from our statistical analyses: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ind.box <- ggpubr::ggboxplot(dfIndSamples, x = "PatientRace", y = "Verbal", color = "PatientRace", palette=c("#00AFBB", "#FC4E07"), add = "jitter", title = "Figure 1. Physician Verbal Engagement as a Function of Patient Race") -ind.test <- ind.test %>% rstatix::add_xy_position(x = "PatientRace") #autocomputes p-value labels positions -ind.box <- ind.box + - ggpubr::stat_pvalue_manual(ind.test, label = "p.signif", tip.length=.02, hide.ns = FALSE, y.position = c(18)) + - labs(subtitle = rstatix::get_test_label(ind.test, detailed=TRUE)) #adds t-test results - -ind.box -``` -Between the *rstatix* and *ggpubr* tools, there is a great deal of flexibility in creating figures. Determining which figure is best will likely depend on your outlet, your audience, your goals, and your personal preferences. For example, a print journal might prefer a black-and-white figure (with no fill in the boxes). This is accomplished easily enough by removing (or, hashtagging out) the "color" and "palette" arguments. - -## Power in Independent Samples *t*-tests - -Researchers often use power analysis packages to estimate the sample size needed to detect a statistically significant effect, if, in fact, there is one. Utilized another way, these tools allows us to determine the probability of detecting an effect of a given size with a given level of confidence. If the probability is unacceptably low, we may want to revise or stop. A helpful overview of power as well as guidelines for how to use the *pwr* package can be found at a [Quick-R website](https://www.statmethods.net/stats/power.html) [@kabacoff_power_2017]. - -In Champely's *pwr* package, we can conduct a power analysis for a variety of designs, including the independent samples *t*-test that we worked in this lesson. There are a number of interrelating elements of power: - -* Sample size, *n* refers to the number of observations in each group; our vignette had 33 -* *d* refers to the difference between means divided by the pooled standard deviation; we can use the value of Cohen's *d* for this -* *power* refers to the power of a statistical test; conventionally it is set at .80 -* *sig.level* refers to our desired alpha level; conventionally it is set at .05 -* *type* indicates the type of test we ran; this was "two.sample" -* *alternative* refers to whether the hypothesis is non-directional/two-tailed ("two.sided") or directional/one-tailed("less" or "greater") - -In this script, we must specify *all-but-one* parameter; the remaining parameter must be defined as NULL. R will calculate the value for the missing parameter. - -When we conduct a "power analysis" (i.e., the likelihood of a hypothesis test detecting an effect if there is one), we specify, "power=NULL". Using the data from our results, we learn from this first run, that our statistical power was 0.38. That is, given the value of the mean difference (1.276) we had a 38% chance of detecting a statistically significant effect if there was one. This is consistent with our non-significant result. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.t.test(d= -0.412,n = 33, power=NULL,sig.level=0.05,type="two.sample",alternative="two.sided") -``` -Researchers frequently use these tools to estimate the sample size required to obtain a statistically significant effect. In these scenarios we set *n* to *NULL*. Using the results from the simulation of our research vignette, you can see that we would have needed 93 individuals (per group; 186 total) for the *p* value to be < .05. - - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwr::pwr.t.test(d= -0.412,n = NULL, power=0.8,sig.level=0.05,type="two.sample",alternative="two.sided") -``` -Given that we had a non-significant result, this is not surprising. None-the-less, let's try it again. Below I will re-simulate the data for the verbal scores and change only the sample size: - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -set.seed(230525) -#sample size, M, and SD for Black then White patients -rVerbal <- c(rnorm(93, mean=8.37, sd=3.36), rnorm(93, mean = 8.41, sd=3.21)) -#set upper bound -rVerbal[rVerbal>27]<-3 -#set lower bound -rVerbal[rVerbal<0]<-0 -#sample size, M, and SD for Black then White patients -rNonverbal <- c(rnorm(93, mean=2.68, sd=.84), rnorm(93, mean = 2.93, sd=.77)) -#set upper bound -rNonverbal[rNonverbal>5]<-5 -#set lower bound -rNonverbal[rNonverbal<0]<-0 - -rID<-factor(seq(1,186)) -#name factors and identify how many in each group; should be in same order as first row of script -rPatientRace<-c(rep("Black", 93), rep("White", 93)) -#groups the 3 variables into a single df: ID#, DV, condition -rdfIndSamples <-data.frame(rID, rPatientRace, rVerbal, rNonverbal) - -rdfIndSamples$rPatientRace <- factor(rdfIndSamples$rPatientRace, levels = c("Black", "White")) -``` - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::t_test(rdfIndSamples, rVerbal~rPatientRace, var.equal=TRUE, detailed=TRUE) -rstatix::cohens_d(rdfIndSamples, rVerbal~rPatientRace, var.equal = TRUE) -``` - -Curiously, our result is still not statistically significant: $t(184) = 1.713, p = 0.088, d = 0.251, CI95[-0.129, 1.832]$. Given the closeness of our means (9.025, 8.173), this makes sense to me. Additionally, it does show us, though, how power is influenced by sample size. Holding all else equal, the larger the sample, the more likely we are to have a statistically significant result. - -## Practice Problems - -The suggestions for homework differ in degree of complexity. I encourage you to start with a problem that feels "do-able" and then try at least one more problem that challenges you in some way. Regardless, your choices should meet you where you are (e.g., in terms of your self-efficacy for statistics, your learning goals, and competing life demands). - -Additionally, please complete at least one set of *hand calculations*, that is using the code demonstrated in the chapter to work through the formulas that compute the independent samples *t*-test. At this stage in your learning, you may ignore any missingness in your dataset by excluding all rows with missing data in your variables of interest. - -### Problem #1: Rework the research vignette as demonstrated, but change the random seed - -If this topic feels a bit overwhelming, simply change the random seed in the data simulation of the research vignette, then rework the problem. This should provide minor changes to the data (maybe even in the second or third decimal point), but the results will likely be very similar. That said, don't be alarmed if what was non-significant in my working of the problem becomes significant. Our selection of *p* < .05 (and the corresponding 95% confidence interval) means that 5% of the time there could be a difference in statistical significance. - -### Problem #2: Rework the research vignette, but change something about the simulation - -Rework the independent samples *t*-test in the lesson by changing something else about the simulation. You might have noticed that my re-simulation of a smaller sample size did not produce a statistically significant result. You may wish to pick a value in between the primary lecture *N* and the re-simulation to see what it takes to achieve statistical significance. Alternatively, you could specify different means and/or standard deviations. - -### Problem #3: Rework the research vignette, but swap one or more variables - -Use the simulated data, but select the nonverbal communication variables that were evaluated in the Elliott et al. [-@elliott_differences_2016]study. Compare your results to those reported in the mansucript. - -### Problem #4: Use other data that is available to you - -Using data for which you have permission and access (e.g., IRB approved data you have collected or from your lab; data you simulate from a published article; data from an open science repository; data from other chapters in this OER), complete an independent samples *t*-test. - - -### Grading Rubric - -Regardless which option(s) you chose, use the elements in the grading rubric to guide you through the practice. - -|Assignment Component | Points Possible | Points Earned| -|:-------------------------------------- |:----------------: |:------------:| -|1. Narrate the research vignette, describing the variables and their role in the analysis | 5 |_____ | -|2. Simulate (or import) and format data | 5 |_____ | -|3. Evaluate statistical assumptions | 5 |_____ | -|4. Conduct an independent samples *t*-test (with an effect size and 95%CIs) |5 | _____ | -|5. APA style results with table(s) and figure | 5 |_____ | -|6. Conduct power analyses to determine the power of the current study and a recommended sample size | 5 |_____ | -|7. Explanation to grader | 5 |_____ | -|**Totals** | 35 |_____ | - -|Hand Calculations |Points Possible | Points Earned -|:-----------------------------------------|:--------------:|:--------------| -|1. Using traditional NHST (null hypothesis testing language), state your null and alternative hypotheses| 2 |_____ | -|2. Using an R package or functions in base R, calculate the means and standard deviations for both levels of the dependent variable | 4 |_____| -|3. Calculate the SE used in the denominator of the *t*-test |4 |_____| -|4. Calculate the independent samples *t*-test| 4 |_____| -|5. Identify the degrees of freedom associated with your *t*-test | 2 | _____| -|6. Locate the test critical value for your test |2 | _____ | -|7. Is the *t*-test statistically significant? Why or why not? | 2 | _____ | -|8. What is the confidence interval around the difference in sample means? |4 |_____ | -|9.Calculate the effect size (i.e., Cohen's *d* associated with your *t*-test |4 | _____ | -|10. Assemble the results into a statistical string |4 | _____ | -|**Totals** | 32 |_____ | - -```{r, child= 'Worked_Examples/15-4-woRked_tInd.Rmd'} -``` - -```{r include=FALSE} -sessionInfo() -``` - - - - - diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/FB11A8A2-contents b/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/FB11A8A2-contents deleted file mode 100644 index 776e41f4..00000000 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/FB11A8A2-contents +++ /dev/null @@ -1,752 +0,0 @@ -# Analysis of Covariance {#ANCOVA} - -[Screencasted Lecture Link](https://youtube.com/playlist?list=PLtz5cFLQl4KM2GjVUMy1Vy816d5lgbOvi) - -```{r include=FALSE} -knitr::opts_chunk$set(echo = TRUE) -knitr::opts_chunk$set(comment = NA) #keeps out the hashtags in the knits -options(scipen=999)#eliminates scientific notation -``` - -The focus of this lecture is analysis of covariance. Sticking with the same research vignette as we used for the mixed design ANOVA, we rearrange the variables a bit to see how they work in an ANCOVA design. The results help clarify the distinction between *moderator* and *covariate.* - -## Navigating this Lesson - -There is about just about an hour of lecture. If you work through the materials with me, plan for an additional hour or two - -While the majority of R objects and data you will need are created within the R script that sources the chapter, occasionally there are some that cannot be created from within the R framework. Additionally, sometimes links fail. All original materials are provided at the [Github site](https://github.com/lhbikos/ReCenterPsychStats) that hosts the book. More detailed guidelines for ways to access all these materials are provided in the OER's [introduction](#ReCintro) - -### Learning Objectives - -Learning objectives from this lecture include the following: - -* Define a *covariate* and distinguish it from a *moderator.* -* Recognize the case where ANCOVA is a defensible statistical approach for analyzing the data. -* Name and test the assumptions underlying ANCOVA. -* Analyze, interpret, and write up results for ANCOVA. -* List the conditions that are prerequisite for the appropriate use of a covariate or control variable. - -### Planning for Practice - -In each of these lessons I provide suggestions for practice that allow you to select from problems that vary in degree of difficulty The least complex is to change the random seed and rework the problem demonstrated in the lesson. The results *should* map onto the ones obtained in the lecture. - -The second option comes from the research vignette. For this ANCOVA article, I take a lot of liberties with the variables and research design. You could further mix and match for a different ANCOVA constellation. - -As a third option, you are welcome to use data to which you have access and is suitable for ANCOVA. In either case the practice options suggest that you: - -* test the statistical assumptions -* conduct an ANCOVA, including - - omnibus test and effect size - - report main effects and engage in any follow-up testing - - interpret results in light of the role of the second predictor variable as a *covariate* (as opposed to the moderating role in the prior lessons) -* write a results section to include a figure and tables - -### Readings & Resources - -In preparing this chapter, I drew heavily from the following resource(s). Other resources are cited (when possible, linked) in the text with complete citations in the reference list. - -* Green, S. B., & Salkind, N. J. (2017). One-Way Analysis of Covariance (Lesson 27). In *Using SPSS for Windows and Macintosh: Analyzing and understanding data* (Eighth edition., pp. 151–160). Boston: Pearson. OR - - This lesson provides an excellent review of ANCOVA with examples of APA style write-ups. The downside is that it is written for use in SPSS. -* ANCOVA in R: The Ultimate Practical Guide. (n.d.). Retrieved from https://www.datanovia.com/en/lessons/ancova-in-r/ - - This is the workflow we are using for the lecture and written specifically for R. -* Bernerth, J. B., & Aguinis, H. (2016). A critical review and best‐practice recommendations for control variable usage. *Personnel Psychology, 69*(1), 229–283. https://doi.org/10.1111/peps.12103 - - An article from the industrial-organizational psychology world. Especially relevant for this lesson is the flowchart on page 273 and the discussion (pp. 270 to the end). -* Murrar, S., & Brauer, M. (2018). Entertainment-education effectively reduces prejudice. *Group Processes & Intergroup Relations, 21*(7), 1053–1077. https://doi.org/10.1177/1368430216682350 - - This article is the source of our research vignette. I used this same article in the lesson on [mixed design ANOVA](#Mixed). Swapping variable roles can be useful in demonstrating how ANCOVA is different than mixed design ANOVA. - -### Packages - -The packages used in this lesson are embedded in this code. When the hashtags are removed, the script below will (a) check to see if the following packages are installed on your computer and, if not (b) install them. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#used to convert data from long to wide -#if(!require(reshape2)){install.packages("reshape2")} -#if(!require(broom)){install.packages("broom")} -#if(!require(tidyverse)){install.packages("tidyverse")} -#if(!require(psych)){install.packages("psych")} -#easy plots -#if(!require(ggpubr)){install.packages("ggpubr")} -#pipe-friendly R functions -#if(!require(rstatix)){install.packages("rstatix")} -#export objects for table making -#if(!require(MASS)){install.packages("MASS")} -#if(!require(knitr)){install.packages("knitr")} -#if(!require(dplyr)){install.packages("dplyr")} -#if(!require(apaTables)){install.packages("apaTables")} -``` - -## Introducing Analysis of Covariance (ANCOVA) - -Analysis of covariance (ANCOVA) evaluates the null hypothesis that - -* population means on a dependent variable are equal across levels of a factor(s) adjusting for differences on a covariate(s); stated differently - -* the population adjusted means are equal across groups - -This lecture introduces a distinction between **moderators** and **covariates**. - -**Moderator**: a variable that changes the strength or direction of an effect between two variables X (predictor, independent variable) and Y (criterion, dependent variable). - -**Covariate**: an observed, continuous variable, that (when used properly) has a relationship with the dependent variable. It is included in the analysis, as a predictor, so that the predictive relationship between the independent (IV) and dependent (DV) are adjusted. - -Understanding this difference may be facilitated by understanding one of the assumptions of ANCOVA -- that the slopes relating the covariate to the dependent variable are the same for all groups (i.e., the homogeneity-of-slopes assumption). If this assumption is violated then the between-group differences in adjusted means are not interpretable and the covariate should be treated as a moderator and analyses that assess the simple main effects (i.e., follow-up to a significant interaction) should be conducted. - -A one-way ANCOVA requires three variables: - -* IV/factor -- categorical (2 or more) -* DV -- continuous -* covariate -- continuous - -Green and Salkind [-@green_one-way_2017] identified common uses of ANCOVA: - -* Studies with a pretest and random assignment of subjects to factor levels. Variations on this research design include: - - assignment to factor levels based on that pretest, - - matching based on the pretest, and random assignment to factor levels, - - simply using the pretest as a covariate for the posttest DV. -* Studies with a potentially confounding variable (best when there is theoretical justification and prior empirical evidence for such) over which the researcher wants "control" - -Although it is possible to have multi-way (e.g., 2-way, 3-way) ANCOVA, in this lecture we will only work two, one-way ANCOVAs representing these common use cases. - -### Workflow for ANCOVA - -Our analytic process will be similar to others in the ANOVA series. An ANCOVA workflow maps this in further detail. - -![Image of the ANCOVA workflow](images/ANCOVA/wf_ANCOVA.jpg) - -1. Prepare the data -2. Evaluate potential violation of the assumptions -3. Compute the omnibus ANCOVA, and follow-up accordingly - - If significant: follow-up with post-hoc comparisons, planned contrasts, and/or polynomial - - If non-significant: stopping. - -ANCOVA has four primary assumptions: - -**Linearity**: The covariate is linearly related to the dependent variable within all levels of the factor (IV). - -**Homogeneity of regression slopes**: The weights or slopes relating the covariate to the DV are equal across all levels of the factor. - -**Normally distributed**: The DV is normally distributed in the population for any specific value of the covariate and for any one level of a factor. This assumption applies to every combination of the values of the covariate and levels ohttps://www.datanovia.com/en/lessons/ancova-in-r/f the factor and requires them all to be normally distributed. To the degree that population distributions are not normal and sample sizes are small, *p* values may not be trustworthy and power reduced. Evaluating this is frequently operationalized by inspecting the residuals and identifying outliers. - -**Homogeneity of variances**: The variances of the DV for the conditional distributions (i.e., every combination of the values of the covariate and levels of the factor) are equal. - -We are following the approach to analyzing ANCOVA identified in the Datanovia lesson on ANCOVA [@datanovia_ancova_nodate]. - -## Research Vignette - -We will continue with the example used in the [mixed design ANOVA lesson](#Mixed) The article does not contain any ANCOVA analyses, but there is enough data that I can demonstrate the two general ways (i.e., controlling for the pretest, controlling for a potentially confounding variable) that ANCOVA is used. - -Here is a quick reminder of the research vignette. - -Murrar and Brauer's [-@murrar_entertainment-education_2018] article described the results of two studies designed to reduce prejudice against Arabs/Muslims. In the lesson on mixed design ANOVA, we only worked the first of two experiments reported in the study. Participants (*N* = 193), all who were White, were randomly assigned to one of two conditions where they watched six episodes of the sitcom [*Friends*](http://www.friends-tv.org/) or [*Little Mosque on the Prairie*](https://en.wikipedia.org/wiki/Little_Mosque_on_the_Prairie). The sitcoms and specific episodes were selected after significant pilot testing. The selection was based on the tension selecting stimuli that were as similar as possible, yet the intervention-oriented sitcom needed to invoke psychological processes known to reduce prejudice. The authors felt that both series had characters that were likable and relateble who were engaged in activities of daily living. The Friends series featured characters who were predominantly White, cis-gendered, and straight. The Little Mosque series portrays the experience Western Muslims and Arabs as they live in a small Canadian town. This study involved assessment across three waves: baseline (before watching the assigned episodes), post1 (immediately after watching the episodes), and post2 (completed 4-6 weeks after watching the episodes). - -The study used *feelings and liking thermometers*, rating their feelings and liking toward 10 different groups of people on a 0 to 100 sliding scale (with higher scores reflecting greater liking and positive feelings). For the purpose of this analysis, the ratings of attitudes toward White people and attitudes toward Arabs/Muslims were used. A third metric was introduced by subtracting the attitudes towards Arabs/Muslims from the attitudes toward Whites. Higher scores indicated more positive attitudes toward Whites where as low scores indicated no difference in attitudes. To recap, there were three potential dependent variables, all continuously scaled: - -* AttWhite: attitudes toward White people; higher scores reflect greater liking -* AttArab: attitudes toward Arab people; higher scores reflect greater liking -* Diff: the difference between AttWhite and AttArab; higher scores reflect a greater liking for White people - -With random assignment, nearly equal cell sizes, a condition with two levels (Friends, Little Mosque), and three waves (baseline, post1, post2), this is perfect for mixed design ANOVA but suitable for an ANCOVA demonstration. - -![Image of the design for the Murrar and Brauer (2018) study](images/mixed/Murrar_design.jpg) - -### Data Simulation - -Below is the code I have used to simulate the data. The simulation includes two dependent variables (AttWhite, AttArab), Wave (baseline, post1, post2), and COND (condition; Friends, Little_Mosque). There is also a caseID (repeated three times across the three waves) and rowID (giving each observation within each case an ID). You can use this simulation for two of the three practice suggestions. - -```{r message=FALSE, warning=FALSE, tidy=TRUE, tidy.opts=list(width.cutoff=70)} -library(tidyverse) -#change this to any different number (and rerun the simulation) to rework the chapter problem -set.seed(210813) -#sample size, M and SD for each cell; this will put it in a long file -AttWhite<-round(c(rnorm(98,mean=76.79,sd=18.55),rnorm(95,mean=75.37,sd=18.99),rnorm(98, mean=77.47, sd=18.95), rnorm(95, mean=75.81, sd=19.29), rnorm(98, mean=77.79, sd=17.25), rnorm(95, mean=75.89, sd=19.44)),3) -#set upper bound for variable -AttWhite[AttWhite>100]<-100 -#set lower bound for variable -AttWhite[AttWhite<0]<-0 -AttArab<-round(c(rnorm(98,mean=64.11,sd=20.97),rnorm(95,mean=64.37,sd=20.03),rnorm(98, mean=64.16, sd=21.64), rnorm(95, mean=70.52, sd=18.55), rnorm(98, mean=65.29, sd=19.76), rnorm(95, mean=70.30, sd=17.98)),3) -#set upper bound for variable -AttArab[AttArab>100]<-100 -#set lower bound for variable -AttArab[AttArab<0]<-0 -rowID <- factor(seq(1,579)) -caseID <- rep((1:193),3) -Wave <- c(rep("Baseline",193), rep("Post1", 193), rep ("Post2", 193)) -COND <- c(rep("Friends", 98), rep("LittleMosque", 95), rep("Friends", 98), rep("LittleMosque", 95), rep("Friends", 98), rep("LittleMosque", 95)) -#groups the 3 variables into a single df: ID#, DV, condition -Murrar_df<- data.frame(rowID, caseID, Wave, COND, AttArab, AttWhite) -#make caseID a factor -Murrar_df[,'caseID'] <- as.factor(Murrar_df[,'caseID']) -#make Wave an ordered factor -Murrar_df$Wave <- factor(Murrar_df$Wave, levels = c("Baseline", "Post1", "Post2")) -#make COND an ordered factor -Murrar_df$COND <- factor(Murrar_df$COND, levels = c("Friends", "LittleMosque")) -#creates the difference score -Murrar_df$Diff <- Murrar_df$AttWhite - Murrar_df$AttArab -``` - -Let's check the structure. We want - -* rowID and caseID to be unordered factors, -* Wave and COND to be ordered factors, -* AttArab, AttWhite, and Diff to be numerical - -```{r} -str(Murrar_df) -``` -The structure looks satisfactory. R will automatically "order" factors alphabetically or numerically. In this lesson's example the alphabettical ordering (i.e., Baseline, Post1, Post2; Friends, LittleMosque) is consistent with the logic in our study. - -If you want to export this data as a file to your computer, remove the hashtags to save it (and re-import it) as a .csv ("Excel lite") or .rds (R object) file. This is not a necessary step. - -The code for the .rds file will retain the formatting of the variables, but is not easy to view outside of R. This is what I would do. *Note: My students and I have discovered that the the psych::describeBy() function seems to not work with files in the .rds format, but does work when the data are imported with .csv.* -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#to save the df as an .rds (think "R object") file on your computer; -#it should save in the same file as the .rmd file you are working with -#saveRDS(Murrar_df, "Murrar_RDS.rds") -#bring back the simulated dat from an .rds file -#Murrar_df <- readRDS("Murrar_RDS.rds") -``` - -The code for .csv will likely lose the formatting (i.e., stripping Wave and COND of their ordered factors), but it is easy to view in Excel. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#write the simulated data as a .csv -#write.table(Murrar_df, file="DiffCSV.csv", sep=",", col.names=TRUE, row.names=FALSE) -#bring back the simulated dat from a .csv file -#Murrar_df <- read.csv ("DiffCSV.csv", header = TRUE) -``` - -## Working the ANCOVA -- Scenario #1: Controlling for the pretest - -So that we can begin to understand how the covariate operates, we are going to predict attitudes towards Arabs at post-test (AttArabP1) by condition (COND), controlling for attitudes toward Arabs at baseline (AttArabB). You may notice that in this analysis we are ignoring the second post-test. This is because I am simply demonstrating ANCOVA. To ignore the second post test would be a significant loss of information. - -### Preparing the data - -When the covariate in ANCOVA is a pretest, we need three variables: - -* IV that has two or more levels; in our case it is the Friends and Little Mosque conditions -* DV that is continuous; in our case it is the attitudes toward Arabs at post1 -* Covariate that is continuous; in our case it is the attitudes toward Arabs at baseline - -The form of our data matters. The simulation created a *long* form (formally called the *person-period* form) of data. That is, each observation for each person is listed in its own row. In this dataset where we have 193 people with 3 observation (baseline, post1, post2) each, we have 579 rows. In ANCOVA where we use the pre-test as a covariate, we need all the data to be on a single row.This is termed the *person level* form of data. We can restructure the data with the *data.table* and *reshape2*()* packages. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -# Create a new df (Murrar_wide) -# Identify the original df -#In the transition from long-to-wide it seems like you can only do one time-varying variable at a time -#When there are multiple time-varying and time-static variables, -#put all the time-static variables on the left side of the tilde -#Put the name of the single time-varying variable in the concatonated list -Murrar1 <- reshape2::dcast(data = Murrar_df, formula =caseID +COND ~ Wave, value.var = "AttArab") -#before restructuring a second variable, rename the first variable -Murrar1 <- rename(Murrar1, AttArabB = "Baseline", AttArabP1 = "Post1", AttArabP2 = "Post2") -#repeat the process for additional variables; but give the new df new names -- otherwise you'll overwrite your work -Murrar2 <- reshape2::dcast(data = Murrar_df, formula =caseID ~Wave, value.var = "AttWhite") -Murrar2 <- rename(Murrar2, AttWhiteB = "Baseline", AttWhiteP1 = "Post1", AttWhiteP2 = "Post2") -#Now we join them -Murrar_wide <- dplyr::full_join(Murrar1, Murrar2, by = c("caseID")) - -str(Murrar_wide ) -``` -If you want to export this data as a file to your computer, remove the hashtags to save it (and re-import it) as a .csv ("Excel lite") or .rds (R object) file. This is not a necessary step. - -The code for the .rds file will retain the formatting of the variables, but is not easy to view outside of R. This is what I would do. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#to save the df as an .rds (think "R object") file on your computer; -#it should save in the same file as the .rmd file you are working with -#saveRDS(Murrar_wide, "MurrarW_RDS.rds") -#bring back the simulated dat from an .rds file -#Murrar_wide <- readRDS("MurrarW_RDS.rds") -``` - -The code for .csv will likely lose the formatting (i.e., stripping Wave and COND of their ordered factors), but it is easy to view in Excel. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#write the simulated data as a .csv -#write.table(Murrar_wide, file="MurrarW_CSV.csv", sep=",", col.names=TRUE, row.names=FALSE) -#bring back the simulated dat from a .csv file -#Murrar_wide <- read.csv ("MurrarW_CSV.csv", header = TRUE) -``` - -### Evaluating the statistical assumptions - -There are a number of assumptions in ANCOVA. These include: - -* random sampling -* independence in the scores representing the dependent variable - - there is, of course, intentional dependence in any repeated measures or within-subjects variable -* linearity of the relationship between the covariate and DV within all levels of the independent variable -* homogeneity of the regression slopes -* a normally distributed DV for any specific value of the covariate and for any one level of a factor -* homogeneity of variance - -These are depicted in the flowchart, below. - -![Image of the ANCOVA workflow, showing our current place in the process](images/ANCOVA/wf_ANCOVA_assumptions.jpg) - -#### Linearity assumption - -ANCOVA assumes that there is linearity between the covariate and outcome variable at each level of the grouping variable. In our case this means that there is linearity between the pre-test (covariate) and post-test (outcome variable) at each level of the intervention (Friends, Little Mosque). - -We can create a scatterplot (with regression lines) between covariate (our pretest) and the outcome (post-test1). - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ggpubr::ggscatter ( - Murrar_wide, x = "AttArabB", y = "AttArabP1", - color = "COND", add = "reg.line" -)+ - ggpubr::stat_regline_equation( - aes(label = paste(..eq.label.., ..rr.label.., sep = "~~~~"), color = COND) - ) - -``` -As in not surprising (because we tested a similar set of variables in the mixed design chapter), this relationship look like an interaction effect. Let's continue our exploration. - -#### Homogeneity of regression slopes - -This assumption requires that the slopes of the regression lines formed by the covariate and the outcome variable are the same for each group. The assumption evaluates that there is no interaction between the outcome and covariate. The plotted regression lines should be parallel. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -Murrar_wide %>% rstatix::anova_test(AttArabP1 ~ COND*AttArabB) -``` -Because the statistically significant interaction term is violation of homogeneity of regression slopes $(F [1, 189] = 4.297, p = .040, \eta^2 = 0.022)$ we should not proceed with ANCOVA as a statistical option. However, for the sake of demonstration, I will continue. One of the reasons I wanted to work this example as ANCOVA is to demonstrate that covariates and moderators each have their role. We can already see how this data is best analyzed with mixed design ANOVA. - -#### Normality of residuals - -Our goal here is to specify a model and extract *residuals*: the difference between the observed value of the DV and its predicted value. Each data point has one residual. The sum and mean of residuals are equal to 0. - -Once we have saved the residuals, we can treat them as data and evaluate the shape of their distribution. We hope that the distribution is not statistically significantly different from a normal one. We first compute the model with *lm()* (lm stands for "linear model"). This is a linear regression. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Create a linear regression model predicting DV from COV & IV -AttArabB_Mod <- lm (AttArabP1 ~ AttArabB + COND, data = Murrar_wide) -AttArabB_Mod -``` -With the *broom::augment()* function we can augment our *lm()* model object to add fitted values and residuals. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#new model by augmenting the lm model -AttArabB_Mod.metrics <- broom::augment(AttArabB_Mod) -#shows the first three rows of the UEmodel.metrics -head(AttArabB_Mod.metrics,3) -``` - -From this, we can assess the normality of the residuals using the Shapiro Wilk test - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#apply shapiro_test to that augmented model -rstatix::shapiro_test(AttArabB_Mod.metrics$.resid) -``` -The statistically significant Shapiro Wilk test has indicated a violation of the normality assumption (*W* = 0.984, *p* = .026). - -#### Homogeneity of variances - -ANCOVA presumes that the variance of the residuals is equal for all groups. We can check this with the Levene's test. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -AttArabB_Mod.metrics %>% rstatix::levene_test(.resid ~ COND) -``` -A non-significant Levene's test indicated no violation of the homogeneity of the residual variances for all groups $(F[1, 191] = 3.515 p = .062)$. - -#### Outliers - -We can identify outliers by examining the standardized (or studentized) residuals. This is the residual divided by its estimated standard error. Standardized residuals are interpreted as the number of standard errors away from the regression line. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#from our model metrics -#show us any standardized residuals that are >3 -AttArabB_Mod.metrics%>% - filter(abs(.std.resid)>3)%>% - as.data.frame() -``` -We do have one outlier with a standardized residual that has an absolute value greater than 3. At this point I am making a mental note of this. If this were "for real" I might more closely inspect these data. I would look at the whole response. If any response seemed invalid (e.g., random, extreme, or erratic responding) I would delete it. If the responses seemed valid, I *could* truncate them to exactly 3 SEs or. I could also ignore it. Kline [-@kline_data_2016] has a great section on some of these options. - -Code for deleting outliers can be found in earlier chapters, including [Mixed Design ANOVA](#Mixed). - -As noted by the suggestion of an interaction effect, our preliminary analyses suggests that ANCOVA is not the best option. We know from the prior lesson that a mixed design ANOVA worked well. In the spirit of an example, here's a preliminary write-up so far: - -#### Summarizing results from the analysis of assumptions - ->A one-way analysis of covariance (ANCOVA) was conducted. The independent variable, condition, had two levels: Friends, Little Mosque. The dependent variable was attitudes towards Arabs expressed by the participant at post-test and covariate was the pre-test assessment of the same variable. A preliminary analysis evaluating the homogeneity-of-slopes assumption indicated that the relationship between the covariate and the dependent variable differed significantly as a function of the independent variable, $F (1, 189) = 4.297, p = .040, \eta^2 = 0.022$. Regarding the assumption that the dependent variable is normally distributed in the population for any specific value of the covariate and for any one level of a factor, results of the Shapiro-Wilk test of normality on the model residuals was also significant,$W = 0.984, p = .026$. Only one datapoint (in the Little Mosque condition) had a standardized residual (-3.37) that exceeded an absolute value of 3.0. A non-significant Levene's test indicated no violation of the homogeneity of the residual variances for all groups, $F(1, 191) = 3.515, p = .062$. - -### Calculating the Omnibus ANOVA - -We are ready to conduct the omnibus ANOVA. - -![Image of the ANCOVA workflow, showing our current place in the process.](images/ANCOVA/wf_ANCOVA_omnibus.jpg) - -*Order of variable entry* matters in ANCOVA. Thinking of the *controlling for* language associate with covariates, we want to remove the effect of the covariate before we run the one-way ANOVA. With this ANCOVA we are asking the question, "Does the condition (Friends or Little Mosque) contribute to more positive attitudes toward Arabs, when controlling for the pre-test score?" - -In repeated measures projects, we expect there to be dependency in the data. That is, in most cases prior waves will have significant prediction on later waves. When ANCOVA uses a prior asssessment or wave as a covariate, that variable "claims" as much variance as possible and the subsequent variable can capture what is left over. - -In the code below, we are predicting attitudes toward Arabs at post1 from the condition (Friends or Little Mosque), controlling for attitudes toward Arabs at baseline. - -The *ges* column provides the effect size, $\eta^2$. Conventionally, values of .01, .06, and .14 are considered to be small, medium, and large effect sizes, respectively. - -You may see different values (.02, .13, .26) offered as small, medium, and large -- these values are used when multiple regression is used. A useful summary of effect sizes, guide to interpreting their magnitudes, and common usage can be found [here](https://imaging.mrc-cbu.cam.ac.uk/statswiki/FAQ/effectSize) [@watson_rules_2020]. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -MurrarB_ANCOVA <- Murrar_wide %>% - rstatix::anova_test(AttArabP1 ~ AttArabB + COND) -rstatix::get_anova_table(MurrarB_ANCOVA ) -``` -There was a non-significant effect of the baseline covariate on the post-test $(F[1, 190] = 0.665, p = .416, \eta^2 = 0.003)$. After controlling for the baseline attitudes toward Arabs, there was a statistically significant effect of condition on post-test attitudes toward Arabs, $F(1,190) = 26.361, p < .001, \eta^2 = 0.122$. This effect appears to be moderate-to-large in size. - -### Post-hoc pairwise comparisons (controlling for the covariate) - -Just like in one-way ANOVA, we follow-up the significant effect of condition. We'll use all-possible pairwise comparisons. In our case, we only have two levels of the categorical factor, so this run wouldn't be necessary. I included it to provide the code for doing so. If there were three or more variables, we would see all possible comparisons. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwc_B <- Murrar_wide %>% - rstatix::emmeans_test( - AttArabP1 ~ COND, covariate = AttArabB, - p.adjust.method = "none" - ) -pwc_B -``` - -Not surprisingly (since this single pairwise comparison is redundant with the omnibus ANCOVA), results suggest a statistically significant difference between Friends and Little Mosque at Post1. - -With the script below we can obtain the covariate-adjusted marginal means. These are termed *estimated marginal means.* Take a look at these and compare them to what we would see in the regular descriptives. It is helpful to see the grand mean (AttArabB) and then the marginal means (emmean). - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -emmeans_B <- rstatix::get_emmeans(pwc_B) -emmeans_B -``` - -Note that the *emmeans* process produces slightly different means than the raw means produced with the *psych* package's *describeBy()* function. Why? Because the *get_emmeans()* function uses the model that included the covariate. That is, the *estimated* means are covariate-adjusted. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -descripts_P1 <- psych::describeBy(AttArabP1 ~ COND, data = Murrar_wide, mat = TRUE) -descripts_P1 -#Note. Recently my students and I have been having intermittent struggles with the describeBy function in the psych package. We have noticed that it is problematic when using .rds files and when using data directly imported from Qualtrics. If you are having similar difficulties, try uploading the .csv file and making the appropriate formatting changes. -``` - -$(M = 59.02, SD = 21.65)$ -$(M = 73.92, SD = 18.51)$ - -In our case the adjustments are very minor. Why? The effect of the attitudes toward Arabs baseline test on the attitudes toward Arabs post test was nonsignificant. We can see this in the bivariate correlations, below. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -MurP1_Rmat <- psych::corr.test(Murrar_wide[c("AttArabB", "AttArabP1")]) -MurP1_Rmat -``` -The correlation between attitudes toward Arabs at baseline and post test are nearly negligible $(r = -0.05, p = .47)$. - -### APA style results for Scenario 1 - -As we assemble the elements for an APA style result sections, a table with the means, adjusted means, and correlations may be helpful. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -apaTables::apa.cor.table(Murrar_wide[c("AttArabB", "AttArabP1")], table.number = 1 ) -#You can save this as a Microsoft word document by adding this statement into the command: filename = "your_filename.doc" -``` - -Additionally, writing this output to excel files helped create the two tables that follow. The *MASS* package is useful to export the model objects into .csv files. They are easily opened in Excel where they can be manipulated into tables for presentations and manuscripts. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -MASS::write.matrix(pwc_B, sep = ",", file = "pwc_B.csv") -MASS::write.matrix(emmeans_B, sep = ",", file = "emmeans_B.csv") -MASS::write.matrix(descripts_P1, sep = ",", file = "descripts_P1.csv") -``` -Ultimately, I would want a table that included this information. Please refer to the APA style manual for more proper formatting for a manuscript that requires APA style. - -|Table 1 -|:-----------------------------------------------| -|Unadjusted and Covariate-Adjusted Descriptive Statistics - -|Condition |Unadjusted |Covariate-Adjusted -|:--------------|:-----------:|:----------------:| - -| |*M* |*SD* |*EMM* |*SE* -|:--------------|:----:|:----:|:----:|:---:| -|Friends |59.02 |21.65 |59.01 |2.04 | -|Little Mosque |73.92 |18.51 |73.93 |2.07 | - -Unlike the figure we created when we were testing assumptions, this script creates a plot from the model (which identifies AttArabB in its role as covariate). Thus, the relationship between condition and AttArabP1 controls for the effect of the AttArabB covariate. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwc_B <- pwc_B %>% rstatix::add_xy_position(x = "COND", fun = "mean_se") -ggpubr::ggline(rstatix::get_emmeans(pwc_B), x = "COND", y = "emmean", title = "Figure 1. Post-test Attitudes by Condition, Controlling for Pre-test Attitudes") + - geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0.2) + - ggpubr::stat_pvalue_manual(pwc_B, hide.ns = TRUE, tip.length = .02, y.position = c(80)) -``` -**Results** - ->A one-way analysis of covariance (ANCOVA) was conducted. The independent variable, condition, had two levels: Friends, Little Mosque. The dependent variable was attitudes towards Arabs expressed by the participant at post-test and covariate was the baseline assessment of the same variable. Descriptive statistics are presented in Table 1. A preliminary analysis evaluating the homogeneity-of-slopes assumption indicated that the relationship between the covariate and the dependent variable differed significantly as a function of the independent variable, $F (1, 189) = 4.297, p = .040, \eta^2 = 0.022$. Regarding the assumption that the dependent variable is normally distributed in the population for any specific value of the covariate and for any one level of a factor, results of the Shapiro-Wilk test of normality on the model residuals was also significant,$W = 0.984, p = .026$. Only one datapoint (in the Little Mosque condition) had a standardized residual (-3.37) that exceeded an absolute value of 3.0. A non-significant Levene's test indicated no violation of the homogeneity of the residual variances for all groups, $F(1, 191) = 3.515 p = .062$. - ->There was a non-significant effect of the baseline covariate on the post-test $(F[1, 190] = 0.665, p = .416, \eta^2 = 0.003)$. After controlling for the baseline attitudes toward Arabs, there was a statistically significant effect of condition on post-test attitudes toward Arabs, $F(1,190) = 26.361, p < .001, \eta^2 = 0.122$. This effect appears to be moderate-to-large. Given there were only two conditions, no further follow-up was required. As illustrated in Figure 1, results suggest that those in the Little Mosque condition $(M = 73.92, SD = 18.51)$ had more favorable attitudes toward Arabs than those in the Friends condition $(M = 59.02, SD = 21.65)$. Means and covariate-adjusted means are presented in Table 1b. - - -## Working the ANCOVA -- Scenario #2: Controlling for a confounding or covarying variable - -In the scenario below, I am simulating a one-way ANCOVA, predicting attitudes toward Arabs at post1 as a function of sitcom condition (Friends, Little Mosque), controlling for the participants' attitudes toward Whites. That is, the ANCOVA will compare the the means of the two groups (at post1, only), adjusted for level of attitudes toward Whites - -TO BE CLEAR: This is not the best way to analyze this data. With such a strong, balanced design, the multi-way, mixed design ANOVAs were an excellent choice that provided much fuller information than this demonstration, below. The purpose of this over-simplified demonstration is merely to give another example of using a variable as a *covariate* rather than a *moderator*. - -### Preparing the data - -When the covariate in ANCOVA is a potentially confounding variable, we need three variables: - -* IV that has two or more levels; in our case it is the Friends and Littls Mosque sitcom conditions. -* DV that is continuous; in our case it attitudes toward Arabs at post1 (AttArabP1). -* Covariate that is continuous; in our case it attitudes toward Whites at post1 (AttWhiteP1). *Note* We could have also chosen attitudes toward Whites at baseline. - -We can continue using the Murrar_wide df. - -### Evaluating the statistical assumptions - -There are a number of assumptions in ANCOVA. These include: - -* random sampling -* independence in the scores representing the dependent variable -* linearity of the relationship between the covariate and DV within all levels of the independent variable -* homogeneity of the regression slopes -* a normally distributed DV for any specific value of the covariate and for any one level of a factor -* homogeneity of variance - -These are depicted in the flowchart, below. - -![Image of the ANCOVA workflow, showing our current place in the process](images/ANCOVA/wf_ANCOVA_assumptions.jpg) - -#### Linearity assumption - -ANCOVA assumes that there is linearity between the covariate and outcome variable at each level of the grouping variable. In our case this means that there is linearity between the attitudes toward Whites (covariate) and attitudes toward Arabs (outcome variable) at each level of the intervention (Friends, Little Mosque). - -We can create a scatterplot (with regression lines) between the covariate (attitudes toward Whites) and the outcome (attitudes toward Arabs). - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -ggpubr::ggscatter ( - Murrar_wide, x = "AttWhiteP1", y = "AttArabP1", - color = "COND", add = "reg.line" -)+ - ggpubr::stat_regline_equation( - aes(label = paste(..eq.label.., ..rr.label.., sep = "~~~~"), color = COND) - ) - -``` -As we look at this scatterplot, we are trying to determine if there is an interaction effect (rather than a covarying effect). The linearity here, looks reasonable and not terribly "interacting" (to help us decide whether empathy should be a covariate or a moderator). More testing can help us make this distinction. - -#### Homogeneity of regression slopes - -This assumption requires that the slopes of the regression lines formed by the covariate and the outcome variable are the same for each group. The assumption evaluates that there is no interaction between the outcome and covariate. The plotted regression lines should be parallel. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -Murrar_wide %>% rstatix::anova_test(AttArabP1 ~ COND*AttWhiteP1) -``` -Preliminary analysis supported ANCOVA as a statistical option in that there was no violation of the homogeneity of regression slopes as the interaction term was not statistically significant, $F (1, 189) = 1.886, p = .171, \eta^2 = 0.010$. - -#### Normality of residuals - -Assessing the normality of residuals means running the model, capturing the unexplained portion of the model (i.e., the *residuals*), and then seeing if they are normally distributed. Proper use of ANCOVA is predicated on normally distributed residuals. - -We first compute the model with *lm()*. The *lm()* function is actually testing what we want to test. However, at this early stage, we are just doing a "quick run and interpretation" to see if we are within the assumptions of ANCOVA. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -#Create a linear regression model predicting DV from COV & IV -WhCov_mod <- lm (AttArabP1 ~ AttWhiteP1 + COND, data = Murrar_wide) -WhCov_mod -``` -We can use the *augment(model)* function from the *broom* package to add fitted values and residuals. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -WhCov_mod.metrics <- broom::augment(WhCov_mod) -#shows the first three rows of the UEcon_model.metrics -head(WhCov_mod.metrics,3) -``` -Now we assess the normality of residuals using the Shapiro Wilk test. The script below captures the ".resid" column from the model. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -rstatix::shapiro_test(WhCov_mod.metrics$.resid) -``` -The statistically significant Shapiro Wilk test indicate a violation of the normality assumption ($W = 0.984, p = .029$). As I mentioned before, there are better ways to analyze this research vignette. None-the-less, we will continue with this demonstration so that you will have the procedural and conceptual framework for conducting ANCOVA. - -#### Homogeneity of variances - -ANCOVA presumes that the variance of the residuals is equal for all groups. We can check this with the Levene's test. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -WhCov_mod.metrics %>% rstatix::levene_test(.resid ~ COND) -``` -Contributing more evidence that ANCOVA is not the best way to analyze this data, a statistically significant Levene's test indicates a violation of the homogeneity of the residual variances $(F[1, 191] = 4.539, p = .034)$. - -#### Outliers - -We can identify outliers by examining the standardized (or studentized) residual. This is the residual divided by its estimated standard error. Standardized residuals are interpreted as the number of standard errors away from the regression line. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -WhCov_mod.metrics %>% - filter(abs(.std.resid)>3)%>% - as.data.frame() -``` -There is one outlier with a standardized residual with an absolute value greater than 3. At this point I am making a mental note of this. If this were "for real" I might more closely inspect these data. I would look at the whole response. If any response seems invalid (e.g., random, erratic, or extreme responding) I would delete it. If the response seem valid, I *could* truncate them to within 3 SEs. I could also ignore it. Kline [-@kline_data_2016] has a great section on some of these options. - -#### Summarizing the results from the analysis of assumptions - ->A one-way analysis of covariance (ANCOVA) was conducted. The independent variable, sitcom condition, had two levels: Friends, Little Mosque. The dependent variable was attitudes towards Arabs at pre-test. Preliminary anlayses which tested the assumptions of ANCOVA were mixed. Results suggesting that the relationship between the covariate and the dependent variable did not differ significantly as a function of the independent variable $(F [1, 189] = 1.886, p = .171, \eta^2 = 0.010)$ provided evidence that we did not violate the homogeneity-of-slopes assumption. In contrast, the Shapiro-Wilk test of normality on the model residuals was statistically significant $(W = 0.984, p = .029)$. This means that we likely violated the assumption that the dependent variable is normally distributed in the population for any specific value of the covariate and for any one level of a factor. Regarding outliers, one datapoint (-3.38) had a standardized residual that exceeded an absolute value of 3.0. Further, a statistically significant Levene's test indicated a violation of the homogeneity of the residual variances for all groups, $(F[1, 191] = 4.539, p = .034)$. - -Because the intent of this analysis was to demonstrate how ANCOVA differs from mixed design ANOVA we proceeded with the analysis. Were this for "real research" we would have chosen a different analysis. - -### Calculating the Omnibus ANOVA - -We are ready to conduct the omnibus ANOVA. - -![Image of the ANCOVA workflow, showing our current place in the process.](images/ANCOVA/wf_ANCOVA_omnibus.jpg) - -*Order of variable entry* matters in ANCOVA. Thinking of the *controlling for* language associated with covariates, we firstly want to remove the effect of the covariate. - -In the code below we are predicting attitudes toward Arabs at post1 from attitudes toward Whites at post1 (the covariate) and sitcom condition (Friends, Little Mosque). - -The *ges* column provides the effect size, $\eta^2$ where a general rule-of-thumb for interpretation is .01 (small), .06 (medium), and .14 (large) [@lakens_calculating_2013]. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -WhCov_ANCOVA <- Murrar_wide %>% - rstatix::anova_test(AttArabP1 ~ AttWhiteP1 + COND) -rstatix::get_anova_table(WhCov_ANCOVA) -``` - -There was a non-significant effect of the attitudes toward Whites covariate on the attitudes toward Arabs at post-test, $F (1, 190) = 0.014, p = .907, \eta^2 < .001$. After controlling for attitudes toward Whites, there was a statistically significant effect in attitudes toward Arabs at post-test between the conditions, $F(1, 190) = 26.119, p < .001, \eta^2 = 0.121$. The effect size was moderate-to-large. - -### Post-hoc pairwise comparisons (controlling for the covariate) - -With only two levels of sitcom condition (Friends, Little Mosque), we do not need to conduct post-hoc pairwise comparisons. However, because many research designs involve three or more levels, I will use code that would evaluates them here. -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwc_cond <- Murrar_wide %>% - rstatix::emmeans_test( - AttArabP1 ~ COND, covariate = AttWhiteP1, - p.adjust.method = "none" - ) -pwc_cond -``` - -Results suggest a statistically significant post-test difference between the Friends and Little Mosque sitcom conditions. -With the script below we can obtain the covariate-adjusted marginal means. These are termed *estimated marginal means.* - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -emmeans_cond <- rstatix::get_emmeans(pwc_cond) -emmeans_cond -``` - -As before, these means are usually different (even if only ever-so-slightly) than the raw means you would obtain from the descriptives. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -descripts_cond <- psych::describeBy(AttArabP1 ~ COND, data = Murrar_wide, mat = TRUE) -descripts_cond -``` - - -### APA style results for Scenario 2 - -Tables with the means, adjusted means, and pairwise comparison output may be helpful. The *apa.cor.table()* function in the *apaTables* package is helpful for providing means, standarddeviations, and correlations. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -apaTables::apa.cor.table(Murrar_wide[c("AttArabP1", "AttWhiteP1")], table.number = 2 ) -#You can save this as a Microsoft word document by adding this statement into the command: filename = "your_filename.doc" -``` - -Writing this output to excel files helped create the two tables that follow. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -MASS::write.matrix(pwc_cond, sep = ",", file = "pwc_con.csv") -MASS::write.matrix(emmeans_cond, sep = ",", file = "emmeans_con.csv") -MASS::write.matrix(descripts_cond, sep = ",", file = "descripts_con.csv") -``` - -Ultimately, I would want a table that included this information. Please refer to the APA style manual for more proper formatting for a manuscript that requires APA style. - -|Table 1b -|:-----------------------------------------------| -|Unadjusted and Covariate-Adjusted Descriptive Statistics - -|Condition |Unadjusted |Covariate-Adjusted -|:--------------|:-----------:|:----------------:| - -| |*M* |*SD* |*EMM* |*SE* -|:--------------|:----:|:----:|:----:|:---:| -|Friends |59.02 |21.65 |59.03 |2.04 | -|Little Mosque |73.92 |18.51 |73.92 |2.08 | - -Unlike the figure we created when we were testing assumptions, this script creates a plot from the model (which identifies AttWhiteP1 in its role as covariate). Thus, the relationship between condition and AttArabP1 controls for the effect of the AttArabB covariate. - -```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} -pwc_cond <- pwc_cond %>% rstatix::add_xy_position(x = "COND", fun = "mean_se") -ggpubr::ggline(rstatix::get_emmeans(pwc_B), x = "COND", y = "emmean", title = "Figure 1. Attitudes toward Arabs by Condition, Controlling for Attitudes toward Whites") + - geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0.2) + - ggpubr::stat_pvalue_manual(pwc_B, hide.ns = TRUE, tip.length = .02, y.position = c(80)) -``` -**Results** - ->A one-way analysis of covariance (ANCOVA) was conducted. The independent variable, sitcom condition, had two levels: Friends, Little Mosque. The dependent variable was attitudes towards Arabs at pre-test. We controlled for attitudes toward Whites. Preliminary analyses which tested the assumptions of ANCOVA were mixed. Results suggesting that the relationship between the covariate and the dependent variable did not differ significantly as a function of the independent variable $(F [1, 189] = 1.886, p = .171, \eta^2 = 0.010)$ provided evidence that we did not violate the homogeneity-of-slopes assumption. In contrast, the Shapiro-Wilk test of normality on the model residuals was statistically significant $(W = 0.984, p = .029)$. This means that we likely violated the assumption that the dependent variable is normally distributed in the population for any specific value of the covariate and for any one level of a factor. Regarding outliers, one datapoint (-3.38) had a standardized residual that exceeded an absolute value of 3.0. Further, a statistically significant Levene's test indicated a violation of the homogeneity of the residual variances for all groups, $(F[1, 191] = 4.539, p = .034)$. - -Because the intent of this analysis was to demonstrate how ANCOVA differs from mixed design ANOVA we proceeded with the analysis. Were this for "real research" we would have chosen a different analysis. - ->There was a non-significant effect of the attitudes toward Whites covariate on the attitudes toward Arabs post-test, $F (1,190) = 0.014, p = .907, \eta^2 < .001$. After controlling for attitudes toward Whites, there was a statistically significant effect in attitudes toward Arabs at post-test between the conditions, $F(1. 190) = 26.119, p < .001, \eta^2 = 0.121$. The effect size was moderately large. Means and covariate-adjusted means are presented in Table 1b. - - -## More (and a recap) on covariates - -Covariates, sometimes termed *controls* are often used to gain statistical control over variables that are difficult to control in a research design. That is, it may be impractical for polychotomize an otherwise continuous variable and/or it is impractical to have multiple factors and so a covariate is a more manageable approach. Common reasons for including covariates include [@bernerth_critical_2016]: - -* they mathematically remove variance associated with nonfocal variables, -* the *purification principle* -- removing unwanted or confusing variance, -* they remove the *noise* in the analysis to clear up the clear up the relationship between IV and DVs. - -Perhaps it is an oversimplification, but we can think of three categories of variables: moderators, covariates, and mediators. Through ANOVA and ANCOVA, we distinguish between moderator and covariate. - -**Moderator**: a variable that changes the strength or direction of an effect between two variables X (predictor, independent variable) and Y (criterion, dependent variable). - -**Covariate**: an observed, continuous variable, that (when used properly) has a relationship with the dependent variable. It is included in the analysis, as a predictor, so that the predictive relationship between the independent (IV) and dependent (DV) are adjusted. - -Bernerth and Aguinis [-@bernerth_critical_2016] conducted a review of how and when control variables were used in nearly 600 articles published between 2003 and 2012. Concurrently with their analysis, they provided guidance for when to use control variables (covariates). The flowchart that accompanies their article is quite helpful. Control variables (covariates) should only be used when: - -1. Theory suggests that the potential covariate(s) relate(s) to variable(s) in the currrent study. -2. There is empirical justification for including the covariate in the study. -3. The covariate can be measured reliably. - -Want more? Instructions for calculating a two-way ANCOVA are here: https://www.datanovia.com/en/lessons/ancova-in-r/ - -## Practice Problems - -The suggestions for homework differ in degree of complexity. I encourage you to start with a problem that feels "do-able" and then try at least one more problem that challenges you in some way. At a minimum your data should have three levels in the independent variable. At least one of the problems you work should have a statistically significant interaction effect that you work all the way through. - -Regardless, your choices should meet you where you are (e.g., in terms of your self-efficacy for statistics, your learning goals, and competing life demands). Whichever you choose, you will focus on these larger steps in one-way ANCOVA, including: - -* test the statistical assumptions -* conduct an ANCOVA -* if the predictor variable has more three or more levels, conduct follow-up testing -* present both means and coviarate-adjusted means -* write a results section to include a figure and tables - - -### Problem #1: Play around with this simulation. - -Copy the script for the simulation and then change (at least) one thing in the simulation to see how it impacts the results. - -* If ANCOVA is new to you, perhaps you just change the number in "set.seed(210813)" from 210813 to something else. Then rework Scenario#1, Scenario#2, or both. Your results should parallel those obtained in the lecture, making it easier for you to check your work as you go. -* If you are interested in power, change the sample size to something larger or smaller. -* If you are interested in variability (i.e., the homogeneity of variance assumption), perhaps you change the standard deviations in a way that violates the assumption. - -### Problem #2: Conduct a one-way ANCOVA with the DV and covariate at post2. - -The Murrar et al. [-@murrar_entertainment-education_2018]article has three waves: baseline, post1, post2. In this lesson, I focused on the post1 waves. Rerun this analysis using the post2 wave data. - -### Problem #3: Try something entirely new. - -Using data for which you have permission and access (e.g., IRB approved data you have collected or from your lab; data you simulate from a published article; data from an open science repository; data from other chapters in this OER), complete an ANCOVA. - -### Grading Rubric - -Regardless which option(s) you chose, use the elements in the grading rubric to guide you through the practice. -Using the lecture and workflow (chart) as a guide, please work through all the steps listed in the proposed assignment/grading rubric. - -|Assignment Component | Points Possible | Points Earned| -|:-------------------------------------- |:----------------: |:------------:| -|1. Narrate the research vignette, describing the IV, DV, and COV. | 5 |_____ | -|2. Simulate (or import) and format data. | 5 |_____ | -|3. Evaluate statistical assumptions. | 5 |_____ | -|4. Conduct omnibus ANCOVA (w effect size).| 5 | _____ | -|5. If the IV has three or more levels, conduct follow-up tests.| 5 |_____ | -|6. Present means and covariate-adjusted means; interpret them.| 5 |_____ | -|7. APA style results with table(s) and figure.| 5 |_____ | -|8. Explanation to grader. | 5 |_____ | -|**Totals** | 35 |_____ | - -```{r, child= 'Worked_Examples/15-10-woRked_ANCOVA.Rmd'} -``` - -```{r include=FALSE} -sessionInfo() -``` - -# References {-#refs} - - diff --git a/.Rproj.user/FFFF18A2/sources/session-cac319c0/00E4BC8F b/.Rproj.user/FFFF18A2/sources/session-cac319c0/00E4BC8F new file mode 100644 index 00000000..21dea9b5 --- /dev/null +++ b/.Rproj.user/FFFF18A2/sources/session-cac319c0/00E4BC8F @@ -0,0 +1,27 @@ +{ + "id": "00E4BC8F", + "path": "C:/Users/lhbik/OneDrive/ReCentering Volumes/ReCenterPsychStats/14-RMmultivariate.Rmd", + "project_path": "14-RMmultivariate.Rmd", + "type": "r_markdown", + "hash": "0", + "contents": "", + "dirty": false, + "created": 1692895678742.0, + "source_on_save": false, + "relative_order": 7, + "properties": { + "source_window_id": "", + "Source": "Source", + "cursorPosition": "110,35", + "scrollLine": "105", + "docOutlineVisible": "1" + }, + "folds": "", + "lastKnownWriteTime": 1692895734, + "encoding": "UTF-8", + "collab_server": "", + "source_window": "", + "last_content_update": 1692895734794, + "read_only": false, + "read_only_alternatives": [] +} \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/2D4197BB-contents b/.Rproj.user/FFFF18A2/sources/session-cac319c0/00E4BC8F-contents similarity index 96% rename from .Rproj.user/FFFF18A2/sources/session-5a13dfdd/2D4197BB-contents rename to .Rproj.user/FFFF18A2/sources/session-cac319c0/00E4BC8F-contents index edfc655b..ffe22af7 100644 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/2D4197BB-contents +++ b/.Rproj.user/FFFF18A2/sources/session-cac319c0/00E4BC8F-contents @@ -1,4 +1,4 @@ -# One-Way Repeated Measures with a Multivariate Approach {-} +# One-Way Repeated Measures with a Multivariate Approach ```{r include=FALSE} knitr::opts_chunk$set(echo = TRUE) @@ -12,7 +12,7 @@ As noted in the lesson on [one-way repeated measures ANOVA](#Repeated), the rese As a quick reminder, I will describe and resimulate the data. The narration will presume familiarity with the [one-way repeated measures ANOVA](#Repeated) lesson. -## Research Vignette {-} +## Research Vignette Amodeo [@amodeo_empowering_2018] and colleagues conducted a mixed methods study (qualitative and quantitative) to evaluate the effectiveness of an empowerment, peer-group-based, intervention with participants (*N* = 8) who experienced transphobic episodes. Focus groups used qualitative methods to summarize emergent themes from the program (identity affirmation, self-acceptance, group as support) and a one-way, repeated measures ANOVA provided evidence of increased resilience from pre to three-month followup. @@ -29,7 +29,7 @@ The within-subjects condition was wave, represented by T1, T2, and T3: The dependent variable (assessed at each wave) was a 14-item resilience scale [@wagnild_development_1993]. Items were assessed on a 7-point scale ranging from *strongly disagree* to *strongly agree* with higher scores indicating higher levels of resilience. An example items was, "I usually manage one way or another." -### Data Simulation {-} +### Data Simulation Below is the code I used to simulate data. The following code assumes 8 participants who each participated in 3 waves (pre, post, followup). The sript produces "long" and "wide" forms are created. ```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} @@ -53,7 +53,7 @@ str(Amodeo_wide) Amodeo_wide$ID <- factor(Amodeo_wide$ID) ``` -## Computing the Omnibus F {-} +## Computing the Omnibus F Without the *rstatix* helper package, here is how the analysis would be run in the package, *car.* Although this package is less intuitive to use, it results in both univariate output (both sphericity assumed and sphericity violated) and multivariate output (which does not require the sphericity assumption). @@ -89,7 +89,7 @@ summary(analysis) ``` The *car::Anova()* function produces both univariate and multivariate results. To begin to understand this data, let's start with what we learned in the [one-way repeated measures ANOVA lesson](#Repeated). -### Univariate Results {-} +### Univariate Results When we ran the univariate approach in the lesson, we first checked the sphericity assumption. Our results here are identical to those from *rstatix::anova_test*. That is, we did not violate the sphericity assumption: Mauchley's test $= .566 p = 0.182$. The *F* test with univariate results was $F(2, 14) = 3.910, p = 0.045$. @@ -98,7 +98,7 @@ When we ran the univariate approach in the lesson, we first checked the spherici The univariate ANOVA results are under the "Univariate Type III Repeated-Measures ANOVA Assuming Sphericity" heading. We find the ANOVA output on the row titled, "waveFactor." The results are identical to what we found in the lesson: $F(2,14) = 3.91, p = 0.045$. I do not see that an effect size is reported. -### Multivariate Results {-} +### Multivariate Results Researchers may prefer the multivariate approach because it does not require the sphericity assumption. Stated another way, if the sphericity assumption is violated, researchers can report the results of the multivariate analysis. @@ -108,10 +108,12 @@ We find the multivariate results in the middle of the output, under the heading, Because follow-up testing is *pairwise* (i.e., there are only two levels being compared), the sphericity assumption is not required and those could proceed in the manner demonstrated in the [one-way repeated measures ANOVA lesson](#Repeated). -### A Brief Commentary on Wrappers +### A Brief Commentary on Wrappers As noted several times, because of its relative ease-of-use, the relevance of information included in the results, and its integration with the *ggpubr* package, I chose to use *rstatix* package in all of the ANOVA lessons. As I worked through this example, I spent several hours creating and interpreting the code. For me, there was value in this exercise: * I am encouraged and reassured with the consistency of results between the two approaches, * I am in awe of the power of these programs and a little intimidated by all the options that are available within a given package, and -* I am deeply grateful to package developers who take the time to create packages for discipline-specific use-cases and then freely share their work with others. Thank you [Alboukadel Kassambara](https://github.com/kassambara/rstatix)! \ No newline at end of file +* I am deeply grateful to package developers who take the time to create packages for discipline-specific use-cases and then freely share their work with others. Thank you [Alboukadel Kassambara](https://github.com/kassambara/rstatix)! + +# References {-#refs} \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/147C569F b/.Rproj.user/FFFF18A2/sources/session-cac319c0/147C569F similarity index 92% rename from .Rproj.user/FFFF18A2/sources/session-5a13dfdd/147C569F rename to .Rproj.user/FFFF18A2/sources/session-cac319c0/147C569F index a20f9213..45ec336b 100644 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/147C569F +++ b/.Rproj.user/FFFF18A2/sources/session-cac319c0/147C569F @@ -3,7 +3,7 @@ "path": "C:/Users/lhbik/OneDrive/ReCentering Volumes/ReCenterPsychStats/01-Introduction.Rmd", "project_path": "01-Introduction.Rmd", "type": "r_markdown", - "hash": "2508219210", + "hash": "0", "contents": "", "dirty": false, "created": 1692648659356.0, @@ -13,7 +13,7 @@ "source_window_id": "", "Source": "Source", "cursorPosition": "43,54", - "scrollLine": "37" + "scrollLine": "0" }, "folds": "", "lastKnownWriteTime": 1692832692, diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/147C569F-contents b/.Rproj.user/FFFF18A2/sources/session-cac319c0/147C569F-contents similarity index 100% rename from .Rproj.user/FFFF18A2/sources/session-5a13dfdd/147C569F-contents rename to .Rproj.user/FFFF18A2/sources/session-cac319c0/147C569F-contents diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/2C20B002 b/.Rproj.user/FFFF18A2/sources/session-cac319c0/2C20B002 similarity index 96% rename from .Rproj.user/FFFF18A2/sources/session-5a13dfdd/2C20B002 rename to .Rproj.user/FFFF18A2/sources/session-cac319c0/2C20B002 index 97aa59a7..70489348 100644 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/2C20B002 +++ b/.Rproj.user/FFFF18A2/sources/session-cac319c0/2C20B002 @@ -13,7 +13,7 @@ "source_window_id": "", "Source": "Source", "cursorPosition": "233,13", - "scrollLine": "222" + "scrollLine": "0" }, "folds": "", "lastKnownWriteTime": 1692833857, diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/2C20B002-contents b/.Rproj.user/FFFF18A2/sources/session-cac319c0/2C20B002-contents similarity index 100% rename from .Rproj.user/FFFF18A2/sources/session-5a13dfdd/2C20B002-contents rename to .Rproj.user/FFFF18A2/sources/session-cac319c0/2C20B002-contents diff --git a/.Rproj.user/FFFF18A2/sources/session-cac319c0/33942B94 b/.Rproj.user/FFFF18A2/sources/session-cac319c0/33942B94 new file mode 100644 index 00000000..22adb643 --- /dev/null +++ b/.Rproj.user/FFFF18A2/sources/session-cac319c0/33942B94 @@ -0,0 +1,27 @@ +{ + "id": "33942B94", + "path": "C:/Users/lhbik/OneDrive/ReCentering Volumes/ReCenterPsychStats/13-moReTwoWay.Rmd", + "project_path": "13-moReTwoWay.Rmd", + "type": "r_markdown", + "hash": "1826163690", + "contents": "", + "dirty": false, + "created": 1692895742715.0, + "source_on_save": false, + "relative_order": 8, + "properties": { + "source_window_id": "", + "Source": "Source", + "cursorPosition": "241,38", + "scrollLine": "240", + "docOutlineVisible": "0" + }, + "folds": "", + "lastKnownWriteTime": 1692895761, + "encoding": "UTF-8", + "collab_server": "", + "source_window": "", + "last_content_update": 1692895761761, + "read_only": false, + "read_only_alternatives": [] +} \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/8F619931-contents b/.Rproj.user/FFFF18A2/sources/session-cac319c0/33942B94-contents similarity index 98% rename from .Rproj.user/FFFF18A2/sources/session-5a13dfdd/8F619931-contents rename to .Rproj.user/FFFF18A2/sources/session-cac319c0/33942B94-contents index 0e987a0b..c358752b 100644 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/8F619931-contents +++ b/.Rproj.user/FFFF18A2/sources/session-cac319c0/33942B94-contents @@ -1,4 +1,4 @@ -# Examples for Follow-up to Factorial ANOVA {-} +# Examples for Follow-up to Factorial ANOVA ```{r include=FALSE} knitr::opts_chunk$set(echo = TRUE) @@ -12,7 +12,7 @@ As noted in the lesson on [factorial ANOVA](#between), the options for follow-up As a quick reminder, I will describe and re-simulate the data. The narration will presume familiarity with the [factorial ANOVA](#between) lesson. -## Research Vignette {-} +## Research Vignette The research vignette for this example was located in Kalimantan, Indonesia and focused on bias in young people from three ethnic groups. The Madurese and Dayaknese groups were engaged in ethnic conflict that spanned 1996 to 2001. The last incidence of mass violence was in 2001 where approximately 500 people (mostly from the Madurese ethnic group) were expelled from the province. Ramdhani et al.'s [-@ramdhani_affective_2018] research hypotheses were based on the roles of the three ethnic groups in the study. The Madurese appear to be viewed as the transgressors when they occupied lands and took employment and business opportunities from the Dayaknese. Ramdhani et al. also included a third group who were not involved in the conflict (Javanese). The research participants were students studying in Yogyakara who were not involved in the conflict. They included 39 Madurese, 35 Dyaknese, and 37 Javanese; 83 were male and 28 were female. @@ -21,7 +21,7 @@ In the study [@ramdhani_affective_2018], participants viewed facial pictures of * Positive: friendly, kind, helpful, happy * Negative: disgusting, suspicious, hateful, angry -### Quick Resimulating of the Data {-} +### Quick Resimulating of the Data Below is script to simulate data for the negative reactions variable from the information available from the manuscript [@ramdhani_affective_2018]. If you would like more information about the details of this simulation, please visit the lesson on [factorial ANOVA](#between). @@ -63,7 +63,7 @@ The code for the .rds file will retain the formatting of the variables, but is n ``` -## Analysis of Simple Main Effects with Orthogonal Contrasts {-} +## Analysis of Simple Main Effects with Orthogonal Contrasts This example follows a significant interaction effect. Specifically, we will analyze the effects of ethnicity of rater (three levels) within photo stimulus (two levels). We will conduct two one-way ANOVAs for the Dayaknese and Madurese photos, separately. In this example, we will utilize orthogonal contrast-coding for rater ethnicity. @@ -184,7 +184,7 @@ I am not aware of an integration of packages that would represent this type of o ggpubr::ggboxplot(Ramdhani_df, x = "Photo", y = "Negative", color = "Rater",xlab = "Rater Ethnicity Represented within Photo Stimulus", ylab = "Negative Reaction", add = "jitter", title = "Figure 1. Simple Main Effect of Rater within Photo Stimulus", ylim = c(1, 7)) ``` -## Analysis of Simple Main Effects with a Polynomial Trend {-} +## Analysis of Simple Main Effects with a Polynomial Trend In the context of the significant interaction effect, we might be interested in polynomial trends for any simple main effects where three or more cells are compared. @@ -239,7 +239,7 @@ The figure we have been using would be appropriate to illustrate the significant ggpubr::ggboxplot(Ramdhani_df, x = "Photo", y = "Negative", color = "Rater",xlab = "Rater Ethnicity Represented within Photo Stimulus", ylab = "Negative Reaction", add = "jitter", title = "Figure 1. Simple Main Effect of Rater within Photo Stimulus", ylim = c(1, 7)) ``` -## All Possible Post Hoc Comparisons {-} +## All Possible Post Hoc Comparisons Another option is the comparison possible cells. These are termed *post hoc comparisons.* They are an alternative to simple main effects; you would not report both. A potential criticism of this approach is that it is atheoretical. Without compelling justification, reviewers may criticize this approach as "fishing," "p-hacking," or "HARKing" (hypothesizing after results are known). None-the-less, particularly when our results are not as expected, I do think having these tools available can be a helpful resource. diff --git a/.Rproj.user/FFFF18A2/sources/session-cac319c0/404DBEBF b/.Rproj.user/FFFF18A2/sources/session-cac319c0/404DBEBF new file mode 100644 index 00000000..970f2c94 --- /dev/null +++ b/.Rproj.user/FFFF18A2/sources/session-cac319c0/404DBEBF @@ -0,0 +1,26 @@ +{ + "id": "404DBEBF", + "path": "C:/Users/lhbik/OneDrive/ReCentering Volumes/ReCenterPsychStats/12-APPENDIX_Type1Error.Rmd", + "project_path": "12-APPENDIX_Type1Error.Rmd", + "type": "r_markdown", + "hash": "3345682820", + "contents": "", + "dirty": false, + "created": 1692895764216.0, + "source_on_save": false, + "relative_order": 9, + "properties": { + "source_window_id": "", + "Source": "Source", + "cursorPosition": "0,16", + "scrollLine": "0" + }, + "folds": "", + "lastKnownWriteTime": 1692895784, + "encoding": "UTF-8", + "collab_server": "", + "source_window": "", + "last_content_update": 1692895784948, + "read_only": false, + "read_only_alternatives": [] +} \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/FA4A1B57-contents b/.Rproj.user/FFFF18A2/sources/session-cac319c0/404DBEBF-contents similarity index 96% rename from .Rproj.user/FFFF18A2/sources/session-5a13dfdd/FA4A1B57-contents rename to .Rproj.user/FFFF18A2/sources/session-cac319c0/404DBEBF-contents index e44523ea..a792b639 100644 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/FA4A1B57-contents +++ b/.Rproj.user/FFFF18A2/sources/session-cac319c0/404DBEBF-contents @@ -1,23 +1,23 @@ # APPENDICES {-} -# Type I Error {-} +# Type I Error [Screencasted Lecture Link](https://youtu.be/q7eQgXqY84Y) -## Type I Error Defined {-} +## Type I Error Defined *Type I error* is the concern about false positives -- that we would incorrectly reject a true null hypothesis (that we would say that there is a statistically significant difference when there is not one). This concern is increased when there are multiple hypothesis tests. This concern increases when we have a large number of pairwise comparisons. Throughout the chapters, I noted the importance and relative risk of Type I error with each statistic and options for follow-up testing. Because there are so many options, I have provided a review and summary of each option in this appendix. For each, I provide a definition, a review of the steps and options for utilizing the statistic, and suggest the types of follow-up for which this approach is indicated. -## Methods for Managing Type I Error {-} +## Methods for Managing Type I Error -### LSD (Least Significant Difference) Method {-} +### LSD (Least Significant Difference) Method The LSD method is especially appropriate in the one-way ANOVA scenario when there are only three levels in the factor. In this case, Green and Salkind [-@green_using_2017] have suggested that alpha can be retained at the alpha level for the "family" ($\alpha_{family}$), which is conventionally $p = .05$ and used both to evaluate the omnibus and, so long as they don't exceed three in number, the planned or pairwise comparisons that follow. -### Traditional Bonferroni {-} +### Traditional Bonferroni The *traditional Bonferroni* is, perhaps, the most well-known approach to managing Type I error. Although the lessons in this OER will frequently suggest another approach to managing Type I error, I will quickly review it now because, conceptually it is easy to understand. We start by establishing the $\alpha\alpha_{family}$; this is traditionally $p = .05$. @@ -44,7 +44,7 @@ Luckily, each of these options has been reverse-engineered so that we do not hav Although the traditional Bonferroni is easy-to-understand and computer, it has been criticized as being too restrictive. That is, it increases the risk of making a Type II error (i.e., failing to reject the null hypothesis when it is false). This is why the majority of follow-up options to ANOVA did not use the traditional Bonferroni. -### Tukey HSD {-} +### Tukey HSD The Tukey HSD (honestly significant difference test) is a multiple comparison procedure used to identify significant differences between means of multiple groups. In the ANOVA context, it examines which specific pairs of groups differ from one another. The Tukey HSD was designed to control for Type I error. It does so by calculating the difference between the largest and smallest group means, then dividing this mean difference by the standard error of the same mean difference. The resulting statitic, *q* has an associated Studentized Range Distribution. Critical values for this distribution come from a Studentized Range q Table and are based on based on the alpha level, the number of groups, and the denominator degrees of freedom (i.e., $df_W$). @@ -52,7 +52,7 @@ The Tukey HSD ("Tukey's honestly significantly different") test automatically co I had intended to demonstrate this with the one-way ANOVA chapter, but could not get the results to render a figure with the significance bars and results. An online search suggested that I am not the only one to have experienced this glitch. -### Holms Sequential Bonferroni {-} +### Holms Sequential Bonferroni The Holm's sequential Bonferroni [@green_using_2017] offers a middle-of-the-road approach (not as strict as .05/9 with the traditional Bonferroni; not as lenient as "none") to managing Type I error. diff --git a/.Rproj.user/FFFF18A2/sources/session-cac319c0/67061575 b/.Rproj.user/FFFF18A2/sources/session-cac319c0/67061575 new file mode 100644 index 00000000..71d6dfec --- /dev/null +++ b/.Rproj.user/FFFF18A2/sources/session-cac319c0/67061575 @@ -0,0 +1,27 @@ +{ + "id": "67061575", + "path": "C:/Users/lhbik/OneDrive/ReCentering Volumes/ReCenterPsychStats/11-ANCOVA.Rmd", + "project_path": "11-ANCOVA.Rmd", + "type": "r_markdown", + "hash": "1041758137", + "contents": "", + "dirty": false, + "created": 1692895649849.0, + "source_on_save": false, + "relative_order": 6, + "properties": { + "source_window_id": "", + "Source": "Source", + "cursorPosition": "749,0", + "scrollLine": "724", + "docOutlineVisible": "1" + }, + "folds": "", + "lastKnownWriteTime": 1692895668, + "encoding": "UTF-8", + "collab_server": "", + "source_window": "", + "last_content_update": 1692895668393, + "read_only": false, + "read_only_alternatives": [] +} \ No newline at end of file diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/EF4A0757-contents b/.Rproj.user/FFFF18A2/sources/session-cac319c0/67061575-contents similarity index 99% rename from .Rproj.user/FFFF18A2/sources/session-5a13dfdd/EF4A0757-contents rename to .Rproj.user/FFFF18A2/sources/session-cac319c0/67061575-contents index e922c0c6..039b9a11 100644 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/EF4A0757-contents +++ b/.Rproj.user/FFFF18A2/sources/session-cac319c0/67061575-contents @@ -747,6 +747,6 @@ Using the lecture and workflow (chart) as a guide, please work through all the s sessionInfo() ``` -# References {-#refs} + diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/9F9AE945 b/.Rproj.user/FFFF18A2/sources/session-cac319c0/9F9AE945 similarity index 96% rename from .Rproj.user/FFFF18A2/sources/session-5a13dfdd/9F9AE945 rename to .Rproj.user/FFFF18A2/sources/session-cac319c0/9F9AE945 index 6c72f9d6..5243cca8 100644 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/9F9AE945 +++ b/.Rproj.user/FFFF18A2/sources/session-cac319c0/9F9AE945 @@ -13,7 +13,7 @@ "source_window_id": "", "Source": "Source", "cursorPosition": "94,152", - "scrollLine": "44" + "scrollLine": "0" }, "folds": "", "lastKnownWriteTime": 1692832724, diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/9F9AE945-contents b/.Rproj.user/FFFF18A2/sources/session-cac319c0/9F9AE945-contents similarity index 100% rename from .Rproj.user/FFFF18A2/sources/session-5a13dfdd/9F9AE945-contents rename to .Rproj.user/FFFF18A2/sources/session-cac319c0/9F9AE945-contents diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/ADD3289F b/.Rproj.user/FFFF18A2/sources/session-cac319c0/ADD3289F similarity index 92% rename from .Rproj.user/FFFF18A2/sources/session-5a13dfdd/ADD3289F rename to .Rproj.user/FFFF18A2/sources/session-cac319c0/ADD3289F index 3ddad219..eb3d0840 100644 --- a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/ADD3289F +++ b/.Rproj.user/FFFF18A2/sources/session-cac319c0/ADD3289F @@ -3,7 +3,7 @@ "path": "C:/Users/lhbik/OneDrive/ReCentering Volumes/ReCenterPsychStats/index.Rmd", "project_path": "index.Rmd", "type": "r_markdown", - "hash": "139863178", + "hash": "0", "contents": "", "dirty": false, "created": 1692834619299.0, @@ -13,7 +13,7 @@ "source_window_id": "", "Source": "Source", "cursorPosition": "45,123", - "scrollLine": "31" + "scrollLine": "0" }, "folds": "", "lastKnownWriteTime": 1692835448, diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/ADD3289F-contents b/.Rproj.user/FFFF18A2/sources/session-cac319c0/ADD3289F-contents similarity index 100% rename from .Rproj.user/FFFF18A2/sources/session-5a13dfdd/ADD3289F-contents rename to .Rproj.user/FFFF18A2/sources/session-cac319c0/ADD3289F-contents diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/D3C1622C b/.Rproj.user/FFFF18A2/sources/session-cac319c0/D3C1622C similarity index 100% rename from .Rproj.user/FFFF18A2/sources/session-5a13dfdd/D3C1622C rename to .Rproj.user/FFFF18A2/sources/session-cac319c0/D3C1622C diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/D3C1622C-contents b/.Rproj.user/FFFF18A2/sources/session-cac319c0/D3C1622C-contents similarity index 100% rename from .Rproj.user/FFFF18A2/sources/session-5a13dfdd/D3C1622C-contents rename to .Rproj.user/FFFF18A2/sources/session-cac319c0/D3C1622C-contents diff --git a/.Rproj.user/FFFF18A2/sources/session-5a13dfdd/lock_file b/.Rproj.user/FFFF18A2/sources/session-cac319c0/lock_file similarity index 100% rename from .Rproj.user/FFFF18A2/sources/session-5a13dfdd/lock_file rename to .Rproj.user/FFFF18A2/sources/session-cac319c0/lock_file diff --git a/.Rproj.user/shared/notebooks/1E6CB830-11-ANCOVA/1/FFFF18A2cac319c0/chunks.json b/.Rproj.user/shared/notebooks/1E6CB830-11-ANCOVA/1/FFFF18A2cac319c0/chunks.json new file mode 100644 index 00000000..dd60b43f --- /dev/null +++ b/.Rproj.user/shared/notebooks/1E6CB830-11-ANCOVA/1/FFFF18A2cac319c0/chunks.json @@ -0,0 +1 @@ +{"chunk_definitions":[],"doc_write_time":1692895668} \ No newline at end of file diff --git a/.Rproj.user/shared/notebooks/1E6CB830-11-ANCOVA/1/s/chunks.json b/.Rproj.user/shared/notebooks/1E6CB830-11-ANCOVA/1/s/chunks.json index b6a1808b..dd60b43f 100644 --- a/.Rproj.user/shared/notebooks/1E6CB830-11-ANCOVA/1/s/chunks.json +++ b/.Rproj.user/shared/notebooks/1E6CB830-11-ANCOVA/1/s/chunks.json @@ -1 +1 @@ -{"chunk_definitions":[],"doc_write_time":1692833954} \ No newline at end of file +{"chunk_definitions":[],"doc_write_time":1692895668} \ No newline at end of file diff --git a/.Rproj.user/shared/notebooks/2A22F7D0-13-moReTwoWay/1/FFFF18A2cac319c0/chunks.json b/.Rproj.user/shared/notebooks/2A22F7D0-13-moReTwoWay/1/FFFF18A2cac319c0/chunks.json new file mode 100644 index 00000000..175862bd --- /dev/null +++ b/.Rproj.user/shared/notebooks/2A22F7D0-13-moReTwoWay/1/FFFF18A2cac319c0/chunks.json @@ -0,0 +1 @@ +{"chunk_definitions":[{"row":6,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","include":false,"label":"unnamed-chunk-98"},"document_id":"1791852A","chunk_id":"cekhgef1pipio","chunk_label":"unnamed-chunk-1"},{"row":42,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"warning":false,"tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-99"},"document_id":"1791852A","chunk_id":"cqyn4wdalasji","chunk_label":"unnamed-chunk-2"},{"row":91,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-100"},"document_id":"1791852A","chunk_id":"ckn2b97vj8vnn","chunk_label":"unnamed-chunk-5"},{"row":104,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"warning":false,"tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-101"},"document_id":"1791852A","chunk_id":"cdmndtzjzukhu","chunk_label":"unnamed-chunk-6"},{"row":110,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-102"},"document_id":"1791852A","chunk_id":"chqgldjtuvecd","chunk_label":"unnamed-chunk-7"},{"row":118,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"warning":false,"tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-103"},"document_id":"1791852A","chunk_id":"chr85na42ksqb","chunk_label":"unnamed-chunk-8"},{"row":125,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-104"},"document_id":"1791852A","chunk_id":"cgp3efu3jjiss","chunk_label":"unnamed-chunk-9"},{"row":132,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-105"},"document_id":"1791852A","chunk_id":"c3td1o64v6x05","chunk_label":"unnamed-chunk-10"},{"row":140,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"warning":false,"tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-106"},"document_id":"1791852A","chunk_id":"c3zem8acu9g6d","chunk_label":"unnamed-chunk-11"},{"row":156,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"warning":false,"tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-107"},"document_id":"1791852A","chunk_id":"c3se7fx7fzx1k","chunk_label":"unnamed-chunk-12"},{"row":163,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"warning":false,"tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-108"},"document_id":"1791852A","chunk_id":"c3bwha12i696e","chunk_label":"unnamed-chunk-13"},{"row":172,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-109"},"document_id":"1791852A","chunk_id":"cnnbpdzgtb2u4","chunk_label":"unnamed-chunk-14"},{"row":184,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-110"},"document_id":"1791852A","chunk_id":"cbhjmv4cvx6ks","chunk_label":"unnamed-chunk-15"},{"row":205,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-111"},"document_id":"1791852A","chunk_id":"cnckeo520dpro","chunk_label":"unnamed-chunk-16"},{"row":217,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-113"},"document_id":"1791852A","chunk_id":"cnhuqr43xr3uh","chunk_label":"unnamed-chunk-17"},{"row":228,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-114"},"document_id":"1791852A","chunk_id":"cj0vz2g10n3fj","chunk_label":"unnamed-chunk-18"},{"row":239,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-115"},"document_id":"1791852A","chunk_id":"cm6kx0et5csy5","chunk_label":"unnamed-chunk-19"},{"row":255,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-116"},"document_id":"1791852A","chunk_id":"c3e4133zua390","chunk_label":"unnamed-chunk-20"},{"row":262,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-123"},"document_id":"1791852A","chunk_id":"c6c41nyicum4p","chunk_label":"unnamed-chunk-21"},{"row":269,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-124"},"document_id":"1791852A","chunk_id":"cbhbw0j2zrd8t","chunk_label":"unnamed-chunk-22"},{"row":278,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-119"},"document_id":"1791852A","chunk_id":"cmqkecirmb7zn","chunk_label":"unnamed-chunk-23"},{"row":286,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-125"},"document_id":"1791852A","chunk_id":"c9qlc1tynjc41","chunk_label":"unnamed-chunk-24"},{"row":290,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-126"},"document_id":"1791852A","chunk_id":"c0km5iob3p79b","chunk_label":"unnamed-chunk-25"},{"row":315,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-122"},"document_id":"1791852A","chunk_id":"c2xqnaj9quv2q","chunk_label":"unnamed-chunk-26"}],"doc_write_time":1692895754,"chunk_rendered_width":400} \ No newline at end of file diff --git a/.Rproj.user/shared/notebooks/2A22F7D0-13-moReTwoWay/1/s/cbhjmv4cvx6ks/000010.png b/.Rproj.user/shared/notebooks/2A22F7D0-13-moReTwoWay/1/s/cbhjmv4cvx6ks/000010.png index 1393bdbb..0c8ce76d 100644 Binary files a/.Rproj.user/shared/notebooks/2A22F7D0-13-moReTwoWay/1/s/cbhjmv4cvx6ks/000010.png and b/.Rproj.user/shared/notebooks/2A22F7D0-13-moReTwoWay/1/s/cbhjmv4cvx6ks/000010.png differ diff --git a/.Rproj.user/shared/notebooks/2A22F7D0-13-moReTwoWay/1/s/chunks.json b/.Rproj.user/shared/notebooks/2A22F7D0-13-moReTwoWay/1/s/chunks.json index b8e57873..eaa52a57 100644 --- a/.Rproj.user/shared/notebooks/2A22F7D0-13-moReTwoWay/1/s/chunks.json +++ b/.Rproj.user/shared/notebooks/2A22F7D0-13-moReTwoWay/1/s/chunks.json @@ -1 +1 @@ -{"chunk_definitions":[{"row":6,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","include":false,"label":"unnamed-chunk-98"},"document_id":"1791852A","chunk_id":"cekhgef1pipio","chunk_label":"unnamed-chunk-1"},{"row":42,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"warning":false,"tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-99"},"document_id":"1791852A","chunk_id":"cqyn4wdalasji","chunk_label":"unnamed-chunk-2"},{"row":91,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-100"},"document_id":"1791852A","chunk_id":"ckn2b97vj8vnn","chunk_label":"unnamed-chunk-5"},{"row":104,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"warning":false,"tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-101"},"document_id":"1791852A","chunk_id":"cdmndtzjzukhu","chunk_label":"unnamed-chunk-6"},{"row":110,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-102"},"document_id":"1791852A","chunk_id":"chqgldjtuvecd","chunk_label":"unnamed-chunk-7"},{"row":118,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"warning":false,"tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-103"},"document_id":"1791852A","chunk_id":"chr85na42ksqb","chunk_label":"unnamed-chunk-8"},{"row":125,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-104"},"document_id":"1791852A","chunk_id":"cgp3efu3jjiss","chunk_label":"unnamed-chunk-9"},{"row":132,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-105"},"document_id":"1791852A","chunk_id":"c3td1o64v6x05","chunk_label":"unnamed-chunk-10"},{"row":140,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"warning":false,"tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-106"},"document_id":"1791852A","chunk_id":"c3zem8acu9g6d","chunk_label":"unnamed-chunk-11"},{"row":156,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"warning":false,"tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-107"},"document_id":"1791852A","chunk_id":"c3se7fx7fzx1k","chunk_label":"unnamed-chunk-12"},{"row":163,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"warning":false,"tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-108"},"document_id":"1791852A","chunk_id":"c3bwha12i696e","chunk_label":"unnamed-chunk-13"},{"row":172,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-109"},"document_id":"1791852A","chunk_id":"cnnbpdzgtb2u4","chunk_label":"unnamed-chunk-14"},{"row":184,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-110"},"document_id":"1791852A","chunk_id":"cbhjmv4cvx6ks","chunk_label":"unnamed-chunk-15"},{"row":205,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-111"},"document_id":"1791852A","chunk_id":"cnckeo520dpro","chunk_label":"unnamed-chunk-16"},{"row":217,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-113"},"document_id":"1791852A","chunk_id":"cnhuqr43xr3uh","chunk_label":"unnamed-chunk-17"},{"row":228,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-114"},"document_id":"1791852A","chunk_id":"cj0vz2g10n3fj","chunk_label":"unnamed-chunk-18"},{"row":239,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-115"},"document_id":"1791852A","chunk_id":"cm6kx0et5csy5","chunk_label":"unnamed-chunk-19"},{"row":255,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-116"},"document_id":"1791852A","chunk_id":"c3e4133zua390","chunk_label":"unnamed-chunk-20"},{"row":262,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-123"},"document_id":"1791852A","chunk_id":"c6c41nyicum4p","chunk_label":"unnamed-chunk-21"},{"row":269,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-124"},"document_id":"1791852A","chunk_id":"cbhbw0j2zrd8t","chunk_label":"unnamed-chunk-22"},{"row":278,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-119"},"document_id":"1791852A","chunk_id":"cmqkecirmb7zn","chunk_label":"unnamed-chunk-23"},{"row":286,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-125"},"document_id":"1791852A","chunk_id":"c9qlc1tynjc41","chunk_label":"unnamed-chunk-24"},{"row":290,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-126"},"document_id":"1791852A","chunk_id":"c0km5iob3p79b","chunk_label":"unnamed-chunk-25"},{"row":315,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-122"},"document_id":"1791852A","chunk_id":"c2xqnaj9quv2q","chunk_label":"unnamed-chunk-26"}],"doc_write_time":1692828334,"chunk_rendered_width":700} \ No newline at end of file +{"chunk_definitions":[{"row":6,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","include":false,"label":"unnamed-chunk-98"},"document_id":"1791852A","chunk_id":"cekhgef1pipio","chunk_label":"unnamed-chunk-1"},{"row":42,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"warning":false,"tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-99"},"document_id":"1791852A","chunk_id":"cqyn4wdalasji","chunk_label":"unnamed-chunk-2"},{"row":91,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-100"},"document_id":"1791852A","chunk_id":"ckn2b97vj8vnn","chunk_label":"unnamed-chunk-5"},{"row":104,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"warning":false,"tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-101"},"document_id":"1791852A","chunk_id":"cdmndtzjzukhu","chunk_label":"unnamed-chunk-6"},{"row":110,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-102"},"document_id":"1791852A","chunk_id":"chqgldjtuvecd","chunk_label":"unnamed-chunk-7"},{"row":118,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"warning":false,"tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-103"},"document_id":"1791852A","chunk_id":"chr85na42ksqb","chunk_label":"unnamed-chunk-8"},{"row":125,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-104"},"document_id":"1791852A","chunk_id":"cgp3efu3jjiss","chunk_label":"unnamed-chunk-9"},{"row":132,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-105"},"document_id":"1791852A","chunk_id":"c3td1o64v6x05","chunk_label":"unnamed-chunk-10"},{"row":140,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"warning":false,"tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-106"},"document_id":"1791852A","chunk_id":"c3zem8acu9g6d","chunk_label":"unnamed-chunk-11"},{"row":156,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"warning":false,"tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-107"},"document_id":"1791852A","chunk_id":"c3se7fx7fzx1k","chunk_label":"unnamed-chunk-12"},{"row":163,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"warning":false,"tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-108"},"document_id":"1791852A","chunk_id":"c3bwha12i696e","chunk_label":"unnamed-chunk-13"},{"row":172,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-109"},"document_id":"1791852A","chunk_id":"cnnbpdzgtb2u4","chunk_label":"unnamed-chunk-14"},{"row":184,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-110"},"document_id":"1791852A","chunk_id":"cbhjmv4cvx6ks","chunk_label":"unnamed-chunk-15"},{"row":205,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-111"},"document_id":"1791852A","chunk_id":"cnckeo520dpro","chunk_label":"unnamed-chunk-16"},{"row":217,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-113"},"document_id":"1791852A","chunk_id":"cnhuqr43xr3uh","chunk_label":"unnamed-chunk-17"},{"row":228,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-114"},"document_id":"1791852A","chunk_id":"cj0vz2g10n3fj","chunk_label":"unnamed-chunk-18"},{"row":239,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-115"},"document_id":"1791852A","chunk_id":"cm6kx0et5csy5","chunk_label":"unnamed-chunk-19"},{"row":255,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-116"},"document_id":"1791852A","chunk_id":"c3e4133zua390","chunk_label":"unnamed-chunk-20"},{"row":262,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-123"},"document_id":"1791852A","chunk_id":"c6c41nyicum4p","chunk_label":"unnamed-chunk-21"},{"row":269,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-124"},"document_id":"1791852A","chunk_id":"cbhbw0j2zrd8t","chunk_label":"unnamed-chunk-22"},{"row":278,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-119"},"document_id":"1791852A","chunk_id":"cmqkecirmb7zn","chunk_label":"unnamed-chunk-23"},{"row":286,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-125"},"document_id":"1791852A","chunk_id":"c9qlc1tynjc41","chunk_label":"unnamed-chunk-24"},{"row":290,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-126"},"document_id":"1791852A","chunk_id":"c0km5iob3p79b","chunk_label":"unnamed-chunk-25"},{"row":315,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-122"},"document_id":"1791852A","chunk_id":"c2xqnaj9quv2q","chunk_label":"unnamed-chunk-26"}],"doc_write_time":1692895754} \ No newline at end of file diff --git a/.Rproj.user/shared/notebooks/2A22F7D0-13-moReTwoWay/1/s/cm6kx0et5csy5/000010.png b/.Rproj.user/shared/notebooks/2A22F7D0-13-moReTwoWay/1/s/cm6kx0et5csy5/000010.png index 1393bdbb..0c8ce76d 100644 Binary files a/.Rproj.user/shared/notebooks/2A22F7D0-13-moReTwoWay/1/s/cm6kx0et5csy5/000010.png and b/.Rproj.user/shared/notebooks/2A22F7D0-13-moReTwoWay/1/s/cm6kx0et5csy5/000010.png differ diff --git a/.Rproj.user/shared/notebooks/69AFCD42-14-RMmultivariate/1/FFFF18A2cac319c0/chunks.json b/.Rproj.user/shared/notebooks/69AFCD42-14-RMmultivariate/1/FFFF18A2cac319c0/chunks.json new file mode 100644 index 00000000..155b811e --- /dev/null +++ b/.Rproj.user/shared/notebooks/69AFCD42-14-RMmultivariate/1/FFFF18A2cac319c0/chunks.json @@ -0,0 +1 @@ +{"chunk_definitions":[{"row":53,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-1"},"document_id":"B561ADE4","chunk_id":"cgcg01j9znp6d","chunk_label":"unnamed-chunk-2"},{"row":78,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"warning":false,"tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-2"},"document_id":"B561ADE4","chunk_id":"cx2yyqx781wcb","chunk_label":"unnamed-chunk-3"},{"row":88,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-3"},"document_id":"B561ADE4","chunk_id":"c9u5dbtl55x28","chunk_label":"unnamed-chunk-4"}],"doc_write_time":1692895687} \ No newline at end of file diff --git a/.Rproj.user/shared/notebooks/69AFCD42-14-RMmultivariate/1/s/chunks.json b/.Rproj.user/shared/notebooks/69AFCD42-14-RMmultivariate/1/s/chunks.json index 34b0cbab..155b811e 100644 --- a/.Rproj.user/shared/notebooks/69AFCD42-14-RMmultivariate/1/s/chunks.json +++ b/.Rproj.user/shared/notebooks/69AFCD42-14-RMmultivariate/1/s/chunks.json @@ -1 +1 @@ -{"chunk_definitions":[{"row":53,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-1"},"document_id":"B561ADE4","chunk_id":"cgcg01j9znp6d","chunk_label":"unnamed-chunk-2"},{"row":78,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"warning":false,"tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-2"},"document_id":"B561ADE4","chunk_id":"cx2yyqx781wcb","chunk_label":"unnamed-chunk-3"},{"row":88,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-3"},"document_id":"B561ADE4","chunk_id":"c9u5dbtl55x28","chunk_label":"unnamed-chunk-4"}],"doc_write_time":1692828754} \ No newline at end of file +{"chunk_definitions":[{"row":53,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-1"},"document_id":"B561ADE4","chunk_id":"cgcg01j9znp6d","chunk_label":"unnamed-chunk-2"},{"row":78,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"warning":false,"tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-2"},"document_id":"B561ADE4","chunk_id":"cx2yyqx781wcb","chunk_label":"unnamed-chunk-3"},{"row":88,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","tidy":true,"tidy.opts":{"width.cutoff":70},"label":"unnamed-chunk-3"},"document_id":"B561ADE4","chunk_id":"c9u5dbtl55x28","chunk_label":"unnamed-chunk-4"}],"doc_write_time":1692895687} \ No newline at end of file diff --git a/.Rproj.user/shared/notebooks/8570AA1D-12-APPENDIX_Type1Error/1/FFFF18A2cac319c0/chunks.json b/.Rproj.user/shared/notebooks/8570AA1D-12-APPENDIX_Type1Error/1/FFFF18A2cac319c0/chunks.json new file mode 100644 index 00000000..cefc4878 --- /dev/null +++ b/.Rproj.user/shared/notebooks/8570AA1D-12-APPENDIX_Type1Error/1/FFFF18A2cac319c0/chunks.json @@ -0,0 +1 @@ +{"chunk_definitions":[],"doc_write_time":1692895779} \ No newline at end of file diff --git a/.Rproj.user/shared/notebooks/8570AA1D-12-APPENDIX_Type1Error/1/s/chunks.json b/.Rproj.user/shared/notebooks/8570AA1D-12-APPENDIX_Type1Error/1/s/chunks.json index 1c778f15..cefc4878 100644 --- a/.Rproj.user/shared/notebooks/8570AA1D-12-APPENDIX_Type1Error/1/s/chunks.json +++ b/.Rproj.user/shared/notebooks/8570AA1D-12-APPENDIX_Type1Error/1/s/chunks.json @@ -1 +1 @@ -{"chunk_definitions":[],"doc_write_time":1692828253} \ No newline at end of file +{"chunk_definitions":[],"doc_write_time":1692895779} \ No newline at end of file diff --git a/11-ANCOVA.Rmd b/11-ANCOVA.Rmd index e922c0c6..039b9a11 100644 --- a/11-ANCOVA.Rmd +++ b/11-ANCOVA.Rmd @@ -747,6 +747,6 @@ Using the lecture and workflow (chart) as a guide, please work through all the s sessionInfo() ``` -# References {-#refs} + diff --git a/12-APPENDIX_Type1Error.Rmd b/12-APPENDIX_Type1Error.Rmd index e44523ea..a792b639 100644 --- a/12-APPENDIX_Type1Error.Rmd +++ b/12-APPENDIX_Type1Error.Rmd @@ -1,23 +1,23 @@ # APPENDICES {-} -# Type I Error {-} +# Type I Error [Screencasted Lecture Link](https://youtu.be/q7eQgXqY84Y) -## Type I Error Defined {-} +## Type I Error Defined *Type I error* is the concern about false positives -- that we would incorrectly reject a true null hypothesis (that we would say that there is a statistically significant difference when there is not one). This concern is increased when there are multiple hypothesis tests. This concern increases when we have a large number of pairwise comparisons. Throughout the chapters, I noted the importance and relative risk of Type I error with each statistic and options for follow-up testing. Because there are so many options, I have provided a review and summary of each option in this appendix. For each, I provide a definition, a review of the steps and options for utilizing the statistic, and suggest the types of follow-up for which this approach is indicated. -## Methods for Managing Type I Error {-} +## Methods for Managing Type I Error -### LSD (Least Significant Difference) Method {-} +### LSD (Least Significant Difference) Method The LSD method is especially appropriate in the one-way ANOVA scenario when there are only three levels in the factor. In this case, Green and Salkind [-@green_using_2017] have suggested that alpha can be retained at the alpha level for the "family" ($\alpha_{family}$), which is conventionally $p = .05$ and used both to evaluate the omnibus and, so long as they don't exceed three in number, the planned or pairwise comparisons that follow. -### Traditional Bonferroni {-} +### Traditional Bonferroni The *traditional Bonferroni* is, perhaps, the most well-known approach to managing Type I error. Although the lessons in this OER will frequently suggest another approach to managing Type I error, I will quickly review it now because, conceptually it is easy to understand. We start by establishing the $\alpha\alpha_{family}$; this is traditionally $p = .05$. @@ -44,7 +44,7 @@ Luckily, each of these options has been reverse-engineered so that we do not hav Although the traditional Bonferroni is easy-to-understand and computer, it has been criticized as being too restrictive. That is, it increases the risk of making a Type II error (i.e., failing to reject the null hypothesis when it is false). This is why the majority of follow-up options to ANOVA did not use the traditional Bonferroni. -### Tukey HSD {-} +### Tukey HSD The Tukey HSD (honestly significant difference test) is a multiple comparison procedure used to identify significant differences between means of multiple groups. In the ANOVA context, it examines which specific pairs of groups differ from one another. The Tukey HSD was designed to control for Type I error. It does so by calculating the difference between the largest and smallest group means, then dividing this mean difference by the standard error of the same mean difference. The resulting statitic, *q* has an associated Studentized Range Distribution. Critical values for this distribution come from a Studentized Range q Table and are based on based on the alpha level, the number of groups, and the denominator degrees of freedom (i.e., $df_W$). @@ -52,7 +52,7 @@ The Tukey HSD ("Tukey's honestly significantly different") test automatically co I had intended to demonstrate this with the one-way ANOVA chapter, but could not get the results to render a figure with the significance bars and results. An online search suggested that I am not the only one to have experienced this glitch. -### Holms Sequential Bonferroni {-} +### Holms Sequential Bonferroni The Holm's sequential Bonferroni [@green_using_2017] offers a middle-of-the-road approach (not as strict as .05/9 with the traditional Bonferroni; not as lenient as "none") to managing Type I error. diff --git a/13-moReTwoWay.Rmd b/13-moReTwoWay.Rmd index 0e987a0b..c358752b 100644 --- a/13-moReTwoWay.Rmd +++ b/13-moReTwoWay.Rmd @@ -1,4 +1,4 @@ -# Examples for Follow-up to Factorial ANOVA {-} +# Examples for Follow-up to Factorial ANOVA ```{r include=FALSE} knitr::opts_chunk$set(echo = TRUE) @@ -12,7 +12,7 @@ As noted in the lesson on [factorial ANOVA](#between), the options for follow-up As a quick reminder, I will describe and re-simulate the data. The narration will presume familiarity with the [factorial ANOVA](#between) lesson. -## Research Vignette {-} +## Research Vignette The research vignette for this example was located in Kalimantan, Indonesia and focused on bias in young people from three ethnic groups. The Madurese and Dayaknese groups were engaged in ethnic conflict that spanned 1996 to 2001. The last incidence of mass violence was in 2001 where approximately 500 people (mostly from the Madurese ethnic group) were expelled from the province. Ramdhani et al.'s [-@ramdhani_affective_2018] research hypotheses were based on the roles of the three ethnic groups in the study. The Madurese appear to be viewed as the transgressors when they occupied lands and took employment and business opportunities from the Dayaknese. Ramdhani et al. also included a third group who were not involved in the conflict (Javanese). The research participants were students studying in Yogyakara who were not involved in the conflict. They included 39 Madurese, 35 Dyaknese, and 37 Javanese; 83 were male and 28 were female. @@ -21,7 +21,7 @@ In the study [@ramdhani_affective_2018], participants viewed facial pictures of * Positive: friendly, kind, helpful, happy * Negative: disgusting, suspicious, hateful, angry -### Quick Resimulating of the Data {-} +### Quick Resimulating of the Data Below is script to simulate data for the negative reactions variable from the information available from the manuscript [@ramdhani_affective_2018]. If you would like more information about the details of this simulation, please visit the lesson on [factorial ANOVA](#between). @@ -63,7 +63,7 @@ The code for the .rds file will retain the formatting of the variables, but is n ``` -## Analysis of Simple Main Effects with Orthogonal Contrasts {-} +## Analysis of Simple Main Effects with Orthogonal Contrasts This example follows a significant interaction effect. Specifically, we will analyze the effects of ethnicity of rater (three levels) within photo stimulus (two levels). We will conduct two one-way ANOVAs for the Dayaknese and Madurese photos, separately. In this example, we will utilize orthogonal contrast-coding for rater ethnicity. @@ -184,7 +184,7 @@ I am not aware of an integration of packages that would represent this type of o ggpubr::ggboxplot(Ramdhani_df, x = "Photo", y = "Negative", color = "Rater",xlab = "Rater Ethnicity Represented within Photo Stimulus", ylab = "Negative Reaction", add = "jitter", title = "Figure 1. Simple Main Effect of Rater within Photo Stimulus", ylim = c(1, 7)) ``` -## Analysis of Simple Main Effects with a Polynomial Trend {-} +## Analysis of Simple Main Effects with a Polynomial Trend In the context of the significant interaction effect, we might be interested in polynomial trends for any simple main effects where three or more cells are compared. @@ -239,7 +239,7 @@ The figure we have been using would be appropriate to illustrate the significant ggpubr::ggboxplot(Ramdhani_df, x = "Photo", y = "Negative", color = "Rater",xlab = "Rater Ethnicity Represented within Photo Stimulus", ylab = "Negative Reaction", add = "jitter", title = "Figure 1. Simple Main Effect of Rater within Photo Stimulus", ylim = c(1, 7)) ``` -## All Possible Post Hoc Comparisons {-} +## All Possible Post Hoc Comparisons Another option is the comparison possible cells. These are termed *post hoc comparisons.* They are an alternative to simple main effects; you would not report both. A potential criticism of this approach is that it is atheoretical. Without compelling justification, reviewers may criticize this approach as "fishing," "p-hacking," or "HARKing" (hypothesizing after results are known). None-the-less, particularly when our results are not as expected, I do think having these tools available can be a helpful resource. diff --git a/14-RMmultivariate.Rmd b/14-RMmultivariate.Rmd index a7edf89a..ffe22af7 100644 --- a/14-RMmultivariate.Rmd +++ b/14-RMmultivariate.Rmd @@ -1,4 +1,4 @@ -# One-Way Repeated Measures with a Multivariate Approach {-} +# One-Way Repeated Measures with a Multivariate Approach ```{r include=FALSE} knitr::opts_chunk$set(echo = TRUE) @@ -12,7 +12,7 @@ As noted in the lesson on [one-way repeated measures ANOVA](#Repeated), the rese As a quick reminder, I will describe and resimulate the data. The narration will presume familiarity with the [one-way repeated measures ANOVA](#Repeated) lesson. -## Research Vignette {-} +## Research Vignette Amodeo [@amodeo_empowering_2018] and colleagues conducted a mixed methods study (qualitative and quantitative) to evaluate the effectiveness of an empowerment, peer-group-based, intervention with participants (*N* = 8) who experienced transphobic episodes. Focus groups used qualitative methods to summarize emergent themes from the program (identity affirmation, self-acceptance, group as support) and a one-way, repeated measures ANOVA provided evidence of increased resilience from pre to three-month followup. @@ -29,7 +29,7 @@ The within-subjects condition was wave, represented by T1, T2, and T3: The dependent variable (assessed at each wave) was a 14-item resilience scale [@wagnild_development_1993]. Items were assessed on a 7-point scale ranging from *strongly disagree* to *strongly agree* with higher scores indicating higher levels of resilience. An example items was, "I usually manage one way or another." -### Data Simulation {-} +### Data Simulation Below is the code I used to simulate data. The following code assumes 8 participants who each participated in 3 waves (pre, post, followup). The sript produces "long" and "wide" forms are created. ```{r tidy=TRUE, tidy.opts=list(width.cutoff=70)} @@ -53,7 +53,7 @@ str(Amodeo_wide) Amodeo_wide$ID <- factor(Amodeo_wide$ID) ``` -## Computing the Omnibus F {-} +## Computing the Omnibus F Without the *rstatix* helper package, here is how the analysis would be run in the package, *car.* Although this package is less intuitive to use, it results in both univariate output (both sphericity assumed and sphericity violated) and multivariate output (which does not require the sphericity assumption). @@ -89,7 +89,7 @@ summary(analysis) ``` The *car::Anova()* function produces both univariate and multivariate results. To begin to understand this data, let's start with what we learned in the [one-way repeated measures ANOVA lesson](#Repeated). -### Univariate Results {-} +### Univariate Results When we ran the univariate approach in the lesson, we first checked the sphericity assumption. Our results here are identical to those from *rstatix::anova_test*. That is, we did not violate the sphericity assumption: Mauchley's test $= .566 p = 0.182$. The *F* test with univariate results was $F(2, 14) = 3.910, p = 0.045$. @@ -98,7 +98,7 @@ When we ran the univariate approach in the lesson, we first checked the spherici The univariate ANOVA results are under the "Univariate Type III Repeated-Measures ANOVA Assuming Sphericity" heading. We find the ANOVA output on the row titled, "waveFactor." The results are identical to what we found in the lesson: $F(2,14) = 3.91, p = 0.045$. I do not see that an effect size is reported. -### Multivariate Results {-} +### Multivariate Results Researchers may prefer the multivariate approach because it does not require the sphericity assumption. Stated another way, if the sphericity assumption is violated, researchers can report the results of the multivariate analysis. @@ -108,10 +108,12 @@ We find the multivariate results in the middle of the output, under the heading, Because follow-up testing is *pairwise* (i.e., there are only two levels being compared), the sphericity assumption is not required and those could proceed in the manner demonstrated in the [one-way repeated measures ANOVA lesson](#Repeated). -### A Brief Commentary on Wrappers {-} +### A Brief Commentary on Wrappers As noted several times, because of its relative ease-of-use, the relevance of information included in the results, and its integration with the *ggpubr* package, I chose to use *rstatix* package in all of the ANOVA lessons. As I worked through this example, I spent several hours creating and interpreting the code. For me, there was value in this exercise: * I am encouraged and reassured with the consistency of results between the two approaches, * I am in awe of the power of these programs and a little intimidated by all the options that are available within a given package, and -* I am deeply grateful to package developers who take the time to create packages for discipline-specific use-cases and then freely share their work with others. Thank you [Alboukadel Kassambara](https://github.com/kassambara/rstatix)! \ No newline at end of file +* I am deeply grateful to package developers who take the time to create packages for discipline-specific use-cases and then freely share their work with others. Thank you [Alboukadel Kassambara](https://github.com/kassambara/rstatix)! + +# References {-#refs} \ No newline at end of file diff --git a/ReCenterPsychStats.log b/ReCenterPsychStats.log index 604c3321..b264707e 100644 --- a/ReCenterPsychStats.log +++ b/ReCenterPsychStats.log @@ -1,4 +1,4 @@ -This is XeTeX, Version 3.141592653-2.6-0.999995 (TeX Live 2023) (preloaded format=xelatex 2023.7.15) 23 AUG 2023 17:06 +This is XeTeX, Version 3.141592653-2.6-0.999995 (TeX Live 2023) (preloaded format=xelatex 2023.7.15) 24 AUG 2023 09:52 entering extended mode restricted \write18 enabled. %&-line parsing enabled. @@ -785,9 +785,7 @@ LaTeX Font Info: Font shape `TU/latinmodern-math.otf(3)/m/n' will be \tf@toc=\write5 \openout5 = `ReCenterPsychStats.toc'. -[15] [16 - -] +[15] [16] File: images/ReCenterPsychStats-bookcover2.jpg Graphic file (type bmp) @@ -798,7 +796,9 @@ Underfull \hbox (badness 10000) in paragraph at lines 146--147 Underfull \vbox (badness 10000) has occurred while \output is active [] -[17] +[17 + +] Overfull \vbox (155.12541pt too high) has occurred while \output is active [] [18] [19] [20 @@ -1815,60 +1815,86 @@ Underfull \vbox (badness 5345) has occurred while \output is active [] ] [526 -] [527] [528 - -] [529] [530] [531] [532 +] +Chapter 12. +[527] [528] [529] [530 -] [533] [534] +] +Chapter 13. +[531] [532] File: images/factorial/WrkFlw_IntORTH.jpg Graphic file (type bmp) -[535] [536] [537] [538] [539] +[533] [534] [535] [536] [537] File: 13-moReTwoWay_files/figure-latex/unnamed-chunk-15-1.pdf Graphic file (type pdf) File: images/factorial/WrkFlw_Poly.jpg Graphic file (type bmp) -[540] [541] [542] +[538] [539] [540] File: 13-moReTwoWay_files/figure-latex/unnamed-chunk-19-1.pdf Graphic file (type pdf) Underfull \vbox (badness 10000) has occurred while \output is active [] -[543] +[541] File: images/factorial/WrkFlw_IntPH.jpg Graphic file (type bmp) -[544] [545] [546] [547] -Overfull \hbox (1.64238pt too wide) in paragraph at lines 22767--22767 +[542] [543] [544] [545] +Overfull \hbox (1.64238pt too wide) in paragraph at lines 22750--22750 [] \TU/lmtt/m/n/10.95 .. ..$ : chr [1:3] "Javanese-Dayaknese" "Madurese-Dayaknese" "Madurese-Javanese"[] [] -Overfull \hbox (611.00975pt too wide) in paragraph at lines 22767--22767 +Overfull \hbox (611.00975pt too wide) in paragraph at lines 22750--22750 [] \TU/lmtt/m/n/10.95 .. ..$ : chr [1:15] "Javanese:Dayaknese-Dayaknese:Dayaknese" "Dayaknese:Madurese-Dayaknese:Dayaknese" "Madurese:Madurese-Dayaknese:Dayaknese" "Madurese:Dayaknese-Dayaknese:Dayaknese" ...[] [] -Overfull \hbox (64.87862pt too wide) in paragraph at lines 22767--22767 +Overfull \hbox (64.87862pt too wide) in paragraph at lines 22750--22750 [] \TU/lmtt/m/n/10.95 - attr(*, "orig.call")= language aov(formula = Negative ~ Rater * Photo, data = Ramdhani_df)[] [] File: images/factorial/Holmsequential.jpg Graphic file (type bmp) -[548] +[546] File: images/factorial/HolmsSelect.jpg Graphic file (type bmp) -Underfull \hbox (badness 10000) in paragraph at lines 22825--22826 +Underfull \hbox (badness 10000) in paragraph at lines 22808--22809 [][] [] -[549] [550 +[547] [548 + +] +Chapter 14. +[549] +Overfull \hbox (4.8326pt too wide) has occurred while \output is active +\TU/lmr/m/n/10.95 550 \TU/lmr/m/sl/10.95 CHAPTER 14. ONE-WAY REPEATED MEASURES WITH A MULTIVARIATE APPROACH + [] -] [551] [552] [553] +[550] [551] Underfull \vbox (badness 10000) has occurred while \output is active [] -[554] [555] (./ReCenterPsychStats.bbl [556] [557 -] [558] +Overfull \hbox (4.8326pt too wide) has occurred while \output is active +\TU/lmr/m/n/10.95 552 \TU/lmr/m/sl/10.95 CHAPTER 14. ONE-WAY REPEATED MEASURES WITH A MULTIVARIATE APPROACH + [] + +[552] [553] +Overfull \hbox (4.8326pt too wide) has occurred while \output is active +\TU/lmr/m/n/10.95 554 \TU/lmr/m/sl/10.95 CHAPTER 14. ONE-WAY REPEATED MEASURES WITH A MULTIVARIATE APPROACH + [] + +[554] (./ReCenterPsychStats.bbl [555 + +] +Overfull \hbox (4.8326pt too wide) has occurred while \output is active +\TU/lmr/m/n/10.95 556 \TU/lmr/m/sl/10.95 CHAPTER 14. ONE-WAY REPEATED MEASURES WITH A MULTIVARIATE APPROACH + [] + +[556 + +] [557] [558] Underfull \hbox (badness 10000) in paragraph at lines 178--182 [][]$[][][][][] [] [] [] [][][][][] [] [][][][][][][][][][] [] [][][] [] [][][][][][][][][][][] [] [][][][][][][] [] [][][][][][][][][][] [] [][][][] [] [][] [] [][][][][][][][] [] [][][][][][][][][][] [] [] @@ -1912,13 +1938,13 @@ L3 programming layer <2023-06-30> LaTeX Warning: There were multiply-defined labels. Package rerunfilecheck Info: File `ReCenterPsychStats.out' has not changed. -(rerunfilecheck) Checksum: 702567383FD6E90A041A2939CAA1DE13;89338. +(rerunfilecheck) Checksum: 657B199A3AE1981192C51A6B8BE53B12;93593. ) Here is how much of TeX's memory you used: - 20301 strings out of 477889 - 421627 string characters out of 5821843 + 20308 strings out of 477889 + 421719 string characters out of 5821843 1951869 words of memory out of 5000000 - 40830 multiletter control sequences out of 15000+600000 + 40837 multiletter control sequences out of 15000+600000 564574 words of font info for 96 fonts, out of 8000000 for 9000 14 hyphenation exceptions out of 8191 90i,10n,120p,2342b,559s stack positions out of 10000i,1000n,20000p,200000b,200000s diff --git a/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-10-1.pdf b/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-10-1.pdf index 2002415a..b420c221 100644 Binary files a/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-10-1.pdf and b/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-10-1.pdf differ diff --git a/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-20-1.pdf b/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-20-1.pdf index 2002415a..b420c221 100644 Binary files a/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-20-1.pdf and b/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-20-1.pdf differ diff --git a/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-48-1.pdf b/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-48-1.pdf index 79ead7da..8f8bec62 100644 Binary files a/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-48-1.pdf and b/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-48-1.pdf differ diff --git a/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-49-1.pdf b/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-49-1.pdf index 1887ca99..7e848bf4 100644 Binary files a/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-49-1.pdf and b/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-49-1.pdf differ diff --git a/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-59-1.pdf b/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-59-1.pdf index d8523c64..93ecc9b1 100644 Binary files a/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-59-1.pdf and b/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-59-1.pdf differ diff --git a/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-68-1.pdf b/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-68-1.pdf index 94a2687a..8c9001fd 100644 Binary files a/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-68-1.pdf and b/_bookdown_files/03-Preliminaries_files/figure-latex/unnamed-chunk-68-1.pdf differ diff --git a/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-11-1.pdf b/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-11-1.pdf index 36c14c07..df14ae38 100644 Binary files a/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-11-1.pdf and b/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-11-1.pdf differ diff --git a/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-15-1.pdf b/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-15-1.pdf index 0a7b6801..f228087e 100644 Binary files a/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-15-1.pdf and b/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-15-1.pdf differ diff --git a/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-18-1.pdf b/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-18-1.pdf index 88cb0e2c..2ba2973c 100644 Binary files a/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-18-1.pdf and b/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-18-1.pdf differ diff --git a/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-21-1.pdf b/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-21-1.pdf index e2e97bd1..1ef3b119 100644 Binary files a/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-21-1.pdf and b/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-21-1.pdf differ diff --git a/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-29-1.pdf b/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-29-1.pdf index 3bb7d89d..bcc53251 100644 Binary files a/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-29-1.pdf and b/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-29-1.pdf differ diff --git a/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-30-1.pdf b/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-30-1.pdf index 49801738..313b6253 100644 Binary files a/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-30-1.pdf and b/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-30-1.pdf differ diff --git a/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-4-1.pdf b/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-4-1.pdf index 2dfecf13..93161765 100644 Binary files a/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-4-1.pdf and b/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-4-1.pdf differ diff --git a/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-42-1.pdf b/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-42-1.pdf index db2ddd6b..3db457a8 100644 Binary files a/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-42-1.pdf and b/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-42-1.pdf differ diff --git a/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-58-1.pdf b/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-58-1.pdf index acf3749a..817e867b 100644 Binary files a/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-58-1.pdf and b/_bookdown_files/04-tOneSample_files/figure-latex/unnamed-chunk-58-1.pdf differ diff --git a/_bookdown_files/05-tIndSample_files/figure-latex/unnamed-chunk-10-1.pdf b/_bookdown_files/05-tIndSample_files/figure-latex/unnamed-chunk-10-1.pdf index 70e8ad82..883aec79 100644 Binary files a/_bookdown_files/05-tIndSample_files/figure-latex/unnamed-chunk-10-1.pdf and b/_bookdown_files/05-tIndSample_files/figure-latex/unnamed-chunk-10-1.pdf differ diff --git a/_bookdown_files/05-tIndSample_files/figure-latex/unnamed-chunk-27-1.pdf b/_bookdown_files/05-tIndSample_files/figure-latex/unnamed-chunk-27-1.pdf index 4e5a692e..22995930 100644 Binary files a/_bookdown_files/05-tIndSample_files/figure-latex/unnamed-chunk-27-1.pdf and b/_bookdown_files/05-tIndSample_files/figure-latex/unnamed-chunk-27-1.pdf differ diff --git a/_bookdown_files/05-tIndSample_files/figure-latex/unnamed-chunk-44-1.pdf b/_bookdown_files/05-tIndSample_files/figure-latex/unnamed-chunk-44-1.pdf index 841ec636..2b1b471c 100644 Binary files a/_bookdown_files/05-tIndSample_files/figure-latex/unnamed-chunk-44-1.pdf and b/_bookdown_files/05-tIndSample_files/figure-latex/unnamed-chunk-44-1.pdf differ diff --git a/_bookdown_files/05-tIndSample_files/figure-latex/unnamed-chunk-49-1.pdf b/_bookdown_files/05-tIndSample_files/figure-latex/unnamed-chunk-49-1.pdf index e42fd25d..8b70bc87 100644 Binary files a/_bookdown_files/05-tIndSample_files/figure-latex/unnamed-chunk-49-1.pdf and b/_bookdown_files/05-tIndSample_files/figure-latex/unnamed-chunk-49-1.pdf differ diff --git a/_bookdown_files/06-tPairedSamples_files/figure-latex/unnamed-chunk-28-1.pdf b/_bookdown_files/06-tPairedSamples_files/figure-latex/unnamed-chunk-28-1.pdf index 564d65ca..2043f1b6 100644 Binary files a/_bookdown_files/06-tPairedSamples_files/figure-latex/unnamed-chunk-28-1.pdf and b/_bookdown_files/06-tPairedSamples_files/figure-latex/unnamed-chunk-28-1.pdf differ diff --git a/_bookdown_files/06-tPairedSamples_files/figure-latex/unnamed-chunk-47-1.pdf b/_bookdown_files/06-tPairedSamples_files/figure-latex/unnamed-chunk-47-1.pdf index 92a4e662..1fc7f384 100644 Binary files a/_bookdown_files/06-tPairedSamples_files/figure-latex/unnamed-chunk-47-1.pdf and b/_bookdown_files/06-tPairedSamples_files/figure-latex/unnamed-chunk-47-1.pdf differ diff --git a/_bookdown_files/06-tPairedSamples_files/figure-latex/unnamed-chunk-53-1.pdf b/_bookdown_files/06-tPairedSamples_files/figure-latex/unnamed-chunk-53-1.pdf index 040e78eb..2102d371 100644 Binary files a/_bookdown_files/06-tPairedSamples_files/figure-latex/unnamed-chunk-53-1.pdf and b/_bookdown_files/06-tPairedSamples_files/figure-latex/unnamed-chunk-53-1.pdf differ diff --git a/_bookdown_files/06-tPairedSamples_files/figure-latex/unnamed-chunk-7-1.pdf b/_bookdown_files/06-tPairedSamples_files/figure-latex/unnamed-chunk-7-1.pdf index ccb3f03a..b1103db3 100644 Binary files a/_bookdown_files/06-tPairedSamples_files/figure-latex/unnamed-chunk-7-1.pdf and b/_bookdown_files/06-tPairedSamples_files/figure-latex/unnamed-chunk-7-1.pdf differ diff --git a/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-15-1.pdf b/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-15-1.pdf index 47409522..1d96903a 100644 Binary files a/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-15-1.pdf and b/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-15-1.pdf differ diff --git a/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-16-1.pdf b/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-16-1.pdf index 5ab244a9..15564033 100644 Binary files a/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-16-1.pdf and b/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-16-1.pdf differ diff --git a/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-17-1.pdf b/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-17-1.pdf index d0e1e770..554e1f62 100644 Binary files a/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-17-1.pdf and b/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-17-1.pdf differ diff --git a/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-45-1.pdf b/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-45-1.pdf index 0c91b8d8..effcc462 100644 Binary files a/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-45-1.pdf and b/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-45-1.pdf differ diff --git a/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-56-1.pdf b/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-56-1.pdf index 41116529..a3f6627a 100644 Binary files a/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-56-1.pdf and b/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-56-1.pdf differ diff --git a/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-58-1.pdf b/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-58-1.pdf index bc3d1178..cadfe61f 100644 Binary files a/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-58-1.pdf and b/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-58-1.pdf differ diff --git a/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-69-1.pdf b/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-69-1.pdf index 56c5f807..0d7b28d3 100644 Binary files a/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-69-1.pdf and b/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-69-1.pdf differ diff --git a/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-83-1.pdf b/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-83-1.pdf index c0806aaf..b3e732de 100644 Binary files a/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-83-1.pdf and b/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-83-1.pdf differ diff --git a/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-86-1.pdf b/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-86-1.pdf index 5ebf3281..90739247 100644 Binary files a/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-86-1.pdf and b/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-86-1.pdf differ diff --git a/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-93-1.pdf b/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-93-1.pdf index c73ef4de..5cab0527 100644 Binary files a/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-93-1.pdf and b/_bookdown_files/07-OnewayANOVA_files/figure-latex/unnamed-chunk-93-1.pdf differ diff --git a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-10-1.pdf b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-10-1.pdf index 25dbb038..f8982181 100644 Binary files a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-10-1.pdf and b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-10-1.pdf differ diff --git a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-102-1.pdf b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-102-1.pdf index 7682ebab..b7a249f5 100644 Binary files a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-102-1.pdf and b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-102-1.pdf differ diff --git a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-11-1.pdf b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-11-1.pdf index 2ed16d7f..fbfa288a 100644 Binary files a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-11-1.pdf and b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-11-1.pdf differ diff --git a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-12-1.pdf b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-12-1.pdf index 6ec79791..c8885b90 100644 Binary files a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-12-1.pdf and b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-12-1.pdf differ diff --git a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-13-1.pdf b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-13-1.pdf index 8ca13474..eb6a6c13 100644 Binary files a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-13-1.pdf and b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-13-1.pdf differ diff --git a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-38-1.pdf b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-38-1.pdf index 313b3e99..399ef864 100644 Binary files a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-38-1.pdf and b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-38-1.pdf differ diff --git a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-39-1.pdf b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-39-1.pdf index 324de558..f1c03a2d 100644 Binary files a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-39-1.pdf and b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-39-1.pdf differ diff --git a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-49-1.pdf b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-49-1.pdf index ffcbdb5c..add04645 100644 Binary files a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-49-1.pdf and b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-49-1.pdf differ diff --git a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-53-1.pdf b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-53-1.pdf index c4f66dcb..b4d7e8ee 100644 Binary files a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-53-1.pdf and b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-53-1.pdf differ diff --git a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-56-1.pdf b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-56-1.pdf index f65f846e..ace84b0b 100644 Binary files a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-56-1.pdf and b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-56-1.pdf differ diff --git a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-58-1.pdf b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-58-1.pdf index 41a56978..0fac79d1 100644 Binary files a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-58-1.pdf and b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-58-1.pdf differ diff --git a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-63-1.pdf b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-63-1.pdf index d35ac711..1c02fd2d 100644 Binary files a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-63-1.pdf and b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-63-1.pdf differ diff --git a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-66-1.pdf b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-66-1.pdf index 3bed52e5..902c81e8 100644 Binary files a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-66-1.pdf and b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-66-1.pdf differ diff --git a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-67-1.pdf b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-67-1.pdf index d915ccd6..0828563a 100644 Binary files a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-67-1.pdf and b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-67-1.pdf differ diff --git a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-90-1.pdf b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-90-1.pdf index b34fbce6..2d2d1773 100644 Binary files a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-90-1.pdf and b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-90-1.pdf differ diff --git a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-94-1.pdf b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-94-1.pdf index a3c3cc96..b8e4bb54 100644 Binary files a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-94-1.pdf and b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-94-1.pdf differ diff --git a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-95-1.pdf b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-95-1.pdf index 059b4351..332dcc73 100644 Binary files a/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-95-1.pdf and b/_bookdown_files/08-FactorialANOVA_files/figure-latex/unnamed-chunk-95-1.pdf differ diff --git a/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-13-1.pdf b/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-13-1.pdf index 40fb4a59..1d885cd1 100644 Binary files a/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-13-1.pdf and b/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-13-1.pdf differ diff --git a/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-33-1.pdf b/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-33-1.pdf index 41b5351b..ece42dbb 100644 Binary files a/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-33-1.pdf and b/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-33-1.pdf differ diff --git a/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-35-1.pdf b/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-35-1.pdf index 3a72b793..0abc0158 100644 Binary files a/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-35-1.pdf and b/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-35-1.pdf differ diff --git a/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-40-1.pdf b/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-40-1.pdf index febe0cfb..98d459af 100644 Binary files a/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-40-1.pdf and b/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-40-1.pdf differ diff --git a/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-58-1.pdf b/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-58-1.pdf index 2c3d55f9..062fa741 100644 Binary files a/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-58-1.pdf and b/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-58-1.pdf differ diff --git a/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-62-1.pdf b/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-62-1.pdf index 2f8306ad..492bea7a 100644 Binary files a/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-62-1.pdf and b/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-62-1.pdf differ diff --git a/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-66-1.pdf b/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-66-1.pdf index 69822d87..8cbb1a8e 100644 Binary files a/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-66-1.pdf and b/_bookdown_files/09-OneWayRepeated_files/figure-latex/unnamed-chunk-66-1.pdf differ diff --git a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-12-1.pdf b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-12-1.pdf index c61941ea..d3a48126 100644 Binary files a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-12-1.pdf and b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-12-1.pdf differ diff --git a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-13-1.pdf b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-13-1.pdf index 290d569b..2662a826 100644 Binary files a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-13-1.pdf and b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-13-1.pdf differ diff --git a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-14-1.pdf b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-14-1.pdf index 590c035c..bc2630ec 100644 Binary files a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-14-1.pdf and b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-14-1.pdf differ diff --git a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-15-1.pdf b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-15-1.pdf index 408d5547..6691ce84 100644 Binary files a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-15-1.pdf and b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-15-1.pdf differ diff --git a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-19-1.pdf b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-19-1.pdf index 09269c94..c3166904 100644 Binary files a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-19-1.pdf and b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-19-1.pdf differ diff --git a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-20-1.pdf b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-20-1.pdf index c2985294..97634866 100644 Binary files a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-20-1.pdf and b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-20-1.pdf differ diff --git a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-22-1.pdf b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-22-1.pdf index 37460a7a..ae2dd0cd 100644 Binary files a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-22-1.pdf and b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-22-1.pdf differ diff --git a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-32-1.pdf b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-32-1.pdf index b0788ff5..f0096b1c 100644 Binary files a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-32-1.pdf and b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-32-1.pdf differ diff --git a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-36-1.pdf b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-36-1.pdf index 74034bf8..c66f9b8a 100644 Binary files a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-36-1.pdf and b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-36-1.pdf differ diff --git a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-38-1.pdf b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-38-1.pdf index 6c351de9..c71d43ef 100644 Binary files a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-38-1.pdf and b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-38-1.pdf differ diff --git a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-39-1.pdf b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-39-1.pdf index 41b08fe8..c66f9b8a 100644 Binary files a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-39-1.pdf and b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-39-1.pdf differ diff --git a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-54-1.pdf b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-54-1.pdf index a3183328..3a83cd3f 100644 Binary files a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-54-1.pdf and b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-54-1.pdf differ diff --git a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-59-1.pdf b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-59-1.pdf index 33e76c65..b7390503 100644 Binary files a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-59-1.pdf and b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-59-1.pdf differ diff --git a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-60-1.pdf b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-60-1.pdf index 730e01f3..e64973ac 100644 Binary files a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-60-1.pdf and b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-60-1.pdf differ diff --git a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-67-1.pdf b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-67-1.pdf index 27ba66ae..f3a6c034 100644 Binary files a/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-67-1.pdf and b/_bookdown_files/10-MixedANOVA_files/figure-latex/unnamed-chunk-67-1.pdf differ diff --git a/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-10-1.pdf b/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-10-1.pdf index 3e505f05..dff14841 100644 Binary files a/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-10-1.pdf and b/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-10-1.pdf differ diff --git a/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-24-1.pdf b/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-24-1.pdf index 24193f30..e0ff9af8 100644 Binary files a/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-24-1.pdf and b/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-24-1.pdf differ diff --git a/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-25-1.pdf b/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-25-1.pdf index e6af2230..6e2c02ae 100644 Binary files a/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-25-1.pdf and b/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-25-1.pdf differ diff --git a/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-38-1.pdf b/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-38-1.pdf index 0b63e545..c93b8d5c 100644 Binary files a/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-38-1.pdf and b/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-38-1.pdf differ diff --git a/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-50-1.pdf b/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-50-1.pdf index c3afe7b3..8c435a57 100644 Binary files a/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-50-1.pdf and b/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-50-1.pdf differ diff --git a/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-61-1.pdf b/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-61-1.pdf index b55254ba..ebed342b 100644 Binary files a/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-61-1.pdf and b/_bookdown_files/11-ANCOVA_files/figure-latex/unnamed-chunk-61-1.pdf differ diff --git a/_bookdown_files/13-moReTwoWay_files/figure-latex/unnamed-chunk-15-1.pdf b/_bookdown_files/13-moReTwoWay_files/figure-latex/unnamed-chunk-15-1.pdf index ac84b6e4..7f765732 100644 Binary files a/_bookdown_files/13-moReTwoWay_files/figure-latex/unnamed-chunk-15-1.pdf and b/_bookdown_files/13-moReTwoWay_files/figure-latex/unnamed-chunk-15-1.pdf differ diff --git a/_bookdown_files/13-moReTwoWay_files/figure-latex/unnamed-chunk-19-1.pdf b/_bookdown_files/13-moReTwoWay_files/figure-latex/unnamed-chunk-19-1.pdf index bdf294e3..7f765732 100644 Binary files a/_bookdown_files/13-moReTwoWay_files/figure-latex/unnamed-chunk-19-1.pdf and b/_bookdown_files/13-moReTwoWay_files/figure-latex/unnamed-chunk-19-1.pdf differ diff --git a/docs/11-ANCOVA.md b/docs/11-ANCOVA.md index 0e48c289..775ee228 100644 --- a/docs/11-ANCOVA.md +++ b/docs/11-ANCOVA.md @@ -1433,6 +1433,6 @@ ggpubr::ggline(rstatix::get_emmeans(emmeans_MLTV), x = "Centering", y = "emmean" -# References {-#refs} + diff --git a/docs/12-APPENDIX_Type1Error.md b/docs/12-APPENDIX_Type1Error.md index 414b1665..458954ec 100644 --- a/docs/12-APPENDIX_Type1Error.md +++ b/docs/12-APPENDIX_Type1Error.md @@ -1,23 +1,23 @@ # APPENDICES {-} -# Type I Error {-} +# Type I Error [Screencasted Lecture Link](https://youtu.be/q7eQgXqY84Y) -## Type I Error Defined {-} +## Type I Error Defined *Type I error* is the concern about false positives -- that we would incorrectly reject a true null hypothesis (that we would say that there is a statistically significant difference when there is not one). This concern is increased when there are multiple hypothesis tests. This concern increases when we have a large number of pairwise comparisons. Throughout the chapters, I noted the importance and relative risk of Type I error with each statistic and options for follow-up testing. Because there are so many options, I have provided a review and summary of each option in this appendix. For each, I provide a definition, a review of the steps and options for utilizing the statistic, and suggest the types of follow-up for which this approach is indicated. -## Methods for Managing Type I Error {-} +## Methods for Managing Type I Error -### LSD (Least Significant Difference) Method {-} +### LSD (Least Significant Difference) Method The LSD method is especially appropriate in the one-way ANOVA scenario when there are only three levels in the factor. In this case, Green and Salkind [-@green_using_2017] have suggested that alpha can be retained at the alpha level for the "family" ($\alpha_{family}$), which is conventionally $p = .05$ and used both to evaluate the omnibus and, so long as they don't exceed three in number, the planned or pairwise comparisons that follow. -### Traditional Bonferroni {-} +### Traditional Bonferroni The *traditional Bonferroni* is, perhaps, the most well-known approach to managing Type I error. Although the lessons in this OER will frequently suggest another approach to managing Type I error, I will quickly review it now because, conceptually it is easy to understand. We start by establishing the $\alpha\alpha_{family}$; this is traditionally $p = .05$. @@ -54,7 +54,7 @@ Luckily, each of these options has been reverse-engineered so that we do not hav Although the traditional Bonferroni is easy-to-understand and computer, it has been criticized as being too restrictive. That is, it increases the risk of making a Type II error (i.e., failing to reject the null hypothesis when it is false). This is why the majority of follow-up options to ANOVA did not use the traditional Bonferroni. -### Tukey HSD {-} +### Tukey HSD The Tukey HSD (honestly significant difference test) is a multiple comparison procedure used to identify significant differences between means of multiple groups. In the ANOVA context, it examines which specific pairs of groups differ from one another. The Tukey HSD was designed to control for Type I error. It does so by calculating the difference between the largest and smallest group means, then dividing this mean difference by the standard error of the same mean difference. The resulting statitic, *q* has an associated Studentized Range Distribution. Critical values for this distribution come from a Studentized Range q Table and are based on based on the alpha level, the number of groups, and the denominator degrees of freedom (i.e., $df_W$). @@ -62,7 +62,7 @@ The Tukey HSD ("Tukey's honestly significantly different") test automatically co I had intended to demonstrate this with the one-way ANOVA chapter, but could not get the results to render a figure with the significance bars and results. An online search suggested that I am not the only one to have experienced this glitch. -### Holms Sequential Bonferroni {-} +### Holms Sequential Bonferroni The Holm's sequential Bonferroni [@green_using_2017] offers a middle-of-the-road approach (not as strict as .05/9 with the traditional Bonferroni; not as lenient as "none") to managing Type I error. diff --git a/docs/13-moReTwoWay.md b/docs/13-moReTwoWay.md index f2ca8163..a7ead814 100644 --- a/docs/13-moReTwoWay.md +++ b/docs/13-moReTwoWay.md @@ -1,4 +1,4 @@ -# Examples for Follow-up to Factorial ANOVA {-} +# Examples for Follow-up to Factorial ANOVA @@ -8,7 +8,7 @@ As noted in the lesson on [factorial ANOVA](#between), the options for follow-up As a quick reminder, I will describe and re-simulate the data. The narration will presume familiarity with the [factorial ANOVA](#between) lesson. -## Research Vignette {-} +## Research Vignette The research vignette for this example was located in Kalimantan, Indonesia and focused on bias in young people from three ethnic groups. The Madurese and Dayaknese groups were engaged in ethnic conflict that spanned 1996 to 2001. The last incidence of mass violence was in 2001 where approximately 500 people (mostly from the Madurese ethnic group) were expelled from the province. Ramdhani et al.'s [-@ramdhani_affective_2018] research hypotheses were based on the roles of the three ethnic groups in the study. The Madurese appear to be viewed as the transgressors when they occupied lands and took employment and business opportunities from the Dayaknese. Ramdhani et al. also included a third group who were not involved in the conflict (Javanese). The research participants were students studying in Yogyakara who were not involved in the conflict. They included 39 Madurese, 35 Dyaknese, and 37 Javanese; 83 were male and 28 were female. @@ -17,7 +17,7 @@ In the study [@ramdhani_affective_2018], participants viewed facial pictures of * Positive: friendly, kind, helpful, happy * Negative: disgusting, suspicious, hateful, angry -### Quick Resimulating of the Data {-} +### Quick Resimulating of the Data Below is script to simulate data for the negative reactions variable from the information available from the manuscript [@ramdhani_affective_2018]. If you would like more information about the details of this simulation, please visit the lesson on [factorial ANOVA](#between). @@ -70,7 +70,7 @@ The code for the .rds file will retain the formatting of the variables, but is n ``` -## Analysis of Simple Main Effects with Orthogonal Contrasts {-} +## Analysis of Simple Main Effects with Orthogonal Contrasts This example follows a significant interaction effect. Specifically, we will analyze the effects of ethnicity of rater (three levels) within photo stimulus (two levels). We will conduct two one-way ANOVAs for the Dayaknese and Madurese photos, separately. In this example, we will utilize orthogonal contrast-coding for rater ethnicity. @@ -279,7 +279,7 @@ ggpubr::ggboxplot(Ramdhani_df, x = "Photo", y = "Negative", color = "Rater", ![](13-moReTwoWay_files/figure-docx/unnamed-chunk-15-1.png) -## Analysis of Simple Main Effects with a Polynomial Trend {-} +## Analysis of Simple Main Effects with a Polynomial Trend In the context of the significant interaction effect, we might be interested in polynomial trends for any simple main effects where three or more cells are compared. @@ -387,7 +387,7 @@ ggpubr::ggboxplot(Ramdhani_df, x = "Photo", y = "Negative", color = "Rater", ![](13-moReTwoWay_files/figure-docx/unnamed-chunk-19-1.png) -## All Possible Post Hoc Comparisons {-} +## All Possible Post Hoc Comparisons Another option is the comparison possible cells. These are termed *post hoc comparisons.* They are an alternative to simple main effects; you would not report both. A potential criticism of this approach is that it is atheoretical. Without compelling justification, reviewers may criticize this approach as "fishing," "p-hacking," or "HARKing" (hypothesizing after results are known). None-the-less, particularly when our results are not as expected, I do think having these tools available can be a helpful resource. diff --git a/docs/14-RMmultivariate.md b/docs/14-RMmultivariate.md index 9dfd3afe..485fa19d 100644 --- a/docs/14-RMmultivariate.md +++ b/docs/14-RMmultivariate.md @@ -1,4 +1,4 @@ -# One-Way Repeated Measures with a Multivariate Approach {-} +# One-Way Repeated Measures with a Multivariate Approach @@ -8,7 +8,7 @@ As noted in the lesson on [one-way repeated measures ANOVA](#Repeated), the rese As a quick reminder, I will describe and resimulate the data. The narration will presume familiarity with the [one-way repeated measures ANOVA](#Repeated) lesson. -## Research Vignette {-} +## Research Vignette Amodeo [@amodeo_empowering_2018] and colleagues conducted a mixed methods study (qualitative and quantitative) to evaluate the effectiveness of an empowerment, peer-group-based, intervention with participants (*N* = 8) who experienced transphobic episodes. Focus groups used qualitative methods to summarize emergent themes from the program (identity affirmation, self-acceptance, group as support) and a one-way, repeated measures ANOVA provided evidence of increased resilience from pre to three-month followup. @@ -25,7 +25,7 @@ The within-subjects condition was wave, represented by T1, T2, and T3: The dependent variable (assessed at each wave) was a 14-item resilience scale [@wagnild_development_1993]. Items were assessed on a 7-point scale ranging from *strongly disagree* to *strongly agree* with higher scores indicating higher levels of resilience. An example items was, "I usually manage one way or another." -### Data Simulation {-} +### Data Simulation Below is the code I used to simulate data. The following code assumes 8 participants who each participated in 3 waves (pre, post, followup). The sript produces "long" and "wide" forms are created. @@ -64,7 +64,7 @@ str(Amodeo_wide) Amodeo_wide$ID <- factor(Amodeo_wide$ID) ``` -## Computing the Omnibus F {-} +## Computing the Omnibus F Without the *rstatix* helper package, here is how the analysis would be run in the package, *car.* Although this package is less intuitive to use, it results in both univariate output (both sphericity assumed and sphericity violated) and multivariate output (which does not require the sphericity assumption). @@ -194,7 +194,7 @@ waveFactor 0.8172743 0.05734876 ``` The *car::Anova()* function produces both univariate and multivariate results. To begin to understand this data, let's start with what we learned in the [one-way repeated measures ANOVA lesson](#Repeated). -### Univariate Results {-} +### Univariate Results When we ran the univariate approach in the lesson, we first checked the sphericity assumption. Our results here are identical to those from *rstatix::anova_test*. That is, we did not violate the sphericity assumption: Mauchley's test $= .566 p = 0.182$. The *F* test with univariate results was $F(2, 14) = 3.910, p = 0.045$. @@ -203,7 +203,7 @@ When we ran the univariate approach in the lesson, we first checked the spherici The univariate ANOVA results are under the "Univariate Type III Repeated-Measures ANOVA Assuming Sphericity" heading. We find the ANOVA output on the row titled, "waveFactor." The results are identical to what we found in the lesson: $F(2,14) = 3.91, p = 0.045$. I do not see that an effect size is reported. -### Multivariate Results {-} +### Multivariate Results Researchers may prefer the multivariate approach because it does not require the sphericity assumption. Stated another way, if the sphericity assumption is violated, researchers can report the results of the multivariate analysis. @@ -213,10 +213,12 @@ We find the multivariate results in the middle of the output, under the heading, Because follow-up testing is *pairwise* (i.e., there are only two levels being compared), the sphericity assumption is not required and those could proceed in the manner demonstrated in the [one-way repeated measures ANOVA lesson](#Repeated). -### A Brief Commentary on Wrappers {-} +### A Brief Commentary on Wrappers As noted several times, because of its relative ease-of-use, the relevance of information included in the results, and its integration with the *ggpubr* package, I chose to use *rstatix* package in all of the ANOVA lessons. As I worked through this example, I spent several hours creating and interpreting the code. For me, there was value in this exercise: * I am encouraged and reassured with the consistency of results between the two approaches, * I am in awe of the power of these programs and a little intimidated by all the options that are available within a given package, and * I am deeply grateful to package developers who take the time to create packages for discipline-specific use-cases and then freely share their work with others. Thank you [Alboukadel Kassambara](https://github.com/kassambara/rstatix)! + +# References {-#refs} diff --git a/docs/404.html b/docs/404.html index 193d2591..3525df97 100644 --- a/docs/404.html +++ b/docs/404.html @@ -648,42 +648,42 @@
  • 11.8.1 Working the Problem with R and R Packages
  • -
  • References
  • APPENDICES
  • -
  • Type I Error +
  • 12 Type I Error
  • -
  • Examples for Follow-up to Factorial ANOVA +
  • 13 Examples for Follow-up to Factorial ANOVA
  • -
  • One-Way Repeated Measures with a Multivariate Approach +
  • 14 One-Way Repeated Measures with a Multivariate Approach
  • +
  • References
  • Published with bookdown
  • diff --git a/docs/ANCOVA.html b/docs/ANCOVA.html index ce7fbe97..16011933 100644 --- a/docs/ANCOVA.html +++ b/docs/ANCOVA.html @@ -30,7 +30,7 @@ - + @@ -648,42 +648,42 @@
  • 11.8.1 Working the Problem with R and R Packages
  • -
  • References
  • APPENDICES
  • -
  • Type I Error +
  • 12 Type I Error
  • -
  • Examples for Follow-up to Factorial ANOVA +
  • 13 Examples for Follow-up to Factorial ANOVA
  • -
  • One-Way Repeated Measures with a Multivariate Approach +
  • 14 One-Way Repeated Measures with a Multivariate Approach
  • +
  • References
  • Published with bookdown
  • @@ -1906,11 +1906,12 @@

    APA style results with table(s) and figure ggpubr::stat_pvalue_manual(emmeans_MLTV, hide.ns = TRUE, tip.length = 0.02, , y.position = c(5))

    + -

    References

    +

    References

    Bernerth, J. B., & Aguinis, H. (2016). A critical review and best‐practice recommendations for control variable usage. Personnel Psychology, 69(1), 229–283. https://doi.org/10.1111/peps.12103 @@ -1940,7 +1941,7 @@

    References

    - + diff --git a/docs/Mixed.html b/docs/Mixed.html index 43399af5..2da2b1ca 100644 --- a/docs/Mixed.html +++ b/docs/Mixed.html @@ -648,42 +648,42 @@
  • 11.8.1 Working the Problem with R and R Packages
  • -
  • References
  • APPENDICES
  • -
  • Type I Error +
  • 12 Type I Error
  • -
  • Examples for Follow-up to Factorial ANOVA +
  • 13 Examples for Follow-up to Factorial ANOVA
  • -
  • One-Way Repeated Measures with a Multivariate Approach +
  • 14 One-Way Repeated Measures with a Multivariate Approach
  • +
  • References
  • Published with bookdown
  • @@ -1962,7 +1962,7 @@

    Conduct power analyses to determine the power of the current study and a rec -

    References

    +

    References

    Green, S. B., & Salkind, N. J. (2017c). Using SPSS for Windows and Macintosh: Analyzing and understanding data (Eighth edition.). Pearson. diff --git a/docs/ReCenterPsychStats.docx b/docs/ReCenterPsychStats.docx index cee1d404..01d25665 100644 Binary files a/docs/ReCenterPsychStats.docx and b/docs/ReCenterPsychStats.docx differ diff --git a/docs/ReCenterPsychStats.epub b/docs/ReCenterPsychStats.epub index d0aea492..00f5bb8a 100644 Binary files a/docs/ReCenterPsychStats.epub and b/docs/ReCenterPsychStats.epub differ diff --git a/docs/ReCenterPsychStats.pdf b/docs/ReCenterPsychStats.pdf index 933f9e01..d5233a6d 100644 Binary files a/docs/ReCenterPsychStats.pdf and b/docs/ReCenterPsychStats.pdf differ diff --git a/docs/ReCenterPsychStats.tex b/docs/ReCenterPsychStats.tex index 5b136413..0e29d27d 100644 --- a/docs/ReCenterPsychStats.tex +++ b/docs/ReCenterPsychStats.tex @@ -129,7 +129,7 @@ \title{ReCentering Psych Stats} \author{Lynette H. Bikos, PhD, ABPP (she/her)} -\date{Last updated 23 Aug 2023} +\date{Last updated 24 Aug 2023} \begin{document} \maketitle @@ -169,7 +169,7 @@ \chapter*{BOOK COVER}\label{book-cover}} \chapter*{PREFACE}\label{preface}} -\textbf{If you are viewing this document, you should know that this is a book-in-progress. Early drafts are released for the purpose teaching my classes and gaining formative feedback from a host of stakeholders. The document was last updated on 23 Aug 2023}. Emerging volumes on other statistics are posted on the \href{https://lhbikos.github.io/BikosRVT/ReCenter.html}{ReCentering Psych Stats} page at my research team's website. +\textbf{If you are viewing this document, you should know that this is a book-in-progress. Early drafts are released for the purpose teaching my classes and gaining formative feedback from a host of stakeholders. The document was last updated on 24 Aug 2023}. Emerging volumes on other statistics are posted on the \href{https://lhbikos.github.io/BikosRVT/ReCenter.html}{ReCentering Psych Stats} page at my research team's website. \href{https://youtu.be/yy0z85Wla7o}{Screencasted Lecture Link} @@ -22046,41 +22046,32 @@ \subsubsection*{APA style results with table(s) and figure}\label{apa-style-resu \includegraphics{11-ANCOVA_files/figure-latex/unnamed-chunk-61-1.pdf} -\hypertarget{refs}{% -\chapter*{References}\label{refs}} - - \hypertarget{appendices}{% \chapter*{APPENDICES}\label{appendices}} \hypertarget{type-i-error}{% -\chapter*{Type I Error}\label{type-i-error}} - +\chapter{Type I Error}\label{type-i-error}} \href{https://youtu.be/q7eQgXqY84Y}{Screencasted Lecture Link} \hypertarget{type-i-error-defined}{% -\section*{Type I Error Defined}\label{type-i-error-defined}} - +\section{Type I Error Defined}\label{type-i-error-defined}} \emph{Type I error} is the concern about false positives -- that we would incorrectly reject a true null hypothesis (that we would say that there is a statistically significant difference when there is not one). This concern is increased when there are multiple hypothesis tests. This concern increases when we have a large number of pairwise comparisons. Throughout the chapters, I noted the importance and relative risk of Type I error with each statistic and options for follow-up testing. Because there are so many options, I have provided a review and summary of each option in this appendix. For each, I provide a definition, a review of the steps and options for utilizing the statistic, and suggest the types of follow-up for which this approach is indicated. \hypertarget{methods-for-managing-type-i-error}{% -\section*{Methods for Managing Type I Error}\label{methods-for-managing-type-i-error}} - +\section{Methods for Managing Type I Error}\label{methods-for-managing-type-i-error}} \hypertarget{lsd-least-significant-difference-method}{% -\subsection*{LSD (Least Significant Difference) Method}\label{lsd-least-significant-difference-method}} - +\subsection{LSD (Least Significant Difference) Method}\label{lsd-least-significant-difference-method}} The LSD method is especially appropriate in the one-way ANOVA scenario when there are only three levels in the factor. In this case, Green and Salkind \citeyearpar{green_using_2017} have suggested that alpha can be retained at the alpha level for the ``family'' (\(\alpha_{family}\)), which is conventionally \(p = .05\) and used both to evaluate the omnibus and, so long as they don't exceed three in number, the planned or pairwise comparisons that follow. \hypertarget{traditional-bonferroni}{% -\subsection*{Traditional Bonferroni}\label{traditional-bonferroni}} - +\subsection{Traditional Bonferroni}\label{traditional-bonferroni}} The \emph{traditional Bonferroni} is, perhaps, the most well-known approach to managing Type I error. Although the lessons in this OER will frequently suggest another approach to managing Type I error, I will quickly review it now because, conceptually it is easy to understand. We start by establishing the \(\alpha\alpha_{family}\); this is traditionally \(p = .05\). @@ -22127,8 +22118,7 @@ \subsection*{Traditional Bonferroni}\label{traditional-bonferroni}} Although the traditional Bonferroni is easy-to-understand and computer, it has been criticized as being too restrictive. That is, it increases the risk of making a Type II error (i.e., failing to reject the null hypothesis when it is false). This is why the majority of follow-up options to ANOVA did not use the traditional Bonferroni. \hypertarget{tukey-hsd}{% -\subsection*{Tukey HSD}\label{tukey-hsd}} - +\subsection{Tukey HSD}\label{tukey-hsd}} The Tukey HSD (honestly significant difference test) is a multiple comparison procedure used to identify significant differences between means of multiple groups. In the ANOVA context, it examines which specific pairs of groups differ from one another. The Tukey HSD was designed to control for Type I error. It does so by calculating the difference between the largest and smallest group means, then dividing this mean difference by the standard error of the same mean difference. The resulting statitic, \emph{q} has an associated Studentized Range Distribution. Critical values for this distribution come from a Studentized Range q Table and are based on based on the alpha level, the number of groups, and the denominator degrees of freedom (i.e., \(df_W\)). @@ -22137,16 +22127,14 @@ \subsection*{Tukey HSD}\label{tukey-hsd}} I had intended to demonstrate this with the one-way ANOVA chapter, but could not get the results to render a figure with the significance bars and results. An online search suggested that I am not the only one to have experienced this glitch. \hypertarget{holms-sequential-bonferroni}{% -\subsection*{Holms Sequential Bonferroni}\label{holms-sequential-bonferroni}} - +\subsection{Holms Sequential Bonferroni}\label{holms-sequential-bonferroni}} The Holm's sequential Bonferroni \citep{green_using_2017} offers a middle-of-the-road approach (not as strict as .05/9 with the traditional Bonferroni; not as lenient as ``none'') to managing Type I error. If we were to hand-calculate the Holms, we would rank order the \emph{p} values associated with the 9 comparisons in order from lowest (e.g., 0.000001448891) to highest (e.g., 1.000). The first \emph{p} value is evaluated with the most strict criterion (.05/9; the traditional Bonferonni approach). Then, each successive comparison calculates the \emph{p} value by using the number of \emph{remaining} comparisons as the denominator (e.g., .05/8, .05/7, .05/6). As the \emph{p} values increase and the alpha levels relax, there will be a cut-point where remaining comparisons are not statistically significant. Luckily, most R packages offer the Holm's sequential Bonferroni as an option. The algorithm behind the output rearranges the mathematical formula and produces a \emph{p} value that we can interpret according to the traditional values of \(p < .05, p < .01\) and \(p < .001\). \citep{green_using_2017} \hypertarget{examples-for-follow-up-to-factorial-anova}{% -\chapter*{Examples for Follow-up to Factorial ANOVA}\label{examples-for-follow-up-to-factorial-anova}} - +\chapter{Examples for Follow-up to Factorial ANOVA}\label{examples-for-follow-up-to-factorial-anova}} \href{https://youtube.com/playlist?list=PLtz5cFLQl4KNxh3GDsCUg8yxtOM9l0WPf\&si=rqdj6oyjCJ78Zj8P}{Screencasted Lecture Link} @@ -22155,8 +22143,7 @@ \chapter*{Examples for Follow-up to Factorial ANOVA}\label{examples-for-follow-u As a quick reminder, I will describe and re-simulate the data. The narration will presume familiarity with the \protect\hyperlink{between}{factorial ANOVA} lesson. \hypertarget{research-vignette-9}{% -\section*{Research Vignette}\label{research-vignette-9}} - +\section{Research Vignette}\label{research-vignette-9}} The research vignette for this example was located in Kalimantan, Indonesia and focused on bias in young people from three ethnic groups. The Madurese and Dayaknese groups were engaged in ethnic conflict that spanned 1996 to 2001. The last incidence of mass violence was in 2001 where approximately 500 people (mostly from the Madurese ethnic group) were expelled from the province. Ramdhani et al.'s \citeyearpar{ramdhani_affective_2018} research hypotheses were based on the roles of the three ethnic groups in the study. The Madurese appear to be viewed as the transgressors when they occupied lands and took employment and business opportunities from the Dayaknese. Ramdhani et al.~also included a third group who were not involved in the conflict (Javanese). The research participants were students studying in Yogyakara who were not involved in the conflict. They included 39 Madurese, 35 Dyaknese, and 37 Javanese; 83 were male and 28 were female. @@ -22171,8 +22158,7 @@ \section*{Research Vignette}\label{research-vignette-9}} \end{itemize} \hypertarget{quick-resimulating-of-the-data}{% -\subsection*{Quick Resimulating of the Data}\label{quick-resimulating-of-the-data}} - +\subsection{Quick Resimulating of the Data}\label{quick-resimulating-of-the-data}} Below is script to simulate data for the negative reactions variable from the information available from the manuscript \citep{ramdhani_affective_2018}. If you would like more information about the details of this simulation, please visit the lesson on \protect\hyperlink{between}{factorial ANOVA}. @@ -22230,8 +22216,7 @@ \subsection*{Quick Resimulating of the Data}\label{quick-resimulating-of-the-dat \end{Shaded} \hypertarget{analysis-of-simple-main-effects-with-orthogonal-contrasts}{% -\section*{Analysis of Simple Main Effects with Orthogonal Contrasts}\label{analysis-of-simple-main-effects-with-orthogonal-contrasts}} - +\section{Analysis of Simple Main Effects with Orthogonal Contrasts}\label{analysis-of-simple-main-effects-with-orthogonal-contrasts}} This example follows a significant interaction effect. Specifically, we will analyze the effects of ethnicity of rater (three levels) within photo stimulus (two levels). We will conduct two one-way ANOVAs for the Dayaknese and Madurese photos, separately. In this example, we will utilize orthogonal contrast-coding for rater ethnicity. @@ -22483,8 +22468,7 @@ \section*{Analysis of Simple Main Effects with Orthogonal Contrasts}\label{analy \includegraphics{13-moReTwoWay_files/figure-latex/unnamed-chunk-15-1.pdf} \hypertarget{analysis-of-simple-main-effects-with-a-polynomial-trend}{% -\section*{Analysis of Simple Main Effects with a Polynomial Trend}\label{analysis-of-simple-main-effects-with-a-polynomial-trend}} - +\section{Analysis of Simple Main Effects with a Polynomial Trend}\label{analysis-of-simple-main-effects-with-a-polynomial-trend}} In the context of the significant interaction effect, we might be interested in polynomial trends for any simple main effects where three or more cells are compared. @@ -22605,8 +22589,7 @@ \section*{Analysis of Simple Main Effects with a Polynomial Trend}\label{analysi \includegraphics{13-moReTwoWay_files/figure-latex/unnamed-chunk-19-1.pdf} \hypertarget{all-possible-post-hoc-comparisons}{% -\section*{All Possible Post Hoc Comparisons}\label{all-possible-post-hoc-comparisons}} - +\section{All Possible Post Hoc Comparisons}\label{all-possible-post-hoc-comparisons}} Another option is the comparison possible cells. These are termed \emph{post hoc comparisons.} They are an alternative to simple main effects; you would not report both. A potential criticism of this approach is that it is atheoretical. Without compelling justification, reviewers may criticize this approach as ``fishing,'' ``p-hacking,'' or ``HARKing'' (hypothesizing after results are known). None-the-less, particularly when our results are not as expected, I do think having these tools available can be a helpful resource. @@ -22825,8 +22808,7 @@ \section*{All Possible Post Hoc Comparisons}\label{all-possible-post-hoc-compari \includegraphics{images/factorial/HolmsSelect.jpg} Given that my ``tinkering around'' analysis resembles the results of the simple main effects analyses in the \protect\hyperlink{between}{factorial lessonn}, I will not write this up as an APA style results section, but rather offer this is as a set of tools when you would like to explore the data in an atheoretical manner. \hypertarget{one-way-repeated-measures-with-a-multivariate-approach}{% -\chapter*{One-Way Repeated Measures with a Multivariate Approach}\label{one-way-repeated-measures-with-a-multivariate-approach}} - +\chapter{One-Way Repeated Measures with a Multivariate Approach}\label{one-way-repeated-measures-with-a-multivariate-approach}} \href{https://youtu.be/1c3N733nSM0}{Screencasted Lecture Link} @@ -22835,8 +22817,7 @@ \chapter*{One-Way Repeated Measures with a Multivariate Approach}\label{one-way- As a quick reminder, I will describe and resimulate the data. The narration will presume familiarity with the \protect\hyperlink{Repeated}{one-way repeated measures ANOVA} lesson. \hypertarget{research-vignette-10}{% -\section*{Research Vignette}\label{research-vignette-10}} - +\section{Research Vignette}\label{research-vignette-10}} Amodeo \citep{amodeo_empowering_2018} and colleagues conducted a mixed methods study (qualitative and quantitative) to evaluate the effectiveness of an empowerment, peer-group-based, intervention with participants (\emph{N} = 8) who experienced transphobic episodes. Focus groups used qualitative methods to summarize emergent themes from the program (identity affirmation, self-acceptance, group as support) and a one-way, repeated measures ANOVA provided evidence of increased resilience from pre to three-month followup. @@ -22867,8 +22848,7 @@ \section*{Research Vignette}\label{research-vignette-10}} The dependent variable (assessed at each wave) was a 14-item resilience scale \citep{wagnild_development_1993}. Items were assessed on a 7-point scale ranging from \emph{strongly disagree} to \emph{strongly agree} with higher scores indicating higher levels of resilience. An example items was, ``I usually manage one way or another.'' \hypertarget{data-simulation-7}{% -\subsection*{Data Simulation}\label{data-simulation-7}} - +\subsection{Data Simulation}\label{data-simulation-7}} Below is the code I used to simulate data. The following code assumes 8 participants who each participated in 3 waves (pre, post, followup). The sript produces ``long'' and ``wide'' forms are created. @@ -22912,8 +22892,7 @@ \subsection*{Data Simulation}\label{data-simulation-7}} \end{Shaded} \hypertarget{computing-the-omnibus-f}{% -\section*{Computing the Omnibus F}\label{computing-the-omnibus-f}} - +\section{Computing the Omnibus F}\label{computing-the-omnibus-f}} Without the \emph{rstatix} helper package, here is how the analysis would be run in the package, \emph{car.} Although this package is less intuitive to use, it results in both univariate output (both sphericity assumed and sphericity violated) and multivariate output (which does not require the sphericity assumption). @@ -23062,8 +23041,7 @@ \section*{Computing the Omnibus F}\label{computing-the-omnibus-f}} The \emph{car::Anova()} function produces both univariate and multivariate results. To begin to understand this data, let's start with what we learned in the \protect\hyperlink{Repeated}{one-way repeated measures ANOVA lesson}. \hypertarget{univariate-results}{% -\subsection*{Univariate Results}\label{univariate-results}} - +\subsection{Univariate Results}\label{univariate-results}} When we ran the univariate approach in the lesson, we first checked the sphericity assumption. Our results here are identical to those from \emph{rstatix::anova\_test}. That is, we did not violate the sphericity assumption: Mauchley's test \(= .566 p = 0.182\). The \emph{F} test with univariate results was \(F(2, 14) = 3.910, p = 0.045\). @@ -23074,8 +23052,7 @@ \subsection*{Univariate Results}\label{univariate-results}} The univariate ANOVA results are under the ``Univariate Type III Repeated-Measures ANOVA Assuming Sphericity'' heading. We find the ANOVA output on the row titled, ``waveFactor.'' The results are identical to what we found in the lesson: \(F(2,14) = 3.91, p = 0.045\). I do not see that an effect size is reported. \hypertarget{multivariate-results}{% -\subsection*{Multivariate Results}\label{multivariate-results}} - +\subsection{Multivariate Results}\label{multivariate-results}} Researchers may prefer the multivariate approach because it does not require the sphericity assumption. Stated another way, if the sphericity assumption is violated, researchers can report the results of the multivariate analysis. @@ -23088,8 +23065,7 @@ \subsection*{Multivariate Results}\label{multivariate-results}} Because follow-up testing is \emph{pairwise} (i.e., there are only two levels being compared), the sphericity assumption is not required and those could proceed in the manner demonstrated in the \protect\hyperlink{Repeated}{one-way repeated measures ANOVA lesson}. \hypertarget{a-brief-commentary-on-wrappers}{% -\subsection*{A Brief Commentary on Wrappers}\label{a-brief-commentary-on-wrappers}} - +\subsection{A Brief Commentary on Wrappers}\label{a-brief-commentary-on-wrappers}} As noted several times, because of its relative ease-of-use, the relevance of information included in the results, and its integration with the \emph{ggpubr} package, I chose to use \emph{rstatix} package in all of the ANOVA lessons. As I worked through this example, I spent several hours creating and interpreting the code. For me, there was value in this exercise: @@ -23103,6 +23079,10 @@ \subsection*{A Brief Commentary on Wrappers}\label{a-brief-commentary-on-wrapper I am deeply grateful to package developers who take the time to create packages for discipline-specific use-cases and then freely share their work with others. Thank you \href{https://github.com/kassambara/rstatix}{Alboukadel Kassambara}! \end{itemize} +\hypertarget{refs}{% +\chapter*{References}\label{refs}} + + \bibliography{STATSnMETH.bib} \end{document} diff --git a/docs/ReCintro.html b/docs/ReCintro.html index fe508e9e..deb3155e 100644 --- a/docs/ReCintro.html +++ b/docs/ReCintro.html @@ -648,42 +648,42 @@
  • 11.8.1 Working the Problem with R and R Packages
  • -
  • References
  • APPENDICES
  • -
  • Type I Error +
  • 12 Type I Error
  • -
  • Examples for Follow-up to Factorial ANOVA +
  • 13 Examples for Follow-up to Factorial ANOVA
  • -
  • One-Way Repeated Measures with a Multivariate Approach +
  • 14 One-Way Repeated Measures with a Multivariate Approach
  • +
  • References
  • Published with bookdown
  • diff --git a/docs/Ready.html b/docs/Ready.html index b1c5939e..f69de504 100644 --- a/docs/Ready.html +++ b/docs/Ready.html @@ -648,42 +648,42 @@
  • 11.8.1 Working the Problem with R and R Packages
  • -
  • References
  • APPENDICES
  • -
  • Type I Error +
  • 12 Type I Error
  • -
  • Examples for Follow-up to Factorial ANOVA +
  • 13 Examples for Follow-up to Factorial ANOVA
  • -
  • One-Way Repeated Measures with a Multivariate Approach +
  • 14 One-Way Repeated Measures with a Multivariate Approach
  • +
  • References
  • Published with bookdown
  • @@ -1102,7 +1102,7 @@

    Run the describe() function from the psych package with your simulated data

    -

    References

    +

    References

    Gladwell, M. (2008). Outliers: The story of success (First edition.). Little, Brown; Company. diff --git a/docs/Repeated.html b/docs/Repeated.html index ed49a583..25eabb80 100644 --- a/docs/Repeated.html +++ b/docs/Repeated.html @@ -648,42 +648,42 @@
  • 11.8.1 Working the Problem with R and R Packages
  • -
  • References
  • APPENDICES
  • -
  • Type I Error +
  • 12 Type I Error
  • -
  • Examples for Follow-up to Factorial ANOVA +
  • 13 Examples for Follow-up to Factorial ANOVA
  • -
  • One-Way Repeated Measures with a Multivariate Approach +
  • 14 One-Way Repeated Measures with a Multivariate Approach
  • +
  • References
  • Published with bookdown
  • @@ -2223,7 +2223,7 @@

    Assemble the results into a statistical string

    Amodeo, A. L., Picariello, S., Valerio, P., & Scandurra, C. (2018). Empowering transgender youths: Promoting resilience through a group training program. Journal of Gay & Lesbian Mental Health, 22(1), 3–19. https://alliance-primo.hosted.exlibrisgroup.com diff --git a/docs/acknowledgements.html b/docs/acknowledgements.html index d0d15ad8..174f96b0 100644 --- a/docs/acknowledgements.html +++ b/docs/acknowledgements.html @@ -648,42 +648,42 @@
  • 11.8.1 Working the Problem with R and R Packages
  • -
  • References
  • APPENDICES
  • -
  • Type I Error +
  • 12 Type I Error
  • -
  • Examples for Follow-up to Factorial ANOVA +
  • 13 Examples for Follow-up to Factorial ANOVA
  • -
  • One-Way Repeated Measures with a Multivariate Approach +
  • 14 One-Way Repeated Measures with a Multivariate Approach
  • +
  • References
  • Published with bookdown
  • @@ -718,7 +718,7 @@

    ACKNOWLEDGEMENTS

    Byrne, B. M. (2016). Structural Equation Modeling with AMOS: Basic Concepts, Applications, and Programming, Third Edition. Taylor & Francis Group. http://ebookcentral.proquest.com/lib/spu/detail.action?docID=4556523 diff --git a/docs/analysis-of-variance.html b/docs/analysis-of-variance.html index 623e52da..a0d009c7 100644 --- a/docs/analysis-of-variance.html +++ b/docs/analysis-of-variance.html @@ -648,42 +648,42 @@
  • 11.8.1 Working the Problem with R and R Packages
  • -
  • References
  • APPENDICES
  • -
  • Type I Error +
  • 12 Type I Error
  • -
  • Examples for Follow-up to Factorial ANOVA +
  • 13 Examples for Follow-up to Factorial ANOVA
  • -
  • One-Way Repeated Measures with a Multivariate Approach +
  • 14 One-Way Repeated Measures with a Multivariate Approach
  • +
  • References
  • Published with bookdown
  • diff --git a/docs/appendices.html b/docs/appendices.html index bb026fbd..38ed02ed 100644 --- a/docs/appendices.html +++ b/docs/appendices.html @@ -29,7 +29,7 @@ - + @@ -648,42 +648,42 @@
  • 11.8.1 Working the Problem with R and R Packages
  • -
  • References
  • APPENDICES
  • -
  • Type I Error +
  • 12 Type I Error
  • -
  • Examples for Follow-up to Factorial ANOVA +
  • 13 Examples for Follow-up to Factorial ANOVA
  • -
  • One-Way Repeated Measures with a Multivariate Approach +
  • 14 One-Way Repeated Measures with a Multivariate Approach
  • +
  • References
  • Published with bookdown
  • @@ -712,7 +712,7 @@

    APPENDICES

    - +
    diff --git a/docs/between.html b/docs/between.html index a1cd3bce..96ae9302 100644 --- a/docs/between.html +++ b/docs/between.html @@ -648,42 +648,42 @@
  • 11.8.1 Working the Problem with R and R Packages
  • -
  • References
  • APPENDICES
  • -
  • Type I Error +
  • 12 Type I Error
  • -
  • Examples for Follow-up to Factorial ANOVA +
  • 13 Examples for Follow-up to Factorial ANOVA
  • -
  • One-Way Repeated Measures with a Multivariate Approach +
  • 14 One-Way Repeated Measures with a Multivariate Approach
  • +
  • References
  • Published with bookdown
  • @@ -2969,7 +2969,7 @@

    Assemble the results into their statistical strings

    Field, A. P. (2012). Discovering statistics using R. Sage. diff --git a/docs/examples-for-follow-up-to-factorial-anova.html b/docs/examples-for-follow-up-to-factorial-anova.html index d780df8e..ff7d825f 100644 --- a/docs/examples-for-follow-up-to-factorial-anova.html +++ b/docs/examples-for-follow-up-to-factorial-anova.html @@ -4,20 +4,20 @@ - Examples for Follow-up to Factorial ANOVA | ReCentering Psych Stats - + Chapter 13 Examples for Follow-up to Factorial ANOVA | ReCentering Psych Stats + - + - + - + - + @@ -648,42 +648,42 @@
  • 11.8.1 Working the Problem with R and R Packages
  • -
  • References
  • APPENDICES
  • -
  • Type I Error +
  • 12 Type I Error
  • -
  • Examples for Follow-up to Factorial ANOVA +
  • 13 Examples for Follow-up to Factorial ANOVA
  • -
  • One-Way Repeated Measures with a Multivariate Approach +
  • 14 One-Way Repeated Measures with a Multivariate Approach
  • +
  • References
  • Published with bookdown
  • @@ -704,21 +704,21 @@

    -
    -

    Examples for Follow-up to Factorial ANOVA

    +
    +

    Chapter 13 Examples for Follow-up to Factorial ANOVA

    Screencasted Lecture Link

    As noted in the lesson on factorial ANOVA, the options for follow-up to a significant interaction effect are infinite. In order to maintain a streamlined chapter with minimal distractions to student learning (through numerous examples and changes in R packages), I have moved examples of some these variations to this section.

    As a quick reminder, I will describe and re-simulate the data. The narration will presume familiarity with the factorial ANOVA lesson.

    -
    -

    Research Vignette

    +
    +

    13.1 Research Vignette

    The research vignette for this example was located in Kalimantan, Indonesia and focused on bias in young people from three ethnic groups. The Madurese and Dayaknese groups were engaged in ethnic conflict that spanned 1996 to 2001. The last incidence of mass violence was in 2001 where approximately 500 people (mostly from the Madurese ethnic group) were expelled from the province. Ramdhani et al.’s (2018) research hypotheses were based on the roles of the three ethnic groups in the study. The Madurese appear to be viewed as the transgressors when they occupied lands and took employment and business opportunities from the Dayaknese. Ramdhani et al. also included a third group who were not involved in the conflict (Javanese). The research participants were students studying in Yogyakara who were not involved in the conflict. They included 39 Madurese, 35 Dyaknese, and 37 Javanese; 83 were male and 28 were female.

    In the study (Ramdhani et al., 2018), participants viewed facial pictures of three men and three women (in traditional dress) from each ethnic group (6 photos per ethnic group). Participant were asked, “How do you feel when you see this photo? Please indicate your answers based on your actual feelings.” Participants responded on a 7-point Likert scale ranging from 1 (strongly disagree) to 7 (strongly agree). Higher scores indicated ratings of higher intensity on that scale. The two scales included the following words:

    • Positive: friendly, kind, helpful, happy
    • Negative: disgusting, suspicious, hateful, angry
    -
    -

    Quick Resimulating of the Data

    +
    +

    13.1.1 Quick Resimulating of the Data

    Below is script to simulate data for the negative reactions variable from the information available from the manuscript (Ramdhani et al., 2018). If you would like more information about the details of this simulation, please visit the lesson on factorial ANOVA.

    library(tidyverse)
     set.seed(210731)
    @@ -757,8 +757,8 @@ 

    Quick Resimulating of the Data# readRDS('Ramdhani_RDS.rds') str(Ramdhani_RDS)

    -
    -

    Analysis of Simple Main Effects with Orthogonal Contrasts

    +
    +

    13.2 Analysis of Simple Main Effects with Orthogonal Contrasts

    This example follows a significant interaction effect. Specifically, we will analyze the effects of ethnicity of rater (three levels) within photo stimulus (two levels). We will conduct two one-way ANOVAs for the Dayaknese and Madurese photos, separately. In this example, we will utilize orthogonal contrast-coding for rater ethnicity.

    In the lesson on factorial ANOVA I used the rstatix package. I am not aware of a way to do this type of analysis in rstatix, therefore this worked example will use functions from base R.

    This is our place on the ANOVA workflow.

    @@ -880,8 +880,8 @@

    Analysis of Simple Main Effects with Orthogonal Contrasts ylim = c(1, 7))

    -
    -

    Analysis of Simple Main Effects with a Polynomial Trend

    +
    +

    13.3 Analysis of Simple Main Effects with a Polynomial Trend

    In the context of the significant interaction effect, we might be interested in polynomial trends for any simple main effects where three or more cells are compared.

    Why? If there are only two cells being compared, then the significance of that has already been tested and if significant, it is also a significant linear effect (because the shape between any two points is a line).

    Here is where we are in the workflow:

    @@ -956,8 +956,8 @@

    Analysis of Simple Main Effects with a Polynomial Trend ylim = c(1, 7))

    -
    -

    All Possible Post Hoc Comparisons

    +
    +

    13.4 All Possible Post Hoc Comparisons

    Another option is the comparison possible cells. These are termed post hoc comparisons. They are an alternative to simple main effects; you would not report both. A potential criticism of this approach is that it is atheoretical. Without compelling justification, reviewers may criticize this approach as “fishing,” “p-hacking,” or “HARKing” (hypothesizing after results are known). None-the-less, particularly when our results are not as expected, I do think having these tools available can be a helpful resource.

    The figure shows our place on the Two-Way ANOVA Workflow.

    @@ -1085,7 +1085,7 @@

    All Possible Post Hoc Comparisons

    Green, S. B., & Salkind, N. J. (2017c). Using SPSS for Windows and Macintosh: Analyzing and understanding data (Eighth edition.). Pearson. diff --git a/docs/index.html b/docs/index.html index a93caec3..04c0a43c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -648,42 +648,42 @@
  • 11.8.1 Working the Problem with R and R Packages
  • -
  • References
  • APPENDICES
  • -
  • Type I Error +
  • 12 Type I Error
  • -
  • Examples for Follow-up to Factorial ANOVA +
  • 13 Examples for Follow-up to Factorial ANOVA
  • -
  • One-Way Repeated Measures with a Multivariate Approach +
  • 14 One-Way Repeated Measures with a Multivariate Approach
  • +
  • References
  • Published with bookdown
  • @@ -707,7 +707,7 @@

    BOOK COVER

    diff --git a/docs/index.md b/docs/index.md index a1d17f89..3686a6f0 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,7 +1,7 @@ --- title: "ReCentering Psych Stats" author: "Lynette H. Bikos, PhD, ABPP (she/her)" -date: "Last updated 23 Aug 2023" +date: "Last updated 24 Aug 2023" documentclass: book site: bookdown::bookdown_site bibliography: STATSnMETH.bib #This is my own bibtex file from my Zotero account. If this file is not in the project folder there will be an error and the book will not build. @@ -46,7 +46,7 @@ ISBN-13: 979-8-9868768-2-5 (Ebook - online); ISBN-13: 979-8-9868768-3-2 (Ebook # PREFACE {-} -**If you are viewing this document, you should know that this is a book-in-progress. Early drafts are released for the purpose teaching my classes and gaining formative feedback from a host of stakeholders. The document was last updated on 23 Aug 2023**. Emerging volumes on other statistics are posted on the [ReCentering Psych Stats](https://lhbikos.github.io/BikosRVT/ReCenter.html) page at my research team's website. +**If you are viewing this document, you should know that this is a book-in-progress. Early drafts are released for the purpose teaching my classes and gaining formative feedback from a host of stakeholders. The document was last updated on 24 Aug 2023**. Emerging volumes on other statistics are posted on the [ReCentering Psych Stats](https://lhbikos.github.io/BikosRVT/ReCenter.html) page at my research team's website. [Screencasted Lecture Link](https://youtu.be/yy0z85Wla7o) diff --git a/docs/one-way-repeated-measures-with-a-multivariate-approach.html b/docs/one-way-repeated-measures-with-a-multivariate-approach.html index 63481ad0..189b6aa0 100644 --- a/docs/one-way-repeated-measures-with-a-multivariate-approach.html +++ b/docs/one-way-repeated-measures-with-a-multivariate-approach.html @@ -4,20 +4,20 @@ - One-Way Repeated Measures with a Multivariate Approach | ReCentering Psych Stats - + Chapter 14 One-Way Repeated Measures with a Multivariate Approach | ReCentering Psych Stats + - + - + - + - + @@ -30,7 +30,7 @@ - + @@ -648,42 +648,42 @@
  • 11.8.1 Working the Problem with R and R Packages
  • -
  • References
  • APPENDICES
  • -
  • Type I Error +
  • 12 Type I Error
  • -
  • Examples for Follow-up to Factorial ANOVA +
  • 13 Examples for Follow-up to Factorial ANOVA
  • -
  • One-Way Repeated Measures with a Multivariate Approach +
  • 14 One-Way Repeated Measures with a Multivariate Approach
  • +
  • References
  • Published with bookdown
  • @@ -704,13 +704,13 @@

    -
    -

    One-Way Repeated Measures with a Multivariate Approach

    +
    +

    Chapter 14 One-Way Repeated Measures with a Multivariate Approach

    Screencasted Lecture Link

    As noted in the lesson on one-way repeated measures ANOVA, the researcher can use a univariate or multivariate approach to analyzing the data. The rstatix::anova_test() is limited to the univariate approach. In order to maintain a streamlined chapter with minimal distractions to student learning I have chosen to provide a quick and separate demonstration of the multivariate approach in this appendix. In-so-doing, I will use the car package.

    As a quick reminder, I will describe and resimulate the data. The narration will presume familiarity with the one-way repeated measures ANOVA lesson.

    -
    -

    Research Vignette

    +
    +

    14.1 Research Vignette

    Amodeo (Amodeo et al., 2018) and colleagues conducted a mixed methods study (qualitative and quantitative) to evaluate the effectiveness of an empowerment, peer-group-based, intervention with participants (N = 8) who experienced transphobic episodes. Focus groups used qualitative methods to summarize emergent themes from the program (identity affirmation, self-acceptance, group as support) and a one-way, repeated measures ANOVA provided evidence of increased resilience from pre to three-month followup.

    Eight participants (seven transgender women and one genderqueer person) participated in the intervention. The mean age was 28.5 (SD = 5.85). All participants were located in Italy.

    The within-subjects condition was wave, represented by T1, T2, and T3:

    @@ -725,8 +725,8 @@

    Research Vignette(Wagnild & Young, 1993). Items were assessed on a 7-point scale ranging from strongly disagree to strongly agree with higher scores indicating higher levels of resilience. An example items was, “I usually manage one way or another.”

    -
    -

    Data Simulation

    +
    +

    14.1.1 Data Simulation

    Below is the code I used to simulate data. The following code assumes 8 participants who each participated in 3 waves (pre, post, followup). The sript produces “long” and “wide” forms are created.

    set.seed(2022)
     # gives me 8 numbers, assigning each number 3 consecutive spots, in
    @@ -756,8 +756,8 @@ 

    Data Simulation
    Amodeo_wide$ID <- factor(Amodeo_wide$ID)

    -
    -

    Computing the Omnibus F

    +
    +

    14.2 Computing the Omnibus F

    Without the rstatix helper package, here is how the analysis would be run in the package, car. Although this package is less intuitive to use, it results in both univariate output (both sphericity assumed and sphericity violated) and multivariate output (which does not require the sphericity assumption).

    Evaluating the data requires that we create some objects that will be fed into function. We can name these objects anything we like.

    In ths script below I define the objects that are required.

    @@ -864,8 +864,8 @@

    Computing the Omnibus Fone-way repeated measures ANOVA lesson.

    -
    -

    Univariate Results

    +
    +

    14.2.1 Univariate Results

    When we ran the univariate approach in the lesson, we first checked the sphericity assumption. Our results here are identical to those from rstatix::anova_test. That is, we did not violate the sphericity assumption: Mauchley’s test \(= .566 p = 0.182\). The F test with univariate results was \(F(2, 14) = 3.910, p = 0.045\).

    The Greenhouse Geiser estimate was 0.698 the corrected p = .068. @@ -873,8 +873,8 @@

    Univariate Results\(F(2,14) = 3.91, p = 0.045\). I do not see that an effect size is reported.

    -
    -

    Multivariate Results

    +
    +

    14.2.2 Multivariate Results

    Researchers may prefer the multivariate approach because it does not require the sphericity assumption. Stated another way, if the sphericity assumption is violated, researchers can report the results of the multivariate analysis.

    We find the multivariate results in the middle of the output, under the heading, “Multivariate Tests: waveFactor.” There are four choices: Pillai, Wilks, Hotelling-Lawley, and Roy. Green and Salkind (2017b) have noted that in the one-way within-subjects ANOVA, all four will yield the same F and p values. They recommended reporting Wilks’ lambda because researchers will have greatest familiarity with it. Thus, I would write up the result of this omnibus test like this:

    @@ -882,126 +882,18 @@

    Multivariate Resultsone-way repeated measures ANOVA lesson.

    -
    -

    A Brief Commentary on Wrappers

    +
    +

    14.2.3 A Brief Commentary on Wrappers

    As noted several times, because of its relative ease-of-use, the relevance of information included in the results, and its integration with the ggpubr package, I chose to use rstatix package in all of the ANOVA lessons. As I worked through this example, I spent several hours creating and interpreting the code. For me, there was value in this exercise:

    • I am encouraged and reassured with the consistency of results between the two approaches,
    • I am in awe of the power of these programs and a little intimidated by all the options that are available within a given package, and
    • I am deeply grateful to package developers who take the time to create packages for discipline-specific use-cases and then freely share their work with others. Thank you Alboukadel Kassambara!
    - -
    -
    -Amodeo, A. L., Picariello, S., Valerio, P., & Scandurra, C. (2018). Empowering transgender youths: Promoting resilience through a group training program. Journal of Gay & Lesbian Mental Health, 22(1), 3–19. https://alliance-primo.hosted.exlibrisgroup.com -
    -
    -Bernerth, J. B., & Aguinis, H. (2016). A critical review and best‐practice recommendations for control variable usage. Personnel Psychology, 69(1), 229–283. https://doi.org/10.1111/peps.12103 -
    -
    -Butler, R., Monsalve, M., Thomas, G. W., Herman, T., Segre, A. M., Polgreen, P. M., & Suneja, M. (2018). Estimating Time Physicians and Other Health Care Workers Spend with Patients in an Intensive Care Unit Using a Sensor Network. The American Journal of Medicine, 131(8), 972.e9–972.e15. https://doi.org/10.1016/j.amjmed.2018.03.015 -
    -
    -Byrne, B. M. (2016). Structural Equation Modeling with AMOS: Basic Concepts, Applications, and Programming, Third Edition. Taylor & Francis Group. http://ebookcentral.proquest.com/lib/spu/detail.action?docID=4556523 -
    -
    -Chen, T., Xu, M., Tu, J., Wang, H., & Niu, X. (2018). Relationship between Omnibus and Post-hoc Tests: An Investigation of performance of the F test in ANOVA. Shanghai Archives of Psychiatry, 30(1), 60–64. https://doi.org/10.11919/j.issn.1002-0829.218014 -
    -
    -Cohen, J., Cohen, P., West, S. G., & Aiken, L. S. (2003). Applied multiple regression/correlation analysis for the behavioral sciences (3rd ed.). LErlbaum Associates. -
    -
    -Crump, M. J. C. (2018). Simulating and analyzing data in R (Chapter 5). In Programming for Psychologists: Data Creation and Analysis. https://crumplab.github.io/programmingforpsych/index.html -
    -
    -Datanovia. (n.d.). ANCOVA in R: The Ultimate Practical Guide. In Datanovia. Retrieved November 3, 2020, from https://www.datanovia.com/en/lessons/ancova-in-r/ -
    -
    -Elliott, A. M., Alexander, S. C., Mescher, C. A., Mohan, D., & Barnato, A. E. (2016). Differences in PhysiciansVerbal and Nonverbal Communication With Black and White Patients at the End of Life. Journal of Pain and Symptom Management, 51(1), 1–8. https://doi.org/10.1016/j.jpainsymman.2015.07.008 -
    -
    -Field, A. P. (2012). Discovering statistics using R. Sage. -
    -
    -Gladwell, M. (2008). Outliers: The story of success (First edition.). Little, Brown; Company. -
    -
    -Green, S. B., & Salkind, N. J. (2017a). One-Way Analysis of Covariance (Lesson 27). In Using SPSS for Windows and Macintosh: Analyzing and understanding data (Eighth edition., pp. 151–160). Pearson. -
    -
    -Green, S. B., & Salkind, N. J. (2017b). One-Way Repeated Measures Analysis of Variance (Lesson 29). In Using SPSS for Windows and Macintosh: Analyzing and understanding data (Eighth edition., pp. 209–217). Pearson. -
    -
    -Green, S. B., & Salkind, N. J. (2017c). Using SPSS for Windows and Macintosh: Analyzing and understanding data (Eighth edition.). Pearson. -
    -
    -Jhangiani, R. S., Chiang, I.-C. A., Cuttler, C., & Leighton, D. C. (2019). Research Methods in Psychology. https://doi.org/10.17605/OSF.IO/HF7DQ -
    -
    -Joanes, D. N., & Gill, C. A. (1998). Comparing Measures of Sample Skewness and Kurtosis. Journal of the Royal Statistical Society. Series D (The Statistician), 47(1), 183–189. https://www.jstor.org/stable/2988433 -
    -
    -Kabacoff, R. I. (2017). Power Analysis. In Quick-R by datacamp. https://www.statmethods.net/stats/power.html
    -
    -Kassambara, A. (n.d.-a). ANOVA in R: The Ultimate Guide. In Datanovia. Retrieved December 28, 2022, from https://www.datanovia.com/en/lessons/anova-in-r/
    -
    -Kassambara, A. (n.d.-b). Pipe-Friendly Framework for Basic Statistical Tests. Retrieved December 22, 2022, from https://rpkgs.datanovia.com/rstatix/
    -
    -Kline, R. B. (2016a). Data Preparation and Psychometrics Review (Chapter 4). In Principles and practice of structural equation modeling (4th ed., pp. 64–96). Guilford Publications. http://ebookcentral.proquest.com/lib/spu/detail.action?docID=4000663 -
    -
    -Kline, R. B. (2016b). Principles and practice of structural equation modeling (4th ed.). Guilford Publications. http://ebookcentral.proquest.com/lib/spu/detail.action?docID=4000663 -
    -
    -Lakens, D. (2013). Calculating and reporting effect sizes to facilitate cumulative science: A practical primer for t-tests and ANOVAs. Frontiers in Psychology, 4. https://doi.org/10.3389/fpsyg.2013.00863 -
    -
    -Lui, P. P. (2020). Racial Microaggression, Overt Discrimination, and Distress: (In)Direct Associations With Psychological Adjustment. The Counseling Psychologist, 32. -
    -
    -Mallinckrodt, B., Miles, J. R., & Levy, J. J. (2014). The scientist-practitioner-advocate model: Addressing contemporary training needs for social justice advocacy. Training and Education in Professional Psychology, 8(4), 303–311. https://doi.org/10.1037/tep0000045 -
    -
    -Murrar, S., & Brauer, M. (2018). Entertainment-education effectively reduces prejudice. Group Processes & Intergroup Relations, 21(7), 1053–1077. https://doi.org/10.1177/1368430216682350 -
    -
    -Navarro, D. (2020a). Book: Learning Statistics with R - A tutorial for Psychology Students and other Beginners. Open Education Resource (OER) LibreTexts Project. https://stats.libretexts.org/Bookshelves/Applied_Statistics/Book%3A_Learning_Statistics_with_R_-_A_tutorial_for_Psychology_Students_and_other_Beginners_(Navarro) -
    -
    -Navarro, D. (2020b). Chapter 14: Comparing Several Means (One-Way ANOVA). In Book: Learning Statistics with R - A tutorial for Psychology Students and other Beginners. Open Education Resource (OER) LibreTexts Project. https://stats.libretexts.org/Bookshelves/Applied_Statistics/Book%3A_Learning_Statistics_with_R_-_A_tutorial_for_Psychology_Students_and_other_Beginners_(Navarro) -
    -
    -Ramdhani, N., Thontowi, H. B., & Ancok, D. (2018). Affective Reactions Among Students Belonging to Ethnic Groups Engaged in Prior Conflict. Journal of Pacific Rim Psychology, 12, e2. https://doi.org/10.1017/prp.2017.22 -
    -
    -Revelle, W. (2021). An introduction to the psych package: Part I: Data entry and data description. 60. https://rdrr.io/cran/psych/f/inst/doc/intro.pdf -
    -
    -Rodgers, J. L. (2010). The epistemology of mathematical and statistical modeling: A quiet methodological revolution. American Psychologist, 65(1), 1–12. https://doi.org/10.1037/a0018326 -
    -
    -Stanley, D. J., & Spence, J. R. (2018). Reproducible Tables in Psychology Using the apaTables Package. Advances in Methods and Practices in Psychological Science, 1(3), 415–431. https://doi.org/10.1177/2515245918773743 -
    -
    -Tran, A. G. T. T., & Lee, R. M. (2014). You speak English well! Asian Americans’ reactions to an exceptionalizing stereotype. Journal of Counseling Psychology, 61(3), 484–490. https://doi.org/10.1037/cou0000034 -
    -
    -Wagnild, G. M., & Young, H. M. (1993). Development and psychometric evaluation of the Resilience Scale. Journal of Nursing Measurement, 1(2), 165–178. https://ezproxy.spu.edu/login?url=http://search.ebscohost.com/login.aspx?direct=true&AuthType=ip&db=psyh&AN=1996-05738-006&site=ehost-live -
    -
    -Watson, P. (2020). Rules of thumb on magnitudes of effect sizes. In MRC Cognition and Brain Sciences Unit, University of Cambridge. https://imaging.mrc-cbu.cam.ac.uk/statswiki/FAQ/effectSize -
    -
    -Zach. (2019). How to Read the F-Distribution Table. In Statology. https://www.statology.org/how-to-read-the-f-distribution-table/ -
    -
    -
    -
    -
    -

    References

    +

    References

    Amodeo, A. L., Picariello, S., Valerio, P., & Scandurra, C. (2018). Empowering transgender youths: Promoting resilience through a group training program. Journal of Gay & Lesbian Mental Health, 22(1), 3–19. https://alliance-primo.hosted.exlibrisgroup.com @@ -1018,8 +910,8 @@

    References

    - - + +

    diff --git a/docs/oneway.html b/docs/oneway.html index 3512aaca..c4b95645 100644 --- a/docs/oneway.html +++ b/docs/oneway.html @@ -648,42 +648,42 @@
  • 11.8.1 Working the Problem with R and R Packages
  • -
  • References
  • APPENDICES
  • -
  • Type I Error +
  • 12 Type I Error
  • -
  • Examples for Follow-up to Factorial ANOVA +
  • 13 Examples for Follow-up to Factorial ANOVA
  • -
  • One-Way Repeated Measures with a Multivariate Approach +
  • 14 One-Way Repeated Measures with a Multivariate Approach
  • +
  • References
  • Published with bookdown
  • @@ -2532,7 +2532,7 @@

    Assemble the results into a statistical string

    Chen, T., Xu, M., Tu, J., Wang, H., & Niu, X. (2018). Relationship between Omnibus and Post-hoc Tests: An Investigation of performance of the F test in ANOVA. Shanghai Archives of Psychiatry, 30(1), 60–64. https://doi.org/10.11919/j.issn.1002-0829.218014 diff --git a/docs/preface.html b/docs/preface.html index 60d5ba53..093e5485 100644 --- a/docs/preface.html +++ b/docs/preface.html @@ -648,42 +648,42 @@
  • 11.8.1 Working the Problem with R and R Packages
  • -
  • References
  • APPENDICES
  • -
  • Type I Error +
  • 12 Type I Error
  • -
  • Examples for Follow-up to Factorial ANOVA +
  • 13 Examples for Follow-up to Factorial ANOVA
  • -
  • One-Way Repeated Measures with a Multivariate Approach +
  • 14 One-Way Repeated Measures with a Multivariate Approach
  • +
  • References
  • Published with bookdown
  • @@ -706,7 +706,7 @@

    PREFACE

    -

    If you are viewing this document, you should know that this is a book-in-progress. Early drafts are released for the purpose teaching my classes and gaining formative feedback from a host of stakeholders. The document was last updated on 23 Aug 2023. Emerging volumes on other statistics are posted on the ReCentering Psych Stats page at my research team’s website.

    +

    If you are viewing this document, you should know that this is a book-in-progress. Early drafts are released for the purpose teaching my classes and gaining formative feedback from a host of stakeholders. The document was last updated on 24 Aug 2023. Emerging volumes on other statistics are posted on the ReCentering Psych Stats page at my research team’s website.

    Screencasted Lecture Link

    To center a variable in regression means to set its value at zero and interpret all other values in relation to this reference point. Regarding race and gender, researchers often center male and White at zero. Further, it is typical that research vignettes in statistics textbooks are similarly seated in a White, Western (frequently U.S.), heteronormative, framework. The purpose of this project is to create a set of open educational resources (OER) appropriate for doctoral and post-doctoral training that contribute to a socially responsive pedagogy – that is, it contributes to justice, equity, diversity, and inclusion.

    Statistics training in doctoral programs are frequently taught with fee-for-use programs (e.g., SPSS/AMOS, SAS, MPlus) that may not be readily available to the post-doctoral professional. In recent years, there has been an increase and improvement in R packages (e.g., psych, lavaan) used for analyses common to psychological research. Correspondingly, many graduate programs are transitioning to statistics training in R (free and open source). This is a challenge for post-doctoral psychologists who were trained with other software. This OER will offer statistics training with R and be freely available (specifically in a GitHub repository and posted through GitHub Pages) under a Creative Commons Attribution - Non Commercial - Share Alike license [CC BY-NC-SA 4.0].

    @@ -729,7 +729,7 @@

    Copyright with Open AccessA GitHub open-source repository contains all of the text and source code for the book, including data and images.

    -

    References

    +

    References

    Field, A. P. (2012). Discovering statistics using R. Sage. diff --git a/docs/preliminaries.html b/docs/preliminaries.html index b8a6ce9f..d5953ea5 100644 --- a/docs/preliminaries.html +++ b/docs/preliminaries.html @@ -648,42 +648,42 @@
  • 11.8.1 Working the Problem with R and R Packages
  • -
  • References
  • APPENDICES
  • -
  • Type I Error +
  • 12 Type I Error
  • -
  • Examples for Follow-up to Factorial ANOVA +
  • 13 Examples for Follow-up to Factorial ANOVA
  • -
  • One-Way Repeated Measures with a Multivariate Approach +
  • 14 One-Way Repeated Measures with a Multivariate Approach
  • +
  • References
  • Published with bookdown
  • @@ -2107,7 +2107,7 @@

    Calculate value of correlation coefficient

    Cohen, J., Cohen, P., West, S. G., & Aiken, L. S. (2003). Applied multiple regression/correlation analysis for the behavioral sciences (3rd ed.). LErlbaum Associates. diff --git a/docs/reference-keys.txt b/docs/reference-keys.txt index 86cb2aba..c4bb61aa 100644 --- a/docs/reference-keys.txt +++ b/docs/reference-keys.txt @@ -397,3 +397,23 @@ problem-3-try-something-entirely-new.-3 grading-rubric-7 homeworked-example-9 working-the-problem-with-r-and-r-packages-8 +type-i-error +type-i-error-defined +methods-for-managing-type-i-error +lsd-least-significant-difference-method +traditional-bonferroni +tukey-hsd +holms-sequential-bonferroni +examples-for-follow-up-to-factorial-anova +research-vignette-9 +quick-resimulating-of-the-data +analysis-of-simple-main-effects-with-orthogonal-contrasts +analysis-of-simple-main-effects-with-a-polynomial-trend +all-possible-post-hoc-comparisons +one-way-repeated-measures-with-a-multivariate-approach +research-vignette-10 +data-simulation-7 +computing-the-omnibus-f +univariate-results +multivariate-results +a-brief-commentary-on-wrappers diff --git a/docs/refs.html b/docs/refs.html index c80bf1f7..a7f8ec6a 100644 --- a/docs/refs.html +++ b/docs/refs.html @@ -29,8 +29,8 @@ - - + + @@ -648,42 +648,42 @@
  • 11.8.1 Working the Problem with R and R Packages
  • -
  • References
  • APPENDICES
  • -
  • Type I Error +
  • 12 Type I Error
  • -
  • Examples for Follow-up to Factorial ANOVA +
  • 13 Examples for Follow-up to Factorial ANOVA
  • -
  • One-Way Repeated Measures with a Multivariate Approach +
  • 14 One-Way Repeated Measures with a Multivariate Approach
  • +
  • References
  • Published with bookdown
  • @@ -707,14 +707,121 @@

    References

    +
    +
    +Amodeo, A. L., Picariello, S., Valerio, P., & Scandurra, C. (2018). Empowering transgender youths: Promoting resilience through a group training program. Journal of Gay & Lesbian Mental Health, 22(1), 3–19. https://alliance-primo.hosted.exlibrisgroup.com +
    +
    +Bernerth, J. B., & Aguinis, H. (2016). A critical review and best‐practice recommendations for control variable usage. Personnel Psychology, 69(1), 229–283. https://doi.org/10.1111/peps.12103 +
    +
    +Butler, R., Monsalve, M., Thomas, G. W., Herman, T., Segre, A. M., Polgreen, P. M., & Suneja, M. (2018). Estimating Time Physicians and Other Health Care Workers Spend with Patients in an Intensive Care Unit Using a Sensor Network. The American Journal of Medicine, 131(8), 972.e9–972.e15. https://doi.org/10.1016/j.amjmed.2018.03.015 +
    +
    +Byrne, B. M. (2016). Structural Equation Modeling with AMOS: Basic Concepts, Applications, and Programming, Third Edition. Taylor & Francis Group. http://ebookcentral.proquest.com/lib/spu/detail.action?docID=4556523 +
    +
    +Chen, T., Xu, M., Tu, J., Wang, H., & Niu, X. (2018). Relationship between Omnibus and Post-hoc Tests: An Investigation of performance of the F test in ANOVA. Shanghai Archives of Psychiatry, 30(1), 60–64. https://doi.org/10.11919/j.issn.1002-0829.218014 +
    +
    +Cohen, J., Cohen, P., West, S. G., & Aiken, L. S. (2003). Applied multiple regression/correlation analysis for the behavioral sciences (3rd ed.). LErlbaum Associates. +
    +
    +Crump, M. J. C. (2018). Simulating and analyzing data in R (Chapter 5). In Programming for Psychologists: Data Creation and Analysis. https://crumplab.github.io/programmingforpsych/index.html +
    +
    +Datanovia. (n.d.). ANCOVA in R: The Ultimate Practical Guide. In Datanovia. Retrieved November 3, 2020, from https://www.datanovia.com/en/lessons/ancova-in-r/ +
    +
    +Elliott, A. M., Alexander, S. C., Mescher, C. A., Mohan, D., & Barnato, A. E. (2016). Differences in PhysiciansVerbal and Nonverbal Communication With Black and White Patients at the End of Life. Journal of Pain and Symptom Management, 51(1), 1–8. https://doi.org/10.1016/j.jpainsymman.2015.07.008 +
    +
    +Field, A. P. (2012). Discovering statistics using R. Sage. +
    +
    +Gladwell, M. (2008). Outliers: The story of success (First edition.). Little, Brown; Company. +
    +
    +Green, S. B., & Salkind, N. J. (2017a). One-Way Analysis of Covariance (Lesson 27). In Using SPSS for Windows and Macintosh: Analyzing and understanding data (Eighth edition., pp. 151–160). Pearson. +
    +
    +Green, S. B., & Salkind, N. J. (2017b). One-Way Repeated Measures Analysis of Variance (Lesson 29). In Using SPSS for Windows and Macintosh: Analyzing and understanding data (Eighth edition., pp. 209–217). Pearson. +
    +
    +Green, S. B., & Salkind, N. J. (2017c). Using SPSS for Windows and Macintosh: Analyzing and understanding data (Eighth edition.). Pearson. +
    +
    +Jhangiani, R. S., Chiang, I.-C. A., Cuttler, C., & Leighton, D. C. (2019). Research Methods in Psychology. https://doi.org/10.17605/OSF.IO/HF7DQ +
    +
    +Joanes, D. N., & Gill, C. A. (1998). Comparing Measures of Sample Skewness and Kurtosis. Journal of the Royal Statistical Society. Series D (The Statistician), 47(1), 183–189. https://www.jstor.org/stable/2988433 +
    +
    +Kabacoff, R. I. (2017). Power Analysis. In Quick-R by datacamp. https://www.statmethods.net/stats/power.html +
    +
    +Kassambara, A. (n.d.-a). ANOVA in R: The Ultimate Guide. In Datanovia. Retrieved December 28, 2022, from https://www.datanovia.com/en/lessons/anova-in-r/ +
    +
    +Kassambara, A. (n.d.-b). Pipe-Friendly Framework for Basic Statistical Tests. Retrieved December 22, 2022, from https://rpkgs.datanovia.com/rstatix/ +
    +
    +Kline, R. B. (2016a). Data Preparation and Psychometrics Review (Chapter 4). In Principles and practice of structural equation modeling (4th ed., pp. 64–96). Guilford Publications. http://ebookcentral.proquest.com/lib/spu/detail.action?docID=4000663 +
    +
    +Kline, R. B. (2016b). Principles and practice of structural equation modeling (4th ed.). Guilford Publications. http://ebookcentral.proquest.com/lib/spu/detail.action?docID=4000663 +
    +
    +Lakens, D. (2013). Calculating and reporting effect sizes to facilitate cumulative science: A practical primer for t-tests and ANOVAs. Frontiers in Psychology, 4. https://doi.org/10.3389/fpsyg.2013.00863 +
    +
    +Lui, P. P. (2020). Racial Microaggression, Overt Discrimination, and Distress: (In)Direct Associations With Psychological Adjustment. The Counseling Psychologist, 32. +
    +
    +Mallinckrodt, B., Miles, J. R., & Levy, J. J. (2014). The scientist-practitioner-advocate model: Addressing contemporary training needs for social justice advocacy. Training and Education in Professional Psychology, 8(4), 303–311. https://doi.org/10.1037/tep0000045 +
    +
    +Murrar, S., & Brauer, M. (2018). Entertainment-education effectively reduces prejudice. Group Processes & Intergroup Relations, 21(7), 1053–1077. https://doi.org/10.1177/1368430216682350 +
    +
    +Navarro, D. (2020a). Book: Learning Statistics with R - A tutorial for Psychology Students and other Beginners. Open Education Resource (OER) LibreTexts Project. https://stats.libretexts.org/Bookshelves/Applied_Statistics/Book%3A_Learning_Statistics_with_R_-_A_tutorial_for_Psychology_Students_and_other_Beginners_(Navarro) +
    +
    +Navarro, D. (2020b). Chapter 14: Comparing Several Means (One-Way ANOVA). In Book: Learning Statistics with R - A tutorial for Psychology Students and other Beginners. Open Education Resource (OER) LibreTexts Project. https://stats.libretexts.org/Bookshelves/Applied_Statistics/Book%3A_Learning_Statistics_with_R_-_A_tutorial_for_Psychology_Students_and_other_Beginners_(Navarro) +
    +
    +Ramdhani, N., Thontowi, H. B., & Ancok, D. (2018). Affective Reactions Among Students Belonging to Ethnic Groups Engaged in Prior Conflict. Journal of Pacific Rim Psychology, 12, e2. https://doi.org/10.1017/prp.2017.22 +
    +
    +Revelle, W. (2021). An introduction to the psych package: Part I: Data entry and data description. 60. https://rdrr.io/cran/psych/f/inst/doc/intro.pdf +
    +
    +Rodgers, J. L. (2010). The epistemology of mathematical and statistical modeling: A quiet methodological revolution. American Psychologist, 65(1), 1–12. https://doi.org/10.1037/a0018326 +
    +
    +Stanley, D. J., & Spence, J. R. (2018). Reproducible Tables in Psychology Using the apaTables Package. Advances in Methods and Practices in Psychological Science, 1(3), 415–431. https://doi.org/10.1177/2515245918773743 +
    +
    +Tran, A. G. T. T., & Lee, R. M. (2014). You speak English well! Asian Americans’ reactions to an exceptionalizing stereotype. Journal of Counseling Psychology, 61(3), 484–490. https://doi.org/10.1037/cou0000034 +
    +
    +Wagnild, G. M., & Young, H. M. (1993). Development and psychometric evaluation of the Resilience Scale. Journal of Nursing Measurement, 1(2), 165–178. https://ezproxy.spu.edu/login?url=http://search.ebscohost.com/login.aspx?direct=true&AuthType=ip&db=psyh&AN=1996-05738-006&site=ehost-live +
    +
    +Watson, P. (2020). Rules of thumb on magnitudes of effect sizes. In MRC Cognition and Brain Sciences Unit, University of Cambridge. https://imaging.mrc-cbu.cam.ac.uk/statswiki/FAQ/effectSize +
    +
    +Zach. (2019). How to Read the F-Distribution Table. In Statology. https://www.statology.org/how-to-read-the-f-distribution-table/ +
    +

    - - + +
    @@ -745,7 +852,7 @@

    References11.8.1 Working the Problem with R and R Packages -
  • References
  • APPENDICES
  • -
  • Type I Error +
  • 12 Type I Error
  • -
  • Examples for Follow-up to Factorial ANOVA +
  • 13 Examples for Follow-up to Factorial ANOVA
  • -
  • One-Way Repeated Measures with a Multivariate Approach +
  • 14 One-Way Repeated Measures with a Multivariate Approach
  • +
  • References
  • Published with bookdown
  • @@ -719,7 +719,7 @@

    t-testssuggestions for practice that vary in degree of challenge.

    -

    References

    +

    References

    Elliott, A. M., Alexander, S. C., Mescher, C. A., Mohan, D., & Barnato, A. E. (2016). Differences in PhysiciansVerbal and Nonverbal Communication With Black and White Patients at the End of Life. Journal of Pain and Symptom Management, 51(1), 1–8. https://doi.org/10.1016/j.jpainsymman.2015.07.008 diff --git a/docs/tIndSample.html b/docs/tIndSample.html index 416ef8f8..bf2f0833 100644 --- a/docs/tIndSample.html +++ b/docs/tIndSample.html @@ -648,42 +648,42 @@
  • 11.8.1 Working the Problem with R and R Packages
  • -
  • References
  • APPENDICES
  • -
  • Type I Error +
  • 12 Type I Error
  • -
  • Examples for Follow-up to Factorial ANOVA +
  • 13 Examples for Follow-up to Factorial ANOVA
  • -
  • One-Way Repeated Measures with a Multivariate Approach +
  • 14 One-Way Repeated Measures with a Multivariate Approach
  • +
  • References
  • Published with bookdown
  • @@ -1719,7 +1719,7 @@

    Assemble the results into a statistical string

    Elliott, A. M., Alexander, S. C., Mescher, C. A., Mohan, D., & Barnato, A. E. (2016). Differences in PhysiciansVerbal and Nonverbal Communication With Black and White Patients at the End of Life. Journal of Pain and Symptom Management, 51(1), 1–8. https://doi.org/10.1016/j.jpainsymman.2015.07.008 diff --git a/docs/tOneSample.html b/docs/tOneSample.html index 72c43137..a7c408b0 100644 --- a/docs/tOneSample.html +++ b/docs/tOneSample.html @@ -648,42 +648,42 @@
  • 11.8.1 Working the Problem with R and R Packages
  • -
  • References
  • APPENDICES
  • -
  • Type I Error +
  • 12 Type I Error
  • -
  • Examples for Follow-up to Factorial ANOVA +
  • 13 Examples for Follow-up to Factorial ANOVA
  • -
  • One-Way Repeated Measures with a Multivariate Approach +
  • 14 One-Way Repeated Measures with a Multivariate Approach
  • +
  • References
  • Published with bookdown
  • @@ -1698,7 +1698,7 @@

    Calculate the effect size (i.e., Cohen’s d associated with your <

    -

    References

    +

    References

    Butler, R., Monsalve, M., Thomas, G. W., Herman, T., Segre, A. M., Polgreen, P. M., & Suneja, M. (2018). Estimating Time Physicians and Other Health Care Workers Spend with Patients in an Intensive Care Unit Using a Sensor Network. The American Journal of Medicine, 131(8), 972.e9–972.e15. https://doi.org/10.1016/j.amjmed.2018.03.015 diff --git a/docs/tPaired.html b/docs/tPaired.html index 7e9246e5..fa48324b 100644 --- a/docs/tPaired.html +++ b/docs/tPaired.html @@ -648,42 +648,42 @@
  • 11.8.1 Working the Problem with R and R Packages
  • -
  • References
  • APPENDICES
  • -
  • Type I Error +
  • 12 Type I Error
  • -
  • Examples for Follow-up to Factorial ANOVA +
  • 13 Examples for Follow-up to Factorial ANOVA
  • -
  • One-Way Repeated Measures with a Multivariate Approach +
  • 14 One-Way Repeated Measures with a Multivariate Approach
  • +
  • References
  • Published with bookdown
  • @@ -1772,7 +1772,7 @@

    Assemble the results into a statistical string

    Elliott, A. M., Alexander, S. C., Mescher, C. A., Mohan, D., & Barnato, A. E. (2016). Differences in PhysiciansVerbal and Nonverbal Communication With Black and White Patients at the End of Life. Journal of Pain and Symptom Management, 51(1), 1–8. https://doi.org/10.1016/j.jpainsymman.2015.07.008 diff --git a/docs/type-i-error.html b/docs/type-i-error.html index 71fef492..6b8ab4fb 100644 --- a/docs/type-i-error.html +++ b/docs/type-i-error.html @@ -4,20 +4,20 @@ - Type I Error | ReCentering Psych Stats - + Chapter 12 Type I Error | ReCentering Psych Stats + - + - + - + - + @@ -648,42 +648,42 @@
  • 11.8.1 Working the Problem with R and R Packages
  • -
  • References
  • APPENDICES
  • -
  • Type I Error +
  • 12 Type I Error
  • -
  • Examples for Follow-up to Factorial ANOVA +
  • 13 Examples for Follow-up to Factorial ANOVA
  • -
  • One-Way Repeated Measures with a Multivariate Approach +
  • 14 One-Way Repeated Measures with a Multivariate Approach
  • +
  • References
  • Published with bookdown
  • @@ -704,22 +704,22 @@

    -
    -

    Type I Error

    +
    +

    Chapter 12 Type I Error

    Screencasted Lecture Link

    -
    -

    Type I Error Defined

    +
    +

    12.1 Type I Error Defined

    Type I error is the concern about false positives – that we would incorrectly reject a true null hypothesis (that we would say that there is a statistically significant difference when there is not one). This concern is increased when there are multiple hypothesis tests. This concern increases when we have a large number of pairwise comparisons.

    Throughout the chapters, I noted the importance and relative risk of Type I error with each statistic and options for follow-up testing. Because there are so many options, I have provided a review and summary of each option in this appendix. For each, I provide a definition, a review of the steps and options for utilizing the statistic, and suggest the types of follow-up for which this approach is indicated.

    -
    -

    Methods for Managing Type I Error

    -
    -

    LSD (Least Significant Difference) Method

    +
    +

    12.2 Methods for Managing Type I Error

    +
    +

    12.2.1 LSD (Least Significant Difference) Method

    The LSD method is especially appropriate in the one-way ANOVA scenario when there are only three levels in the factor. In this case, Green and Salkind (2017c) have suggested that alpha can be retained at the alpha level for the “family” (\(\alpha_{family}\)), which is conventionally \(p = .05\) and used both to evaluate the omnibus and, so long as they don’t exceed three in number, the planned or pairwise comparisons that follow.

    -
    -

    Traditional Bonferroni

    +
    +

    12.2.2 Traditional Bonferroni

    The traditional Bonferroni is, perhaps, the most well-known approach to managing Type I error. Although the lessons in this OER will frequently suggest another approach to managing Type I error, I will quickly review it now because, conceptually it is easy to understand. We start by establishing the \(\alpha\alpha_{family}\); this is traditionally \(p = .05\).

    Next, we determine how many pairwise comparisons that we are going to conduct. If we are going to conduct all possible comparisons, we could use this formula: \(N_{pc}=\frac{N_{g}(N-1)}{2}\), where

    -
    -

    Tukey HSD

    +
    +

    12.2.3 Tukey HSD

    The Tukey HSD (honestly significant difference test) is a multiple comparison procedure used to identify significant differences between means of multiple groups. In the ANOVA context, it examines which specific pairs of groups differ from one another. The Tukey HSD was designed to control for Type I error. It does so by calculating the difference between the largest and smallest group means, then dividing this mean difference by the standard error of the same mean difference. The resulting statitic, q has an associated Studentized Range Distribution. Critical values for this distribution come from a Studentized Range q Table and are based on based on the alpha level, the number of groups, and the denominator degrees of freedom (i.e., \(df_W\)).

    The Tukey HSD (“Tukey’s honestly significantly different”) test automatically controls for Type I error (i.e., false positives) by using the studentized range distribution to calculate a critical value. Subsequently, it compares the difference between pairs of means to this critical value. In the rstatix package, the tukey_hsd() function will perform the t-tests of all possible pairwise combinations. The Tukey HSD p value is automatically adjusted. In fact, there is nothing additional that can be specified about p values (i.e., there are no other choice options).

    I had intended to demonstrate this with the one-way ANOVA chapter, but could not get the results to render a figure with the significance bars and results. An online search suggested that I am not the only one to have experienced this glitch.

    -
    -

    Holms Sequential Bonferroni

    +
    +

    12.2.4 Holms Sequential Bonferroni

    The Holm’s sequential Bonferroni (Green & Salkind, 2017c) offers a middle-of-the-road approach (not as strict as .05/9 with the traditional Bonferroni; not as lenient as “none”) to managing Type I error.

    If we were to hand-calculate the Holms, we would rank order the p values associated with the 9 comparisons in order from lowest (e.g., 0.000001448891) to highest (e.g., 1.000). The first p value is evaluated with the most strict criterion (.05/9; the traditional Bonferonni approach). Then, each successive comparison calculates the p value by using the number of remaining comparisons as the denominator (e.g., .05/8, .05/7, .05/6). As the p values increase and the alpha levels relax, there will be a cut-point where remaining comparisons are not statistically significant. Luckily, most R packages offer the Holm’s sequential Bonferroni as an option. The algorithm behind the output rearranges the mathematical formula and produces a p value that we can interpret according to the traditional values of \(p < .05, p < .01\) and \(p < .001\). (Green & Salkind, 2017c)

    @@ -752,7 +752,7 @@

    Holms Sequential Bonferroni

    Green, S. B., & Salkind, N. J. (2017c). Using SPSS for Windows and Macintosh: Analyzing and understanding data (Eighth edition.). Pearson.