R-help to exercise 16 in BSS

 

 

# Read the data into a dataframe, give names to the variables, and inspect the data:

gun<-read.table("http://www.math.uio.no/avdc/kurs/STK4900/data/gun.dat", col.names=c("method","phys","team","rounds"))

gun

 

# Check that the data correspond to those given in the exercise.

 

# Attach the dataframe

attach(gun)

 

# QUESTION 1)

 

# Compute correlations:

cor(gun)

 

# How are the correlations between the covariates ("method","phys","team")?

# Can you explain the reason for this?

# How are the correlations between the covariates and "rounds"?

 

 

# QUESTIONS 2-4)

# Define the covariates as factors (categorical covariates):

method=factor(method)

phys=factor(phys)

team=factor(team)

 

# Use sum-contrasts (which is common for anova):

options(contrasts=c("contr.sum","contr.poly"))

 

# Fit a model with main effects and interactions and write the anova table:

gfit<-lm(rounds~method*phys*team)

anova(gfit)

 

# What does the anova table tell you? Which factors are significant?

 

# Look at the estimates:

summary(gfit)

 

# Give an interpretation of the (most important) estimates.