Skip to content

Commit

Permalink
Render code harmless
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspercooper committed May 22, 2018
1 parent 71c84c7 commit 081525f
Showing 1 changed file with 93 additions and 93 deletions.
186 changes: 93 additions & 93 deletions R/randomized_saturation_designer.R
@@ -1,93 +1,93 @@
N_networks <- 10
max_network_size <- 20
min_network_size <- 10
ate <- .5
outcome_sd <- 1
ate_per_neighbor_treated <- .01
saturations <- c(0,.25,.5,.75)
icc <- .1

population <- declare_population(
networks = add_level(
N = N_networks,
network_size = round(runif(N,min_network_size,max_network_size))
),
individuals = add_level(
N = network_size,
u_0 = draw_normal_icc(mean = 0,
clusters = networks,
sd = outcome_sd,
ICC = icc)
)
)

assign_S_to_clusters <- declare_assignment(
clusters = networks,
conditions = saturations,
assignment_variable = "S"
)
assign_Z_to_individuals <- declare_assignment(
handler = function(data){
data$Z <- with(data,block_ra(
blocks = networks, block_prob = tapply(S,networks,mean)))
return(data)
}
)

within_cluster_spillover <- declare_step(
individuals = modify_level(
n_neighbors_treated = ave(x = Z, networks, FUN = sum)),
label = "Add spillover variables")

potential_outcomes_no_spillover <-
declare_potential_outcomes(Y ~ u_0 + ate * Z)
potential_outcomes_spillover <- declare_potential_outcomes(
Y_S ~ u_0 + ate * Z +
n_neighbors_treated * ate_per_neighbor_treated)

ate <- declare_estimand(ate = mean(Y_Z_1 - Y_Z_0))
spillover <- declare_estimand(spillover = ate_per_neighbor_treated)

reveal_Y_S <- declare_reveal(Y_S,Z)
reveal_Y <- declare_reveal(Y,Z)

estimator <- declare_estimator(
formula = Y_S ~ Z + n_neighbors_treated,
model = lm_robust,
clusters = networks,
coefficients = c(Z,n_neighbors_treated),
estimand = c(ate,spillover),
label = "OLS"
)

design <- declare_design(
population,
assign_S_to_clusters,
assign_Z_to_individuals,
potential_outcomes_no_spillover,
within_cluster_spillover,
potential_outcomes_spillover,
estimands,
reveal_Y_S,
reveal_Y,
estimator
)


diagnose_design(design,sims = 1000,bootstrap = F)
















# N_networks <- 10
# max_network_size <- 20
# min_network_size <- 10
# ate <- .5
# outcome_sd <- 1
# ate_per_neighbor_treated <- .01
# saturations <- c(0,.25,.5,.75)
# icc <- .1
#
# population <- declare_population(
# networks = add_level(
# N = N_networks,
# network_size = round(runif(N,min_network_size,max_network_size))
# ),
# individuals = add_level(
# N = network_size,
# u_0 = draw_normal_icc(mean = 0,
# clusters = networks,
# sd = outcome_sd,
# ICC = icc)
# )
# )
#
# assign_S_to_clusters <- declare_assignment(
# clusters = networks,
# conditions = saturations,
# assignment_variable = "S"
# )
# assign_Z_to_individuals <- declare_assignment(
# handler = function(data){
# data$Z <- with(data,block_ra(
# blocks = networks, block_prob = tapply(S,networks,mean)))
# return(data)
# }
# )
#
# within_cluster_spillover <- declare_step(
# individuals = modify_level(
# n_neighbors_treated = ave(x = Z, networks, FUN = sum)),
# label = "Add spillover variables")
#
# potential_outcomes_no_spillover <-
# declare_potential_outcomes(Y ~ u_0 + ate * Z)
# potential_outcomes_spillover <- declare_potential_outcomes(
# Y_S ~ u_0 + ate * Z +
# n_neighbors_treated * ate_per_neighbor_treated)
#
# ate <- declare_estimand(ate = mean(Y_Z_1 - Y_Z_0))
# spillover <- declare_estimand(spillover = ate_per_neighbor_treated)
#
# reveal_Y_S <- declare_reveal(Y_S,Z)
# reveal_Y <- declare_reveal(Y,Z)
#
# estimator <- declare_estimator(
# formula = Y_S ~ Z + n_neighbors_treated,
# model = lm_robust,
# clusters = networks,
# coefficients = c(Z,n_neighbors_treated),
# estimand = c(ate,spillover),
# label = "OLS"
# )
#
# design <- declare_design(
# population,
# assign_S_to_clusters,
# assign_Z_to_individuals,
# potential_outcomes_no_spillover,
# within_cluster_spillover,
# potential_outcomes_spillover,
# estimands,
# reveal_Y_S,
# reveal_Y,
# estimator
# )
#
#
# diagnose_design(design,sims = 1000,bootstrap = F)
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#

0 comments on commit 081525f

Please sign in to comment.