Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects...

32
Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test

Transcript of Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects...

Page 1: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

Part IVThe General Linear Model.

Multiple Explanatory Variables

Chapter 13.3 Fixed *Random Effects

Paired t-test

Page 2: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

Overview of GLM

GLM

Regression

ANOVA

ANCOVA

One-Way ANOVA

Two-Way ANOVA

Simple regression Multiple regression

Two categories (t-test)

Multiple categories - Fixed (e.g., treatment, age)

- Random (e.g., subjects, litters)

2 fixed factors 1 fixed & 1 random

(e.g., Paired t-test)

Multi-Way ANOVA

Page 3: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

GLM: Paired t-test

Two factors (2 explanatory variables on a nominal

scale)

One fixed (2 categories)

The other random (many categories)

+Fixed factor

Random factor

Remove var. among units → sensitive test

Page 4: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

• Sleep data example, used by W. Gosset (1908) in the paper that introduced the t-test

• Are the effects of 2 sleep inducing drugs: Hyoscyamine (Drug A) and L Hyoscine (Drug B), controlled for among subject variation, different?

GLM | Paired t-test

Subject DrugA Drug B

1 0.7 1.9

2 -1.6 0.8

3 -0.2 1.1

4 -1.2 0.1

5 -0.1 -0.1

6 3.4 4.4

7 3.7 5.5

8 0.8 1.6

9 0.0 4.6

10 2.0 3.4Data are means

Page 5: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

1. Construct ModelResponse variable: T=hours of extra sleep – ratio scale

Explanatory variables:

1. Drug. XD = Drug A, Drug B. Nominal scale

Fixed effect

2. Subject. XS = [1,2,…,10]. Nominal scale

Random effect

Mean value for each subject varies randomly and is not under the control of the investigator

Page 6: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

1. Construct ModelVerbal: Hours of extra sleep depends on drug.Graphical:

Page 7: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

1. Construct ModelVerbal: Hours of extra sleep depends on drug.Graphical:

Page 8: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

1. Construct ModelVerbal: Hours of extra sleep depends on drug.Graphical:

Page 9: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

1. Construct ModelFormal:

Can we have an interaction term?

Let’s look at the df

dfDrug =

dfSubject =

dfDrug*Subject =

Dfresidual =

Page 10: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

1. Construct ModelVerbal: Hours of extra sleep depends on drug.Graphical:

Page 11: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

1. Construct ModelFormal:Revised Model:

Page 12: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

2. Execute analysis

lm1 <- lm(T~XS+XD, data=sleep)XS T XD

1 0.7 A

2 -1.6 A

3 -0.2 A

4 -1.2 A

5 -0.1 A

6 3.4 A

7 3.7 A

8 0.8 A

9 0.0 A

10 2.0 A

1 1.9 B

2 0.8 B

3 1.1 B

4 0.1 B

5 -0.1 B

6 4.4 B

7 5.5 B

8 1.6 B

9 4.6 B

10 3.4 B

R: multiple ways to model random effectsInstead of lm:

lmer{lme4}lme{nlme}use aov() , specifying

Error(subject)

Page 13: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

2. Execute analysis

1. Compute

2. Compute mean per drug mean (TD=A)= 0.75 hs

3. Compute drug effect

4. Compute mean per subject mean(TS=1)= 1.3 hs

5. Compute subject effect

6. Compute fits

7. Compute residuals residuals = T - fits

hs54.1ˆ0

