# Exercises for 2.4: Linear models

## Preliminaries

• load the driving.Rdata file.
• type head( driving ) to look at the first few observations
• load the following packages: lsr, car
load( "~/Work/Research/Rbook/workshop_dsto/datasets/driving.Rdata")
library(lsr)
library(car)

## Exercise 2.4.1: Multiple regression

• use lm() to fit a regression model with the RT at time 1 as the outcome variable, including age and errors at time 1 as predictors. Save the results to a variable called mod.1
• use summary() to run the hypothesis tests etc associated with mod.1
• use standardCoefs() to extract standardised regression coefficients

## Exercise 2.4.2: Regression diagnostic plots

• use plot() to draw the standard regression diagnostic plots associated with mod.1

## Exercise 2.4.3: One-way ANOVA

• use aov() to fit an ANOVA model with number of errors at time 1 as the outcome, and with groups defined by distractor type. Save the results to a variable called mod.2.
• use the Anova() function [not anova()] to produce the ANOVA table
• use etaSquared() to estimate the effect size
• use TukeyHSD() to run posthoc tests
• also, use bars() to plot the group means and confidence intervals, since that’s always useful when making sense of the results!

## Exercise 2.4.4: Factorial ANOVA

• use aov() to fit an ANOVA model that has number of errors at time 1 as the outcome, and with groups defined by distractor type and by peak hour. Include interaction terms in the model. Save the results to a variable called mod.3.
• use Anova() to produce the ANOVA table
• use etaSquared() to estimate the effect size
• use TukeyHSD() to run posthoc tests
• also, use bars() to plot the group means and confidence intervals, since that’s always useful when making sense of the results!

## Exercise 2.4.5: Hierarchical regression

• use lm() to fit a stage one model that has errors at time 1 as the outcome, and age and gender as predictors (save it as mod.4a). Then fit the stage 2 model that also includes distractor as an additional predictor (mod.4b).
• use anova() to run the hierarchical regression