Comparing Groups 1
Two Independent Groups ● Parametric t.test(q1 ~ gender) ● Non-parametric wilcox.test(q1 ~ gender) ● Bayesian library(devtools) install_github(" rasmusab/bayesian_first_aid") library("BayesianFirstAid") bayes.t.test(q1 ~ gender)
t-Test for Independent Groups Welch Two Sample t-test data: q1 by gender t = 4.9784 , df = 97.998 , p-value = 2.748e-06 alternative hypothesis: true diff. in means is not equal to 0 95 percent confidence interval: 0.58789 1.36724 sample estimates: mean in group Female mean in group Male 3.9583 2.9808
Two Matched Groups ● Parametric t.test(pretest, posttest, paired = TRUE ) ● Non-parametric wilcox.test(pretest, posttest, paired = TRUE ) ● Bayesian library("BayesianFirstAid") bayes.t.test(pretest, posttest, paired = TRUE )
t-Test for Matched Groups Paired t-test data: posttest and pretest t = 14.4597 , df = 99 , p-value < 2.2e-16 alternative hypothesis: true diff. in means is not equal to 0 95 percent confidence interval: 6.11708 8.06292 sample estimates: mean of the differences 7.09
Means for Matched Groups > mean(pretest) [ 1 ] 74.97 > mean(posttest) [ 1 ] 82.06
ANOVA: Getting Means > by(posttest, workshop, mean, na.rm = TRUE ) workshop: R [ 1 ] 86.25806 ---------------------- workshop: SAS [ 1 ] 79.625 ----------------------- workshop: SPSS [ 1 ] 81.72 ----------------------- workshop: Stata [ 1 ] 78.94737
ANOVA: Getting Variances > by(posttest, workshop, var, na.rm = TRUE ) workshop: R [ 1 ] 24.99785 ----------------- workshop: SAS [ 1 ] 37.54891 ----------------- workshop: SPSS [ 1 ] 19.54333 ----------------- workshop: Stata [ 1 ] 73.60819
ANOVA: Testing Variances # car=Companion to Applied Regr. > library("car") > leveneTest(posttest, workshop) Levene's Test for Homogeneity of Variance (center = median) Df F value Pr(> F ) group 3 2.51 0.06337 . 95 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 9
ANOVA Models ● Parametric summary(aov(posttest ~ workshop)) ● Non-parametric kruskal.test(posttest ~ workshop) ● Mixed Models ● See lme in the nlme package documented in: ● Mixed-E ff ects Models in S and S-PLUS, Pinheiro & Bates
ANOVA Model >myModel <- aov(posttest ~ workshop) >summary(myModel) # or anova() Analysis of Variance Table Response: posttest Df Sum Sq Mean Sq F value Pr(> F ) workshop 3 875.4 291.8 8.135 7.06e-05 Residuals 95 3407.5 35.9
ANOVA Model > plot(myModel)
Post-Hoc With t-Tests (Use pairwise.wilcox.test for nonparametric) > pairwise.t.test(posttest,workshop) Pairwise comparisons using t tests with pooled SD data: posttest and workshop R SAS SPSS SAS 0.00048 - - SPSS 0.02346 0.44791 - Stata 0.00038 0.71335 0.39468
Post-Hoc With Tukey > TukeyHSD(myModel, "workshop") Tukey multiple comparisons of means 95 % family-wise confidence level Fit: aov(formula = posttest ~ workshop, data = mydata100) $workshop diff lwr upr p adj SAS-R - 6.63306 - 10.8914 - 2.37472 0.00055 SPSS-R - 4.53806 - 8.7481 - 0.32799 0.02943 Stata-R - 7.31070 - 11.8739 - 2.74745 0.00036 SPSS-SAS 2.09500 - 2.3808 6.57078 0.61321 Stata-SAS - 0.67763 - 5.4871 4.13185 0.98281 Stata-SPSS - 2.77263 - 7.5394 1.99416 0.42904
Tukey Plot > plot(TukeyHSD(myModel, "workshop"))
ANOVA and ANCOVA FORMULA ANOVA and ANCOVA MODELS (“data=” applies only to formulas!) One-way Analysis of Variance y ~ x y ~ a + b + a:b Two-way Analysis of Variance with interaction or y ~ a*b (Be careful!) Three-way ANOVA with all interactions y ~ a*b*c y ~ (a + b + c) ^ 2 Three-way ANOVA with only 2-way interactions or y ~ a * b * c - a:b:c y ~ b %in% a ANOVA nesting b within a or y ~ a/b Separate slopes: y ~ x + a Analysis of Covariance (ANCOVA) Common slopes: y ~ x * a
Type III Sums of Squares ● The default in SAS, SPSS & Stata ● Many R users dislike them ● Interactions may make them suspect ● Built-in anova does Type I sequential tests ● car package's Anova (note capital “A”) does: Type II (default) and Type III ● For Type III, precede Anova call with: options(contrasts = c(“contr.sum","contr.poly")) ● The default is "contr.treatment"
Recommend
More recommend