Course Notes Home

Exercise 1

Write a for loop to fit a linear regression model for each of the 7 test scores as the dependent variable including age, and collection site as covariates. Save the regression coefficient and P-value for each test. Use the following excerpt of code to create an empty matrix to fill with results.

output<-matrix(data = NA, nrow = 7, ncol = 2)
rownames(output)<-paste("Test", 1:7, sep = "")
colnames(output)<-c("Coeff", "P")

Use a scatterplot to visualise any significant results (P < 0.05). Can you add a line of best fit from your regression model?

Add an interaction term to the model to see if the effect differs between males and females.

Recreate the scatterplot and add two lines of best fit, one for females and one for males.

Solutions