Presentation is loading. Please wait.

Presentation is loading. Please wait.

Generalized Linear Mixed Models

Similar presentations


Presentation on theme: "Generalized Linear Mixed Models"— Presentation transcript:

1 Generalized Linear Mixed Models
Bodo Winter

2 Regression with categorical predictors

3 Regression with categorical predictors

4 Regression with categorical predictors

5 Regression with categorical predictors

6 Regression with categorical predictors

7 Regression with categorical predictors

8 Regression with categorical predictors

9 Regression with categorical predictors

10 Regression with categorical predictors

11 Output for categorical predictors
Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) <2e-16 *** genderFemale <2e-16 *** The males are in the intercept (=109) The slope for “female” is the change with respect to the male group

12 Default: Treatment coding

13 Default: Treatment coding
pitch gender male male male male female female female female

14 Default: Treatment coding
pitch gender gender male male male male female female female female 1 these are called dummy codes by default, R does “treatment coding” and assumes that the alphanumerically first element is the reference level

15 Changing the reference level
xdata$myfac = relevel(xdata$myfac,ref=“male”) Before releveling: Estimate Std. Error t value Pr(>|t|) (Intercept) <2e-16 *** genderFemale <2e-16 *** After releveling: (Intercept) <2e-16 *** myfactor.revmale <2e-16 ***

16 Other coding schemes

17 Other coding schemes

18 the intercept is now the mean of all pitch values (ignoring gender)
Other coding schemes the intercept is now the mean of all pitch values (ignoring gender)

19 this is now the difference from the mean (=55)
Other coding schemes This is called sum coding this is now the difference from the mean (=55)

20 Other coding schemes This is called deviation coding

21 Female = 0, Male = 1 (Treatment coding) Estimate Std
Female = 0, Male = 1 (Treatment coding) Estimate Std. Error t value Pr(>|t|) (Intercept) e-09 *** gender e-06 *** Female = -1, Male = 1 (Sum coding) (Intercept) e-09 *** gender e-06 *** Female = -0.5, Male = 0.5 (Deviation coding) gender e-06 ***

22 An extended linear Model
Y ~ b b1*X b2*X error coefficients predictors can be continuous or categorical and there can be (in principle) infinitely many

23 Interactions

24 Continuous * categorical interaction

25 Continuous * categorical interaction

26 Continuous * categorical interaction
RT ~ Noise + Gender

27 Continuous * categorical interaction
RT ~ Noise + Gender + Noise:Gender RT ~ Noise * Gender

28 Continuous * categorical interaction

29 Continuous * categorical interaction

30 Continuous * categorical interaction

31 Schielzeth (2010) example Schielzeth, H. (2010). Simple means to improve the interpretability of regression coefficients. Methods in Ecology and Evolution, 1(2),

32 Interpreting cont * cat interactions
Example: Intercept 500 Noise 2 GenderF -150 Noise:GenderF 5 Y ~ b b1*X b2*X b3*(X1*X2) interaction term

33 Interpreting cont * cat interactions
Example: Intercept 500 Noise 2 GenderF -150 Noise:GenderF 5 say you wanted the prediction for noise = 10 for females Y ~ b b1*X b2*X b3*(X1*X2)

34 Interpreting cont * cat interactions
Example: Intercept 500 Noise 2 GenderF -150 Noise:GenderF 5 say you wanted the prediction for noise = 10 for females Y ~ b1*X b2*X b3*(X1*X2)

35 Interpreting cont * cat interactions
Example: Intercept 500 Noise 2 GenderF -150 Noise:GenderF 5 say you wanted the prediction for noise = 10 for females Y ~ * b2*X b3*(X1*X2)

36 Interpreting cont * cat interactions
Example: Intercept 500 Noise 2 GenderF -150 Noise:GenderF 5 say you wanted the prediction for noise = 10 for females Y ~ * (-150)* b3*(X1*X2)

37 Interpreting cont * cat interactions
Example: Intercept 500 Noise 2 GenderF -150 Noise:GenderF 5 say you wanted the prediction for noise = 10 for females Y ~ * (-150)* *(10*1) “1” for female and “10” for the noise value we wanted

38 Interpreting cont * cat interactions
Example: Intercept 500 Noise 2 GenderF -150 Noise:GenderF 5 What about the men? Y ~ * (-150)* *(1*10)

39 Interpreting cont * cat interactions
Example: Intercept 500 Noise 2 GenderF -150 Noise:GenderF 5 What about the men? Y ~ * (-150)* *(0*10)

40 Interactions between continuous variables
No interaction Interaction

41 Interactions between continuous variables
No interaction Interaction

