Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull Request follow-up for #30: Reset radom seed #59

Merged
merged 25 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b808c55
Added basic tests
mcaceresb Jan 23, 2024
bec685f
Fixed minor typo; fixed tests
mcaceresb Jan 23, 2024
75bad16
Added pandoc to gh actions
mcaceresb Jan 23, 2024
5edb20d
Still trying pandoc
mcaceresb Jan 23, 2024
a661e06
Still trying pandoc
mcaceresb Jan 23, 2024
0ac3cc1
Still trying pandoc (typo)
mcaceresb Jan 23, 2024
38d1a4e
Added latex
mcaceresb Jan 23, 2024
a96bb36
Debugging missing extra packages
mcaceresb Jan 23, 2024
0bdc444
Moved lfe install to test script
mcaceresb Jan 23, 2024
34fcca8
Moved lfe install to test script (debugging)
mcaceresb Jan 23, 2024
038800c
Added testthat
mcaceresb Jan 23, 2024
ab47038
Added haven for some reason
mcaceresb Jan 23, 2024
1c9d5e4
Gave up and added lfe to recomended packages (for test)
mcaceresb Jan 23, 2024
cb169a7
Merge branch 'asheshrambachan:master' into master
mcaceresb Jan 26, 2024
ba948ed
Merge branch 'asheshrambachan:master' into master
mcaceresb Mar 10, 2024
6dc2af0
Merge branch 'asheshrambachan:master' into master
mcaceresb Mar 19, 2024
ca449e9
Merge branch 'asheshrambachan:master' into master
mcaceresb Apr 16, 2024
1c8bd1f
Merge branch 'asheshrambachan:master' into master
mcaceresb May 21, 2024
d4b7cce
Merge branch 'asheshrambachan:master' into master
mcaceresb Jun 11, 2024
83da362
Merge branch 'asheshrambachan:master' into master
mcaceresb Jun 21, 2024
4deeb22
Reset random seed, if it exists, after createSensitivityResults*()
mcaceresb Jun 21, 2024
c54302d
Merge branch 'master' of github.com:mcaceresb/HonestDiD
mcaceresb Jun 21, 2024
dd56898
Make internal seed user-accessible
mcaceresb Jul 10, 2024
4adfc6c
Added seed option to function docs
mcaceresb Jul 10, 2024
6f332d3
Added seed option to function docs (v2)
mcaceresb Jul 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions R/arp-nuisance.R
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@

# HYBRID HELPER FUNCTIONS ---------------------------------------------
.compute_least_favorable_cv <- function(X_T, sigma, hybrid_kappa, sims = 1000,
rowsForARP = NULL) {
rowsForARP = NULL, seed = 0) {
# Computes the least favorable critical value following the algorithm in
# Section 6.2 of Andrews, Roth, Pakes (2019).
#
Expand Down Expand Up @@ -383,7 +383,7 @@
base::return(if (error_flag) NA else lpSolveAPI::get.objective(linprog))
}

