-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexploration.R
More file actions
31 lines (25 loc) · 867 Bytes
/
exploration.R
File metadata and controls
31 lines (25 loc) · 867 Bytes
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
library(survey)
library(haven)
source("CIarrFcn.R")
# Integrating survey package output in with the existing function
surveyci <- function(formula,design,deff) {
if(length(all.vars(formula))>1) {
message("Nope.")
return()
}
p <- svymean(formula,design,na.rm=TRUE,deff=deff)
n <- sum(c(!is.na(design$variables[all.vars(formula)])))
n_eff <- n/deff(p)
CIarrFcn(p*n_eff,n_eff,0.05)
}
# Example
ess_rf <- read_dta("chapter_exercises_ess6rf.dta")
ess_design <- svydesign(id=~psu,strata=~stratify,weights=~pspwght,data=ess_rf)
surveyci(~voted_lastelection,ess_design,deff="replace")
voted_mean <- svymean(~voted_lastelection,ess_design,na.rm=TRUE,deff="replace")
# Allow infinite df
# Wald
confint(voted_mean,df=Inf)
# Logit
confint(svyciprop(~voted_lastelection,ess_design,method="logit",df=Inf))
# Similar but not identical results so far...