Back to Course

FoSSA Français

0% Complete
0/0 Steps
  1. Information sur le cours

    Rencontrez l'équipe enseignante
  2. Jeu de données du cours 1
  3. Jeu de données du cours 2
  4. MODULE A1: INTRODUCTION AUX STATISTIQUES AVEC R ET STATA
    A1.1 Qu'est-ce que les Statistiques?
  5. A1.2.1a Introduction à Stata
  6. A1.2.2b: Introduction à R
  7. A1.2.2c: Introduction to SPSS
  8. A1.3: Statistiques Descriptives
  9. A1.4: Estimations et Intervalles de Confiance
  10. A1.5: Tests d'Hypothèses
  11. A1.6: Transformation de Variables
  12. Fin du Module A1
    1 Quiz
  13. MODULE A2: CALCULS DE PUISSANCE STATISTIQUE & DE TAILLE D’ÉCHANTILLON
    A2.1 Concepts Clés
  14. A2.2 Calculs de puissance pour une différence de moyennes
  15. A2.3 Calculs de puissance pour une différence de proportions
  16. A2.4 Calcul de taille d’échantillon pour les essais randomisés (RCTs)
  17. A2.5 Calculs de taille d’échantillon pour les études transversales (ou sondages)
  18. A2.6 Calcul de taille d'échantillon pour un devis cas-contrôle
  19. Fin du Module A2
    1 Quiz
  20. MODULE B1: RÉGRESSION LINÉAIRE
    B1.1 Corrélation et Nuages de Points (scatterplots)
  21. B1.2 Différences Entre Moyennes (ANOVA à un facteur)
  22. B1.3 Régression Linéaire Univariée
  23. B1.4 Régression Linéaire Multivariée
  24. B1.5 Sélection de Modèles et Tests F
  25. B1.6 Diagnostics de Régression
  26. Fin du Module B1
    1 Quiz
  27. MODULE B2: COMPARAISONS MULTIPLES & MESURES RÉPÉTÉES
    B2.1 ANOVA Approfondie— Tests Post-Hoc
  28. B2.2 Correction pour Comparaisons Multiples
  29. B2.3 ANOVA à deux facteurs (Two-way ANOVA)
  30. B2.4 Mesures Répétées et Test T Apparié
  31. B2.5 ANOVA pour Mesures Répétées
  32. Fin du Module B2
    1 Quiz
  33. MODULE B3: MÉTHODES NON-PARAMETRIC
    B3.1 Hypothèses des Tests Paramétriques
  34. B3.2 Test U de Mann-Whitney
  35. B3.3 Test de Kruskal-Wallis
  36. B3.4 Test des rangs signés de Wilcoxon
  37. B3.5 Test de Friedman
  38. B3.6 Corrélation des Rangs de Spearman
  39. Fin du Module B3
    1 Quiz
  40. MODULE C1: DONNÉES BINAIRES & RÉGRESSION LOGISTIQUE
    C1.1 Introduction à la prévalence, au Risque, aux Cotes (Odds) et aux Taux
  41. C1.2 Le Test du Chi Carré & le Test de Tendance
  42. C1.3 Régression Logistique Univariée
  43. C1.4 Régression Logistique Multivariée
  44. Fin du Module C1
    1 Quiz
  45. MODULE C2: DONNÉES DE SURVIE
    C2.1 Introduction aux Données de Survie
  46. C2.2 Fonction de Survie de Kaplan-Meier & Test du Log-Rank
  47. C2.3 Régression de Cox à Risque Proportionnel
  48. C2.4 Régression de Poisson
  49. Fin du Module C2
    1 Quiz
Lesson 29 of 49
In Progress

B2.3 ANOVA à deux facteurs (Two-way ANOVA)

Learning Outcomes

By the end of this section, students will be able to:

  • Explain when and how to use post hoc testing 
  • Explain the concept of multiple comparisons and be able to correct for it in their analysis
  • Apply extensions to the basic ANOVA test and interpret their results
  • Explain when and how to use repeated measures statistics

You can download a copy of the slides here: B2.3 Two-way ANOVA

B2.3 PRACTICAL: R

We can also use the ANOVA to further investigate the effect of different categorical explanatory variables.

To demonstrate this, we are going to use a two-way ANOVA to examine multiple explanatory variables and interactions between them.

To continue our example, we want to examine if there are significant differences in the mean SBP between BMI groups that also smoke (or not).

For a two-way ANOVA the command is the same as in B2.1, but with a second variable:

white.data$smoked<-factor(white.data$currsmoker)

model2<- aov(sbp~bmi_fact+smoked, data=white.data)

To make this a two-way factorial ANOVA (i.e with an interaction between the independent variables), we substitute an ‘*’ for the ‘+’ sign:

model3<- aov(sbp~bmi_fact*smoked, data=white.data)

> summary(model3)

                        Df  Sum Sq Mean Sq F value   Pr(>F)   

bmi_fact           3    6415  2138.2   6.981 0.000111 ***

smoked             1     190   189.6   0.619 0.431468   

bmi_fact:smoked    3    1558   519.2   1.695 0.165772   

Residuals       4288 1313282   306.3                    

Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

31 observations deleted due to missingness

  • Question B2.3a: Run the two-way factorial ANOVA and interpret your output. How does this compare to the previous test on these relationships?  
  • Question B2.3b: When we are using interaction terms like this if they do not contribute to the model (i.e. are not significant) we can remove them and see if this makes a difference to the other relationships. Go back and run the test a second time but without the interaction between BMI group and current smoking included. What do you notice?
Answer

Answer B2.3a: Test one, including the interaction term, shows a significant relationship between BMI group and SBP but current smoking and the interaction are non-significant. The interaction is adding the least to the model (has the highest P value).

Answer B2.3b:

> model2<- aov(sbp~bmi_fact+smoked, data=white.data)

> summary(model2)

  Df  Sum Sq Mean Sq F value   Pr(>F)   

bmi_fact       3    6415  2138.2   6.978 0.000111 ***

smoked         1     190   189.6   0.619 0.431580   

Residuals   4291 1314840   306.4                    

Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

31 observations deleted due to missingness

When we remove the interaction term we see the BMI grouping is still showing a significant relationship on its own, but that current smoker is not. If you go back to practical B1.4 you can compare these results to those from the multivariable linear regression which included these two variables plus LDL-C. You can see that ANOVA without the interaction, is very similar to the linear regression. More on this in section B2.6

Minimal Adequate Model

As current smoker is also non-significant on its own, so you could choose to remove this as well and see what happens to the model. This is a simplified method of model optimisation known as the Minimal Adequate Model, meaning that you remove variables in order from least significant to most significant, until you end up with the simplest model you can. This can be a helpful process if you need to mentally work through your model and understand what each part is contributing. You never want to remove a variable that is significant on its own, or part of a significant interaction, but you can see how removing other non-significant variables can change the overall model. You can do this with any type of General Linear Model.

B2.3 PRACTICAL: Stata

We can also use the ANOVA to further investigate the effect of different categorical explanatory variables.

To demonstrate this, we are going to use a two-way ANOVA to examine multiple explanatory variables and interactions between them.

For a two-way ANOVA the command is:

anova outcome_var var1 var2

Var1 and var2 are assumed to be categorical (but you can override this).

To continue our example, we want to examine if there are significant differences in the mean SBP between BMI groups that also smoke (or not).

To make this a two-way factorial ANOVA (i.e with an interaction between the independent variables), we type:

anova sbp bmi_grp4##currsmoker

  • Question B2.3a: Run the two-way factorial ANOVA and interpret your output. How does this compare to the previous test on these relationships?  
  • Question B2.3b: When we are using interaction terms like this if they do not contribute to the model (i.e. are not significant) we can remove them and see if this makes a difference to the other relationships. Go back and run the test a second time but without the interaction between BMI group and current smoking included. What do you notice?