base::set.seed(0)
base::set.seed(seed)
if (base::is.null(X_T)) { # no nuisance parameter case
xi.draws = t( t(mvtnorm::rmvnorm(n = sims, sigma = sigma)) /base::sqrt(base::diag(sigma)) )
eta_vec = matrixStats::rowMaxs(xi.draws)
Expand Down
10 changes: 5 additions & 5 deletions R/deltarm.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
.computeConditionalCS_DeltaRM_fixedS <- function(s, max_positive, Mbar,
betahat, sigma, numPrePeriods, numPostPeriods, l_vec,
alpha, hybrid_flag, hybrid_kappa,
postPeriodMomentsOnly, gridPoints, grid.ub, grid.lb) {
postPeriodMomentsOnly, gridPoints, grid.ub, grid.lb, seed = 0) {
# This function computes the ARP CI that includes nuisance parameters
# for Delta^{RM}(Mbar) for a fixed s and (+),(-). This functions uses ARP_computeCI for all
# of its computations. It is used as a helper function in computeConditionalCS_DeltaRM below.
Expand Down Expand Up @@ -223,7 +223,7 @@
if (numPostPeriods == 1) {
if (hybrid_flag == "LF") {
# Compute LF CV and store it in hybrid_list
lf_cv = .compute_least_favorable_cv(X_T = NULL, sigma = A_RM_s %*% sigma %*% base::t(A_RM_s), hybrid_kappa = hybrid_kappa)
lf_cv = .compute_least_favorable_cv(X_T = NULL, sigma = A_RM_s %*% sigma %*% base::t(A_RM_s), hybrid_kappa = hybrid_kappa, seed = seed)
hybrid_list$lf_cv = lf_cv
}
# Compute confidence set
Expand All @@ -250,7 +250,7 @@ computeConditionalCS_DeltaRM <- function(betahat, sigma, numPrePeriods, numPostP
l_vec = .basisVector(index = 1, size = numPostPeriods), Mbar = 0,
alpha = 0.05, hybrid_flag = "LF", hybrid_kappa = alpha/10,
returnLength = FALSE, postPeriodMomentsOnly = TRUE,
gridPoints = 10^3, grid.ub = NA, grid.lb = NA) {
gridPoints = 10^3, grid.ub = NA, grid.lb = NA, seed = 0) {
# This function computes the ARP CI that includes nuisance parameters
# for Delta^{RM}(Mbar). This functions uses ARP_computeCI for all
# of its computations.
Expand Down Expand Up @@ -292,7 +292,7 @@ computeConditionalCS_DeltaRM <- function(betahat, sigma, numPrePeriods, numPostP
numPostPeriods = numPostPeriods, l_vec = l_vec,
alpha = alpha, hybrid_flag = hybrid_flag, hybrid_kappa = hybrid_kappa,
postPeriodMomentsOnly = postPeriodMomentsOnly,
gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb)
gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb, seed = seed)
CIs_RM_plus_allS[,s_i] = CI_s_plus$accept

# Compute CI for s, (-) and bind it to all CI's for (-)
Expand All @@ -301,7 +301,7 @@ computeConditionalCS_DeltaRM <- function(betahat, sigma, numPrePeriods, numPostP
numPostPeriods = numPostPeriods, l_vec = l_vec,
alpha = alpha, hybrid_flag = hybrid_flag, hybrid_kappa = hybrid_kappa,
postPeriodMomentsOnly = postPeriodMomentsOnly,
gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb)
gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb, seed = seed)
CIs_RM_minus_allS[,s_i] = CI_s_minus$accept
}

Expand Down
10 changes: 5 additions & 5 deletions R/deltarmb.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
.computeConditionalCS_DeltaRMB_fixedS <- function(s, max_positive, Mbar,
betahat, sigma, numPrePeriods, numPostPeriods, l_vec,
alpha, hybrid_flag, hybrid_kappa, biasDirection,
postPeriodMomentsOnly, gridPoints, grid.ub, grid.lb) {
postPeriodMomentsOnly, gridPoints, grid.ub, grid.lb, seed = 0) {
# This function computes the ARP CI that includes nuisance parameters
# for Delta^{MB}(Mbar) for a fixed s and (+),(-). This functions uses ARP_computeCI for all
# of its computations. It is used as a helper function in computeConditionalCS_DeltaMB below.
Expand Down Expand Up @@ -238,7 +238,7 @@
if (numPostPeriods == 1) {
if (hybrid_flag == "LF") {
# Compute LF CV and store it in hybrid_list
lf_cv = .compute_least_favorable_cv(X_T = NULL, sigma = A_RMB_s %*% sigma %*% base::t(A_RMB_s), hybrid_kappa = hybrid_kappa)
lf_cv = .compute_least_favorable_cv(X_T = NULL, sigma = A_RMB_s %*% sigma %*% base::t(A_RMB_s), hybrid_kappa = hybrid_kappa, seed = seed)
hybrid_list$lf_cv = lf_cv
}
# Compute confidence set
Expand Down Expand Up @@ -267,7 +267,7 @@ computeConditionalCS_DeltaRMB <- function(betahat, sigma, numPrePeriods, numPost
alpha = 0.05, hybrid_flag = "LF", hybrid_kappa = alpha/10,
returnLength = FALSE, biasDirection = "positive",
postPeriodMomentsOnly = TRUE,
gridPoints = 10^3, grid.ub = NA, grid.lb = NA) {
gridPoints = 10^3, grid.ub = NA, grid.lb = NA, seed = 0) {
# This function computes the ARP CI that includes nuisance parameters
# for Delta^{MB}(Mbar). This functions uses ARP_computeCI for all
# of its computations.
Expand Down Expand Up @@ -310,7 +310,7 @@ computeConditionalCS_DeltaRMB <- function(betahat, sigma, numPrePeriods, numPost
numPostPeriods = numPostPeriods, l_vec = l_vec,
alpha = alpha, hybrid_flag = hybrid_flag, hybrid_kappa = hybrid_kappa,
postPeriodMomentsOnly = postPeriodMomentsOnly, biasDirection = biasDirection,
gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb)
gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb, seed = seed)
CIs_RMB_plus_allS[,s_i] = CI_s_plus$accept

# Compute CI for s, (-) and bind it to all CI's for (-)
Expand All @@ -319,7 +319,7 @@ computeConditionalCS_DeltaRMB <- function(betahat, sigma, numPrePeriods, numPost
numPostPeriods = numPostPeriods, l_vec = l_vec,
alpha = alpha, hybrid_flag = hybrid_flag, hybrid_kappa = hybrid_kappa,
postPeriodMomentsOnly = postPeriodMomentsOnly, biasDirection = biasDirection,
gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb)
gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb, seed = seed)
CIs_RMB_minus_allS[,s_i] = CI_s_minus$accept
}

Expand Down
10 changes: 5 additions & 5 deletions R/deltarmm.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
betahat, sigma, numPrePeriods, numPostPeriods, l_vec,
alpha, hybrid_flag, hybrid_kappa,
postPeriodMomentsOnly, monotonicityDirection,
gridPoints, grid.ub, grid.lb) {
gridPoints, grid.ub, grid.lb, seed = 0) {
# This function computes the ARP CI that includes nuisance parameters
# for Delta^{RMM}(Mbar) for a fixed s and (+),(-). This functions uses ARP_computeCI for all
# of its computations. It is used as a helper function in computeConditionalCS_DeltaRM below.
Expand Down Expand Up @@ -239,7 +239,7 @@
if (numPostPeriods == 1) {
if (hybrid_flag == "LF") {
# Compute LF CV and store it in hybrid_list
lf_cv = .compute_least_favorable_cv(X_T = NULL, sigma = A_RMM_s %*% sigma %*% base::t(A_RMM_s), hybrid_kappa = hybrid_kappa)
lf_cv = .compute_least_favorable_cv(X_T = NULL, sigma = A_RMM_s %*% sigma %*% base::t(A_RMM_s), hybrid_kappa = hybrid_kappa, seed = seed)
hybrid_list$lf_cv = lf_cv
}
# Compute confidence set
Expand All @@ -266,7 +266,7 @@ computeConditionalCS_DeltaRMM <- function(betahat, sigma, numPrePeriods, numPost
l_vec = .basisVector(index = 1, size = numPostPeriods), Mbar = 0,
alpha = 0.05, hybrid_flag = "LF", hybrid_kappa = alpha/10,
returnLength = FALSE, postPeriodMomentsOnly = TRUE, monotonicityDirection = "increasing",
gridPoints = 10^3, grid.ub = NA, grid.lb = NA) {
gridPoints = 10^3, grid.ub = NA, grid.lb = NA, seed = 0) {
# This function computes the ARP CI that includes nuisance parameters
# for Delta^{RMM}(Mbar). This functions uses ARP_computeCI for all
# of its computations.
Expand Down Expand Up @@ -308,7 +308,7 @@ computeConditionalCS_DeltaRMM <- function(betahat, sigma, numPrePeriods, numPost
numPostPeriods = numPostPeriods, l_vec = l_vec,
alpha = alpha, hybrid_flag = hybrid_flag, hybrid_kappa = hybrid_kappa,
postPeriodMomentsOnly = postPeriodMomentsOnly, monotonicityDirection = monotonicityDirection,
gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb)
gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb, seed = seed)
CIs_RMM_plus_allS[,s_i] = CI_s_plus$accept

# Compute CI for s, (-) and bind it to all CI's for (-)
Expand All @@ -317,7 +317,7 @@ computeConditionalCS_DeltaRMM <- function(betahat, sigma, numPrePeriods, numPost
numPostPeriods = numPostPeriods, l_vec = l_vec,
alpha = alpha, hybrid_flag = hybrid_flag, hybrid_kappa = hybrid_kappa,
postPeriodMomentsOnly = postPeriodMomentsOnly, monotonicityDirection = monotonicityDirection,
gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb)
gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb, seed = seed)
CIs_RMM_minus_allS[,s_i] = CI_s_minus$accept
}

