forked from UW-POLS503/assignment-2017-2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment2.R
More file actions
53 lines (36 loc) · 1.39 KB
/
Copy pathAssignment2.R
File metadata and controls
53 lines (36 loc) · 1.39 KB
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
M1 <- lm(paupratiodiff ~ outratiodiff + year + Type, data = pauperism)
M2 <- lm(paupratiodiff ~ outratiodiff + (popratiodiff + oldratiodiff) * (year + Type), data = pauperism)
M3 <- lm(-1 + paupratiodiff ~ (outratiodiff + popratiodiff + oldratiodiff) * (year + Type), data = pauperism)
M4 <- lm(paupratiodiff ~ (outratiodiff + popratiodiff + oldratiodiff) * (year + Type), data = pauperism)
M1
M2
M3
M4
### y in a linear regression is predicted value.
### difference between residual and error: distance computed from a data set (in a model) is a residual; error is the true value of the residual. basically, residual is error with hat on it (estimation of the error)
# Bootstrapping
bsdata <- modelr::bootstrap(car::Duncan, n = 1024)
glimpse(bsdata)
bsdata[["strap"]][[1]]
str(bsdata[["strap"]][[1]])
library(broom)
bs_coef <- map_df(bsdata$strap, function(dat) {
lm(prestige ~ type + income + education, data = dat) %>%
tidy() %>%
select(term, estimate)
})
# The quantile confidence intervals:
alpha <- 0.95
bs_coef %>%
group_by(term) %>%
summarise(
conf.low = quantile(estimate, (1-alpha) / 2),
conf.high = quantile(estimate, 1 - (1 - alpha) / 2)
) %>%
left_join(select(tidy(mod),
term, estimate),
by = "term") %>%
select(term, estimate)
library(devtools)
install_github("jrnold/resamplr")
bsdata <- bootstrap(group_by(car::Duncan, type), 1024)