Created
April 16, 2020 20:09
-
-
Save jwbowers/ab639e6a2045a054e457c52df03c0982 to your computer and use it in GitHub Desktop.
A simple sampling design for declare design
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> pop <- declare_population(N, | |
+ covid=rbinom(N,size=1,prob=covidprob)) | |
> samp <- declare_sampling(n=n) | |
> sim_design <- pop + samp | |
> set.seed(12345) | |
> tmp <- draw_data(redesign(sim_design,N=40,n=20,covidprob=.5)) | |
> table(tmp$covid) | |
0 1 | |
9 11 | |
> stopifnot( abs( mean(tmp$covid) - .5 ) < .1) | |
> estimand <- declare_estimand(mean(covid),label="prop covid") | |
> estimator1 <- declare_estimator(covid~1,model=lm_robust, se_type="HC0", label="prop positive") | |
> estimator2 <- declare_estimator(,label="prop pos with error") | |
> sim_design_est <- sim_design + estimand + estimator1 ## + estimator2 | |
> d_N40_n20_p5 <- redesign(sim_design_est,N=40,n=20,covidprob=.5) | |
> draw_estimands(d_N40_n20_p5) | |
estimand_label estimand | |
1 prop covid 0.6 | |
> draw_estimands(d_N40_n20_p5) | |
estimand_label estimand | |
1 prop covid 0.5 | |
> draw_estimands(d_N40_n20_p5) | |
estimand_label estimand | |
1 prop covid 0.4 | |
> draw_estimates(d_N40_n20_p5) | |
estimator_label term estimate std.error statistic p.value conf.low conf.high df outcome | |
1 prop positive (Intercept) 0.4 0.1095445 3.651484 0.001697388 0.1707207 0.6292793 19 covid | |
> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment