### ANOVA with Bonferroni post hocs/simple effects
Wk01d<- read.csv("Class06b_2014.csv")
head(Wk01d)
##   ï..const NumDevice PlatPref  TechSat
## 1 1 1 1 36.33687
## 2 1 1 1 42.39843
## 3 1 1 1 56.66463
## 4 1 1 1 39.65149
## 5 1 1 1 58.40328
## 6 1 1 1 46.81188
#Two way design

#Omnibus
anova(lm(TechSat ~ NumDevice * PlatPref, Wk01d))
## Analysis of Variance Table
##
## Response: TechSat
## Df Sum Sq Mean Sq F value Pr(>F)
## NumDevice 1 0.8 0.78 0.0082 0.9283608
## PlatPref 1 1507.5 1507.52 15.7776 0.0002605 ***
## NumDevice:PlatPref 1 750.8 750.78 7.8576 0.0074999 **
## Residuals 44 4204.1 95.55
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#Simple effects
#use subset(data, condition) to divide the original dataset
#In this case, it compares a dichotomous effect (PlatPref) at each level of the other
#so no further posthocs are needed
#Dev=1
datac1 <- subset(Wk01d, NumDevice == '1')
#Dev=2
datac2 <- subset(Wk01d, NumDevice == '2')
#Dev=3
datac3 <- subset(Wk01d, NumDevice == '3')

#run ANOVA on the Device subsets to investigate the impacts of platform preference within each
#Dev=1
anova(lm(TechSat ~ PlatPref, datac1))
## Analysis of Variance Table
##
## Response: TechSat
## Df Sum Sq Mean Sq F value Pr(>F)
## PlatPref 1 10.56 10.563 0.1098 0.7453
## Residuals 14 1347.19 96.228
#Dev=2
anova(lm(TechSat ~ PlatPref, datac2))
## Analysis of Variance Table
##
## Response: TechSat
## Df Sum Sq Mean Sq F value Pr(>F)
## PlatPref 1 484.0 484.00 4.6979 0.04793 *
## Residuals 14 1442.3 103.03
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#Dev=3
anova(lm(TechSat ~ PlatPref, datac3))
## Analysis of Variance Table
##
## Response: TechSat
## Df Sum Sq Mean Sq F value Pr(>F)
## PlatPref 1 1764.0 1764.00 17.465 0.0009276 ***
## Residuals 14 1414.1 101.01
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
### 7. Plotting the interaction
#This is a nice, SPSS like package for plotting
#It is a bit buggy, because some sub-packages aren't loading right; hence all the extra install /
#library calls
#A nice surprise is that it also gives SPSS like output, including -- surprisingly --
#Bonferroni-style simple effects post hocs!

#install.packages("rlang")
#install.packages('TMB', type='source')
#install.packages("CGPfunctions")
library(rlang)
library(CGPfunctions)
## Registered S3 methods overwritten by 'lme4':
## method from
## cooks.distance.influence.merMod car
## influence.merMod car
## dfbeta.influence.merMod car
## dfbetas.influence.merMod car
## 
## Attaching package: 'CGPfunctions'
## The following object is masked from 'package:DescTools':
##
## Mode
library(TMB)

