-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpoisson_model_code_completed.Rmd
93 lines (62 loc) · 1.36 KB
/
poisson_model_code_completed.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
---
title: "Poisson Regression Code"
output: html_document
---
# Load and Format data
Here, we read and format data.
```{r}
library("pscl")
bioChemists$kid5 <- factor(bioChemists$kid5)
```
# Summary of Data
```{r}
head(bioChemists)
```
```{r}
summary(bioChemists)
```
# Poisson Regression in R
## Constant Term
We will now build a logistic model with a constant term and a TotalVolume term.
```{r}
model_constant <-glm(art ~ 1, data = bioChemists,family = poisson(link = log))
```
### Model Summary
```{r}
summary(model_constant)
```
You can also get the coefficents of the model.
```{r}
print(coef(model_constant))
```
## Model with Constant + Gender Term
We will now build a Poisson model with a constant term and sex.
```{r}
model_sex <-glm(art ~ 1 + fem, data = bioChemists,family = poisson(link = log))
```
### Model Summary
```{r}
summary(model_sex)
```
## Model Comparison
We can compare models using the anova function.
```{r}
anova(model_constant, model_sex, test='Chisq')
```
## Model with fem and ment
### Create Model
```{r}
model_sex_ment <- glm(art ~ 1 + fem + ment, data=bioChemists, family=poisson(link=log))
```
### Model Summary
```{r}
summary(model_sex_ment)
```
### Anova with null model
```{r}
anova(model_constant, model_sex_ment, test='Chisq')
```
### Anova with model with only sex
```{r}
anova(model_sex, model_sex_ment, test='Chisq')
```