-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathPoisson Regression.Rmd
63 lines (51 loc) · 1.21 KB
/
Poisson Regression.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
---
title: "Poisson Regression"
author: "Murat Koptur"
date: "`r format(Sys.time(), '%d %B %Y')`"
output: rmarkdown::github_document
---
```{r echo=FALSE}
knitr::opts_chunk$set(fig.path='figures/poisson-')
```
```{r}
library(bayesplot)
library(ggplot2)
library(readr)
library(reshape2)
library(rstanarm)
```
```{r}
awards <- read_csv("../data/awards.csv",
col_types = cols(id = col_skip(), prog = col_factor(levels = c("1", "2", "3"))))
head(awards)
```
```{r}
awards_melted <- melt(awards)
head(awards_melted)
```
```{r}
ggplot(data = awards_melted, aes(x = value)) +
geom_histogram(aes(y = ..ncount..)) +
geom_density(aes(y = ..scaled..)) +
facet_wrap(~variable, scales = "free") +
labs(x = "Values", y = "Frequencies", title = "Histograms")
```
```{r}
awards$math <- scale(awards$math)
```
```{r}
model1 <- glm(num_awards ~ math + prog, data = awards, family = poisson)
summary(model1)
```
```{r}
model2 <- stan_glm(num_awards ~ math + prog, data = awards, family = poisson,
prior = normal(0, 10), prior_intercept = normal(0, 10))
summary(model2)
```
```{r}
posterior_interval(model2, prob = 0.95)
plot(model2, plotfun = "areas", prob = 0.95)
```
```{r}
pp_check(model2)
```