Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model...

41
Topic 26: Analysis of Covariance

Transcript of Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model...

Page 1: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Topic 26: Analysis of Covariance

Page 2: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Outline

• One-way analysis of covariance

–Data

–Model

– Inference

–Diagnostics and rememdies

• Multifactor analysis of covariance

Page 3: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Data for One-Way ANCOVA

• Yij is the jth observation on the response variable in the ith group

• Xij is the jth observation on the covariate in the ith group

• i = 1, . . . , r levels (groups) of factor

• j = 1, . . . , ni observations for level i

Page 4: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

KNNL Example (pg 927)

• Y is cases of crackers sold during promotion period

• Factor is the type of promotion (r=3)– Customers sample crackers in store– Additional shelf space– Special display shelves

• ni=5 different stores per type

• The covariate X is the number of cases of crackers sold at the store in the preceding period

Page 5: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Data

data a1; infile 'c:\...\CH22TA01.DAT'; input cases last trt store;proc print data=a1; run;

Page 6: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Output

Obs cases last trt store 1 38 21 1 1 2 39 26 1 2 3 36 22 1 3 4 45 28 1 4 5 33 19 1 5 6 43 34 2 1 7 38 26 2 2

Page 7: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Output

Obs cases last trt store 8 38 29 2 3 9 27 18 2 410 34 25 2 511 24 23 3 112 32 29 3 213 31 30 3 314 21 16 3 415 28 29 3 5

Page 8: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Plot the data

title1 'Plot of the data';symbol1 v='1' i=none c=black;symbol2 v='2' i=none c=black;symbol3 v='3' i=none c=black;proc gplot data=a1; plot cases*last=trt/frame;run;

Page 9: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.
Page 10: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Background

• Covariates are sometimes called concomitant variables

• Covariates should be related to the response variable

• Covariates should not be affected by the treatment variable (factor)

• Often they are some kind of baseline or pretest value

Page 11: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Basic ideas• A covariate can reduce the MSE,

thereby increasing power

• A covariate can adjust for differences in characteristics of subjects in the treatment groups

• We assume that the covariate will be linearly related to the response and that the relationship will be the same for all levels of the factor. Similar to comparing regression lines.

Page 12: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Cell Means Model for one-way ancova

– the ij are iid N(0, σ2)

–Yij ~N( , σ2) and indep

• For each i, we have a simple linear regression

• The slopes are the same

• The intercepts can be different

