forked from saudiwin/idealstan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_hier_cov.R
53 lines (42 loc) · 1.71 KB
/
test_hier_cov.R
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
# test hierarchical covariates
require(idealstan)
require(ggplot2)
require(bayesplot)
require(tidyverse)
require(lubridate)
# use a small subset of the rollcall data
rollcalls <- readRDS('~/idalstan_compare/data/rollcalls.rds') %>%
select(cast_code,rollnumber,congress,year,district_code,state_abbrev,date,
bioname,party_code,date_month,unemp_rate) %>%
mutate(item=paste0(congress,"_",rollnumber),
cast_code=recode_factor(cast_code,Abstention=NA_character_),
cast_code=as.numeric(cast_code)-1,
bioname=factor(bioname)) %>%
filter(bioname %in% c("BARTON, Joe Linus",
"DeFAZIO, Peter Anthony",
"LEVIN, Sander Martin",
"ROGERS, Harold Dallas (Hal)"),
date_month<ymd("1991-01-01")) %>%
distinct
unemp1 <- rollcalls %>%
id_make(outcome_disc="cast_code",
item_id="item",
person_id="bioname",
group_id="party_code",
time_id = "date_month",
person_cov = ~unemp_rate*party_code)
unemp1_fit <- id_estimate(unemp1,model_type=2,
vary_ideal_pts = 'AR1',
niters=300,
warmup=300,
nchains=1,
ncores=1,const_type = "persons",
restrict_ind_high = "BARTON, Joe Linus",
restrict_ind_low="DeFAZIO, Peter Anthony",
fix_low=0,restrict_sd_low = 3,
fixtype="prefix",time_center_cutoff = 5,
id_refresh=100)
# now let's do some "technical" analysis
id_plot_legis_dyn(unemp1_fit)
debugonce(id_plot_cov)
id_plot_cov(unemp1_fit)