From b808c5521599710b608bf91917c030023b4e402c Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 00:49:19 -0500 Subject: [PATCH 01/17] Added basic tests --- .github/workflows/tests.yml | 41 ++++++++++ tests/test_base.R | 155 ++++++++++++++++++++++++++++++++++++ 2 files changed, 196 insertions(+) create mode 100644 .github/workflows/tests.yml create mode 100644 tests/test_base.R diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..7b4e700 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,41 @@ +name: Unit and build tests + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + workflow_dispatch: + branches: [ master ] + +jobs: + tests: + runs-on: ${{ matrix.config.os }} + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + strategy: + matrix: + config: + - {os: macos-latest, r: 'release'} + - {os: ubuntu-latest, r: 'release'} + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up R + uses: r-lib/actions/setup-r@v2 + with: + r-version: ${{ matrix.config.r }} + use-public-rspm: true + + - name: Install dependencies + uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::devtools, any::lfe + needs: devtools, lfe + + - name: Check build + run: | + devtools::document() + devtools::check() + shell: Rscript {0} diff --git a/tests/test_base.R b/tests/test_base.R new file mode 100644 index 0000000..503277e --- /dev/null +++ b/tests/test_base.R @@ -0,0 +1,155 @@ +# remove.packages("HonestDiD") +# install.packages(".", repos=NULL, type="source") +# testthat::test_dir("tests") + +library(lfe) +library(HonestDiD) +data(BCdata_EventStudy) +data(LWdata_EventStudy) + +BC_numPrePeriods <- length(BCdata_EventStudy$prePeriodIndices) +BC_numPostPeriods <- length(BCdata_EventStudy$postPeriodIndices) +BC_l_vec <- basisVector(index = 1, size = BC_numPostPeriods) +BC_l_vec <- cbind(c(1, 0, 0, 0)) + +test_that("HonestDiD base run with no errors", { + BC_DeltaSDNB_RobustResults <- + createSensitivityResults(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = BC_numPrePeriods, + numPostPeriods = BC_numPostPeriods, + l_vec = BC_l_vec, + method = "FLCI", + Mvec = seq(from=0, to=0.3, by=0.1)) + + BC_DeltaSDNB_RobustResultsConditional <- + createSensitivityResults(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = BC_numPrePeriods, + numPostPeriods = BC_numPostPeriods, + l_vec = BC_l_vec, + method = "Conditional", + Mvec = seq(from=0, to=0.3, by=0.1)) + + BC_DeltaSDNB_RobustResultsCF <- + createSensitivityResults(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = BC_numPrePeriods, + numPostPeriods = BC_numPostPeriods, + l_vec = BC_l_vec, + method = "C-F", + Mvec = seq(from=0, to=0.3, by=0.1)) + + BC_DeltaSDNB_RobustResultsCLF <- + createSensitivityResults(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = BC_numPrePeriods, + numPostPeriods = BC_numPostPeriods, + l_vec = BC_l_vec, + method = "C-LF", + Mvec = seq(from=0, to=0.3, by=0.1)) + + BC_OriginalResults <- + constructOriginalCS(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = BC_numPrePeriods, + numPostPeriods = BC_numPostPeriods, + l_vec = BC_l_vec) + + BC_DeltaSDNB_SensitivityPlot <- + createSensitivityPlot(robustResults = BC_DeltaSDNB_RobustResults, + originalResults = BC_OriginalResults) + + expect_silent(BC_DeltaSDNB_RobustResults) + expect_silent(BC_DeltaSDNB_RobustResultsConditional) + expect_silent(BC_DeltaSDNB_RobustResultsCF) + expect_silent(BC_DeltaSDNB_RobustResultsCLF) + expect_silent(BC_DriginalResults) + expect_silent(BC_DeltaSDNB_SensitivityPlot) +}) + +test_that("HonestDiD options run with no errors", { + LWdata_RawData = haven::read_dta(system.file("extdata", "LWdata_RawData.dta", package = "HonestDiD")) + sum(LWdata_RawData$nobs) + + # Estimate event study using lfe package + EmpFemale.EventStudy = lfe::felm(emp ~ + rtESV13 + rtESV14 + rtESV15 + + rtESV16 + rtESV17 + rtESV18 + + rtESV19 + rtESV110 + rtESV111 + # End Pre-periods + rtESV113 + rtESV114 + rtESV115 + + rtESV116 + rtESV117 + rtESV118 + + rtESV119 + rtESV120 + rtESV121 + + rtESV122 + rtESV123 + rtESV124 + + rtESV125 + rtESV126 + rtESV127 + + rtESV128 + rtESV129 + rtESV130 + + rtESV131 + rtESV132 + rtESV133 + + rtESV134 + rtESV135 + # End post-periods + yearsfcor + yearsflr + aveitc + fscontrol + + asian + black + hispanic + other | + factor(PUS_SURVEY_YEAR)*factor(BIRTHYEAR) + + factor(PUS_SURVEY_YEAR) + factor(BIRTHSTATE) | + 0 | BIRTHSTATE, + data = LWdata_RawData, + weights = LWdata_RawData$nobs) + summary(EmpFemale.EventStudy) + + coefIndex = which(grepl(x = dimnames(EmpFemale.EventStudy$coefficients)[[1]], pattern = "rtESV")) + betahat = EmpFemale.EventStudy$beta[coefIndex, ] + + # Extract estimated variance-covariance matrix of event study coefficients + sigma = EmpFemale.EventStudy$clustervcv[coefIndex, coefIndex] + + # Construct vector of event times and the scalar reference period + timeVec = c(seq(from = -11, to = -3, by = 1), seq(from = -1, to = 21, by = 1)) + referencePeriod <- -2 + postPeriodIndices <- which(timeVec > -2) + prePeriodIndices <- which(timeVec < -2) + LW_numPrePeriods <- length(prePeriodIndices) + LW_numPostPeriods <- length(postPeriodIndices) + LW_l_vec <- basisVector(index = 1, size = LW_numPostPeriods) + + for( method in c("C-F", "C-LF", "Conditional", "FLCI") ) { + for( monotonicityDirection in c("increasing", "decreasing") ) { + for ( biasDirection in c("positive", "negative") ) { + LW_DeltaSDNB_RobustResultsCLF <- + createSensitivityResults(betahat = betahat, + sigma = sigma, + numPrePeriods = LW_numPrePeriods, + numPostPeriods = LW_numPostPeriods, + l_vec = LW_l_vec, + method = method, + monotonicityDirection = monotonicityDirection, + biasDirection = biasDirection, + Mvec = seq(from=0, to=0.3, by=0.1)) + print(LW_DeltaSDNB_RobustResults) + expect_silent(LW_DeltaSDNB_RobustResults) + } + } + } + + for ( method in c("C-F", "C-LF", "Conditional") ) { + for ( monotonicityDirection in c("increasing", "decreasing") ) { + for ( biasDirection in c("positive", "negative") ) { + for ( bound in c("deviation from parallel trends", "deviation from linear trend") ) { + BC_DeltaRM_RobustResults <- + createSensitivityResults_relativeMagnitudes(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = BC_numPrePeriods, + numPostPeriods = BC_numPostPeriods, + l_vec = BC_l_vec, + gridPoints = 100, + grid.ub = 1, + grid.lb = -1, + bound = bound, + method = method, + monotonicityDirection = monotonicityDirection, + biasDirection = biasDirection, + Mbarvec = seq(from=0, to=2, by=0.5)) + print(BC_DeltaRM_RobustResults) + expect_silent(BC_DeltaRM_RobustResults) + } + } + } + } +}) From bec685fbce3f1dd3b2a31aa31bc7fa0d3d969868 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 01:03:31 -0500 Subject: [PATCH 02/17] Fixed minor typo; fixed tests --- R/deltarmm.R | 2 +- tests/test_base.R | 65 ++++++++++++++++++++++++++++++----------------- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/R/deltarmm.R b/R/deltarmm.R index c95cacb..932a235 100644 --- a/R/deltarmm.R +++ b/R/deltarmm.R @@ -301,7 +301,7 @@ computeConditionalCS_DeltaRMM <- function(betahat, sigma, numPrePeriods, numPost alpha = alpha, hybrid_flag = hybrid_flag, hybrid_kappa = hybrid_kappa, postPeriodMomentsOnly = postPeriodMomentsOnly, monotonicityDirection = monotonicityDirection, gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb) - CIs_RM_plus_allS[,s_i] = CI_s_plus$accept + CIs_RMM_plus_allS[,s_i] = CI_s_plus$accept # Compute CI for s, (-) and bind it to all CI's for (-) CI_s_minus = .computeConditionalCS_DeltaRMM_fixedS(s = s_indices[s_i], max_positive = FALSE, Mbar = Mbar, diff --git a/tests/test_base.R b/tests/test_base.R index 503277e..a5efbca 100644 --- a/tests/test_base.R +++ b/tests/test_base.R @@ -112,7 +112,7 @@ test_that("HonestDiD options run with no errors", { for( method in c("C-F", "C-LF", "Conditional", "FLCI") ) { for( monotonicityDirection in c("increasing", "decreasing") ) { for ( biasDirection in c("positive", "negative") ) { - LW_DeltaSDNB_RobustResultsCLF <- + LW_DeltaSDNB_RobustResults <- createSensitivityResults(betahat = betahat, sigma = sigma, numPrePeriods = LW_numPrePeriods, @@ -122,33 +122,52 @@ test_that("HonestDiD options run with no errors", { monotonicityDirection = monotonicityDirection, biasDirection = biasDirection, Mvec = seq(from=0, to=0.3, by=0.1)) - print(LW_DeltaSDNB_RobustResults) + print(c(method, monotonicityDirection, biasDirection, LW_DeltaSDNB_RobustResults)) expect_silent(LW_DeltaSDNB_RobustResults) } } } - for ( method in c("C-F", "C-LF", "Conditional") ) { - for ( monotonicityDirection in c("increasing", "decreasing") ) { - for ( biasDirection in c("positive", "negative") ) { - for ( bound in c("deviation from parallel trends", "deviation from linear trend") ) { - BC_DeltaRM_RobustResults <- - createSensitivityResults_relativeMagnitudes(betahat = BCdata_EventStudy$betahat, - sigma = BCdata_EventStudy$sigma, - numPrePeriods = BC_numPrePeriods, - numPostPeriods = BC_numPostPeriods, - l_vec = BC_l_vec, - gridPoints = 100, - grid.ub = 1, - grid.lb = -1, - bound = bound, - method = method, - monotonicityDirection = monotonicityDirection, - biasDirection = biasDirection, - Mbarvec = seq(from=0, to=2, by=0.5)) - print(BC_DeltaRM_RobustResults) - expect_silent(BC_DeltaRM_RobustResults) - } + for ( method in c(NULL, "C-LF", "Conditional") ) { + for ( monotonicityDirection in c("increasing", "decreasing", NULL) ) { + for ( bound in c("deviation from parallel trends", "deviation from linear trend") ) { + BC_DeltaRM_RobustResults <- + createSensitivityResults_relativeMagnitudes(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = BC_numPrePeriods, + numPostPeriods = BC_numPostPeriods, + l_vec = BC_l_vec, + gridPoints = 100, + grid.ub = 1, + grid.lb = -1, + bound = bound, + method = method, + monotonicityDirection = monotonicityDirection, + Mbarvec = seq(from=0, to=1, by=0.5)) + print(c(method, monotonicityDirection, biasDirection, bound, BC_DeltaRM_RobustResults)) + expect_silent(BC_DeltaRM_RobustResults) + } + } + } + + for ( method in c(NULL, "C-LF", "Conditional") ) { + for ( biasDirection in c("positive", "negative", NULL) ) { + for ( bound in c("deviation from parallel trends", "deviation from linear trend") ) { + BC_DeltaRM_RobustResults <- + createSensitivityResults_relativeMagnitudes(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = BC_numPrePeriods, + numPostPeriods = BC_numPostPeriods, + l_vec = BC_l_vec, + gridPoints = 100, + grid.ub = 1, + grid.lb = -1, + bound = bound, + method = method, + biasDirection = biasDirection, + Mbarvec = seq(from=0, to=1, by=0.5)) + print(c(method, monotonicityDirection, biasDirection, bound, BC_DeltaRM_RobustResults)) + expect_silent(BC_DeltaRM_RobustResults) } } } From 75bad16aa0287a69037489213d4e920721583844 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 01:12:07 -0500 Subject: [PATCH 03/17] Added pandoc to gh actions --- .github/workflows/tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7b4e700..c9c96a1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,6 +22,9 @@ jobs: - name: Checkout code uses: actions/checkout@v3 + - name: Setup pandoc + uses: docker://pandoc/core:2.9 + - name: Set up R uses: r-lib/actions/setup-r@v2 with: From 5edb20d46c7473fcc177ad06d57081789a8f8365 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 06:26:49 -0500 Subject: [PATCH 04/17] Still trying pandoc --- .github/workflows/tests.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c9c96a1..85c348c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,9 +22,6 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - name: Setup pandoc - uses: docker://pandoc/core:2.9 - - name: Set up R uses: r-lib/actions/setup-r@v2 with: @@ -34,10 +31,11 @@ jobs: - name: Install dependencies uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::devtools, any::lfe - needs: devtools, lfe + extra-packages: any::devtools, any::lfe, any::knitr + needs: devtools, lfe, knitr - name: Check build + uses: docker://pandoc/core:2.9 run: | devtools::document() devtools::check() From a661e06a0f0ec04fbe3dd67897365594e2f8bfe6 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 06:37:04 -0500 Subject: [PATCH 05/17] Still trying pandoc --- .github/workflows/tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 85c348c..1657c19 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -34,8 +34,10 @@ jobs: extra-packages: any::devtools, any::lfe, any::knitr needs: devtools, lfe, knitr + - name: Setup pandoc + uses: r-lib/actions/setup-padoc@v2 + - name: Check build - uses: docker://pandoc/core:2.9 run: | devtools::document() devtools::check() From 0ac3cc1ee8f62b9485090a5d9cb806120558e4d2 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 06:43:54 -0500 Subject: [PATCH 06/17] Still trying pandoc (typo) --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1657c19..422b381 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,7 +35,7 @@ jobs: needs: devtools, lfe, knitr - name: Setup pandoc - uses: r-lib/actions/setup-padoc@v2 + uses: r-lib/actions/setup-pandoc@v2 - name: Check build run: | From 38d1a4e1315669bc9a9a47f92516076fae1c6a6f Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 07:00:17 -0500 Subject: [PATCH 07/17] Added latex --- .github/workflows/tests.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 422b381..0650505 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -31,12 +31,15 @@ jobs: - name: Install dependencies uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::devtools, any::lfe, any::knitr - needs: devtools, lfe, knitr + extra-packages: any::devtools, any::lfe, any::knitr, any::formatR + needs: devtools, lfe, knitr, formatR - name: Setup pandoc uses: r-lib/actions/setup-pandoc@v2 + - name: Setup LaTeX + uses: r-lib/actions/setup-tinytex@v2 + - name: Check build run: | devtools::document() From a96bb36043d150459e1c2dc3a5ca0298f53a55bf Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 07:38:30 -0500 Subject: [PATCH 08/17] Debugging missing extra packages --- .github/workflows/tests.yml | 12 ++++++++++-- R/honest_did.R | 4 ++++ R/sensitivityresults.R | 2 +- man/createEventStudyPlot.Rd | 2 +- tests/test_base.R | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0650505..a6a0e5d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -31,8 +31,16 @@ jobs: - name: Install dependencies uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::devtools, any::lfe, any::knitr, any::formatR - needs: devtools, lfe, knitr, formatR + extra-packages: | + any::devtools + any::lfe + any::knitr + any::formatR + any::haven + needs: | + devtools + knitr + rmarkdown - name: Setup pandoc uses: r-lib/actions/setup-pandoc@v2 diff --git a/R/honest_did.R b/R/honest_did.R index cf72ec4..0741b79 100644 --- a/R/honest_did.R +++ b/R/honest_did.R @@ -10,6 +10,7 @@ honest_did <- function(...) UseMethod("honest_did") #' using the approach of Rambachan and Roth (2021) when #' the event study is estimating using the `did` package #' +#' @param es Result from aggte (object of class AGGTEobj). #' @param e event time to compute the sensitivity analysis for. #' The default value is `e=0` corresponding to the "on impact" #' effect of participating in the treatment. @@ -18,6 +19,9 @@ honest_did <- function(...) UseMethod("honest_did") #' in pre-treatment periods) or "relative_magnitude" (which #' conducts a sensitivity analysis based on the relative magnitudes #' of deviations from parallel trends in pre-treatment periods). +#' @param gridPoints Number of grid points used for the underlying test +#' inversion. Default equals 100. User may wish to change the number of grid +#' points for computational reasons. #' @inheritParams HonestDiD::createSensitivityResults #' @inheritParams HonestDid::createSensitivityResults_relativeMagnitudes honest_did.AGGTEobj <- function(es, diff --git a/R/sensitivityresults.R b/R/sensitivityresults.R index bbe6888..e6cb97b 100644 --- a/R/sensitivityresults.R +++ b/R/sensitivityresults.R @@ -732,7 +732,7 @@ constructOriginalCS <- function(betahat, sigma, createEventStudyPlot <- function(betahat, stdErrors = NULL, sigma = NULL, numPrePeriods, numPostPeriods, alpha = 0.05, timeVec, referencePeriod, - useRelativeEventTime = F) { + useRelativeEventTime = FALSE) { if (base::is.null(stdErrors) & base::is.null(sigma)) { base::stop("User must specify either vector of standard errors or vcv matrix!") } else if (base::is.null(stdErrors) & !is.null(sigma)) { diff --git a/man/createEventStudyPlot.Rd b/man/createEventStudyPlot.Rd index fa8a7ca..24f864d 100644 --- a/man/createEventStudyPlot.Rd +++ b/man/createEventStudyPlot.Rd @@ -9,7 +9,7 @@ Constructs event study plot using the estimated event study coefficients and sta } \usage{ createEventStudyPlot(betahat, stdErrors = NULL, sigma = NULL, - numPrePeriods, numPostPeriods, alpha, timeVec, + numPrePeriods, numPostPeriods, alpha = 0.05, timeVec, referencePeriod, useRelativeEventTime = FALSE) } %- maybe also 'usage' for other objects documented here. diff --git a/tests/test_base.R b/tests/test_base.R index a5efbca..cb58118 100644 --- a/tests/test_base.R +++ b/tests/test_base.R @@ -64,7 +64,7 @@ test_that("HonestDiD base run with no errors", { expect_silent(BC_DeltaSDNB_RobustResultsConditional) expect_silent(BC_DeltaSDNB_RobustResultsCF) expect_silent(BC_DeltaSDNB_RobustResultsCLF) - expect_silent(BC_DriginalResults) + expect_silent(BC_OriginalResults) expect_silent(BC_DeltaSDNB_SensitivityPlot) }) From 0bdc444e76ad7d46c14e139c1cc1707a1084e459 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 08:19:08 -0500 Subject: [PATCH 09/17] Moved lfe install to test script --- .github/workflows/tests.yml | 1 - tests/test_base.R | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a6a0e5d..f793a54 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -33,7 +33,6 @@ jobs: with: extra-packages: | any::devtools - any::lfe any::knitr any::formatR any::haven diff --git a/tests/test_base.R b/tests/test_base.R index cb58118..67d604d 100644 --- a/tests/test_base.R +++ b/tests/test_base.R @@ -2,6 +2,7 @@ # install.packages(".", repos=NULL, type="source") # testthat::test_dir("tests") +install.packages("lfe") library(lfe) library(HonestDiD) data(BCdata_EventStudy) From 34fcca81bb730f950f023f9559661b1f7fb741d2 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 11:01:51 -0500 Subject: [PATCH 10/17] Moved lfe install to test script (debugging) --- tests/test_base.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_base.R b/tests/test_base.R index 67d604d..41c14ff 100644 --- a/tests/test_base.R +++ b/tests/test_base.R @@ -2,7 +2,7 @@ # install.packages(".", repos=NULL, type="source") # testthat::test_dir("tests") -install.packages("lfe") +install.packages("lfe", repos="http://cran.us.r-project.org") library(lfe) library(HonestDiD) data(BCdata_EventStudy) From 038800ca0db7b67e73aeb2b32d7fff93245b7f66 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 11:27:47 -0500 Subject: [PATCH 11/17] Added testthat --- .github/workflows/tests.yml | 2 ++ DESCRIPTION | 1 + tests/test_base.R | 1 + 3 files changed, 4 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f793a54..2fb1edf 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -36,10 +36,12 @@ jobs: any::knitr any::formatR any::haven + any::testthat needs: | devtools knitr rmarkdown + testthat - name: Setup pandoc uses: r-lib/actions/setup-pandoc@v2 diff --git a/DESCRIPTION b/DESCRIPTION index 3891189..c0d34c7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -23,6 +23,7 @@ Imports: TruncatedNormal (>= 1.0) Suggests: knitr, + testthat, rmarkdown Authors@R: c(person(given = "Ashesh", diff --git a/tests/test_base.R b/tests/test_base.R index 41c14ff..981c66d 100644 --- a/tests/test_base.R +++ b/tests/test_base.R @@ -4,6 +4,7 @@ install.packages("lfe", repos="http://cran.us.r-project.org") library(lfe) +library(testthat) library(HonestDiD) data(BCdata_EventStudy) data(LWdata_EventStudy) From ab47038c3261226bddeb67b70d59a5047e9af357 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 11:55:06 -0500 Subject: [PATCH 12/17] Added haven for some reason --- .github/workflows/tests.yml | 1 + DESCRIPTION | 1 + tests/test_base.R | 1 + 3 files changed, 3 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2fb1edf..b17b422 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -42,6 +42,7 @@ jobs: knitr rmarkdown testthat + haven - name: Setup pandoc uses: r-lib/actions/setup-pandoc@v2 diff --git a/DESCRIPTION b/DESCRIPTION index c0d34c7..6bd9c4b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,6 +24,7 @@ Imports: Suggests: knitr, testthat, + haven, rmarkdown Authors@R: c(person(given = "Ashesh", diff --git a/tests/test_base.R b/tests/test_base.R index 981c66d..1a06d1a 100644 --- a/tests/test_base.R +++ b/tests/test_base.R @@ -4,6 +4,7 @@ install.packages("lfe", repos="http://cran.us.r-project.org") library(lfe) +library(haven) library(testthat) library(HonestDiD) data(BCdata_EventStudy) From 1c9d5e4841b3ca2082a4a7f02de027a1999e41e5 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 23 Jan 2024 16:21:03 -0500 Subject: [PATCH 13/17] Gave up and added lfe to recomended packages (for test) --- .github/workflows/tests.yml | 4 +++- DESCRIPTION | 1 + R/honest_did.R | 8 ++++++-- tests/test_base.R | 1 - 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b17b422..428757c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,14 +35,16 @@ jobs: any::devtools any::knitr any::formatR - any::haven any::testthat + any::haven + any::lfe needs: | devtools knitr rmarkdown testthat haven + lfe - name: Setup pandoc uses: r-lib/actions/setup-pandoc@v2 diff --git a/DESCRIPTION b/DESCRIPTION index 6bd9c4b..4bf4de7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -25,6 +25,7 @@ Suggests: knitr, testthat, haven, + lfe, rmarkdown Authors@R: c(person(given = "Ashesh", diff --git a/R/honest_did.R b/R/honest_did.R index 0741b79..81dcc62 100644 --- a/R/honest_did.R +++ b/R/honest_did.R @@ -2,6 +2,8 @@ #' #' @description a function to compute a sensitivity analysis #' using the approach of Rambachan and Roth (2021) +#' +#' @param ... Parameters to pass to the relevant method. honest_did <- function(...) UseMethod("honest_did") #' @title honest_did.AGGTEobj @@ -20,8 +22,10 @@ honest_did <- function(...) UseMethod("honest_did") #' conducts a sensitivity analysis based on the relative magnitudes #' of deviations from parallel trends in pre-treatment periods). #' @param gridPoints Number of grid points used for the underlying test -#' inversion. Default equals 100. User may wish to change the number of grid -#' points for computational reasons. +#' inversion. Default equals 100. User may wish to change the number of grid +#' points for computational reasons. +#' @param ... Parameters to pass to `createSensitivityResults` or +#' `createSensitivityResults_relativeMagnitudes`. #' @inheritParams HonestDiD::createSensitivityResults #' @inheritParams HonestDid::createSensitivityResults_relativeMagnitudes honest_did.AGGTEobj <- function(es, diff --git a/tests/test_base.R b/tests/test_base.R index 1a06d1a..a9b68b4 100644 --- a/tests/test_base.R +++ b/tests/test_base.R @@ -2,7 +2,6 @@ # install.packages(".", repos=NULL, type="source") # testthat::test_dir("tests") -install.packages("lfe", repos="http://cran.us.r-project.org") library(lfe) library(haven) library(testthat) From 4deeb2298011a46fd6c7b98f158ba69d9d70fef6 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Fri, 21 Jun 2024 07:52:46 -0400 Subject: [PATCH 14/17] Reset random seed, if it exists, after createSensitivityResults*() --- R/sensitivityresults.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/R/sensitivityresults.R b/R/sensitivityresults.R index e6cb97b..defd50d 100644 --- a/R/sensitivityresults.R +++ b/R/sensitivityresults.R @@ -18,6 +18,9 @@ createSensitivityResults <- function(betahat, sigma, biasDirection = NULL, alpha = 0.05, parallel = FALSE) { + if ( !base::exists(".Random.seed", .GlobalEnv) ) stats::runif(1) + rseed.cached <- base::get(".Random.seed", .GlobalEnv) + base::on.exit({base::assign(".Random.seed", rseed.cached, .GlobalEnv)}) .stopIfNotConformable(betahat, sigma, numPrePeriods, numPostPeriods, l_vec) .warnIfNotSymmPSD(sigma) @@ -419,6 +422,9 @@ createSensitivityResults_relativeMagnitudes <- function(betahat, sigma, grid.ub = NA, grid.lb = NA, parallel = FALSE) { + if ( !base::exists(".Random.seed", .GlobalEnv) ) stats::runif(1) + rseed.cached <- base::get(".Random.seed", .GlobalEnv) + base::on.exit({base::assign(".Random.seed", rseed.cached, .GlobalEnv)}) .stopIfNotConformable(betahat, sigma, numPrePeriods, numPostPeriods, l_vec) .warnIfNotSymmPSD(sigma) From dd568985f5b462f275c8bc9cfdb2dcc2816f1a5d Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 9 Jul 2024 21:15:38 -0400 Subject: [PATCH 15/17] Make internal seed user-accessible --- R/arp-nuisance.R | 4 +- R/deltarm.R | 10 ++--- R/deltarmb.R | 10 ++--- R/deltarmm.R | 10 ++--- R/deltasd.R | 4 +- R/deltasdb.R | 4 +- R/deltasdm.R | 4 +- R/deltasdrm.R | 10 ++--- R/deltasdrmb.R | 10 ++--- R/deltasdrmm.R | 10 ++--- R/flci.R | 13 ++++--- R/sensitivityresults.R | 84 ++++++++++++++++++++---------------------- 12 files changed, 85 insertions(+), 88 deletions(-) diff --git a/R/arp-nuisance.R b/R/arp-nuisance.R index 782ec5c..3040bd3 100644 --- a/R/arp-nuisance.R +++ b/R/arp-nuisance.R @@ -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). # @@ -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) diff --git a/R/deltarm.R b/R/deltarm.R index f5d3a57..70152b8 100644 --- a/R/deltarm.R +++ b/R/deltarm.R @@ -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. @@ -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 @@ -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. @@ -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 (-) @@ -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 } diff --git a/R/deltarmb.R b/R/deltarmb.R index ae6a8e2..c467e43 100644 --- a/R/deltarmb.R +++ b/R/deltarmb.R @@ -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. @@ -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 @@ -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. @@ -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 (-) @@ -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 } diff --git a/R/deltarmm.R b/R/deltarmm.R index 826372c..876cb47 100644 --- a/R/deltarmm.R +++ b/R/deltarmm.R @@ -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. @@ -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 @@ -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. @@ -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 (-) @@ -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 } diff --git a/R/deltasd.R b/R/deltasd.R index 0efa145..16bde1f 100644 --- a/R/deltasd.R +++ b/R/deltasd.R @@ -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. @@ -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 diff --git a/R/deltasdb.R b/R/deltasdb.R index a9f2bc4..7aa6cf3 100644 --- a/R/deltasdb.R +++ b/R/deltasdb.R @@ -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. @@ -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 diff --git a/R/deltasdm.R b/R/deltasdm.R index 9d8a2c1..90e671d 100644 --- a/R/deltasdm.R +++ b/R/deltasdm.R @@ -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. @@ -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 diff --git a/R/deltasdrm.R b/R/deltasdrm.R index 01f125d..5e0f812 100644 --- a/R/deltasdrm.R +++ b/R/deltasdrm.R @@ -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. @@ -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 @@ -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. @@ -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 (-) @@ -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) diff --git a/R/deltasdrmb.R b/R/deltasdrmb.R index c1653e9..f05fd57 100644 --- a/R/deltasdrmb.R +++ b/R/deltasdrmb.R @@ -194,7 +194,7 @@ .computeConditionalCS_DeltaSDRMB_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^{SDRMB}(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_DeltaSDRMB below. @@ -233,7 +233,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_SDRMB_s %*% sigma %*% base::t(A_SDRMB_s), hybrid_kappa = hybrid_kappa) + lf_cv = .compute_least_favorable_cv(X_T = NULL, sigma = A_SDRMB_s %*% sigma %*% base::t(A_SDRMB_s), hybrid_kappa = hybrid_kappa, seed = seed) hybrid_list$lf_cv = lf_cv } # Compute confidence set @@ -262,7 +262,7 @@ computeConditionalCS_DeltaSDRMB <- function(betahat, sigma, numPrePeriods, numPo Mbar = 0, alpha = 0.05, hybrid_flag = "LF", hybrid_kappa = alpha/10, returnLength = FALSE, postPeriodMomentsOnly = TRUE, biasDirection = "positive", - 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^{SDRMB}(Mbar). This functions uses ARP_computeCI for all # of its computations. @@ -311,7 +311,7 @@ computeConditionalCS_DeltaSDRMB <- function(betahat, sigma, numPrePeriods, numPo 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_SDRMB_plus_allS[,s_i] = CI_s_plus$accept # Compute CI for s, (-) and bind it to all CI's for (-) @@ -320,7 +320,7 @@ computeConditionalCS_DeltaSDRMB <- function(betahat, sigma, numPrePeriods, numPo 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_SDRMB_minus_allS[,s_i] = CI_s_minus$accept } CIs_SDRMB_plus_maxS = base::apply(CIs_SDRMB_plus_allS, MARGIN = 1, FUN = base::max) diff --git a/R/deltasdrmm.R b/R/deltasdrmm.R index 53608df..78459f2 100644 --- a/R/deltasdrmm.R +++ b/R/deltasdrmm.R @@ -195,7 +195,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^{SDRMM}(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_DeltaSDRMM below. @@ -236,7 +236,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_SDRMM_s %*% sigma %*% base::t(A_SDRMM_s), hybrid_kappa = hybrid_kappa) + lf_cv = .compute_least_favorable_cv(X_T = NULL, sigma = A_SDRMM_s %*% sigma %*% base::t(A_SDRMM_s), hybrid_kappa = hybrid_kappa, seed = seed) hybrid_list$lf_cv = lf_cv } # Compute confidence set @@ -266,7 +266,7 @@ computeConditionalCS_DeltaSDRMM <- function(betahat, sigma, numPrePeriods, numPo 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^{SDRMM}(Mbar). This functions uses ARP_computeCI for all # of its computations. @@ -315,7 +315,7 @@ computeConditionalCS_DeltaSDRMM <- function(betahat, sigma, numPrePeriods, numPo 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_SDRMM_plus_allS[,s_i] = CI_s_plus$accept # Compute CI for s, (-) and bind it to all CI's for (-) @@ -324,7 +324,7 @@ computeConditionalCS_DeltaSDRMM <- function(betahat, sigma, numPrePeriods, numPo 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_SDRMM_minus_allS[,s_i] = CI_s_minus$accept } CIs_SDRMM_plus_maxS = base::apply(CIs_SDRMM_plus_allS, MARGIN = 1, FUN = base::max) diff --git a/R/flci.R b/R/flci.R index 3150b46..2a507e0 100644 --- a/R/flci.R +++ b/R/flci.R @@ -215,10 +215,10 @@ .findOptimalFLCI_helper <- function(sigma, M, numPrePeriods, numPostPeriods, - l_vec, numPoints = 100, alpha){ + l_vec, numPoints = 100, alpha, seed = 0){ h0 <- .findHForMinimumBias(sigma = sigma, numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, l_vec = l_vec) hMin <- .findLowestH(sigma = sigma, numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, l_vec = l_vec) - hstar <- .findOptimalCIDerivativeBisection(hMin, h0, M, numPoints, alpha, sigma, numPrePeriods, numPostPeriods, l_vec, TRUE) + hstar <- .findOptimalCIDerivativeBisection(hMin, h0, M, numPoints, alpha, sigma, numPrePeriods, numPostPeriods, l_vec, TRUE, seed=seed) if ( base::is.na(hstar) ) { # Numerical derivatives will occasionally fail; fall back into grid @@ -260,14 +260,14 @@ } .findOptimalCIDerivativeBisection <- function(a, b, M, numPoints, alpha, sigma, - numPrePeriods, numPostPeriods, l_vec, returnDF) { + numPrePeriods, numPostPeriods, l_vec, returnDF, seed=0) { # Function of h, which is convex (returns CI half length) .f <- function(h, ...) { biasDF <- .findWorstCaseBiasGivenH(h, sigma, numPrePeriods, numPostPeriods, l_vec, returnDF) maxBias <- M * biasDF$value if (biasDF$value < Inf) { - base::return(.qfoldednormal(p = 1-alpha, mu = maxBias/h) * h) + base::return(.qfoldednormal(p = 1-alpha, mu = maxBias/h, seed=seed) * h) } else { base::return(NaN) } @@ -319,14 +319,15 @@ findOptimalFLCI <- function(betahat, sigma, M = 0, numPrePeriods, numPostPeriods, l_vec = .basisVector(index = 1, size = numPostPeriods), - numPoints = 100, alpha = 0.05) { + numPoints = 100, alpha = 0.05, seed = 0) { FLCI_Results = .findOptimalFLCI_helper(sigma = sigma, M = M, numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, l_vec = l_vec, numPoints = numPoints, - alpha = alpha) + alpha = alpha, + seed = seed) FLCI = base::c(base::t(FLCI_Results$optimalVec) %*% betahat - FLCI_Results$optimalHalfLength, base::t(FLCI_Results$optimalVec) %*% betahat + FLCI_Results$optimalHalfLength) diff --git a/R/sensitivityresults.R b/R/sensitivityresults.R index defd50d..4b079d8 100644 --- a/R/sensitivityresults.R +++ b/R/sensitivityresults.R @@ -17,10 +17,8 @@ createSensitivityResults <- function(betahat, sigma, monotonicityDirection = NULL, biasDirection = NULL, alpha = 0.05, - parallel = FALSE) { - if ( !base::exists(".Random.seed", .GlobalEnv) ) stats::runif(1) - rseed.cached <- base::get(".Random.seed", .GlobalEnv) - base::on.exit({base::assign(".Random.seed", rseed.cached, .GlobalEnv)}) + parallel = FALSE, + seed = 0) { .stopIfNotConformable(betahat, sigma, numPrePeriods, numPostPeriods, l_vec) .warnIfNotSymmPSD(sigma) @@ -47,7 +45,7 @@ createSensitivityResults <- function(betahat, sigma, Results = foreach::foreach(m = 1:base::length(Mvec), .combine = 'rbind') %do% { temp = findOptimalFLCI(betahat = betahat, sigma = sigma, numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, - l_vec = l_vec, M = Mvec[m], alpha = alpha) + l_vec = l_vec, M = Mvec[m], alpha = alpha, seed = seed) tibble::tibble(lb = temp$FLCI[1], ub = temp$FLCI[2], method = "FLCI", Delta = "DeltaSD", M = Mvec[m]) } @@ -55,7 +53,7 @@ createSensitivityResults <- function(betahat, sigma, Results = foreach::foreach(m = 1:base::length(Mvec), .combine = 'rbind') %dopar% { temp = findOptimalFLCI(betahat = betahat, sigma = sigma, numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, - l_vec = l_vec, M = Mvec[m], alpha = alpha) + l_vec = l_vec, M = Mvec[m], alpha = alpha, seed = seed) tibble::tibble(lb = temp$FLCI[1], ub = temp$FLCI[2], method = "FLCI", Delta = "DeltaSD", M = Mvec[m]) } @@ -67,7 +65,7 @@ createSensitivityResults <- function(betahat, sigma, numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, M = Mvec[m], - hybrid_flag = "ARP") + hybrid_flag = "ARP", seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = "Conditional", @@ -79,7 +77,7 @@ createSensitivityResults <- function(betahat, sigma, numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, M = Mvec[m], - hybrid_flag = "ARP") + hybrid_flag = "ARP", seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = "Conditional", @@ -93,7 +91,7 @@ createSensitivityResults <- function(betahat, sigma, numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, M = Mvec[m], - hybrid_flag = "FLCI") + hybrid_flag = "FLCI", seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = "C-F", @@ -105,7 +103,7 @@ createSensitivityResults <- function(betahat, sigma, numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, M = Mvec[m], - hybrid_flag = "FLCI") + hybrid_flag = "FLCI", seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = "C-F", @@ -119,7 +117,7 @@ createSensitivityResults <- function(betahat, sigma, numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, M = Mvec[m], - hybrid_flag = "LF") + hybrid_flag = "LF", seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = "C-LF", @@ -131,7 +129,7 @@ createSensitivityResults <- function(betahat, sigma, numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, M = Mvec[m], - hybrid_flag = "LF") + hybrid_flag = "LF", seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = "C-LF", @@ -158,7 +156,7 @@ createSensitivityResults <- function(betahat, sigma, Results = foreach::foreach(m = 1:base::length(Mvec), .combine = 'rbind') %do% { temp = findOptimalFLCI(betahat = betahat, sigma = sigma, numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, - l_vec = l_vec, M = Mvec[m], alpha = alpha) + l_vec = l_vec, M = Mvec[m], alpha = alpha, seed = seed) tibble::tibble(lb = temp$FLCI[1], ub = temp$FLCI[2], method = "FLCI", Delta = Delta, M = Mvec[m]) } @@ -166,7 +164,7 @@ createSensitivityResults <- function(betahat, sigma, Results = foreach::foreach(m = 1:base::length(Mvec), .combine = 'rbind') %dopar% { temp = findOptimalFLCI(betahat = betahat, sigma = sigma, numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, - l_vec = l_vec, M = Mvec[m], alpha = alpha) + l_vec = l_vec, M = Mvec[m], alpha = alpha, seed = seed) tibble::tibble(lb = temp$FLCI[1], ub = temp$FLCI[2], method = "FLCI", Delta = Delta, M = Mvec[m]) } @@ -179,7 +177,7 @@ createSensitivityResults <- function(betahat, sigma, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, M = Mvec[m], biasDirection = biasDirection, - hybrid_flag = "ARP") + hybrid_flag = "ARP", seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = "Conditional", @@ -192,7 +190,7 @@ createSensitivityResults <- function(betahat, sigma, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, M = Mvec[m], biasDirection = biasDirection, - hybrid_flag = "ARP") + hybrid_flag = "ARP", seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = "Conditional", @@ -207,7 +205,7 @@ createSensitivityResults <- function(betahat, sigma, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, M = Mvec[m], biasDirection = biasDirection, - hybrid_flag = "FLCI") + hybrid_flag = "FLCI", seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = "C-F", @@ -220,7 +218,7 @@ createSensitivityResults <- function(betahat, sigma, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, M = Mvec[m], biasDirection = biasDirection, - hybrid_flag = "FLCI") + hybrid_flag = "FLCI", seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = "C-F", @@ -235,7 +233,7 @@ createSensitivityResults <- function(betahat, sigma, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, M = Mvec[m], biasDirection = biasDirection, - hybrid_flag = "LF") + hybrid_flag = "LF", seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = "C-LF", @@ -248,7 +246,7 @@ createSensitivityResults <- function(betahat, sigma, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, M = Mvec[m], biasDirection = biasDirection, - hybrid_flag = "LF") + hybrid_flag = "LF", seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = "C-LF", @@ -275,7 +273,7 @@ createSensitivityResults <- function(betahat, sigma, Results = foreach::foreach(m = 1:base::length(Mvec), .combine = 'rbind') %do% { temp = findOptimalFLCI(betahat = betahat, sigma = sigma, numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, - l_vec = l_vec, M = Mvec[m], alpha = alpha) + l_vec = l_vec, M = Mvec[m], alpha = alpha, seed = seed) tibble::tibble(lb = temp$FLCI[1], ub = temp$FLCI[2], method = "FLCI", Delta = Delta, M = Mvec[m]) } @@ -283,7 +281,7 @@ createSensitivityResults <- function(betahat, sigma, Results = foreach::foreach(m = 1:base::length(Mvec), .combine = 'rbind') %dopar% { temp = findOptimalFLCI(betahat = betahat, sigma = sigma, numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, - l_vec = l_vec, M = Mvec[m], alpha = alpha) + l_vec = l_vec, M = Mvec[m], alpha = alpha, seed = seed) tibble::tibble(lb = temp$FLCI[1], ub = temp$FLCI[2], method = "FLCI", Delta = Delta, M = Mvec[m]) } @@ -296,7 +294,7 @@ createSensitivityResults <- function(betahat, sigma, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, M = Mvec[m], monotonicityDirection = monotonicityDirection, - hybrid_flag = "ARP") + hybrid_flag = "ARP", seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = "Conditional", @@ -309,7 +307,7 @@ createSensitivityResults <- function(betahat, sigma, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, M = Mvec[m], monotonicityDirection = monotonicityDirection, - hybrid_flag = "ARP") + hybrid_flag = "ARP", seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = "Conditional", @@ -324,7 +322,7 @@ createSensitivityResults <- function(betahat, sigma, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, M = Mvec[m], monotonicityDirection = monotonicityDirection, - hybrid_flag = "FLCI") + hybrid_flag = "FLCI", seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = "C-F", @@ -338,7 +336,7 @@ createSensitivityResults <- function(betahat, sigma, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, M = Mvec[m], monotonicityDirection = monotonicityDirection, - hybrid_flag = "FLCI") + hybrid_flag = "FLCI", seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = "C-F", @@ -354,7 +352,7 @@ createSensitivityResults <- function(betahat, sigma, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, M = Mvec[m], monotonicityDirection = monotonicityDirection, - hybrid_flag = "LF") + hybrid_flag = "LF", seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = "C-LF", @@ -367,7 +365,7 @@ createSensitivityResults <- function(betahat, sigma, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, M = Mvec[m], monotonicityDirection = monotonicityDirection, - hybrid_flag = "LF") + hybrid_flag = "LF", seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = "C-LF", @@ -421,10 +419,8 @@ createSensitivityResults_relativeMagnitudes <- function(betahat, sigma, gridPoints = 10^3, grid.ub = NA, grid.lb = NA, - parallel = FALSE) { - if ( !base::exists(".Random.seed", .GlobalEnv) ) stats::runif(1) - rseed.cached <- base::get(".Random.seed", .GlobalEnv) - base::on.exit({base::assign(".Random.seed", rseed.cached, .GlobalEnv)}) + parallel = FALSE, + seed = 0) { .stopIfNotConformable(betahat, sigma, numPrePeriods, numPostPeriods, l_vec) .warnIfNotSymmPSD(sigma) @@ -469,7 +465,7 @@ createSensitivityResults_relativeMagnitudes <- function(betahat, sigma, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, Mbar = Mbarvec[m], hybrid_flag = hybrid_flag, - gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb) + gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb, seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = method_named, @@ -482,7 +478,7 @@ createSensitivityResults_relativeMagnitudes <- function(betahat, sigma, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, Mbar = Mbarvec[m], hybrid_flag = hybrid_flag, - gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb) + gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb, seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = method_named, @@ -506,7 +502,7 @@ createSensitivityResults_relativeMagnitudes <- function(betahat, sigma, l_vec = l_vec, alpha = alpha, Mbar = Mbarvec[m], monotonicityDirection = monotonicityDirection, hybrid_flag = hybrid_flag, - gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb) + gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb, seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = method_named, @@ -520,7 +516,7 @@ createSensitivityResults_relativeMagnitudes <- function(betahat, sigma, l_vec = l_vec, alpha = alpha, Mbar = Mbarvec[m], monotonicityDirection = monotonicityDirection, hybrid_flag = hybrid_flag, - gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb) + gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb, seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = method_named, @@ -544,7 +540,7 @@ createSensitivityResults_relativeMagnitudes <- function(betahat, sigma, l_vec = l_vec, alpha = alpha, Mbar = Mbarvec[m], biasDirection = biasDirection, hybrid_flag = hybrid_flag, - gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb) + gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb, seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = method_named, @@ -558,7 +554,7 @@ createSensitivityResults_relativeMagnitudes <- function(betahat, sigma, l_vec = l_vec, alpha = alpha, Mbar = Mbarvec[m], biasDirection = biasDirection, hybrid_flag = hybrid_flag, - gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb) + gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb, seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = method_named, @@ -586,7 +582,7 @@ createSensitivityResults_relativeMagnitudes <- function(betahat, sigma, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, Mbar = Mbarvec[m], hybrid_flag = hybrid_flag, - gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb) + gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb, seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = method_named, @@ -599,7 +595,7 @@ createSensitivityResults_relativeMagnitudes <- function(betahat, sigma, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, Mbar = Mbarvec[m], hybrid_flag = hybrid_flag, - gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb) + gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb, seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = method_named, @@ -623,7 +619,7 @@ createSensitivityResults_relativeMagnitudes <- function(betahat, sigma, l_vec = l_vec, alpha = alpha, Mbar = Mbarvec[m], monotonicityDirection = monotonicityDirection, hybrid_flag = hybrid_flag, - gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb) + gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb, seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = method_named, @@ -637,7 +633,7 @@ createSensitivityResults_relativeMagnitudes <- function(betahat, sigma, l_vec = l_vec, alpha = alpha, Mbar = Mbarvec[m], monotonicityDirection = monotonicityDirection, hybrid_flag = hybrid_flag, - gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb) + gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb, seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = method_named, @@ -661,7 +657,7 @@ createSensitivityResults_relativeMagnitudes <- function(betahat, sigma, l_vec = l_vec, alpha = alpha, Mbar = Mbarvec[m], biasDirection = biasDirection, hybrid_flag = hybrid_flag, - gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb) + gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb, seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = method_named, @@ -675,7 +671,7 @@ createSensitivityResults_relativeMagnitudes <- function(betahat, sigma, l_vec = l_vec, alpha = alpha, Mbar = Mbarvec[m], biasDirection = biasDirection, hybrid_flag = hybrid_flag, - gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb) + gridPoints = gridPoints, grid.ub = grid.ub, grid.lb = grid.lb, seed = seed) tibble::tibble(lb = base::min(temp$grid[temp$accept == 1]), ub = base::max(temp$grid[temp$accept == 1]), method = method_named, From 4adfc6ca60caa0d044220c612b2edbb4a460ec20 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 9 Jul 2024 21:20:22 -0400 Subject: [PATCH 16/17] Added seed option to function docs --- man/computeConditionalCS_DeltaRM.Rd | 5 ++++- man/computeConditionalCS_DeltaRMB.Rd | 5 ++++- man/computeConditionalCS_DeltaRMM.Rd | 5 ++++- man/computeConditionalCS_DeltaSD.Rd | 5 ++++- man/computeConditionalCS_DeltaSDB.Rd | 5 ++++- man/computeConditionalCS_DeltaSDM.Rd | 5 ++++- man/computeConditionalCS_DeltaSDRM.Rd | 5 ++++- man/computeConditionalCS_DeltaSDRMB.Rd | 5 ++++- man/computeConditionalCS_DeltaSDRMM.Rd | 2 +- man/createSensitivityResults.Rd | 18 +++++++++++++----- ...ateSensitivityResults_relativeMagnitudes.Rd | 6 +++++- man/findOptimalFLCI.Rd | 5 ++++- 12 files changed, 55 insertions(+), 16 deletions(-) diff --git a/man/computeConditionalCS_DeltaRM.Rd b/man/computeConditionalCS_DeltaRM.Rd index 42753ca..fbc7051 100644 --- a/man/computeConditionalCS_DeltaRM.Rd +++ b/man/computeConditionalCS_DeltaRM.Rd @@ -12,7 +12,7 @@ computeConditionalCS_DeltaRM(betahat, sigma, numPrePeriods, numPostPeriods, 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) } %- maybe also 'usage' for other objects documented here. \arguments{ @@ -58,6 +58,9 @@ Logical value. If TRUE, function only returns the length of the robust confidenc \item{grid.lb}{ Lower bound of grid for test inversion. The user should only specify this if she wishes to manually specify the upper bound of the grid. Default equals NA sets grid lower bound to equal the lower bound of the identified set under parallel trends minus 20*standard deviation of the point estimate, l_vec'betahat. } + \item{seed}{ + Random seed for internal computations; included for reproducibility. + } } \value{ If returnLength equals TRUE, function returns a scalar that equals the length of the confidence interval. If returnLength equals FALSE, function returns a dataframe with columns diff --git a/man/computeConditionalCS_DeltaRMB.Rd b/man/computeConditionalCS_DeltaRMB.Rd index 6c15ba7..966b030 100644 --- a/man/computeConditionalCS_DeltaRMB.Rd +++ b/man/computeConditionalCS_DeltaRMB.Rd @@ -14,7 +14,7 @@ computeConditionalCS_DeltaRMB(betahat, sigma, numPrePeriods, numPostPeriods, Mbar = 0, 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) } %- maybe also 'usage' for other objects documented here. \arguments{ @@ -63,6 +63,9 @@ Logical value. If TRUE, function only returns the length of the robust confidenc \item{grid.lb}{ Lower bound of grid for test inversion. The user should only specify this if she wishes to manually specify the upper bound of the grid. Default equals NA sets grid lower bound to equal the lower bound of the identified set under parallel trends minus 20*standard deviation of the point estimate, l_vec'betahat. } + \item{seed}{ + Random seed for internal computations; included for reproducibility. + } } \value{ If returnLength equals TRUE, function returns a scalar that equals the length of the confidence interval. If returnLength equals FALSE, function returns a dataframe with columns diff --git a/man/computeConditionalCS_DeltaRMM.Rd b/man/computeConditionalCS_DeltaRMM.Rd index 40647fb..132a4df 100644 --- a/man/computeConditionalCS_DeltaRMM.Rd +++ b/man/computeConditionalCS_DeltaRMM.Rd @@ -15,7 +15,7 @@ computeConditionalCS_DeltaRMM(betahat, sigma, numPrePeriods, numPostPeriods, 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) } %- maybe also 'usage' for other objects documented here. \arguments{ @@ -64,6 +64,9 @@ Specifies direction of monotonicity restriction. If "increasing", underlying tre \item{grid.lb}{ Lower bound of grid for test inversion. The user should only specify this if she wishes to manually specify the upper bound of the grid. Default equals NA sets grid lower bound to equal the lower bound of the identified set under parallel trends minus 20*standard deviation of the point estimate, l_vec'betahat. } + \item{seed}{ + Random seed for internal computations; included for reproducibility. + } } \value{ If returnLength equals TRUE, function returns a scalar that equals the length of the confidence interval. If returnLength equals FALSE, function returns a dataframe with columns diff --git a/man/computeConditionalCS_DeltaSD.Rd b/man/computeConditionalCS_DeltaSD.Rd index ab5563f..3e2a43d 100644 --- a/man/computeConditionalCS_DeltaSD.Rd +++ b/man/computeConditionalCS_DeltaSD.Rd @@ -13,7 +13,7 @@ computeConditionalCS_DeltaSD(betahat, sigma, numPrePeriods, numPostPeriods, 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) } %- maybe also 'usage' for other objects documented here. \arguments{ @@ -59,6 +59,9 @@ Logical value. If TRUE, function only returns the length of the robust confidenc \item{grid.lb}{ Lower bound of grid for test inversion. The user should only specify this if she wishes to manually specify the upper bound of the grid. Default equals NA sets grid lower bound to equal the lower bound of the identified set under parallel trends minus 20*standard deviation of the point estimate, l_vec'betahat. } + \item{seed}{ + Random seed for internal computations; included for reproducibility. + } } \value{ If returnLength equals TRUE, function returns a scalar that equals the length of the confidence interval. If returnLength equals FALSE, function returns a dataframe with columns diff --git a/man/computeConditionalCS_DeltaSDB.Rd b/man/computeConditionalCS_DeltaSDB.Rd index 234adcc..4708fff 100644 --- a/man/computeConditionalCS_DeltaSDB.Rd +++ b/man/computeConditionalCS_DeltaSDB.Rd @@ -13,7 +13,7 @@ computeConditionalCS_DeltaSDB(betahat, sigma, numPrePeriods, numPostPeriods, 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) } %- maybe also 'usage' for other objects documented here. \arguments{ @@ -62,6 +62,9 @@ Logical value. If TRUE, function only returns the length of the robust confidenc \item{grid.lb}{ Lower bound of grid for test inversion. The user should only specify this if she wishes to manually specify the upper bound of the grid. Default equals NA sets grid lower bound to equal the lower bound of the identified set under parallel trends minus 20*standard deviation of the point estimate, l_vec'betahat. } + \item{seed}{ + Random seed for internal computations; included for reproducibility. + } } \value{ If returnLength equals TRUE, function returns a scalar that equals the length of the confidence interval. If returnLength equals FALSE, function returns a dataframe with columns diff --git a/man/computeConditionalCS_DeltaSDM.Rd b/man/computeConditionalCS_DeltaSDM.Rd index a07270f..fa81c4d 100644 --- a/man/computeConditionalCS_DeltaSDM.Rd +++ b/man/computeConditionalCS_DeltaSDM.Rd @@ -13,7 +13,7 @@ computeConditionalCS_DeltaSDM(betahat, sigma, numPrePeriods, numPostPeriods, 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) } %- maybe also 'usage' for other objects documented here. \arguments{ @@ -62,6 +62,9 @@ Specifies direction of monotonicity restriction. If "increasing", underlying tre \item{grid.lb}{ Lower bound of grid for test inversion. The user should only specify this if she wishes to manually specify the upper bound of the grid. Default equals NA sets grid lower bound to equal the lower bound of the identified set under parallel trends minus 20*standard deviation of the point estimate, l_vec'betahat. } + \item{seed}{ + Random seed for internal computations; included for reproducibility. + } } \value{ If returnLength equals TRUE, function returns a scalar that equals the length of the confidence interval. If returnLength equals FALSE, function returns a dataframe with columns diff --git a/man/computeConditionalCS_DeltaSDRM.Rd b/man/computeConditionalCS_DeltaSDRM.Rd index bd0dcea..83fa4b6 100644 --- a/man/computeConditionalCS_DeltaSDRM.Rd +++ b/man/computeConditionalCS_DeltaSDRM.Rd @@ -12,7 +12,7 @@ computeConditionalCS_DeltaSDRM(betahat, sigma, numPrePeriods, numPostPeriods, 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) } %- maybe also 'usage' for other objects documented here. \arguments{ @@ -58,6 +58,9 @@ Logical value. If \code{TRUE}, function only returns the length of the robust co \item{grid.lb}{ Lower bound of grid for test inversion. The user should only specify this if she wishes to manually specify the upper bound of the grid. Default equals \code{NA} sets grid lower bound to equal the lower bound of the identified set under parallel trends minus 20*standard deviation of the point estimate, l_vec'betahat. } + \item{seed}{ + Random seed for internal computations; included for reproducibility. + } } \details{ For the choice \eqn{\Delta^{SDRM}}, \code{numPrePeriods} must be greater than one. As discussed in Section 2.3.2 of Rambachan & Roth (2021), \eqn{\Delta^{SDRM}} uses observed non-linearities in the pre-treatment difference in trends to bound the possible non-linearities in the post-treatment difference in trends. This is only possible if there are multiple pre-treatment periods (i.e., \code{numPrePeriods} > 1). diff --git a/man/computeConditionalCS_DeltaSDRMB.Rd b/man/computeConditionalCS_DeltaSDRMB.Rd index 3f64a04..fcd9d58 100644 --- a/man/computeConditionalCS_DeltaSDRMB.Rd +++ b/man/computeConditionalCS_DeltaSDRMB.Rd @@ -13,7 +13,7 @@ computeConditionalCS_DeltaSDRMB(betahat, sigma, numPrePeriods, numPostPeriods, Mbar = 0, alpha = 0.05, hybrid_flag = "LF", hybrid_kappa = alpha/10, returnLength = FALSE, postPeriodMomentsOnly = TRUE, biasDirection = "positive", - gridPoints=10^3, grid.ub = NA, grid.lb = NA) + gridPoints=10^3, grid.ub = NA, grid.lb = NA, seed = 0) } %- maybe also 'usage' for other objects documented here. \arguments{ @@ -62,6 +62,9 @@ Logical value. If \code{TRUE}, function only returns the length of the robust co \item{grid.lb}{ Lower bound of grid for test inversion. The user should only specify this if she wishes to manually specify the upper bound of the grid. Default equals \code{NA} sets grid lower bound to equal the lower bound of the identified set under parallel trends minus 20*standard deviation of the point estimate, l_vec'betahat. } + \item{seed}{ + Random seed for internal computations; included for reproducibility. + } } \details{ The choice \eqn{\Delta^{SDRMB}} adds an additional sign restriction to \eqn{\Delta^{SDRM}(Mbar)} that restricts the sign of the bias to be either positive (\eqn{\delta \ge 0}) or negative (\eqn{\delta \le 0}). For this choice \eqn{\Delta^{SDRMB}}, \code{numPrePeriods} must be greater than one. As discussed in Section 2.3.2 of Rambachan & Roth (2021), \eqn{\Delta^{SDRM}} uses observed non-linearities in the pre-treatment difference in trends to bound the possible non-linearities in the post-treatment difference in trends. This is only possible if there are multiple pre-treatment periods (i.e., \code{numPrePeriods} > 1). diff --git a/man/computeConditionalCS_DeltaSDRMM.Rd b/man/computeConditionalCS_DeltaSDRMM.Rd index 8203f9b..4fa46bd 100644 --- a/man/computeConditionalCS_DeltaSDRMM.Rd +++ b/man/computeConditionalCS_DeltaSDRMM.Rd @@ -14,7 +14,7 @@ computeConditionalCS_DeltaSDRMM(betahat, sigma, numPrePeriods, numPostPeriods, 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) } %- maybe also 'usage' for other objects documented here. \arguments{ diff --git a/man/createSensitivityResults.Rd b/man/createSensitivityResults.Rd index 427fc32..508fbb6 100644 --- a/man/createSensitivityResults.Rd +++ b/man/createSensitivityResults.Rd @@ -8,11 +8,16 @@ Constructs robust confidence intervals for a choice \eqn{\Delta = \Delta^{SD}(M)}, \eqn{\Delta^{SDB}(M)} and \eqn{\Delta^{SDM}(M)} for vector of possible M values. By default, the function constructs robust confidence intervals for \eqn{\Delta^{SD}(M)}. } \usage{ -createSensitivityResults(betahat, sigma, numPrePeriods, numPostPeriods, - method = NULL, Mvec = NULL, - l_vec = .basisVector(index = 1, size = numPostPeriods), - monotonicityDirection = NULL, - biasDirection = NULL, alpha = 0.05, parallel = FALSE) +createSensitivityResults(betahat, sigma, + numPrePeriods, numPostPeriods, + method = NULL, + Mvec = NULL, + l_vec = .basisVector(index = 1, size = numPostPeriods), + monotonicityDirection = NULL, + biasDirection = NULL, + alpha = 0.05, + parallel = FALSE, + seed = 0) } %- maybe also 'usage' for other objects documented here. \arguments{ @@ -49,6 +54,9 @@ createSensitivityResults(betahat, sigma, numPrePeriods, numPostPeriods, \item{parallel}{ Logical to indicate whether the user would like to construct the robust confidence intervals in parallel. This uses the Foreach package and doParallel package. Default equals FALSE. } + \item{seed}{ + Random seed for internal computations; included for reproducibility. + } } \value{ Returns a dataframe with columns diff --git a/man/createSensitivityResults_relativeMagnitudes.Rd b/man/createSensitivityResults_relativeMagnitudes.Rd index 238451b..5c314fa 100644 --- a/man/createSensitivityResults_relativeMagnitudes.Rd +++ b/man/createSensitivityResults_relativeMagnitudes.Rd @@ -21,7 +21,8 @@ createSensitivityResults_relativeMagnitudes(betahat, sigma, gridPoints = 10^3, grid.ub = NA, grid.lb = NA, - parallel = FALSE) + parallel = FALSE, + seed = 0) } %- maybe also 'usage' for other objects documented here. \arguments{ @@ -70,6 +71,9 @@ createSensitivityResults_relativeMagnitudes(betahat, sigma, \item{grid.lb}{ Lower bound of grid used for underlying test inversion. Default sets grid.lb to be equal to negative twenty times the standard deviation of the estimated target parameter, l_vec * betahat. User may wish to change the lower bound of the grid to suit their application. } + \item{seed}{ + Random seed for internal computations; included for reproducibility. + } } \details{ Note: If the user specifies bound = "deviation from linear trends", then numPrePeriods must be greater than one. By specifying bound = "deviation from linear trends", then the function selects \eqn{\Delta^{SDRM}} as the base choice of \eqn{\Delta}. As discussed in Section 2.3.2 of Rambachan & Roth (2021), \eqn{\Delta^{SDRM}} uses observed non-linearities in the pre-treatment difference in trends to bound the possible non-linearities in the post-treatment difference in trends. This is only possible if there are multiple pre-treatment periods (i.e., numPrePeriods > 1). diff --git a/man/findOptimalFLCI.Rd b/man/findOptimalFLCI.Rd index a4f6980..dfa2cd2 100644 --- a/man/findOptimalFLCI.Rd +++ b/man/findOptimalFLCI.Rd @@ -11,7 +11,7 @@ Constructs optimal fixed length confidence interval for \eqn{\Delta = \Delta^{SD findOptimalFLCI(betahat, sigma, M = 0, numPrePeriods, numPostPeriods, l_vec = .basisVector(index = 1, size = numPostPeriods), - numPoints = 100, alpha = 0.05) + numPoints = 100, alpha = 0.05, seed = 0) } %- maybe also 'usage' for other objects documented here. \arguments{ @@ -39,6 +39,9 @@ findOptimalFLCI(betahat, sigma, M = 0, \item{alpha}{ Desired size of the FLCI. Default equals 0.05 (corresponding to 95\% confidence interval) } + \item{seed}{ + Random seed for internal computations; included for reproducibility. + } } \value{ Returns a list containing items From 6f332d3a16a31b532e417a96fd1a17bae4b80a10 Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Date: Tue, 9 Jul 2024 21:36:14 -0400 Subject: [PATCH 17/17] Added seed option to function docs (v2) --- man/computeConditionalCS_DeltaSDRMM.Rd | 3 +++ 1 file changed, 3 insertions(+) diff --git a/man/computeConditionalCS_DeltaSDRMM.Rd b/man/computeConditionalCS_DeltaSDRMM.Rd index 4fa46bd..7715a5f 100644 --- a/man/computeConditionalCS_DeltaSDRMM.Rd +++ b/man/computeConditionalCS_DeltaSDRMM.Rd @@ -63,6 +63,9 @@ Specifies direction of monotonicity restriction. If "increasing", underlying tre \item{grid.lb}{ Lower bound of grid for test inversion. The user should only specify this if she wishes to manually specify the upper bound of the grid. Default equals NA sets grid lower bound to equal the lower bound of the identified set under parallel trends minus 20*standard deviation of the point estimate, l_vec'betahat. } + \item{seed}{ + Random seed for internal computations; included for reproducibility. + } } \details{ The choice \eqn{\Delta^{SDRMM}} adds an additional shape restriction to \eqn{\Delta^{SDRM}(Mbar)} that restricts the underlying trend to be monotone. For this choice \eqn{\Delta^{SDRMM}}, \code{numPrePeriods} must be greater than one. As discussed in Section 2.3.2 of Rambachan & Roth (2021), \eqn{\Delta^{SDRM}} uses observed non-linearities in the pre-treatment difference in trends to bound the possible non-linearities in the post-treatment difference in trends. This is only possible if there are multiple pre-treatment periods (i.e., \code{numPrePeriods} > 1).