To be solved at home before the exercise session.
y
for three groups (x
). Each group has sample size 15. Below are shown boxplots of the groups, along with outputs given by ANOVA and the Kruskal-Wallis test for the data.
boxplot(y ~ x, data = my_data)
summary(aov(y ~ x, data = my_data))
## Df Sum Sq Mean Sq F value Pr(>F)
## x 1 1.13 1.129 0.586 0.448
## Residuals 43 82.89 1.928
kruskal.test(y ~ x, data = my_data)
##
## Kruskal-Wallis rank sum test
##
## data: y by x
## Kruskal-Wallis chi-squared = 10.185, df = 2, p-value = 0.006142
To be solved at the exercise session.
Sepal.Width
.
mtcars
has measurements for 32 cars. We investigate the relationship between mpg
(miles/gallon, the response) and hp
and am
(horsepowers and transmission type, the explanatory variables) through an analysis of covariance.
lm
, fit a regression model with the covariates hp
, am
and hp:am
(the final one is an interaction effect, the product of the two covariates).mtcars
data set but replace the variable am
with the variable gear
(and make sure its type is factor
). Fit the linear regression model mpg ~ hp + gear
and find out how the function anova
can be used to test whether all regression coefficients related to gear
are equal to zero simultaneously. Note that the situation is different from problem 2 as gear
has three classes (i.e., two coefficients) and thus the \(p\)-values from the model only relate to the hypotheses whether the two coefficients can be set to zero individually.