-
Notifications
You must be signed in to change notification settings - Fork 1
/
poisson_model_exercises.Rmd
125 lines (73 loc) · 2.11 KB
/
poisson_model_exercises.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
---
title: "linear_model_exercises"
output: html_document
---
# Exercise 0:
Load the library below.
```{r}
library(pscl)
```
## Exercise 1: Model with fem, ment_cat.
As seen from the box plots in the presentation and below, the mean of the distributions for each ment might not be linear.
```{r}
library(reshape2)
```
```{r}
df.men <- melt(bioChemists[bioChemists$fem == "Men",c("ment","art")], id.var = "ment")
ggplot(data = df.men, aes(x=ment, y=value)) + geom_boxplot(aes(group=ment))
```
```{r}
df.women <- melt(bioChemists[bioChemists$fem == "Women",c("ment","art")], id.var = "ment")
ggplot(data = df.women, aes(x=ment, y=value)) + geom_boxplot(aes(group=ment)) + ggtitle("Box plot of art vs ment for women")
```
0. It might be better to treat each ment numerical value as a category. Run the code below to create a new column with ment categories.
```{r}
bioChemists$ment_cat <- as.factor(bioChemists$ment)
```
1. Create a model with fem and ment_cat.
```{r}
#solution here
```
2. Print the summary of the model.
```{r}
#solution here
```
3. Using ANOVA, compare this model to the model with only fem.
```{r}
#solution here
```
4. Is the model with ment_cat better than the model with ment?
## Exercise 2: Model with fem, ment interaction
1. Run the code below to create a model with fem and ment interaction.
```{r}
#solution here
```
2. Print the summary of the model.
```{r}
#solution here
```
3. Interpret the model.
i) For men
ii) For women
4. Interpret the significance of effect of the interaction coefficient.
5. Compare the model with ment and sex interaction to the model with no interaction between ment and sex.
```{r}
#solution here
```
## Exercise 3: Model with fem, ment, phd
1. Run the code below to create a model with fem, ment and phd.
```{r}
#solution here
```
2. Print the summary of the model.
```{r}
#solution here
```
3. Interpret the model for each of the cases below
i) For men
ii) For women
4. Interpret the significance of effect of the phd coefficient.
5. Compare the model with ment, sex and phd to the model with ment and sex only.
```{r}
#solution here
```