Last updated: 2022-08-17
Checks: 6 1
Knit directory: schoolsout/
This reproducible R Markdown analysis was created with workflowr (version 1.7.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
The R Markdown file has unstaged changes. To know which version of
the R Markdown file created these results, you’ll want to first commit
it to the Git repo. If you’re still working on the analysis, you can
ignore this warning. When you’re finished, you can run
wflow_publish
to commit the R Markdown file and build the
HTML.
Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.
The command set.seed(20220817)
was run prior to running
the code in the R Markdown file. Setting a seed ensures that any results
that rely on randomness, e.g. subsampling or permutations, are
reproducible.
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.
Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.
The results in this page were generated with repository version 39e6f20. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.
Note that you need to be careful to ensure that all relevant files for
the analysis have been committed to Git prior to generating the results
(you can use wflow_publish
or
wflow_git_commit
). workflowr only checks the R Markdown
file, but you know if there are other scripts or data files that it
depends on. Below is the status of the Git repository when the results
were generated:
Ignored files:
Ignored: .Rhistory
Ignored: .Rproj.user/
Unstaged changes:
Modified: DESCRIPTION
Modified: analysis/main-analysis.Rmd
Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.
These are the previous versions of the repository in which changes were
made to the R Markdown (analysis/main-analysis.Rmd
) and
HTML (docs/main-analysis.html
) files. If you’ve configured
a remote Git repository (see ?wflow_git_remote
), click on
the hyperlinks in the table below to view the files as they were in that
past version.
File | Version | Author | Date | Message |
---|---|---|---|---|
Rmd | 2702044 | Jake Hughey | 2022-08-17 | again. |
html | 5d8c8de | Jake Hughey | 2022-08-17 | Build site. |
html | c9d37eb | Jake Hughey | 2022-08-17 | still trying. |
html | 5a451bd | Jake Hughey | 2022-08-17 | updated ubuntu version. |
Rmd | bd34143 | Jake Hughey | 2022-08-17 | updated main analysis. |
html | bd34143 | Jake Hughey | 2022-08-17 | updated main analysis. |
Rmd | a6c4acb | Jake Hughey | 2022-08-17 | added analysis file. |
Load packages and data.
library('broom')
library('cowplot')
library('data.table')
library('ggplot2')
library('haven')
library('huxtable')
Attaching package: 'huxtable'
The following object is masked from 'package:ggplot2':
theme_grey
theme_set(
theme_bw() +
theme(axis.text = element_text(color = 'black'),
panel.grid.minor = element_blank(),
legend.margin = margin(t = 0, r = 0, b = 0, l = 0, unit = 'cm')))
dataDir = 'data'
dOrig = setDT(read_dta(file.path(dataDir, 'master.dta')))
Melt data.table to long format, scale outcomes by standard deviation of the control group, and rename stuff.
outcomes = data.table(
level = c('average_level', 'place_value_correct', 'operation_frac_correct'),
label = c('Average level', 'Place value', 'Fractions'))
dMelt = melt(
dOrig,
id.vars = c('unique_id', 'treatment', 'treat_pool', 'treat_target', 'tarl_prev'),
measure.vars = outcomes$level, variable.name = 'outcome_name',
value.name = 'outcome_value', variable.factor = FALSE)
dMelt[
, outcome_value := outcome_value / sd(outcome_value[treatment == 0], na.rm = TRUE),
by = outcome_name]
dMelt[, outcome_name := factor(outcome_name, outcomes$level, outcomes$label)]
for (j in c('treat_pool', 'treat_target')) {
a = attr(dOrig[[j]], 'labels')
dMelt[, x := factor(x, a, names(a)), env = list(x = j)]}
Run linear regression on each outcome (although a couple are binary)
for both codings of treatment variable. lm()
automatically
removes missing values.
dFitPool = dMelt[
, .(treat_type = 'pool',
fit = list(lm(outcome_value ~ treat_pool + tarl_prev, data = .SD))),
keyby = outcome_name]
dFitTarget = dMelt[
, .(treat_type = 'target',
fit = list(lm(outcome_value ~ treat_target + tarl_prev, data = .SD))),
keyby = outcome_name]
dFit = rbind(dFitPool, dFitTarget)
dTidy = dFit[, tidy(fit[[1L]], conf.int = TRUE), by = .(treat_type, outcome_name)]
dTidy[, term := factor(
term,
c('(Intercept)', 'treat_poolSMS Only', 'treat_poolPhone + SMS',
'treat_targetNot Targeted', 'treat_targetTargeted', 'tarl_prev'),
c('Intercept', 'SMS Only', 'Phone + SMS', 'Not Targeted', 'Targeted', 'Previous TARL'))]
# dFitPool = dMelt[
# , tidy(lm(
# outcome_value ~ treat_pool + tarl_prev, data = .SD), conf.int = TRUE),
# keyby = outcome_name]
#
# dFitTarget = dMelt[
# , tidy(lm(
# outcome_value ~ treat_target + tarl_prev, data = .SD), conf.int = TRUE),
# keyby = outcome_name]
# dFit = rbind(dFitPool, dFitTarget)
# dFit[, term := factor(
# term,
# c('(Intercept)', 'treat_poolSMS Only', 'treat_poolPhone + SMS',
# 'treat_targetNot Targeted', 'treat_targetTargeted', 'tarl_prev'),
# c('Intercept', 'SMS Only', 'Phone + SMS', 'Not Targeted', 'Targeted', 'Previous TARL'))]
Plot coefficients.
p = ggplot(dTidy[!(term %in% c('Intercept', 'Previous TARL'))]) +
geom_hline(yintercept = 0, color = 'gray', linetype = 'dashed') +
geom_point(
aes(x = term, y = estimate, color = outcome_name, shape = outcome_name),
position = position_dodge(width = 0.5), size = 3) +
geom_linerange(
aes(x = term, ymin = conf.low, ymax = conf.high, color = outcome_name),
position = position_dodge(width = 0.5), size = 1, alpha = 0.5) +
labs(x = 'Treatment', y = 'Learning gains (in standard deviations)',
color = 'Outcome', shape = 'Outcome') +
scale_color_brewer(palette = 'Set2')
p
Version | Author | Date |
---|---|---|
bd34143 | Jake Hughey | 2022-08-17 |
fits = dFit[treat_type == 'pool']$fit
names(fits) = dFit[treat_type == 'pool']$outcome_name
huxreg(
fits, ci_level = 0.95,
error_format = "({std.error})\n[{p.value}]\n{{{conf.low}, {conf.high}}}",
coefs = c('SMS Only' = 'treat_poolSMS Only', 'Phone + SMS' = 'treat_poolPhone + SMS'),
statistics = c('Observations' = 'nobs'))
Average level | Place value | Fractions | |
---|---|---|---|
SMS Only | 0.024 | 0.009 | 0.047 |
(0.046) [0.600] {-0.066, 0.114} | (0.044) [0.833] {-0.078, 0.096} | (0.046) [0.305] {-0.043, 0.136} | |
Phone + SMS | 0.121 ** | 0.114 * | 0.075 |
(0.046) [0.008] {0.031, 0.210} | (0.044) [0.010] {0.027, 0.201} | (0.046) [0.099] {-0.014, 0.165} | |
Observations | 2815 | 2881 | 2751 |
*** p < 0.001; ** p < 0.01; * p < 0.05. |
fits = dFit[treat_type == 'target']$fit
names(fits) = dFit[treat_type == 'target']$outcome_name
huxreg(
fits, ci_level = 0.95,
error_format = "({std.error})\n[{p.value}]\n{{{conf.low}, {conf.high}}}",
coefs = c('Not Targeted' = 'treat_targetNot Targeted', 'Targeted' = 'treat_targetTargeted'),
statistics = c('Observations' = 'nobs'))
Average level | Place value | Fractions | |
---|---|---|---|
Not Targeted | 0.070 | 0.026 | 0.029 |
(0.046) [0.127] {-0.020, 0.159} | (0.044) [0.564] {-0.061, 0.113} | (0.046) [0.521] {-0.060, 0.119} | |
Targeted | 0.076 | 0.098 * | 0.093 * |
(0.046) [0.099] {-0.014, 0.165} | (0.044) [0.027] {0.011, 0.185} | (0.046) [0.042] {0.003, 0.182} | |
Observations | 2815 | 2881 | 2751 |
*** p < 0.001; ** p < 0.01; * p < 0.05. |
sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur ... 10.16
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] huxtable_5.5.0 haven_2.5.0 ggplot2_3.3.6 data.table_1.14.3
[5] cowplot_1.1.1 broom_1.0.0
loaded via a namespace (and not attached):
[1] tidyselect_1.1.2 xfun_0.32 bslib_0.4.0 purrr_0.3.4
[5] colorspace_2.0-3 vctrs_0.4.1 generics_0.1.3 htmltools_0.5.3
[9] yaml_2.3.5 utf8_1.2.2 rlang_1.0.4 jquerylib_0.1.4
[13] later_1.3.0 pillar_1.8.0 glue_1.6.2 withr_2.5.0
[17] DBI_1.1.3 RColorBrewer_1.1-3 lifecycle_1.0.1 stringr_1.4.0
[21] commonmark_1.8.0 munsell_0.5.0 gtable_0.3.0 workflowr_1.7.0
[25] evaluate_0.16 labeling_0.4.2 forcats_0.5.1 knitr_1.39
[29] tzdb_0.3.0 fastmap_1.1.0 httpuv_1.6.5 fansi_1.0.3
[33] highr_0.9 Rcpp_1.0.9 readr_2.1.2 promises_1.2.0.1
[37] backports_1.4.1 scales_1.2.0 cachem_1.0.6 jsonlite_1.8.0
[41] farver_2.1.1 fs_1.5.2 hms_1.1.1 digest_0.6.29
[45] stringi_1.7.8 dplyr_1.0.9 rprojroot_2.0.3 grid_4.2.1
[49] cli_3.3.0 tools_4.2.1 magrittr_2.0.3 sass_0.4.2
[53] tibble_3.1.8 crayon_1.5.1 whisker_0.4 tidyr_1.2.0
[57] pkgconfig_2.0.3 ellipsis_0.3.2 assertthat_0.2.1 rmarkdown_2.14
[61] rstudioapi_0.13 R6_2.5.1 git2r_0.30.1 compiler_4.2.1