Answer

Answer B2.3a: Test one, including the interaction term, shows a significant relationship between the group of explanatory variables and the dependant variables but each of the variables individually (and the interaction) are non-significant. The interaction is adding the least to the model (has the highest P value and the smallest F value).

Answer B2.3b:

When we remove the interaction term we see that the F value for the model overall increases, and the BMI grouping is now showing a significant relationship on its own. If you go back to practical B1.4 you can compare these results to those from the multivariable linear regression which included these two variables plus LDL-C. You can see that ANOVA without the interaction, is very similar to the linear regression. More on this in section B2.6

Minimal Adequate Model

As current smoker is also non-significant on its own, so you could choose to remove this as well and see what happens to the model. This is a simplified method of model optimisation known as the Minimal Adequate Model, meaning that you remove variables in order from least significant to most significant, until you end up with the simplest model you can. This can be a helpful process if you need to mentally work through your model and understand what each part is contributing. You never want to remove a variable that is significant on its own, or part of a significant interaction, but you can see how removing other non-significant variables can change the overall model. You can do this with any type of General Linear Model.

B2.3 PRACTICAL: SPSS

We can also use the ANOVA to further investigate the effect of different categorical explanatory variables.

To demonstrate this, we are going to go back to the General Linear Model commands in SPSS, which gives us the flexibility to add multiple explanatory variables. When we input just categorical variables into the GLM box it will automatically run an ANOVA for us.

Select

Analyze >> General Linear Model >> Univariate

As before put SBP in the Dependant Variable box, and BMI grouping and current smoker in the Fixed Factors box.

Now click on Model on the right hand side.

This time we want to select ‘Build terms’ at the top of the box, we then move each of the variables from the left hand side to the right. We also want to specify the interaction term. To do this hold down the shift key on your keyboard while selecting both terms in the left hand box and then press the blue arrow. Leave the drop down menu in the centre on the default option of ‘Interaction’ then press continue.

You can also use the buttons on the right hand side choose to add in post hoc tests for each explanatory variable, save your residuals, display parameter estimates, or any of the things we did in Module B1.

Run the test and interpret your output. How does this compare to the previous test on these relationships?  

When we are using interaction terms like this if they do not contribute to the model (i.e. are not significant) we can remove them and see if this makes a difference to the other relationships.

Go back and run the test a second time but without the interaction between BMI group and current smoking included. What do you notice?

Answer

Test one, including the interaction term, shows a significant relationship between the group of explanatory variables and the dependant variables (in the corrected model) but each of the variables individually (and the interaction) are non-significant. The interaction is adding the least to the model (has the highest P value).

When we remove the interaction term we see that the F value for the model overall increases, and the BMI grouping is now showing a significant relationship on its own. If you go back to practical B1.4 you can compare these results to those from the multivariable linear regression which included these two variables plus LDL-C. You can see that ANOVA without the interaction, is very similar to the linear regression. More on this in section B2.6

Minimal Adequate Model

As current smoker is also non-significant on its own, so you could choose to remove this as well and see what happens to the model. This is a simplified method of model optimisation known as the Minimal Adequate Model, meaning that you remove variables in order from least significant to most significant, until you end up with the simplest model you can. This can be a helpful process if you need to mentally work through your model and understand what each part is contributing. You never want to remove a variable that is significant on its own, or part of a significant interaction, but you can see how removing other non-significant variables can change the overall model. You can do this with any type of General Linear Model.

👋 Before you go, leave an anonymous rating & feedback

Average rating 4.8 / 5. Vote count: 9

No votes so far! Be the first to rate this post.

Please share any positive or negative feedback you may have.

Feedback is completely anonymous

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Questions or comments?x