Set R to use the sum-to-zero definition of effects and load the
police
data frame with the following commands:
options(contrasts=c("contr.sum","contr.poly"))
load(url("http://pnb.mcmaster.ca/bennett/psy710/datasets/police20.rda") )
Answer all of the following questions and submit your answers as a script file on Avenue 2 Learn. Make sure to begin your script file with the following lines:
# PSYCH 710 Lab 5 Homework
# Script File
# OCT-2023
# Your Name: <<Your name here>>
# Student ID: <<Your ID here>>
# Collaborators: <<Names of your collaborators here>>
Also, make sure that text that is not an R command is preceded by a comment symbol (#). For example, you can insert questions or comments among your commands like this:
# The following command doesn't work... not sure why...
# ttest(x=g1,y=g2) # was trying to do a t test
The data frame police
contains data from a hypothetical
3x3 between-subjects, factorial experiment. A police department
conducted an experiment to evaluate its human relations course for new
officers. The independent variables were the type of beat to which
officers were assigned during the course (factor beat
) and
the length of the course (factor course
). Each subject was
assigned randomly to a single combination of beat
and
course.
The factor beat
has three levels:
innercity
, middleclass
, and
upperclass
. The (unordered) factor course
also
has three levels: short
, medium
, and
long.
The dependent variable is attitude
toward minority groups following the course. The data frame also
contains a variable, id
, which is an id number assigned to
each subject.
The following code creates a new factor, condition
, that
represents the cells in the police
experiment, and then
plots the data.
# ?interaction # read the help page
police$condition <- interaction(police$course,police$beat)
levels(police$condition) <- c("short.inner","med.inner","long.inner",
"short.mid","med.mid","long.mid","short.up","med.up","long.up")
op <- par(no.readonly = T)
par(mar=c(7,4,4,1)+.1)
boxplot(attitude~condition,data=police,xlab="",ylab="attitude",cex.axis=1.2,cex.lab=1.5,las=2)
Use factorial ANOVA to evaluate the main effects
beat
and course
and the beat
x
course
interaction.
Use bartlett.test
to evaluate the hypothesis that
the variance is equal across conditions/groups.
Inspect the data and suggest a reason why the beat \(\times\) course interaction is significant.
course
by performing a
linear contrast that evaluates the difference between mean
attitude
in the short
and long
course conditions. Also, use an interaction contrast to determine if the
result of your comparison of short
and long
courses depends on the level of beat
. Your answer
should include the results of the statistical tests (e.g., values of F,
t, p, etc.), and your conclusion regarding the null hypotheses for the
course
contrast and the interaction contrast.short
and long
courses at each level of the beat
variable. Suppose you
want to evaluate the hypothesis that the value of short-vs.-long
contrast in the innercity
condition differed from the
average of the short-vs.-long contrast values in the
middleclass
and upperclass
conditions. Design
a set of contrast weights that you could use to evaluate this hypothesis
and then perform the contrast.