Comparing Groups – Part 2

35
Comparing Groups – Part 2

description

Comparing Groups – Part 2. Wilcoxon Signed Rank (again). H 0 : θ = 0 H A : θ ≠ 0. θ represents the population mean or median. or in colors… add up the rank_AbsDiff for the green negative scores. - PowerPoint PPT Presentation

Transcript of Comparing Groups – Part 2

Page 1: Comparing Groups – Part 2

Comparing Groups – Part 2

Page 2: Comparing Groups – Part 2

Wilcoxon Signed Rank (again)

Page 3: Comparing Groups – Part 2

H0: θ = 0HA: θ ≠ 0

θ represents the population mean or median

Page 4: Comparing Groups – Part 2

2*

1*

SVn

nST

24/))12(*)1(*(

2/)(

nnnV

RRS

Rn

j

jAbsDiffrankR1

_

or in colors… add up the rank_AbsDiff for the green negative scores

Rn

j

jAbsDiffrankR1

_

or in colors… add up the rank_AbsDiff for the blue positive scores

Page 5: Comparing Groups – Part 2

Rn

j

jAbsDiffrankR1

_

or in colors… add up the rank_AbsDiff for the green negative scores

Rn

j

jAbsDiffrankR1

_

or in colors… add up the rank_AbsDiff for the blue positive scores

R- = 1.5 + 3 + 4.5 + 4.5+ 7.5 + 7.5+7.5+14.5+18.5 = 64.5

R+ = 1.5 + 7.5 + 11 +11 +11 +14.5 +14.5 +14.5+18.5+18.5+18.5+21+22= 188.5

2/)( RRS

188.5-64.5/2=62

Page 6: Comparing Groups – Part 2

One-way ANOVA in R

• In the last lecture I gave you a demonstration of using SAS to conduct a one-way ANOVA. Many people think that R is a superior tool for doing analyses like ANOVA. While R is not critical for simple models like you have seen, it is invaluable for graphics to describe more complicated models.

Page 7: Comparing Groups – Part 2

R and Anxiety Disorders

• Start R and then type library(Rcmdr)

• Load the dataset using the Import Data option on the Data menu.

• Load the Generalized Anxiety Disorder (GAD) data. It has Hamilton Rating Scale for Anxiety data for people taking placebo, high or low dose drug.

Page 8: Comparing Groups – Part 2

Summarize the Data

Page 9: Comparing Groups – Part 2

Show me the means.

• You want to see if there is a difference in means in the 3rd variable for the levels of the 2nd variable. You can request the mean plot:

Page 10: Comparing Groups – Part 2

The Plot of the Design2

22

32

42

52

62

72

8

Factors

me

an

of H

AM

A

PB

LO

HI

DOSEGRP

I really like boxplots to see the variability around these means.

Page 11: Comparing Groups – Part 2

Set Factor Order

Page 12: Comparing Groups – Part 2

Side-by-side Boxplot

Page 13: Comparing Groups – Part 2

Boxplot Reordered

Page 14: Comparing Groups – Part 2

Gad <- na.omit(Gad)plot.design(Gad[, c(2,3)])

attach(Gad)thePlot = (boxplot(HAMA~DOSEGRP, ylab="HAMA", xlab="DOSEGRP"))

where = seq(thePlot$n)theMeans = tapply(HAMA, DOSEGRP, mean)points(where, theMeans, col = "red", pch = 18)

I want means.

PB LO HI

20

25

30

35

DOSEGRP

HA

MA

Page 15: Comparing Groups – Part 2

Testing for Differences

• Once the data is set with the placebo group as the baseline, it is easy to ask for tests for the differences vs. the baseline level.

Page 16: Comparing Groups – Part 2
Page 17: Comparing Groups – Part 2

General Linear Models

• It is important for you to know that ANOVAs are more than stand-alone analyses that are not related to modeling. ANOVA fits into a class of statistics called General Linear Models. They are well implemented in R and Rcmdr.

Page 18: Comparing Groups – Part 2

Notice you now have a working model.

Page 19: Comparing Groups – Part 2

Checking the Model

• With the working model you can get lots of summary information, including diagnostic plots.

Page 20: Comparing Groups – Part 2

More Advanced Contrasts

• There is a plethora of methods for dealing with multiple comparisons. You can search CRAN for specific methods you see in textbooks. For example, Walker uses Dunnett’s T test for contrasting the placebo vs. the other levels.

• I start search CRAN with RSiteSearch(“blah”)

Page 21: Comparing Groups – Part 2

Nasty code….

• I eventually found the method implemented in a package called multcomp:

library(multcomp)

gad.aov = aov(HAMA ~ DOSEGRP, data = Gad)

summary(glht(gad.aov, linfct = mcp(DOSEGRP="Dunnett")))

confint(glht(gad.aov, linfct = mcp(DOSEGRP="Dunnett")))

Page 22: Comparing Groups – Part 2
Page 23: Comparing Groups – Part 2

Two-Way ANOVA

• When you have two or more predictors, you want to know if the variables impact the outcome means by themselves and also if they interact. If variables interact, it means that together they do things to the outcome variable beyond what you would expect from looking at each variable alone. For example, smoking and eating too much both hurt longevity but the combination of the two factors may not be as bad as expected or the combination may be especially lethal.

Page 24: Comparing Groups – Part 2

Anemia

• People with Cervical (C), Prostate(P) or Colorectal (R) cancers with chemotherapy-induced anemia were treated either with a drug or placebo and the changes in their hemoglobin levels were assessed. The question of interest is, does the drug reduce anemia?

Page 25: Comparing Groups – Part 2

Box Plots of Course

• With code or R commander get boxplots for the levels of the predictors:

C P R

-2-1

01

23

TYPE

HG

BC

H

ACT PBO

-2-1

01

23

TRT

HG

BC

H

Page 26: Comparing Groups – Part 2

Design Plots

• You have analysis variables in columns 1, 2 and 4. So specify the design plot like this:

0.6

1.0

1.4

Factors

me

an

of H

GB

CH

ACT

PBO

C

P

RTRT TYPE

Page 27: Comparing Groups – Part 2

Interaction Plots

• In addition to the main effects for the predictors, you want to see if the drug behaves differently in the people with the three different cancer groups. Perhaps it helps increase hemoglobin in one group and decreases it another.

Type your outcome variable last.

Page 28: Comparing Groups – Part 2

• It looks like there are differences between the cancer types and the drug seems to increase the hemoglobin relative to the placebo.

0.5

1.0

1.5

2.0

TRT

me

an

of

HG

BC

H

ACT PBO

TYPE

PCR

Page 29: Comparing Groups – Part 2

Modeling

Anova with a capital A is part of the car package

Page 30: Comparing Groups – Part 2

Results

To turn off the * stuff, type this code before you model:options(show.signif.stars=FALSE)

Page 31: Comparing Groups – Part 2

ANOVA as a Model

• You can build this ANOVA as a linear model.

Page 32: Comparing Groups – Part 2

Remove an explanatory effect.

main effect and interaction

interaction only

used for nesting y ~ A/By ~ A + A:By ~ A + B % in % A

Set interaction limits(A+B+C) ^ 2 is equal toA*B*C - A:B:C

Main effect

Page 33: Comparing Groups – Part 2
Page 34: Comparing Groups – Part 2
Page 35: Comparing Groups – Part 2

SAS EG example

• See the parallel information in the SAS EG project.