Comparing Groups 1 Two Independent Groups Parametric t.test(q1 - - PowerPoint PPT Presentation

comparing groups
SMART_READER_LITE
LIVE PREVIEW

Comparing Groups 1 Two Independent Groups Parametric t.test(q1 - - PowerPoint PPT Presentation

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")


slide-1
SLIDE 1

1

Comparing Groups

slide-2
SLIDE 2

Two Independent Groups

  • Parametric
  • Non-parametric


  • Bayesian

library(devtools) wilcox.test(q1 ~ gender) t.test(q1 ~ gender) install_github(" rasmusab/bayesian_first_aid") library("BayesianFirstAid") bayes.t.test(q1 ~ gender)

slide-3
SLIDE 3

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

slide-4
SLIDE 4

Two Matched Groups

  • Parametric



 


  • Non-parametric



 


  • Bayesian

t.test(pretest, posttest, paired = TRUE) wilcox.test(pretest, posttest, paired = TRUE) library("BayesianFirstAid") bayes.t.test(pretest, posttest, paired = TRUE)

slide-5
SLIDE 5

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

slide-6
SLIDE 6

Means for Matched Groups

> mean(pretest) [1] 74.97 > mean(posttest) [1] 82.06

slide-7
SLIDE 7

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

slide-8
SLIDE 8

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

slide-9
SLIDE 9

ANOVA: Testing Variances

9

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

# car=Companion to Applied Regr. > library("car") > leveneTest(posttest, workshop)

slide-10
SLIDE 10

ANOVA Models

  • Parametric
  • Non-parametric
  • Mixed Models
  • See lme in the nlme package

documented in:

  • Mixed-Effects Models in S and S-PLUS, 


Pinheiro & Bates kruskal.test(posttest ~ workshop) summary(aov(posttest ~ workshop))

slide-11
SLIDE 11

ANOVA Model

Analysis of Variance Table >myModel <- aov(posttest ~ workshop) >summary(myModel) # or anova() 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

slide-12
SLIDE 12

> plot(myModel)

ANOVA Model

slide-13
SLIDE 13

Post-Hoc With t-Tests

(Use pairwise.wilcox.test for nonparametric) 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 > pairwise.t.test(posttest,workshop)

slide-14
SLIDE 14

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

slide-15
SLIDE 15

Tukey Plot

> plot(TukeyHSD(myModel, "workshop"))

slide-16
SLIDE 16

ANOVA and ANCOVA

ANOVA and ANCOVA MODELS FORMULA (“data=” applies only to formulas!) One-way Analysis of Variance y ~ x Two-way Analysis of Variance with interaction y ~ a + b + a:b

  • r

y ~ a*b (Be careful!) Three-way ANOVA with all interactions y ~ a*b*c Three-way ANOVA with only 2-way interactions y ~ (a + b + c) ^ 2

  • r

y ~ a * b * c - a:b:c ANOVA nesting b within a y ~ b %in% a

  • r

y ~ a/b Analysis of Covariance (ANCOVA) Separate slopes: y ~ x + a
 Common slopes: y ~ x * a

slide-17
SLIDE 17

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:

  • The default is "contr.treatment"
  • ptions(contrasts =

c(“contr.sum","contr.poly"))