Betsy Levy Paluck Lab R Package
This package is a collection of functions I wrote during my time as lab manager to facilitate transparent social science. This is a place where lab members can share code and functions they have written together, and learn how to contribute to open-source software.
There are loosely two groups of functions that lab members will find most useful. The first is the workhorse tidy_lm function that runs many regressions models with support for clustered standard errors and presents them in a tidy format.
tidy_lm can supports multiple "styles" of models. These are:
defaultuses all terms at once on all the DVs.
y_1 ~ x_1 + x_2 + x_3
y_2 ~ x_1 + x_2 + x_3
y_3 ~ x_1 + x_2 + x_3
incrementalstarts off with one term and adds one more term each model for each dv.
y_1 ~ x_1
y_1 ~ x_1 + x_2
y_1 ~ x_1 + x_2 + x_3
y_2 ~ x_1
y_2 ~ x_1 + x_2
y_2 ~ x_1 + x_2 + x_3
chordbegins by running a bivariate regression the first term. Then runs a trivariate regression, holding the dv, first is term constant looping through the remaining terms. Lastly, all terms are ran together.
y_1 ~ x_1
y_1 ~ x_1 + x_2
y_1 ~ x_1 + x_3
y_1 ~ x_1 + x_2 + x_3
y_2 ~ x_1
y_2 ~ x_1 + x_2
y_2 ~ x_1 + x_3
y_2 ~ x_1 + x_2 + x_3
bivariateuses all terms individually on each dv.
y_1 ~ x_1
y_1 ~ x_2
y_1 ~ x_3
y_2 ~ x_1
y_2 ~ x_2
y_2 ~ x_3
The second are custom hacks for creating publication quality tables. This is useful for editing tables created by stargazer, knitr::kable or kableExtra. These are numerous and mostly self-explanatory.
-
table_labelAdds dynamic labels to that can be references elsewhere in your .tex file or RMarkdown document via\label{tab:your_label_here} -
add_endnoteImprovement to footnotes fromstargazerfunction with an additionalsize_in_inchesargument to allow for custom sizes -
stargazer_pvaluesthe p-values instargazerare clunky. This reformats the p-values to be 'brackets', 'parentheses' or 'none' to replace thestargazerdefault. -
stargazer_rownameadd custom text to the first column instargazer -
print_tableA cleaner way to print LaTeX tables than simply using thecat(). Equivalent tocat(paste(latex_table, collapse = "\n")) -
kable_resizeAn option for whenkable_styling(full_width = F, latex_options = "scale_down")isn't enough. -
table_numbersAdds custom numbers to a table. Useful for adding secondary counts to tables (e.g., Table 2a, Table 2b). Can also be used to switch primary counts to alternative styles likealphorroman. Requiresheader needs \newcounter{foo}to be added in document YAML to work under header-includes: -
two_digitsRounds numbers to the second digit, and returns them as acharacterin two digits. Useful for number consistency during visualization. -
add_top_row -
add_bottom_row -
add_parentheses -
add_brackets
To install:
install.packages("devtools")
devtools::install_github("johnhenrypezzuto/blpl")