hshsAD 79.0)54.175.0(ˆ

hshsS 24.0)54.13.1(ˆ1

SDfits ˆˆˆ0

Page 14: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

hshshs SAD 24.0ˆ;79.0ˆ;54.1ˆ10

2. Execute analysis

XS T XD β0 βD βS fits res

1 0.7 A1.54

-0.79

-0.24

0.51-

0.19

2 -1.6 A1.54

-0.79

-1.94

-1.19

0.41

3 -0.2 A1.54

-0.79

-1.09

-0.34

-0.14

4 -1.2 A1.54

-0.79

-2.09

-1.34

-0.14

5 -0.1 A1.54

-0.79

-1.64

-0.89

-0.79

1 1.9 B1.54

0.79-

0.242.09 0.19

2 0.8 B1.54

0.79-

1.940.39

-0.41

3 1.1 B1.54

0.79-

1.091.24 0.14

4 0.1 B1.54

0.79-

2.090.24 0.14

5 -0.1 B1.54

0.79-

1.640.69 0.79

Page 15: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

3. Evaluate model

□ Straight line model ok?

□ Errors homogeneous?

□ Errors normal?

□ Errors independent?

Page 16: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

3. Evaluate model

□ Straight line model ok?

□ Errors homogeneous?

□ Errors normal?

□ Errors independent?

NA

Page 17: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

3. Evaluate model

□ Straight line model ok?

□ Errors homogeneous?

□ Errors normal?

□ Errors independent?

NA

Page 18: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

3. Evaluate model

□ Straight line model ok?

□ Errors homogeneous?

□ Errors normal?

□ Errors independent?

NA

Page 19: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

4. State the population and whether the sample is representative.

Drugs set by experimental design fixed effectsWe will infer only to those drugs

Subjects, chosen at random. Hopefully from a larger population random effects

Population of all possible measurements of hours of extra sleep, given the mode of collection

Infer to a population of subjects with characteristics similar to those in the study

Page 20: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

5. Decide on mode of inference. Is hypothesis testing appropriate?

6. State HA / Ho pair, test statistic, distribution, tolerance for Type I error.

– Assume no interaction, i.e. effect of drug is consistent across subjects

– Focus on drug effect

Page 21: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

6. State HA / Ho pair, test statistic, distribution, tolerance for Type I error.

Test Statistic

Distribution of test statitstic

Tolerance for Type I error

Page 22: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

7. ANOVA n = 20

Source df SS MS F p

Subject

Drug

Res______

______

Total

Page 23: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

7. ANOVA n = 20

Source df SS MS F p

Subject 958.078

Drug 112.482

Res___9__

_6.808

Total 19 77.37

Page 24: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

7. ANOVA n = 20

Source df SS MS F p

Subject 958.078

6.453

Drug 112.482

12.48

Res___9__

_6.808

0.7564

Total 19 77.37

Page 25: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

7. ANOVA n = 20

Source df SS MS F p

Subject 958.078

6.453

Drug 112.482

12.48 16.5 0.0028

Res___9__

_6.808

0.7564

Total 19 77.37

Page 26: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

7. ANOVA n = 20Source df SS MS F p

Subject 958.078

6.453

Drug 112.482

12.48 16.5 0.0028

Res___9__

_6.808

0.7564

Total 19 77.37

Source df SS MS F p

Drug 1 12.48 12.48 3.4626 0.079

Res__18__

64.886

3.6048

Total 19 77.37

BUT we did this before Ch 10.2 2 sample t-test

STATISTICAL CONTROL

r2 = 0.91

r2 = 0.16

Page 27: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

8. Decide whether to recompute p-value

Slight deviation from normalityn<30, p=0.0028 not near α no need to recompute

Page 28: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

9. Declare decision about terms

Only the fixed term was tested p=0.0028 < α =0.05Reject H0 extra sleep depends on drug administered

We did a 2 way ANOVA, also known as a paired t-test. 1 random factor1 fixed factor with 2 levels

Page 29: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

9. Declare decision about terms

A B A-B fits res

0.7 1.9 1.2 1.58 -0.38

-1.6 0.8 2.4 1.58 0.82

-0.2 1.1 1.3 1.58 -0.28

-1.2 0.1 1.3 1.58 -0.28

-0.1 -0.1 0.0 1.58 -1.58

3.4 4.4 1.0 1.58 -0.58

3.7 5.5 1.8 1.58 0.22

0.8 1.6 0.8 1.58 -0.78

0.0 4.6 4.6 1.58 3.02

2.0 3.4 1.4 1.58 -0.18

Paired t-test:

1. Calculate difference within each random category

2. Test if the mean diff differs from zero

p=0.0028

Page 30: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.

10.Report and interpret parameters of biological interest

Means per drug, not controlled for among subject variation

SE LCL (5%) UCL(95%)

mean(TA)=0.75 hs

0.5657 -0.53 hs 2.03 hs

mean(TB)=2.33 hs

0.6332 0.89 hs 3.76 hs

Confidence limits for the average difference, controlled for among subject variation

SE LCL (5%) UCL(95%)

mean(TB-TA)=1.58 hs

0.388 0.7 hs 2.46 hs

Page 31: Part IV The General Linear Model. Multiple Explanatory Variables Chapter 13.3 Fixed *Random Effects Paired t-test.