42 Interactions between continuous variables
No interaction Interaction

43 Interactions between continuous variables
No interaction Interaction

44 Interpreting continuous interactions
Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) ** word_frequency CD <2e-16 *** word_frequency:CD <2e-16 *** Y ~ b b1*X b2*X b3*(X1*X2)

45 Interpreting continuous interactions
Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) ** word_frequency CD <2e-16 *** word_frequency:CD <2e-16 *** Y ~ (-1.6)*X *X *(X1*X2) Predictions for word frequency 3 and CD 50 Y = (-1.6)* * *(3*50)

46 Interpreting continuous interactions
Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) ** word_frequency CD <2e-16 *** word_frequency:CD <2e-16 *** Y ~ (-1.6)*X *X *(X1*X2) Predictions for word frequency 3 and CD 50 Y = 801

47 Sign of the interaction
Coefficients: Estimate (Intercept) 10 A +1 B +1 A:B +1 A and B have a positive effect on the response, and A and B together increase the response more than either one of them alone

48 Sign of the interaction
Coefficients: Estimate (Intercept) 10 A +1 B +1 A:B -1 A and B have a positive effect on the response, but both together decrease it

49 Sign of the interaction
Coefficients: Estimate (Intercept) 10 A -1 B -1 A:B +1 A and B have a negative effect on the response, but both together increase it

50 Categorical predictors: Simple vs. Main effects
Simple effect = the effect of A at a specific level of B Main effect = the effect of A averaging over all levels of B

51 2 X 2 Example output with treatment coding
attitude = “inf” or “pol” gender = “F” or “M” Estimate (Intercept) attitudepol genderM attitudepol:genderM informal polite female male

52 2 X 2 Example output with treatment coding
attitude = “inf” or “pol” gender = “F” or “M” Estimate (Intercept) attitudepol genderM attitudepol:genderM informal polite female male

53 2 X 2 Example output with treatment coding
attitude = “inf” or “pol” gender = “F” or “M” Estimate (Intercept) attitudepol genderM attitudepol:genderM informal polite female 260 male

54 2 X 2 Example output with treatment coding
attitude = “inf” or “pol” gender = “F” or “M” Estimate (Intercept) attitudepol genderM attitudepol:genderM informal polite female 260 male

55 2 X 2 Example output with treatment coding
attitude = “inf” or “pol” gender = “F” or “M” Estimate (Intercept) attitudepol genderM attitudepol:genderM informal polite female 260 260-30 male

56 2 X 2 Example output with treatment coding
attitude = “inf” or “pol” gender = “F” or “M” Estimate (Intercept) attitudepol genderM attitudepol:genderM informal polite female 260 260-30 male

57 2 X 2 Example output with treatment coding
attitude = “inf” or “pol” gender = “F” or “M” Estimate (Intercept) attitudepol genderM attitudepol:genderM informal polite female 260 260-30 male

58 2 X 2 Example output with treatment coding
attitude = “inf” or “pol” gender = “F” or “M” Estimate (Intercept) attitudepol genderM attitudepol:genderM informal polite female 260 260-30 male

59 2 X 2 Example output with treatment coding
attitude = “inf” or “pol” gender = “F” or “M” Estimate (Intercept) attitudepol genderM attitudepol:genderM informal polite female 260 260-30 male

60 2 X 2 Example output with treatment coding
attitude = “inf” or “pol” gender = “F” or “M” Opposite sign means that the effect of politeness is smaller for males Estimate (Intercept) attitudepol genderM attitudepol:genderM informal polite female 260 230 male 140 125

61 Increasing interpretability with sum or deviation coding
these are not main effects, they are simple effects!! Treatment coding: Estimate (Intercept) attitudepol genderM attitudepol:genderM 15 that is, they are only the differences between specific levels (not the mean differences of attitude/gender)

62 How to change the coding in R
For a two-level factor: contrasts(df$A) = contr.sum(2) For a three-level factor: contrasts(df$B) = contr.sum(3) etc. …

63 How classical tests map to their LM framework counterparts
One-sample t-test against 0 lm(y ~ 1) # t.test(y, mu = 0) Two-sample t-test (unpaired / independent) lm(y ~ group) # t.test(x, y, paired = F) Paired t-test lm(differences ~ 1) # t.test(x, y, paired = T)

64 How classical tests map to their LM framework counterparts
One-way ANOVA etc. lm(y ~ factor) # aov(y ~ x) ANCOVA lm(y ~ factor * covariate) # ?

65 Exercise: working memory data


Download ppt "Generalized Linear Mixed Models"

Similar presentations


Ads by Google