Skip to content

Instantly share code, notes, and snippets.

View bgall's full-sized avatar

bgall bgall

View GitHub Profile
@bgall
bgall / social_desirability_bias.R
Last active February 5, 2020 18:39
Social Desirability can produce incorrect inferences about the sign of an effect
# Show that social desirability not only produces biased
# "descriptive statistics" (e.g. group means), but can
# produce treatment effects of the opposite sign of
# the true effect. You cannot simply ignore social
# desirability under the assumption that it does
# not affect estimates of causal parameters since
# measures pre-treatment and post-treatment are
# both subject to social desirability.
#
# Note that this arises due to social desirability
@bgall
bgall / benchmarking_dummy_functions
Last active May 19, 2022 08:02
Benchmarking fastDummies::dummy_cols() against modeldb::add_dummy_variables()
# Compare the performance of two purportedly-fast ways of generating dummy variables from character vector.
# NOTE: fastDummies retains the original variable by default while modeldb does not
# Dependencies
library(microbenchmark)
library(fastDummies)
library(modeldb)
library(dplyr)
# Simulate data: 1 million rows, 1 variable with 26 unique values
@bgall
bgall / covariate_adjustment_bias.R
Last active February 9, 2023 22:00
Show bias in covariate adjustment and linear combination "issue"
library(dplyr)
# Wrap data simulation in a function
sim_data <- function(N) {
###########################################################################
# parameters
###########################################################################
set.seed(123)