#IMPORT THE DATA: rm(list = ls()) #Import the data: j <- read.table("S3_Clean.csv",header=TRUE, sep=',') #Ensure that 'Participant' is a Factor: j$Participant <- as.factor(paste(j$Participant,'p')) j$Academic.Qualification <- as.factor(paste(j$Academic.Qualification,'p')) j$Work.in.Healthcare <- as.factor(paste(j$Work.in.Healthcare,'p')) j$pre.post <- as.factor(paste(j$pre.post,'p')) j$Location <- as.factor(paste(j$Location,'p')) nrow(j)/2 str(j) #Should have 91 participants ####################################################################################### ####################################################################################### #Describe the sample: j.half <- j[which(j$pre.post == "pre p"),] #Proportion of subects from each location: table(j.half$Location)/nrow(j.half) #Proportion of subects from each Gender category: table(j.half$Gender)/nrow(j.half) #Proportion of subects from each Healthcare category: table(j.half$Work.in.Healthcare)/nrow(j.half) #Proportion of subects from each Academic category: table(j.half$Academic.Qualification)/nrow(j.half) ####### #Determining Age distributions: #Percent less than 18: table(j.half$Age < 18)/nrow(j.half) #Percent less 18 - 34: table(j.half$Age > 17 & j.half$Age < 35)/nrow(j.half) #Percent less 35 - 50: table(j.half$Age > 34 & j.half$Age < 51)/nrow(j.half) #Percent > 50: table(j.half$Age > 50)/nrow(j.half) ####################################################################################### ####################################################################################### #Plot the data: j$pre.post.12 <- 1 j$pre.post.12[j$pre.post == 'post'] <- 2 library(ggplot2) #USE THIS: ggplot(j, aes(x = pre.post.12, y = Score, group = Participant)) + geom_line(size = 0.5, aes(y = jitter(Score,0.4), x = jitter(pre.post.12,0.1), group = Participant)) + labs(x = "Timing", y = "Score") + theme(axis.text=element_text(size=14), axis.title=element_text(size=16,face="bold"))+ scale_x_discrete(limits = c("Pre","Post")) #Split data by location: ggplot(j, aes(x = pre.post.12, y = Score, group = Participant)) + geom_line(size = 0.5, aes(y = jitter(Score,0.4), x = jitter(pre.post.12,0.1), group = Participant)) + labs(x = "Timing", y = "Score") + theme(axis.text=element_text(size=14), axis.title=element_text(size=16,face="bold"))+ scale_x_discrete(limits = c("Pre","Post")) + facet_grid(. ~ Location) #Split data by Academic Qualification: j.school.some <- j[which(j$Academic.Qualification != "none"),] ggplot(j.school.some, aes(x = pre.post.12, y = Score, group = Participant)) + geom_line(size = 0.5, aes(y = jitter(Score,0.4), x = jitter(pre.post.12,0.1), group = Participant)) + labs(x = "Timing", y = "Score") + theme(axis.text=element_text(size=14), axis.title=element_text(size=16,face="bold"))+ scale_x_discrete(limits = c("Pre","Post")) + facet_grid(. ~ Academic.Qualification) #Split the data by Experience working in Health Care: j$HealthY.N <- "Yes" j$HealthY.N[j$Work.in.Healthcare == 0] <- "No" ggplot(j, aes(x = pre.post.12, y = Score, group = Participant)) + geom_line(size = 0.5, aes(y = jitter(Score,0.4), x = jitter(pre.post.12,0.1), group = Participant)) + labs(x = "Timing", y = "Score") + theme(axis.text=element_text(size=14), axis.title=element_text(size=16,face="bold"))+ scale_x_discrete(limits = c("Pre","Post")) + facet_grid(. ~ HealthY.N) #PLOTS BY QUESTION (8 questions, 8 plots): #brain.stem ggplot(j, aes(x = pre.post.12, y = brain.stem, group = Participant)) + geom_line(size = 0.5, aes(y = jitter(brain.stem,0.4), x = jitter(pre.post.12,0.1), group = Participant)) + labs(x = "Timing", y = "Score") + theme(axis.text=element_text(size=14), axis.title=element_text(size=16,face="bold"))+ scale_x_discrete(limits = c("Pre","Post")) #cerebellum ggplot(j, aes(x = pre.post.12, y = cerebellum, group = Participant)) + geom_line(size = 0.5, aes(y = jitter(cerebellum,0.4), x = jitter(pre.post.12,0.1), group = Participant)) + labs(x = "Timing", y = "Score") + theme(axis.text=element_text(size=14), axis.title=element_text(size=16,face="bold"))+ scale_x_discrete(limits = c("Pre","Post")) #frontal.lobe ggplot(j, aes(x = pre.post.12, y = frontal.lobe, group = Participant)) + geom_line(size = 0.5, aes(y = jitter(frontal.lobe,0.4), x = jitter(pre.post.12,0.1), group = Participant)) + labs(x = "Timing", y = "Score") + theme(axis.text=element_text(size=14), axis.title=element_text(size=16,face="bold"))+ scale_x_discrete(limits = c("Pre","Post")) #occipital.lobe ggplot(j, aes(x = pre.post.12, y = occipital.lobe, group = Participant)) + geom_line(size = 0.5, aes(y = jitter(occipital.lobe,0.4), x = jitter(pre.post.12,0.1), group = Participant)) + labs(x = "Timing", y = "Score") + theme(axis.text=element_text(size=14), axis.title=element_text(size=16,face="bold"))+ scale_x_discrete(limits = c("Pre","Post")) #parietal.lobe ggplot(j, aes(x = pre.post.12, y = parietal.lobe, group = Participant)) + geom_line(size = 0.5, aes(y = jitter(parietal.lobe,0.4), x = jitter(pre.post.12,0.1), group = Participant)) + labs(x = "Timing", y = "Score") + theme(axis.text=element_text(size=14), axis.title=element_text(size=16,face="bold"))+ scale_x_discrete(limits = c("Pre","Post")) #primary.motor ggplot(j, aes(x = pre.post.12, y = primary.motor, group = Participant)) + geom_line(size = 0.5, aes(y = jitter(primary.motor,0.4), x = jitter(pre.post.12,0.1), group = Participant)) + labs(x = "Timing", y = "Score") + theme(axis.text=element_text(size=14), axis.title=element_text(size=16,face="bold"))+ scale_x_discrete(limits = c("Pre","Post")) #primary.sensory ggplot(j, aes(x = pre.post.12, y = primary.sensory, group = Participant)) + geom_line(size = 0.5, aes(y = jitter(primary.sensory,0.4), x = jitter(pre.post.12,0.1), group = Participant)) + labs(x = "Timing", y = "Score") + theme(axis.text=element_text(size=14), axis.title=element_text(size=16,face="bold"))+ scale_x_discrete(limits = c("Pre","Post")) #stroke ggplot(j, aes(x = pre.post.12, y = stroke, group = Participant)) + geom_line(size = 0.5, aes(y = jitter(stroke,0.4), x = jitter(pre.post.12,0.1), group = Participant)) + labs(x = "Timing", y = "Score") + theme(axis.text=element_text(size=14), axis.title=element_text(size=16,face="bold"))+ scale_x_discrete(limits = c("Pre","Post")) ####################################################################################### ####################################################################################### #Now, signed-rank test to address the main question: Do 'pre-' vs. 'post-' differ? j.pre <- j[which(j$pre.post == "pre p"),] j.post <- j[which(j$pre.post == "post p"),] j.post <- data.frame(j.post$Participant,j.post$Score, j.post$stroke) names(j.post) <- c("Participant","Score", "stroke") j.a <- merge(j.pre,j.post,by="Participant") j.a$diff <- j.a$Score.y - j.a$Score.x #NOTE: pre-score = Score.x #NOTE: post-score = Score.y #Q1: do test scores increase from pre- to post? wilcox.test(j.a$Score.x,j.a$Score.y, paired = TRUE) #Wilcoxon signed rank test with continuity correction # #data: j.a$Score.x and j.a$Score.y #V = 72.5, p-value = 1.978e-11 #alternative hypothesis: true location shift is not equal to 0 ####################################################################################### ####################################################################################### #Now, Generalized linear model to address the main question: Do 'pre-' vs. 'post-' differ? j$TotalQs <- 8 changeP.2 <- glm(cbind(Score,TotalQs-Score) ~ pre.post, family = "binomial", data=j) summary(changeP.2) #Call: # glm(formula = cbind(Score, TotalQs - Score) ~ pre.post, family = #"binomial", # data = j) # #Deviance Residuals: # Min 1Q Median 3Q Max #-3.1303 -0.8006 0.1470 1.5112 2.6781 # #Coefficients: # Estimate Std. Error z value Pr(>|z|) # (Intercept) 1.7918 0.1059 16.917 <2e-16 *** # pre.postpre -1.2219 0.1310 -9.325 <2e-16 *** # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # #(Dispersion parameter for binomial family taken to be 1) # #Null deviance: 403.79 on 181 degrees of freedom #Residual deviance: 309.28 on 180 degrees of freedom #AIC: 642.41 # #Number of Fisher Scoring iterations: 4 ## NOTE: Here, and below, we can obtain estimates and effect sizes on the latent scale (i.e., instead of a back-transformed scale) by removing the option, type = "response”, from the emmeans() function. ## library(emmeans) changeP.emmeans.adj.2 <- emmeans(changeP.2,"pre.post", type = "response") changeP.emmeans.adj.2 #pre.post prob SE df asymp.LCL asymp.UCL #post 0.857 0.0130 Inf 0.830 0.881 #pre 0.639 0.0178 Inf 0.603 0.673 # #Confidence level used: 0.95 #Intervals are back-transformed from the logit scale pairs(changeP.emmeans.adj.2) #contrast odds.ratio SE df null z.ratio p.value #post / pre 3.39 0.445 Inf 1 9.325 <.0001 # #Tests are performed on the log odds ratio scale confint(pairs(changeP.emmeans.adj.2)) #contrast odds.ratio SE df asymp.LCL asymp.UCL #post / pre 3.39 0.445 Inf 2.62 4.39 # #Confidence level used: 0.95 #Intervals are back-transformed from the log odds ratio scale ##DOUBLE-CHECK WITH ACCOUNTING FOR OVER_DISPERSION: j <- transform(j, unit = 1:nrow(j)) library(glmmTMB) overall.glm.1 <- glmmTMB(cbind(Score,8-Score) ~ pre.post + (1|unit), family = binomial, data=j) summary(overall.glm.1) #Family: binomial ( logit ) #Formula: cbind(Score, 8 - Score) ~ pre.post + (1 | unit) #Data: j # #AIC BIC logLik deviance df.resid #619.2 628.8 -306.6 613.2 179 # #Random effects: # # Conditional model: # Groups Name Variance Std.Dev. #unit (Intercept) 0.4828 0.6949 #Number of obs: 182, groups: unit, 182 # #Conditional model: # Estimate Std. Error z value Pr(>|z|) #(Intercept) 1.9560 0.1394 14.030 < 2e-16 *** # pre.postpre p -1.3192 0.1742 -7.574 3.63e-14 *** # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 change.emmeans.glmmTMB.1 <- emmeans(overall.glm.1, "pre.post", type = "response") change.emmeans.glmmTMB.1 #pre.post prob SE df lower.CL upper.CL #post p 0.876 0.0151 179 0.843 0.903 #pre p 0.654 0.0251 179 0.603 0.702 # #Confidence level used: 0.95 #Intervals are back-transformed from the logit scale confint((pairs(change.emmeans.glmmTMB.1))) #contrast odds.ratio SE df lower.CL upper.CL #post p / pre p 3.74 0.652 179 2.65 5.27 # #Confidence level used: 0.95 #Intervals are back-transformed from the log odds ratio scale ################################# ################################# ################################# ################################# Question 8 (stroke): how many people’s score improved vs. fell? rise.fall <- j.a$stroke.x-j.a$stroke.y > table(rise.fall == 1) FALSE TRUE 71 20 > table(rise.fall == -1) FALSE TRUE 79 12 > table(rise.fall == 0) FALSE TRUE 32 59 #Overall, 20 people performed better for pre- than post, whereas 12 people improved their score, and 59 remained the same. ####################################################################################### ####################################################################################### #does the pre-score for 'stroke' differ from the expected 25%? #Re-create j.pre and j.post because, above, we dropped some columns (that we now need) for j.post: j.pre <- j[which(j$pre.post == "pre p"),] j.post <- j[which(j$pre.post == "post p"),] #For 'pre' data, tabulate the number of correct and incorrect answers for the 'stroke' question: table(j.pre$stroke == 1) #FALSE TRUE #52 39 binom.test(39, (52+39), p = 0.25, conf.level = 0.95) #Exact binomial test # #data: 39 and (52 + 39) #number of successes = 39, number of trials = 91, p-value = # 0.0002255 #alternative hypothesis: true probability of success is not equal to 0.25 #95 percent confidence interval: # 0.3252887 0.5366348 #sample estimates: # probability of success #0.4285714 #For 'post' data, tabulate the number of correct and incorrect answers for the 'stroke' question: table(j.post$stroke == 1) #FALSE TRUE #60 31 binom.test(31, (60+31), p = 0.25, conf.level = 0.95) #Exact binomial test # #data: 31 and (60 + 31) #number of successes = 31, number of trials = 91, p-value = # 0.05238 #alternative hypothesis: true probability of success is not equal to 0.25 #95 percent confidence interval: # 0.2445169 0.4474951 #sample estimates: # probability of success #0.3406593 ####################################################################################### ####################################################################################### #What would pre- and post-scores look like without Q’s 1 and 3? > mean(j.pre$Score) [1] 5.10989 > mean(j.post$Score) [1] 6.857143 #As almost everyone got Q1 and Q3 right (for both pre- and post-), then we expect that the pre-score will change to about 3.1/6 and the post-score to about 4.8/6 ####################################################################################### ####################################################################################### ##NOTE that REML = FALSE by default in glmmTMB, so that we do not need to set this option to use likelihood ratio tests. #Does Score depend on educational level? j <- transform(j, unit = 1:nrow(j)) j.school.some <- j[which(j$Academic.Qualification != "none p"),] library(glmmTMB) school.TMB <- glmmTMB(cbind(Score,8-Score) ~ pre.post*Academic.Qualification + (1|Participant) + (1|unit), family = binomial, data=j.school.some) school.TMB.noInt <- glmmTMB(cbind(Score,8-Score) ~ pre.post+Academic.Qualification + (1|Participant) + (1|unit), family = binomial, data=j.school.some) school.TMB.noAcademicQ <- glmmTMB(cbind(Score,8-Score) ~ pre.post + (1|Participant) + (1|unit), family = binomial, data=j.school.some) #Likelihood ratio tests reveal no evidence for effect of Academic.Qualification, based on p-values (p = 0.2631): anova(school.TMB, school.TMB.noInt, test="Chi") #Data: j.school.some #Models: # school.TMB.noInt: cbind(Score, 8 - Score) ~ pre.post + Academic.Qualification + , zi=~0, disp=~1 #school.TMB.noInt: (1 | Participant) + (1 | unit), zi=~0, disp=~1 #school.TMB: cbind(Score, 8 - Score) ~ pre.post * Academic.Qualification + , zi=~0, disp=~1 #school.TMB: (1 | Participant) + (1 | unit), zi=~0, disp=~1 #Df AIC BIC logLik deviance Chisq Chi Df #school.TMB.noInt 6 599.42 618.58 -293.71 587.42 #school.TMB 8 600.75 626.29 -292.38 584.75 2.6704 2 #Pr(>Chisq) #school.TMB.noInt #school.TMB 0.2631 #No evidence for effect of Academic>Qualification; p = 0.837 anova(school.TMB.noInt, school.TMB.noAcademicQ, test="Chi") #Data: j.school.some #Models: # school.TMB.noAcademicQ: cbind(Score, 8 - Score) ~ pre.post + (1 #| Participant) + (1 | , zi=~0, disp=~1 # # school.TMB.noAcademicQ: unit), zi=~0, disp=~1 #school.TMB.noInt: cbind(Score, 8 - Score) ~ pre.post + Academic.Qualification + , zi=~0, disp=~1 #school.TMB.noInt: (1 | Participant) + (1 | unit), zi=~0, disp=~1 #Df AIC BIC logLik deviance Chisq #school.TMB.noAcademicQ 4 595.78 608.55 -293.89 587.78 #school.TMB.noInt 6 599.42 618.58 -293.71 587.42 0.3558 #Chi Df Pr(>Chisq) #school.TMB.noAcademicQ #school.TMB.noInt 2 0.837 school.emmeams.noInt <- emmeans(school.TMB.noInt, "Academic.Qualification", type = "response") school.emmeams.noInt #Academic.Qualification prob SE df lower.CL upper.CL #post p 0.794 0.0240 174 0.743 0.837 #school p 0.797 0.0492 174 0.683 0.877 #under p 0.774 0.0287 174 0.712 0.825 # #Results are averaged over the levels of: pre.post #Confidence level used: 0.95 #Intervals are back-transformed from the logit scale ## NOTE: Here, and below, we can obtain 95% CI’s that are NOT adjusted for multiple comparisons by removing the option, adjust = "none”, from the pairs() function. ## pairs(school.emmeams.noInt, adjust = "none") #contrast odds.ratio SE df null t.ratio p.value #post p / school p 0.982 0.329 174 1 -0.054 0.9567 #post p / under p 1.127 0.242 174 1 0.555 0.5794 #school p / under p 1.148 0.394 174 1 0.401 0.6886 # #Results are averaged over the levels of: pre.post #Tests are performed on the log odds ratio scale confint(pairs(school.emmeams.noInt, adjust = "none")) #contrast odds.ratio SE df lower.CL upper.CL #post p / school p 0.982 0.329 174 0.507 1.90 #post p / under p 1.127 0.242 174 0.737 1.72 #school p / under p 1.148 0.394 174 0.583 2.26 # #Results are averaged over the levels of: pre.post #Confidence level used: 0.95 #Intervals are back-transformed from the log odds ratio scale ####################################################################################### ####################################################################################### #Does Score depend on whether you work in Health Care? j$HealthY.N <- "Yes" j$HealthY.N[j$Work.in.Healthcare == "0 p"] <- "No" health.TMB <- glmmTMB(cbind(Score,8-Score) ~ pre.post*HealthY.N + (1|Participant) + (1|unit), family = binomial, data=j) summary(health.TMB) #Family: binomial ( logit ) #Formula: # cbind(Score, 8 - Score) ~ pre.post * HealthY.N + (1 | Participant) + # (1 | unit) #Data: j # #AIC BIC logLik deviance df.resid #607.1 626.3 -297.5 595.1 176 # #Random effects: # # Conditional model: # Groups Name Variance Std.Dev. #Participant (Intercept) 5.046e-01 7.103e-01 #unit (Intercept) 7.933e-09 8.907e-05 #Number of obs: 182, groups: Participant, 91; unit, 182 # #Conditional model: # Estimate Std. Error z value Pr(>|z|) #(Intercept) 1.94937 0.16118 12.094 <2e-16 *** # pre.postpre p -1.41946 0.16264 -8.728 <2e-16 *** # HealthY.NYes 0.05516 0.29773 0.185 0.853 #pre.postpre p:HealthY.NYes 0.32360 0.30663 1.055 0.291 #--- #Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 health.TMB.a <- glmmTMB(cbind(Score,8-Score) ~ pre.post+HealthY.N + (1|Participant) + (1|unit), family = binomial, data=j) summary(health.TMB.a) #Family: binomial ( logit ) #Formula: # cbind(Score, 8 - Score) ~ pre.post + HealthY.N + (1 | Participant) + # (1 | unit) #Data: j # #AIC BIC logLik deviance df.resid #606.2 622.2 -298.1 596.2 177 # #Random effects: # # Conditional model: # Groups Name Variance Std.Dev. #Participant (Intercept) 5.033e-01 0.7094576 #unit (Intercept) 6.707e-09 0.0000819 #Number of obs: 182, groups: Participant, 91; unit, 182 # #Conditional model: # Estimate Std. Error z value Pr(>|z|) #(Intercept) 1.8927 0.1501 12.607 <2e-16 *** # pre.postpre p -1.3325 0.1386 -9.612 <2e-16 *** # HealthY.NYes 0.2660 0.2238 1.188 0.235 #--- #Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 health.TMB.b <- glmmTMB(cbind(Score,8-Score) ~ pre.post + (1|Participant) + (1|unit), family = binomial, data=j) anova(health.TMB, health.TMB.a, type = "Chi") #Data: j #Models: # health.TMB.a: cbind(Score, 8 - Score) ~ pre.post + HealthY.N + (1 | Participant) + , zi=~0, disp=~1 #health.TMB.a: (1 | unit), zi=~0, disp=~1 #health.TMB: cbind(Score, 8 - Score) ~ pre.post * HealthY.N + (1 | Participant) + , zi=~0, disp=~1 #health.TMB: (1 | unit), zi=~0, disp=~1 # Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) #health.TMB.a 5 606.2 622.22 -298.10 596.2 #health.TMB 6 607.1 626.32 -297.55 595.1 1.1012 1 0.294 anova(health.TMB.a, health.TMB.b, type = "Chi") #Data: j #Models: # health.TMB.b: cbind(Score, 8 - Score) ~ pre.post + (1 | Participant) + (1 #| , zi=~0, disp=~1 # #health.TMB.b: unit), zi=~0, disp=~1 #health.TMB.a: cbind(Score, 8 - Score) ~ pre.post + HealthY.N + (1 | Participant) + , zi=~0, disp=~1 #health.TMB.a: (1 | unit), zi=~0, disp=~1 # Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) #health.TMB.b 4 605.61 618.43 -298.81 597.61 #health.TMB.a 5 606.20 622.22 -298.10 596.20 1.4159 1 0.2341 #Given no evidence for an interaction (based on p-value), we'll estimate effects using the model lacking an interaction: health.emmeans <- emmeans(health.TMB.a, "HealthY.N", type = "response") health.emmeans #HealthY.N prob SE df lower.CL upper.CL #No 0.773 0.0212 177 0.729 0.812 #Yes 0.816 0.0291 177 0.752 0.867 # #Results are averaged over the levels of: pre.post #Confidence level used: 0.95 #Intervals are back-transformed from the logit scale pairs(health.emmeans, adjust = "none") #contrast odds.ratio SE df null t.ratio p.value #No / Yes 0.766 0.172 177 1 -1.188 0.2363 # #Results are averaged over the levels of: pre.post #Tests are performed on the log odds ratio scale confint(pairs(health.emmeans, adjust = "none")) #contrast odds.ratio SE df lower.CL upper.CL #No / Yes 0.766 0.172 177 0.493 1.19 # #Results are averaged over the levels of: pre.post #Confidence level used: 0.95 #Intervals are back-transformed from the log odds ratio scale ####################################################################################### ####################################################################################### #Does Score depend on Location? j <- transform(j, unit = 1:nrow(j)) loc.full <- glmmTMB(cbind(Score,8-Score) ~ pre.post * Location + (1|Participant) + (1|unit), family = "binomial",data=j) summary(loc.full) #Family: binomial ( logit ) #Formula: # cbind(Score, 8 - Score) ~ pre.post * Location + (1 | Participant) + # (1 | unit) #Data: j # #AIC BIC logLik deviance df.resid #601.4 633.4 -290.7 581.4 172 # #Random effects: # # Conditional model: # Groups Name Variance Std.Dev. #Participant (Intercept) 3.983e-01 6.311e-01 #unit (Intercept) 5.413e-09 7.358e-05 #Number of obs: 182, groups: Participant, 91; unit, 182 # #Conditional model: # Estimate Std. Error z value Pr(>|z|) #(Intercept) 1.4118 0.2255 6.259 3.86e-10 *** #pre.postpre p -0.9499 0.2393 -3.970 7.20e-05 *** #Locationedin p 0.9920 0.3623 2.738 0.00618 ** #Locationhull p 0.2732 0.3427 0.797 0.42538 #Locationusa p 1.0470 0.3703 2.827 0.00470 ** #pre.postpre p:Locationedin p -0.5244 0.3836 -1.367 0.17157 #pre.postpre p:Locationhull p -0.5438 0.3633 -1.497 0.13442 #pre.postpre p:Locationusa p -0.6282 0.3909 -1.607 0.10800 #--- #Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 loc.noInt <- glmmTMB(cbind(Score,8-Score) ~ pre.post + Location + (1|Participant) + (1|unit), family = "binomial",data=j) summary(loc.noInt) #Family: binomial ( logit ) #Formula: # cbind(Score, 8 - Score) ~ pre.post + Location + (1 | Participant) + # (1 | unit) #Data: j # #AIC BIC logLik deviance df.resid #599.1 621.6 -292.6 585.1 175 # #Random effects: # # Conditional model: # Groups Name Variance Std.Dev. #Participant (Intercept) 3.958e-01 0.6290920 #unit (Intercept) 2.317e-08 0.0001522 #Number of obs: 182, groups: Participant, 91; unit, 182 # #Conditional model: # Estimate Std. Error z value Pr(>|z|) #(Intercept) 1.64231 0.19779 8.303 <2e-16 *** #pre.postpre p -1.33211 0.13862 -9.609 <2e-16 *** #Locationedin p 0.66188 0.25840 2.561 0.0104 * #Locationhull p -0.05814 0.26100 -0.223 0.8237 #Locationusa p 0.64414 0.26174 2.461 0.0139 * #--- #Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 onlyPrePost <- glmmTMB(cbind(Score,8-Score) ~ pre.post + (1|Participant) + (1|unit), family = "binomial",data=j) anova(loc.full, loc.noInt, test = "Chi") #Data: j #Models: # loc.noInt: cbind(Score, 8 - Score) ~ pre.post + Location + (1 | Participant) + , zi=~0, disp=~1 #loc.noInt: (1 | unit), zi=~0, disp=~1 #loc.full: cbind(Score, 8 - Score) ~ pre.post * Location + (1 | Participant) + , zi=~0, disp=~1 #loc.full: (1 | unit), zi=~0, disp=~1 # Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) #loc.noInt 7 599.13 621.56 -292.57 585.13 #loc.full 10 601.40 633.44 -290.70 581.40 3.7386 3 0.2911 anova(loc.noInt, onlyPrePost, test = "Chi") #Data: j #Models: # onlyPrePost: cbind(Score, 8 - Score) ~ pre.post + (1 | Participant) + (1 | , zi=~0, disp=~1 # #onlyPrePost: unit), zi=~0, disp=~1 #loc.noInt: cbind(Score, 8 - Score) ~ pre.post + Location + (1 | Participant) #+ , zi=~0, disp=~1 #loc.noInt: (1 | unit), zi=~0, disp=~1 # Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq) #onlyPrePost 4 605.61 618.43 -298.81 597.61 #loc.noInt 7 599.13 621.56 -292.57 585.13 12.479 3 0.005911 ** #--- #Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 library(emmeans) loc.emmeans <- emmeans(loc.noInt, "Location", type = "response") loc.emmeans #Location prob SE df lower.CL upper.CL #dundee p 0.726 0.0354 175 0.651 0.790 #edin p 0.837 0.0261 175 0.779 0.883 #hull p 0.715 0.0395 175 0.631 0.786 #usa p 0.835 0.0272 175 0.774 0.882 # #Results are averaged over the levels of: pre.post #Confidence level used: 0.95 #Intervals are back-transformed from the logit scale pairs(loc.emmeans, adjust = "none") #contrast odds.ratio SE df null t.ratio p.value #dundee p / edin p 0.516 0.133 175 1 -2.561 0.0113 #dundee p / hull p 1.060 0.277 175 1 0.223 0.8240 #dundee p / usa p 0.525 0.137 175 1 -2.461 0.0148 #edin p / hull p 2.054 0.554 175 1 2.669 0.0083 #edin p / usa p 1.018 0.275 175 1 0.066 0.9477 #hull p / usa p 0.495 0.135 175 1 -2.573 0.0109 # #Results are averaged over the levels of: pre.post #Tests are performed on the log odds ratio scale confint(pairs(loc.emmeans, adjust = "none")) #contrast odds.ratio SE df lower.CL upper.CL #dundee p / edin p 0.516 0.133 175 0.310 0.859 #dundee p / hull p 1.060 0.277 175 0.633 1.774 #dundee p / usa p 0.525 0.137 175 0.313 0.880 #edin p / hull p 2.054 0.554 175 1.206 3.499 #edin p / usa p 1.018 0.275 175 0.598 1.733 #hull p / usa p 0.495 0.135 175 0.289 0.849 # #Results are averaged over the levels of: pre.post #Confidence level used: 0.95 #Intervals are back-transformed from the log odds ratio scale ####################################################################################### #######################################################################################