Expand Down
4 changes: 2 additions & 2 deletions R/deltasd.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ computeConditionalCS_DeltaSD <- function(betahat, sigma, numPrePeriods, numPostP
M = 0, alpha = 0.05, hybrid_flag = "FLCI",
hybrid_kappa = alpha/10, returnLength = FALSE,
postPeriodMomentsOnly = TRUE,
gridPoints =10^3, grid.ub = NA, grid.lb = NA) {
gridPoints =10^3, grid.ub = NA, grid.lb = NA, seed = 0) {
# This function computes the ARP CI that includes nuisance parameters
# for Delta^{SD}(M). This functions uses ARP_computeCI for all
# of its computations.
Expand Down Expand Up @@ -191,7 +191,7 @@ computeConditionalCS_DeltaSD <- function(betahat, sigma, numPrePeriods, numPostP
}
} else if (hybrid_flag == "LF") {
# Compute LF CV
lf_cv = .compute_least_favorable_cv(X_T = NULL, sigma = A_SD %*% sigma %*% base::t(A_SD), hybrid_kappa = hybrid_kappa)
lf_cv = .compute_least_favorable_cv(X_T = NULL, sigma = A_SD %*% sigma %*% base::t(A_SD), hybrid_kappa = hybrid_kappa, seed = seed)

# Store lf cv
hybrid_list$lf_cv = lf_cv
Expand Down
4 changes: 2 additions & 2 deletions R/deltasdb.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ computeConditionalCS_DeltaSDB <- function(betahat, sigma, numPrePeriods, numPost
alpha = 0.05, hybrid_flag = "FLCI", hybrid_kappa = alpha/10,
returnLength = FALSE, biasDirection = "positive",
postPeriodMomentsOnly = TRUE,
gridPoints = 10^3, grid.lb = NA, grid.ub = NA) {
gridPoints = 10^3, grid.lb = NA, grid.ub = NA, seed = 0) {
# This function computes the ARP CI that includes nuisance parameters
# for Delta^{SDPB}(M). This functions uses ARP_computeCI for all
# of its computations.
Expand Down Expand Up @@ -177,7 +177,7 @@ computeConditionalCS_DeltaSDB <- function(betahat, sigma, numPrePeriods, numPost
}
} else if (hybrid_flag == "LF") {
# Compute LF CV
lf_cv = .compute_least_favorable_cv(X_T = NULL, sigma = A_SDB %*% sigma %*% base::t(A_SDB), hybrid_kappa = hybrid_kappa)
lf_cv = .compute_least_favorable_cv(X_T = NULL, sigma = A_SDB %*% sigma %*% base::t(A_SDB), hybrid_kappa = hybrid_kappa, seed = seed)

# Store lf cv
hybrid_list$lf_cv = lf_cv
Expand Down
4 changes: 2 additions & 2 deletions R/deltasdm.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ computeConditionalCS_DeltaSDM <- function(betahat, sigma, numPrePeriods, numPost
alpha = 0.05, monotonicityDirection = "increasing",
hybrid_flag = "FLCI", hybrid_kappa = alpha/10,
returnLength = FALSE, postPeriodMomentsOnly = TRUE,
gridPoints=10^3, grid.lb = NA, grid.ub = NA) {
gridPoints=10^3, grid.lb = NA, grid.ub = NA, seed = 0) {
# This function computes the ARP CI that includes nuisance parameters
# for Delta^{SDI}(M). This functions uses ARP_computeCI for all
# of its computations.
Expand Down Expand Up @@ -164,7 +164,7 @@ computeConditionalCS_DeltaSDM <- function(betahat, sigma, numPrePeriods, numPost
}
} else if (hybrid_flag == "LF") {
# Compute LF CV
lf_cv = .compute_least_favorable_cv(X_T = NULL, sigma = A_SDM %*% sigma %*% t(A_SDM), hybrid_kappa = hybrid_kappa)
lf_cv = .compute_least_favorable_cv(X_T = NULL, sigma = A_SDM %*% sigma %*% t(A_SDM), hybrid_kappa = hybrid_kappa, seed = seed)

# Store lf cv
hybrid_list$lf_cv = lf_cv
Expand Down
10 changes: 5 additions & 5 deletions R/deltasdrm.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
.computeConditionalCS_DeltaSDRM_fixedS <- function(s, max_positive, Mbar,
betahat, sigma, numPrePeriods, numPostPeriods, l_vec,
alpha, hybrid_flag, hybrid_kappa,
postPeriodMomentsOnly, gridPoints, grid.ub, grid.lb) {
postPeriodMomentsOnly, gridPoints, grid.ub, grid.lb, seed = seed) {
# This function computes the ARP CI that includes nuisance parameters
# for Delta^{SDRM}(Mbar) for a fixed s and (+),(-). This functions uses ARP_computeCI for all
# of its computations. It is used as a helper function in computeConditionalCS_DeltaSDRM below.
Expand Down Expand Up @@ -220,7 +220,7 @@
if (numPostPeriods == 1) {
if (hybrid_flag == "LF") {
# Compute LF CV and store it in hybrid_list
lf_cv = .compute_least_favorable_cv(X_T = NULL, sigma = A_SDRM_s %*% sigma %*% base::t(A_SDRM_s), hybrid_kappa = hybrid_kappa)
lf_cv = .compute_least_favorable_cv(X_T = NULL, sigma = A_SDRM_s %*% sigma %*% base::t(A_SDRM_s), hybrid_kappa = hybrid_kappa, seed = 0)
hybrid_list$lf_cv = lf_cv
}
# Compute confidence set
Expand Down Expand Up @@ -248,7 +248,7 @@ computeConditionalCS_DeltaSDRM <- function(betahat, sigma, numPrePeriods, numPos
l_vec = .basisVector(index = 1, size = numPostPeriods), Mbar = 0,
alpha = 0.05, hybrid_flag = "LF", hybrid_kappa = alpha/10,
returnLength = FALSE, postPeriodMomentsOnly = TRUE,
gridPoints = 10^3, grid.ub = NA, grid.lb = NA) {
gridPoints = 10^3, grid.ub = NA, grid.lb = NA, seed = 0) {
# This function computes the ARP CI that includes nuisance parameters
# for Delta^{SDRM}(Mbar). This functions uses ARP_computeCI for all
# of its computations.
Expand Down Expand Up @@ -297,7 +297,7 @@ computeConditionalCS_DeltaSDRM <- function(betahat, sigma, numPrePeriods, numPos
numPostPeriods = numPostPeriods, l_vec = l_vec,
alpha = alpha, hybrid_flag = hybrid_flag, hybrid_kappa = hybrid_kappa,
postPeriodMomentsOnly = postPeriodMomentsOnly,
gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb)
gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb, seed = seed)
CIs_SDRM_plus_allS[,s_i] = CI_s_plus$accept

# Compute CI for s, (-) and bind it to all CI's for (-)
Expand All @@ -306,7 +306,7 @@ computeConditionalCS_DeltaSDRM <- function(betahat, sigma, numPrePeriods, numPos
numPostPeriods = numPostPeriods, l_vec = l_vec,
alpha = alpha, hybrid_flag = hybrid_flag, hybrid_kappa = hybrid_kappa,
postPeriodMomentsOnly = postPeriodMomentsOnly,
gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb)
gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb, seed = seed)
CIs_SDRM_minus_allS[,s_i] = CI_s_minus$accept
}
CIs_SDRM_plus_maxS = base::apply(CIs_SDRM_plus_allS, MARGIN = 1, FUN = max)
Expand Down
Loading
Loading