8  Multivariate Analyses

Week 8 - Multivariate analyses

In this workshop, you will fit multivariate regression models and learn how to interpret them. Workshop materials are available in the github repository ECS200.

Background

Assessment

Task to complete before the end of the workshop.

Analyse the relationship between foraging height and mean shrub size (PC2), accounting for foraging substrate ((1) bark, (2) foliage (leaves and flowers), (3) ground, and (4) air) and sex (male, female). Note: this scenario was not described in the paper and has been created for teaching purposes.

First download the foraging_shrub.csv file on GitHub in the ‘data’ folder and load it in R.

Your tasks are to:

1. Fit a suitable model and create the visualisations for diagnostics checking

  • Create one figure to look at the data and the assumption of linearity
  • Create one figure to look at the assumption of equal variances.
  • Create one figure to look at the assumption that the residuals have a normal distribution
  • Optional: Plot leverage versus the standardised residual plots and note if there are any concerning high leverage points.
  • Consider model selection via stepwise selection. Note the model should have an interaction between the two categorical variables.

2. Assess if each assumption is met for the final model

3. Provide a summary of the model and visualise the model

  • Report the p-values in context (you can write this as a comment in the code), you may want to run both anova and summary on your model.
  • Report the slope and confidence interval for each coefficients (you can write this as a comment in the code too)
  • Visualise the model and/or the full relationship. These two snippets of code might help:
foraging_shrub_pred <- ggpredict(foraging_shrub_lm, terms = c("mean_shrub_size", "sex_mf", "substrate"))
## take a look at it and think of some ways to look at the model visually
## Optional: Run this visualisation of everything to see the impact of sex and substrate on the relationship
ggplot(foraging_shrub, aes(x = mean_shrub_size, y = foraging_height_m,
                           colour = sex_mf)) + 
  geom_point(aes(shape = substrate))+
  theme_minimal() +
  labs(title = "Foraging heights vs mean shrub size (PC2)",
       x = "Mean shrub size (PC)",
       y = "Foraging height (m)")

Extra Stuff

A visual explanation of interactive effects