Plot2WayANOVA(TechSat~NumDevice*PlatPref,
dataframe = Wk01d,
confidence=.95,
plottype = "line",
xlab = "Number of Devices",
ylab = "Tech Satisfaction",
title = NULL,
subtitle = NULL,
interact.line.size = 1,
ci.line.size = 1,
mean.label = FALSE,
mean.ci = TRUE,
mean.size = 4,
mean.shape = 23,
mean.color = "darkred",
mean.label.size = 3,
mean.label.color = "black",
offset.style = "none",
overlay.type = NULL,
posthoc.method = "bonferroni",
show.dots = TRUE,
PlotSave = FALSE)
## 
## Converting NumDevice to a factor --- check your results
## 
## Converting PlatPref to a factor --- check your results
## 
## You have a balanced design.
##                                  term    sumsq   meansq df statistic p.value
## NumDevice NumDevice 1.042 0.521 2 0.005 0.995
## PlatPref PlatPref 1507.521 1507.521 1 15.062 0.000
## NumDevice:PlatPref NumDevice:PlatPref 751.042 375.521 2 3.752 0.032
## ...4 Residuals 4203.611 100.086 42 NA NA
## etasq partial.etasq omegasq partial.omegasq epsilonsq
## NumDevice 0.000 0.000 -0.030 -0.043 -0.031
## PlatPref 0.233 0.264 0.214 0.227 0.218
## NumDevice:PlatPref 0.116 0.152 0.084 0.103 0.085
## ...4 NA NA NA NA NA
## cohens.f power
## NumDevice 0.016 0.051
## PlatPref 0.599 0.973
## NumDevice:PlatPref 0.423 0.687
## ...4 NA NA
## 
## Measures of overall model fit
## # A tibble: 1 x 5
## logLik AIC BIC deviance nobs
## <dbl> <dbl> <dbl> <dbl> <int>
## 1 -175. 365. 378. 4204. 48
## 
## Table of group means
## # A tibble: 6 x 15
## # Groups: NumDevice [3]
## NumDevice PlatPref TheMean TheSD TheSEM CIMuliplier LowerBoundCI UpperBoundCI
## <fct> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 1 50.0 9.9 3.50 2.36 41.7 58.3
## 2 1 2 51.6 9.72 3.44 2.36 43.5 59.7
## 3 2 1 45 10.1 3.57 2.36 36.6 53.4
## 4 2 2 56 10.2 3.61 2.36 47.5 64.5
## 5 3 1 40 10. 3.54 2.36 31.6 48.4
## 6 3 2 61.0 10.1 3.57 2.36 52.6 69.4
## # ... with 7 more variables: LowerBoundSEM <dbl>, UpperBoundSEM <dbl>,
## # LowerBoundSD <dbl>, UpperBoundSD <dbl>, N <int>, LowerBound <dbl>,
## # UpperBound <dbl>
## 
## Post hoc tests for all effects that were significant
## 
## Posthoc multiple comparisons of means : Bonferroni
## 95% family-wise confidence level
##
## $PlatPref
## diff lwr.ci upr.ci pval
## 2-1 11.20833 5.38013 17.03654 0.00036 ***
##
## $`NumDevice:PlatPref`
## diff lwr.ci upr.ci pval
## 2:1-1:1 -5.000 -20.5688665 10.568866 1.0000
## 3:1-1:1 -10.000 -25.5688665 5.568866 0.7814
## 1:2-1:1 1.625 -13.9438665 17.193866 1.0000
## 2:2-1:1 6.000 -9.5688665 21.568866 1.0000
## 3:2-1:1 11.000 -4.5688665 26.568866 0.5015
## 3:1-2:1 -5.000 -20.5688665 10.568866 1.0000
## 1:2-2:1 6.625 -8.9438665 22.193866 1.0000
## 2:2-2:1 11.000 -4.5688665 26.568866 0.5015
## 3:2-2:1 16.000 0.4311335 31.568866 0.0394 *
## 1:2-3:1 11.625 -3.9438665 27.193866 0.3755
## 2:2-3:1 16.000 0.4311335 31.568866 0.0394 *
## 3:2-3:1 21.000 5.4311335 36.568866 0.0020 **
## 2:2-1:2 4.375 -11.1938665 19.943866 1.0000
## 3:2-1:2 9.375 -6.1938665 24.943866 1.0000
## 3:2-2:2 5.000 -10.5688665 20.568866 1.0000
##
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Testing Homogeneity of Variance with Brown-Forsythe
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 5 0.3247 0.8953
## 42
## 
## Testing Normality Assumption with Shapiro-Wilk
## 
## Shapiro-Wilk normality test
##
## data: MyAOV_residuals
## W = 0.96307, p-value = 0.1343
## 
## Interaction graph plotted...