ijijiij )XX(Y ..

)XX( .. iji

Page 13: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Plot of the data with lines

title1 'Plot of the data with lines';symbol1 v='1' i=rl c=black;symbol2 v='2' i=rl c=black;symbol3 v='3' i=rl c=black;proc gplot data=a1; plot cases*last=trt/frame;run;

Page 14: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.
Page 15: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Parameters

• The parameters of the model are

–μi for i = 1 to r

–β

–σ2

Page 16: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Estimates

• We use multiple regression methods to estimate the μi and β

• We use the residuals from the model to estimate σ2

• The estimate is s2 (equal to the MSE)

Page 17: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Factor Effects Model for one way anova

– the ij are iid N(0, σ2)

• The usual constraints are = 0

• Proc glm sets αr= 0

ij..ijiij )XX(Y

Page 18: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Interpretation of model

• Expected value of a Y with level i and Xij=x is

• Expected value of a Y with level i´ and Xij=x is

• The difference is i - i´

• Note that this difference does not depend on the value of x (due to assumption of constant slopes)

)XX( .. i

)XX( .. i

Page 19: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Proc glm

proc glm data=a1; class trt; model cases=last trt;run;

Page 20: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Model output

Source DF MS F PModel 3 202.60 57.78 .0001Error 11 3.50Total 14

Page 21: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Anova table output

Type I Source DF SS MS F Plast 1 190 190 54.38 <.0001trt 2 417 208 59.48 <.0001

Type III Source DF SS MS F Plast 1 269 269 76.72 <.0001trt 2 417 208 59.48 <.0001

Page 22: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Type I vs Type III• Because X for covariate is not

orthogonal (like indep argument before) to X’s for factor

–Order that the X are fit makes a difference. Want to compare means after adjusting for covariate

–General rule to use Type III SS when Type I and III SS differ

Page 23: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Parameter Estimates

proc glm data=a1; class trt; model cases=last trt /solution;run;

Page 24: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Output

Par Est SE t PInt 4.37 B 2.73 1.60 0.1381last 0.89 0.10 8.76 <.0001trt1 12.9 B 1.20 10.76 <.0001trt2 7.9 B 1.18 6.65 <.0001trt3 0.0 B

Common slope is 0.89

Page 25: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Interpretation• Expected value of Y with level i of factor

A and X=x is

• So is the expected value of Y when X is equal to the average covariate value

• This is usually the level of X where the trt means are calculated and compared

• Need to make sure this level of X is reasonable for each level of the factor

)XX( .. i

i ˆˆ

Page 26: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

LSMEANS

• The L(least)S(square) means can be used to obtain these estimates – All other categorical values are set at an

equal mix for all levels (I.e., average over the other factors)

– All continuous values are set at the overall mean

• These are similar to subpopulation mean estimates

Page 27: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Intepretation for KNNL example

• Y is cases of crackers sold under a particular promotion scenario

• X is the cases of crackers sold during the last period

• The LSMEANS are the estimated cases of crackers that would be sold for a store with the ave number of crackers sold during the last period

Page 28: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

LSMEANS Statement

proc glm data=a1; class trt; model cases=last trt; lsmeans trt/ stderr tdiff pdiff cl;run;

Page 29: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Output

treat LSMEAN SE P1 39.8 0.8 <.0001 2 34.7 0.8 <.0001 3 26.8 0.8 <.0001

Page 30: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

OutputLeast Squares Means for Effect treat t for H0: LSMean(i)=LSMean(j) / Pr > |t| Dependent Variable: cases

i/j 1 2 31 4.129808 10.76359 0.0017 <.00012 -4.12981 6.646871 0.0017 <.00013 -10.7636 -6.64687 <.0001 <.0001

Page 31: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Output

treat LSMEAN 95% CL1 39.8 37.9 41.72 34.7 32.8 36.63 26.8 24.9 28.6

Page 32: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Output

Difference Between 95% CL fori j Means LSM(i)-LSM(j)1 2 5.0 2.3 7.71 3 12.9 10.3 15.62 3 7.9 5.2 10.5

Page 33: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Prep data for plot

title1 'Plot of the data with the model';proc glm data=a1; class trt; model cases=last trt; output out=a2 p=pred;

Page 34: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Prep data for plot

data a3; set a2; drop cases pred; if trt eq 1 then do cases1=cases; pred1=pred; output; end;

Page 35: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Prep data for plot if treat eq 2 then do cases2=cases; pred2=pred; output; end; if treat eq 3 then do cases3=cases; pred3=pred; output; end;proc print data=a3; run;

Page 36: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Code for plotsymbol1 v='1' i=none c=black;symbol2 v='2' i=none c=black;symbol3 v='3' i=none c=black;symbol4 v=none i=rl c=black;symbol5 v=none i=rl c=black;symbol6 v=none i=rl c=black;proc gplot data=a3; plot (cases1 cases2 cases3 pred1 pred2 pred3) *last/frame overlay;run;

Page 37: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.
Page 38: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Check for equality of slopes

title1 'Check for equal slopes';proc glm data=a1; class trt; model cases=last trt last*trt;run;

Page 39: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

OutputType ISource DF F Plast 1 54.44 <.0001treat 2 59.55 <.0001last*treat 2 1.01 0.4032

Type III Source DF F Plast 1 69.42 <.0001treat 2 0.18 0.8379last*treat 2 1.01 0.4032

Page 40: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Diagnostics and remedies

• Examine the data and residuals

• Look for outliers that are influential

• Transform if needed, consider Box-Cox

• Examine variances (standard deviations)

–Use a BY statement and look at the MSE

Page 41: Topic 26: Analysis of Covariance. Outline One-way analysis of covariance –Data –Model –Inference –Diagnostics and rememdies Multifactor analysis of covariance.

Last slide

• Read KNNL Ch 22

• We used topic26.sas to generate the output for today