From 10c13d652eca2d47b379d6c48f729b9605662d4a Mon Sep 17 00:00:00 2001 From: Mauricio Caceres Bravo Date: Sun, 22 Oct 2023 15:48:44 -0400 Subject: [PATCH] Pull Request follow-up for #30: Various minor fixes (#42) * Added 'value' to man/constructOriginalCS.Rd * Closed [ in description * Changed all T/F to TRUE/FALSE * Removed all standardtext from .Rd files * Give Ashesh and Jon author and copyright; Ashesh creator/maintainer * Added simple examples for main user funs * Minor fix * Reference vignette name directly in simple examples * Direct users to github README in help files --- DESCRIPTION | 13 +++++++-- R/HonestDiD-Temp.R | 2 +- R/arp-nonuisance.R | 4 +-- R/arp-nuisance.R | 8 ++--- R/delta_utility_functions.R | 2 +- R/deltarm.R | 18 ++++++------ R/deltarmb.R | 20 ++++++------- R/deltarmm.R | 18 ++++++------ R/deltasd.R | 14 ++++----- R/deltasdb.R | 12 ++++---- R/deltasdm.R | 10 +++---- R/deltasdrm.R | 20 ++++++------- R/deltasdrmb.R | 24 +++++++-------- R/deltasdrmm.R | 20 ++++++------- R/flci.R | 10 +++---- R/sensitivityresults.R | 2 +- README.Rmd | 2 +- man/DeltaSD_lowerBound_Mpre.Rd | 4 --- man/DeltaSD_upperBound_Mpre.Rd | 4 --- man/basisVector.Rd | 29 +++++++++---------- man/computeConditionalCS_DeltaRM.Rd | 2 +- man/computeConditionalCS_DeltaRMB.Rd | 4 +-- man/computeConditionalCS_DeltaRMM.Rd | 2 +- man/computeConditionalCS_DeltaSD.Rd | 4 +-- man/computeConditionalCS_DeltaSDB.Rd | 4 +-- man/computeConditionalCS_DeltaSDM.Rd | 2 +- man/computeConditionalCS_DeltaSDRM.Rd | 2 +- man/computeConditionalCS_DeltaSDRMB.Rd | 4 +-- man/computeConditionalCS_DeltaSDRMM.Rd | 4 +-- man/constructOriginalCS.Rd | 27 ++++++++++++++--- man/createEventStudyPlot.Rd | 17 +++++++---- man/createSensitivityPlot.Rd | 20 ++++++++++--- ...reateSensitivityPlot_relativeMagnitudes.Rd | 20 ++++++++++--- man/createSensitivityResults.Rd | 12 +++++--- ...teSensitivityResults_relativeMagnitudes.Rd | 12 +++++--- 35 files changed, 213 insertions(+), 159 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d0ab853..3891189 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,10 +24,17 @@ Imports: Suggests: knitr, rmarkdown -Author: Ashesh Rambachan -Maintainer: Ashesh Rambachan +Authors@R: + c(person(given = "Ashesh", + family = "Rambachan", + role = c("aut", "cph", "cre"), + email = "ashesh.a.rambachan@gmail.com"), + person(given = "Jonathan", + family = "Roth", + role = c("aut", "cph"), + email = "jonathan_roth@brown.edu")) Description: - Provides functions to conduct robust inference in difference-in-differences and event study designs by implementing the methods developed in Rambachan & Roth (2023, RESTUD), "A More Credible Approach to Parallel Trends" [Previously titled "An Honest Approach...". Inference is conducted under a weaker version of the parallel trends assumption. Uniformly valid confidence sets are constructed based upon conditional confidence sets, fixed-length confidence sets and hybridized confidence sets. + Provides functions to conduct robust inference in difference-in-differences and event study designs by implementing the methods developed in Rambachan & Roth (2023, RESTUD), "A More Credible Approach to Parallel Trends" [Previously titled "An Honest Approach..."]. Inference is conducted under a weaker version of the parallel trends assumption. Uniformly valid confidence sets are constructed based upon conditional confidence sets, fixed-length confidence sets and hybridized confidence sets. Encoding: UTF-8 LazyData: true VignetteBuilder: diff --git a/R/HonestDiD-Temp.R b/R/HonestDiD-Temp.R index b9ceeb4..d94a825 100644 --- a/R/HonestDiD-Temp.R +++ b/R/HonestDiD-Temp.R @@ -416,7 +416,7 @@ createEventStudyPlot <- function(betahat, stdErrors = NULL, sigma = NULL, stdErrors = sqrt(diag(sigma)) } - if (useRelativeEventTime == T) { + if (useRelativeEventTime == TRUE) { timeVec = timeVec - referencePeriod referencePeriod = 0 } diff --git a/R/arp-nonuisance.R b/R/arp-nonuisance.R index 9c78fcf..68f5c9d 100644 --- a/R/arp-nonuisance.R +++ b/R/arp-nonuisance.R @@ -70,7 +70,7 @@ # Run the first-stage test if (base::max(A_firststage %*% y - d_firststage) > 0) { - reject <- T + reject <- TRUE } else { # Per ARP (2021), CV = max(0, c_{1-alpha-tilde}), where alpha-tilde = (alpha - kappa)/(1-kappa) # quantile of truncated normal that accounts for failing to reject in the first stage. @@ -181,7 +181,7 @@ } # Compute length, else return grid - if (returnLength == T) { + if (returnLength == TRUE) { gridLength <- 0.5 * ( base::c(0, base::diff(thetaGrid)) + base::c(base::diff(thetaGrid), 0 ) ) base::return(base::sum(resultsGrid[, 2]*gridLength)) } else { diff --git a/R/arp-nuisance.R b/R/arp-nuisance.R index fa884e1..e27a00c 100644 --- a/R/arp-nuisance.R +++ b/R/arp-nuisance.R @@ -400,7 +400,7 @@ eta_vec = base::apply(-xi.draws, 1, .compute_eta, f, C) # We compute the 1-kappa quantile of eta_vec and return this value - base::return(stats::quantile(eta_vec, probs=1-hybrid_kappa, names=FALSE, na.rm=T)) + base::return(stats::quantile(eta_vec, probs=1-hybrid_kappa, names=FALSE, na.rm=TRUE)) } } @@ -513,11 +513,11 @@ # Store which moments are binding: Do so using lambda rather than the moments. B_index = (linSoln$lambda > tol_lambda) - Bc_index = (B_index == F) + Bc_index = (B_index == FALSE) X_TB = base::matrix( X_T_ARP[B_index,], ncol = base::ncol(X_T_ARP) ) # select binding moments # Check whether binding moments have full rank. if (base::is.vector(X_TB)) { - fullRank_flag = F + fullRank_flag = FALSE } else { fullRank_flag = (Matrix::rankMatrix(X_TB) == base::min(base::dim( X_TB ) )) } @@ -761,7 +761,7 @@ } # Compute length, else return grid - if (returnLength == T) { + if (returnLength == TRUE) { gridLength <- 0.5 * ( base::c(0, base::diff(thetaGrid)) + base::c(base::diff(thetaGrid), 0 ) ) base::return(base::sum(resultsGrid[, 2]*gridLength)) } else { diff --git a/R/delta_utility_functions.R b/R/delta_utility_functions.R index 67c71e5..adeed92 100644 --- a/R/delta_utility_functions.R +++ b/R/delta_utility_functions.R @@ -29,7 +29,7 @@ } } - # If postPeriodMomentsOnly == T, exclude moments that only involve pre-periods + # If postPeriodMomentsOnly == TRUE, exclude moments that only involve pre-periods if(postPeriodMomentsOnly){ postPeriodIndices <- (numPrePeriods +1):base::NCOL(A_M) prePeriodOnlyRows <- base::which( base::rowSums( A_M[ , postPeriodIndices] != 0 ) == 0 ) diff --git a/R/deltarm.R b/R/deltarm.R index 07cc534..3ba1164 100644 --- a/R/deltarm.R +++ b/R/deltarm.R @@ -10,10 +10,10 @@ # Delta^{RM} functions ----------------------------------------------- .create_A_RM <- function(numPrePeriods, numPostPeriods, - Mbar = 1, s, max_positive = T, - dropZero = T) { + Mbar = 1, s, max_positive = TRUE, + dropZero = TRUE) { # This function creates a matrix for the linear constraints that - # \delta \in Delta^RM_{s,(.)}(Mbar), where (.) is + if max_positve = T and (-) if max_positive = F. + # \delta \in Delta^RM_{s,(.)}(Mbar), where (.) is + if max_positve = TRUE and (-) if max_positive = FALSE. # # Inputs: # numPrePeriods = number of pre-periods. This is an element of resultsObjects. @@ -27,11 +27,11 @@ Atilde[r, r:(r+1)] = c(-1, 1) } - # Create a vector to extract the max first dif, which corresponds with the first dif for period s, or minus this if max_positive == F + # Create a vector to extract the max first dif, which corresponds with the first dif for period s, or minus this if max_positive == FALSE v_max_dif <- base::matrix(0, nrow = 1, ncol = numPrePeriods + numPostPeriods + 1) v_max_dif[(numPrePeriods+s):(numPrePeriods+1+s)] <- c(-1,1) - if (max_positive == F){ + if (max_positive == FALSE){ v_max_dif <- -v_max_dif } @@ -55,9 +55,9 @@ } } -.create_d_RM <- function(numPrePeriods, numPostPeriods, dropZero = T){ +.create_d_RM <- function(numPrePeriods, numPostPeriods, dropZero = TRUE){ # This function creates a vector for the linear constraints that - # delta is in Delta^RM_{s,(.)}(Mbar), where (.) is + if max_positve = T and - if max_positive = F. + # delta is in Delta^RM_{s,(.)}(Mbar), where (.) is + if max_positve = TRUE and - if max_positive = FALSE. # It implements this using the general characterization of d, NOT the sharp # characterization of the identified set. # @@ -241,7 +241,7 @@ computeConditionalCS_DeltaRM <- function(betahat, sigma, numPrePeriods, numPostPeriods, l_vec = .basisVector(index = 1, size = numPostPeriods), Mbar = 0, alpha = 0.05, hybrid_flag = "LF", hybrid_kappa = alpha/10, - returnLength = F, postPeriodMomentsOnly = T, + returnLength = FALSE, postPeriodMomentsOnly = TRUE, gridPoints = 10^3, grid.ub = NA, grid.lb = NA) { # This function computes the ARP CI that includes nuisance parameters # for Delta^{RM}(Mbar). This functions uses ARP_computeCI for all @@ -304,7 +304,7 @@ computeConditionalCS_DeltaRM <- function(betahat, sigma, numPrePeriods, numPostP CI_RM = tibble::tibble(grid = base::seq(grid.lb, grid.ub, length.out = gridPoints), accept = base::pmax(CIs_RM_plus_maxS, CIs_RM_minus_maxS)) - # Compute length if returnLength == T, else return grid + # Compute length if returnLength == TRUE, else return grid if (returnLength) { gridLength <- 0.5 * ( base::c(0, base::diff(CI_RM$grid)) + base::c(base::diff(CI_RM$grid), 0 ) ) base::return(base::sum(CI_RM$accept*gridLength)) diff --git a/R/deltarmb.R b/R/deltarmb.R index e9f1120..953dd68 100644 --- a/R/deltarmb.R +++ b/R/deltarmb.R @@ -12,10 +12,10 @@ # Delta^{RMB} functions ----------------------------------------------- .create_A_RMB <- function(numPrePeriods, numPostPeriods, - Mbar = 1, s, max_positive = T, - dropZero = T, biasDirection) { + Mbar = 1, s, max_positive = TRUE, + dropZero = TRUE, biasDirection) { # This function creates a matrix for the linear constraints that - # \delta \in Delta^RMB_{s,(.)}(Mbar), where (.) is + if max_positve = T and (-) if max_positive = F. + # \delta \in Delta^RMB_{s,(.)}(Mbar), where (.) is + if max_positve = TRUE and (-) if max_positive = FALSE. # # Inputs: # numPrePeriods = number of pre-periods. This is an element of resultsObjects. @@ -30,11 +30,11 @@ Atilde[r, r:(r+1)] = base::c(-1, 1) } - # Create a vector to extract the max first dif, which corresponds with the first dif for period s, or minus this if max_positive == F + # Create a vector to extract the max first dif, which corresponds with the first dif for period s, or minus this if max_positive == FALSE v_max_dif <- base::matrix(0, nrow = 1, ncol = numPrePeriods + numPostPeriods + 1) v_max_dif[(numPrePeriods+s):(numPrePeriods+1+s)] <- c(-1,1) - if (max_positive == F){ + if (max_positive == FALSE){ v_max_dif <- -v_max_dif } @@ -65,9 +65,9 @@ } } -.create_d_RMB <- function(numPrePeriods, numPostPeriods, dropZero = T){ +.create_d_RMB <- function(numPrePeriods, numPostPeriods, dropZero = TRUE){ # This function creates a vector for the linear constraints that - # delta is in Delta^RMB_{s,(.)}(Mbar), where (.) is + if max_positve = T and - if max_positive = F. + # delta is in Delta^RMB_{s,(.)}(Mbar), where (.) is + if max_positve = TRUE and - if max_positive = FALSE. # It implements this using the general characterization of d, NOT the sharp # characterization of the identified set. # @@ -258,8 +258,8 @@ computeConditionalCS_DeltaRMB <- function(betahat, sigma, numPrePeriods, numPostPeriods, l_vec = .basisVector(index = 1, size = numPostPeriods), Mbar = 0, alpha = 0.05, hybrid_flag = "LF", hybrid_kappa = alpha/10, - returnLength = F, biasDirection = "positive", - postPeriodMomentsOnly = T, + returnLength = FALSE, biasDirection = "positive", + postPeriodMomentsOnly = TRUE, gridPoints = 10^3, grid.ub = NA, grid.lb = NA) { # This function computes the ARP CI that includes nuisance parameters # for Delta^{MB}(Mbar). This functions uses ARP_computeCI for all @@ -323,7 +323,7 @@ computeConditionalCS_DeltaRMB <- function(betahat, sigma, numPrePeriods, numPost CI_RMB = tibble::tibble(grid = base::seq(grid.lb, grid.ub, length.out = gridPoints), accept = base::pmax(CIs_RMB_plus_maxS, CIs_RMB_minus_maxS)) - # Compute length if returnLength == T, else return grid + # Compute length if returnLength == TRUE, else return grid if (returnLength) { gridLength <- 0.5 * ( base::c(0, base::diff(CI_RMB$grid)) + base::c(base::diff(CI_RMB$grid), 0 ) ) base::return(base::sum(CI_RMB$accept*gridLength)) diff --git a/R/deltarmm.R b/R/deltarmm.R index c88d0fc..c95cacb 100644 --- a/R/deltarmm.R +++ b/R/deltarmm.R @@ -11,10 +11,10 @@ # Delta^{RMM} functions ----------------------------------------------- .create_A_RMM <- function(numPrePeriods, numPostPeriods, - Mbar = 1, s, max_positive = T, - dropZero = T, monotonicityDirection) { + Mbar = 1, s, max_positive = TRUE, + dropZero = TRUE, monotonicityDirection) { # This function creates a matrix for the linear constraints that - # \delta \in Delta^RM_{s,(.)}(Mbar), where (.) is + if max_positve = T and (-) if max_positive = F. + # \delta \in Delta^RM_{s,(.)}(Mbar), where (.) is + if max_positve = TRUE and (-) if max_positive = FALSE. # # Inputs: # numPrePeriods = number of pre-periods. This is an element of resultsObjects. @@ -29,11 +29,11 @@ Atilde[r, r:(r+1)] = c(-1, 1) } - # Create a vector to extract the max first dif, which corresponds with the first dif for period s, or minus this if max_positive == F + # Create a vector to extract the max first dif, which corresponds with the first dif for period s, or minus this if max_positive == FALSE v_max_dif <- base::matrix(0, nrow = 1, ncol = numPrePeriods + numPostPeriods + 1) v_max_dif[(numPrePeriods+s):(numPrePeriods+1+s)] <- c(-1,1) - if (max_positive == F){ + if (max_positive == FALSE){ v_max_dif <- -v_max_dif } @@ -63,9 +63,9 @@ } } -.create_d_RMM <- function(numPrePeriods, numPostPeriods, dropZero = T){ +.create_d_RMM <- function(numPrePeriods, numPostPeriods, dropZero = TRUE){ # This function creates a vector for the linear constraints that - # delta is in Delta^RM_{s,(.)}(Mbar), where (.) is + if max_positve = T and - if max_positive = F. + # delta is in Delta^RM_{s,(.)}(Mbar), where (.) is + if max_positve = TRUE and - if max_positive = FALSE. # It implements this using the general characterization of d, NOT the sharp # characterization of the identified set. # @@ -257,7 +257,7 @@ computeConditionalCS_DeltaRMM <- function(betahat, sigma, numPrePeriods, numPostPeriods, l_vec = .basisVector(index = 1, size = numPostPeriods), Mbar = 0, alpha = 0.05, hybrid_flag = "LF", hybrid_kappa = alpha/10, - returnLength = F, postPeriodMomentsOnly = T, monotonicityDirection = "increasing", + returnLength = FALSE, postPeriodMomentsOnly = TRUE, monotonicityDirection = "increasing", gridPoints = 10^3, grid.ub = NA, grid.lb = NA) { # This function computes the ARP CI that includes nuisance parameters # for Delta^{RMM}(Mbar). This functions uses ARP_computeCI for all @@ -320,7 +320,7 @@ computeConditionalCS_DeltaRMM <- function(betahat, sigma, numPrePeriods, numPost CI_RMM = tibble::tibble(grid = base::seq(grid.lb, grid.ub, length.out = gridPoints), accept = base::pmax(CIs_RMM_plus_maxS, CIs_RMM_minus_maxS)) - # Compute length if returnLength == T, else return grid + # Compute length if returnLength == TRUE, else return grid if (returnLength) { gridLength <- 0.5 * ( base::c(0, base::diff(CI_RMM$grid)) + base::c(base::diff(CI_RMM$grid), 0 ) ) base::return(base::sum(CI_RMM$accept*gridLength)) diff --git a/R/deltasd.R b/R/deltasd.R index 3f58a4b..0efa145 100644 --- a/R/deltasd.R +++ b/R/deltasd.R @@ -12,7 +12,7 @@ # In this section, we implement helper functions to place testing with # Delta^{SD}(M) into the form needed to use the ARP functions. -.create_A_SD <- function(numPrePeriods, numPostPeriods, postPeriodMomentsOnly = F) { +.create_A_SD <- function(numPrePeriods, numPostPeriods, postPeriodMomentsOnly = FALSE) { # This function creates a matrix for the linear constraints that \delta \in Delta^SD(M). # It implements this using the general characterization of A, NOT the sharp # characterization of the identified set. @@ -31,7 +31,7 @@ } Atilde = Atilde[, -(numPrePeriods+1)] - # If postPeriodMomentsOnly == T, exclude moments that only involve pre-periods + # If postPeriodMomentsOnly == TRUE, exclude moments that only involve pre-periods if(postPeriodMomentsOnly){ postPeriodIndices <- (numPrePeriods +1):base::NCOL(Atilde) prePeriodOnlyRows <- base::which( base::rowSums( Atilde[ , postPeriodIndices] != 0 ) == 0 ) @@ -43,7 +43,7 @@ base::return(A) } -.create_d_SD <- function(numPrePeriods, numPostPeriods, M, postPeriodMomentsOnly = F) { +.create_d_SD <- function(numPrePeriods, numPostPeriods, M, postPeriodMomentsOnly = FALSE) { # This function creates a vector for the linear constraints that \delta \in Delta^SD(M). # It implements this using the general characterization of d, NOT the sharp # characterization of the identified set. @@ -129,8 +129,8 @@ computeConditionalCS_DeltaSD <- function(betahat, sigma, numPrePeriods, numPostPeriods, l_vec = .basisVector(index = 1, size = numPostPeriods), M = 0, alpha = 0.05, hybrid_flag = "FLCI", - hybrid_kappa = alpha/10, returnLength = F, - postPeriodMomentsOnly = T, + hybrid_kappa = alpha/10, returnLength = FALSE, + postPeriodMomentsOnly = TRUE, gridPoints =10^3, grid.ub = NA, grid.lb = NA) { # This function computes the ARP CI that includes nuisance parameters # for Delta^{SD}(M). This functions uses ARP_computeCI for all @@ -154,8 +154,8 @@ computeConditionalCS_DeltaSD <- function(betahat, sigma, numPrePeriods, numPostP # data_frame containing upper and lower bounds of CI. # Construct A_SD, d_SD - A_SD = .create_A_SD(numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, postPeriodMomentsOnly = F) - d_SD = .create_d_SD(numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, M = M, postPeriodMomentsOnly = F) + A_SD = .create_A_SD(numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, postPeriodMomentsOnly = FALSE) + d_SD = .create_d_SD(numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, M = M, postPeriodMomentsOnly = FALSE) if (postPeriodMomentsOnly & numPostPeriods > 1){ postPeriodIndices <- (numPrePeriods +1):base::NCOL(A_SD) diff --git a/R/deltasdb.R b/R/deltasdb.R index 4d550bd..a9f2bc4 100644 --- a/R/deltasdb.R +++ b/R/deltasdb.R @@ -12,7 +12,7 @@ # In this section, we implement helper functions to place testing with # Delta^{SDB}(M) into the form needed to use the ARP functions. .create_A_SDB <- function(numPrePeriods, numPostPeriods, - biasDirection = "positive", postPeriodMomentsOnly = F) { + biasDirection = "positive", postPeriodMomentsOnly = FALSE) { # This function creates a matrix for the linear constraints that \delta \in Delta^SDB(M). # It implements this using the general characterization of A. # @@ -29,7 +29,7 @@ base::return(A) } -.create_d_SDB <- function(numPrePeriods, numPostPeriods, M, postPeriodMomentsOnly = F) { +.create_d_SDB <- function(numPrePeriods, numPostPeriods, M, postPeriodMomentsOnly = FALSE) { # This function creates a vector for the linear constraints that \delta \in Delta^SDB(M). # It implements this using the general characterization of d. # @@ -112,8 +112,8 @@ computeConditionalCS_DeltaSDB <- function(betahat, sigma, numPrePeriods, numPostPeriods, M = 0, l_vec = .basisVector(index = 1, size=numPostPeriods), alpha = 0.05, hybrid_flag = "FLCI", hybrid_kappa = alpha/10, - returnLength = F, biasDirection = "positive", - postPeriodMomentsOnly = T, + returnLength = FALSE, biasDirection = "positive", + postPeriodMomentsOnly = TRUE, gridPoints = 10^3, grid.lb = NA, grid.ub = NA) { # This function computes the ARP CI that includes nuisance parameters # for Delta^{SDPB}(M). This functions uses ARP_computeCI for all @@ -140,8 +140,8 @@ computeConditionalCS_DeltaSDB <- function(betahat, sigma, numPrePeriods, numPost # Construct A_SDB, d_SDB A_SDB = .create_A_SDB(numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, biasDirection = biasDirection, - postPeriodMomentsOnly = F) - d_SDB = .create_d_SDB(numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, M = M, postPeriodMomentsOnly = F) + postPeriodMomentsOnly = FALSE) + d_SDB = .create_d_SDB(numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, M = M, postPeriodMomentsOnly = FALSE) if (postPeriodMomentsOnly & numPostPeriods > 1) { postPeriodIndices <- (numPrePeriods +1):base::NCOL(A_SDB) diff --git a/R/deltasdm.R b/R/deltasdm.R index d911cd6..9d8a2c1 100644 --- a/R/deltasdm.R +++ b/R/deltasdm.R @@ -13,7 +13,7 @@ # Delta^{SDM}(M) into the form needed to use the ARP functions. .create_A_SDM <- function(numPrePeriods, numPostPeriods, - monotonicityDirection = "increasing", postPeriodMomentsOnly = F) { + monotonicityDirection = "increasing", postPeriodMomentsOnly = FALSE) { # This function creates a matrix for the linear constraints that \delta \in Delta^SDI(M). # It implements this using the general characterization of A. # @@ -28,7 +28,7 @@ base::return(A) } -.create_d_SDM <- function(numPrePeriods, numPostPeriods, M, postPeriodMomentsOnly = F) { +.create_d_SDM <- function(numPrePeriods, numPostPeriods, M, postPeriodMomentsOnly = FALSE) { # This function creates a vector for the linear constraints that \delta \in Delta^SDI(M). # It implements this using the general characterization of d. # @@ -102,7 +102,7 @@ computeConditionalCS_DeltaSDM <- function(betahat, sigma, numPrePeriods, numPost M = 0, l_vec = .basisVector(index = 1, size = numPostPeriods), alpha = 0.05, monotonicityDirection = "increasing", hybrid_flag = "FLCI", hybrid_kappa = alpha/10, - returnLength = F, postPeriodMomentsOnly = T, + returnLength = FALSE, postPeriodMomentsOnly = TRUE, gridPoints=10^3, grid.lb = NA, grid.ub = NA) { # This function computes the ARP CI that includes nuisance parameters # for Delta^{SDI}(M). This functions uses ARP_computeCI for all @@ -127,8 +127,8 @@ computeConditionalCS_DeltaSDM <- function(betahat, sigma, numPrePeriods, numPost # Construct A_SDM, d_SDM A_SDM = .create_A_SDM(numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, - monotonicityDirection = monotonicityDirection, postPeriodMomentsOnly = F) - d_SDM = .create_d_SDM(numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, M = M, postPeriodMomentsOnly = F) + monotonicityDirection = monotonicityDirection, postPeriodMomentsOnly = FALSE) + d_SDM = .create_d_SDM(numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, M = M, postPeriodMomentsOnly = FALSE) if (postPeriodMomentsOnly & numPostPeriods > 1) { postPeriodIndices <- (numPrePeriods +1):base::NCOL(A_SDM) diff --git a/R/deltasdrm.R b/R/deltasdrm.R index c025536..8f31942 100644 --- a/R/deltasdrm.R +++ b/R/deltasdrm.R @@ -12,8 +12,8 @@ # In this section, we implement helper functions to place testing with # Delta^{SDRM}(Mbar) into the form needed to use the ARP functions. .create_A_SDRM <- function(numPrePeriods, numPostPeriods, - Mbar = 1, s, max_positive = T, dropZero = T) { - # This function creates a matrix for the linear constraints that \delta \in Delta^SDRM_{s,.}(Mbar), where . is + if max_positve = T and - if max_positive = F. + Mbar = 1, s, max_positive = TRUE, dropZero = TRUE) { + # This function creates a matrix for the linear constraints that \delta \in Delta^SDRM_{s,.}(Mbar), where . is + if max_positve = TRUE and - if max_positive = FALSE. # # Inputs: # numPrePeriods = number of pre-periods. This is an element of resultsObjects. @@ -27,11 +27,11 @@ Atilde[r, r:(r+2)] = c(1, -2, 1) } - # Create a vector to extract the max second dif, which corresponds with the second dif for period s, or minus this if max_positive == F + # Create a vector to extract the max second dif, which corresponds with the second dif for period s, or minus this if max_positive == FALSE v_max_dif <- base::matrix(0, nrow = 1, ncol = numPrePeriods + numPostPeriods + 1) v_max_dif[(numPrePeriods+1+s-2):(numPrePeriods+1+s)] <- base::c(1,-2, 1) - if (max_positive == F) { + if (max_positive == FALSE) { v_max_dif <- -v_max_dif } @@ -54,8 +54,8 @@ } } -.create_d_SDRM <- function(numPrePeriods, numPostPeriods, dropZero = T){ - # This function creates a vector for the linear constraints that delt is in Delta^SDRM_{s,.}(Mbar), where . is + if max_positve = T and - if max_positive = F. +.create_d_SDRM <- function(numPrePeriods, numPostPeriods, dropZero = TRUE){ + # This function creates a vector for the linear constraints that delt is in Delta^SDRM_{s,.}(Mbar), where . is + if max_positve = TRUE and - if max_positive = FALSE. # It implements this using the general characterization of d, NOT the sharp # characterization of the identified set. # @@ -238,7 +238,7 @@ computeConditionalCS_DeltaSDRM <- function(betahat, sigma, numPrePeriods, numPostPeriods, l_vec = .basisVector(index = 1, size = numPostPeriods), Mbar = 0, alpha = 0.05, hybrid_flag = "LF", hybrid_kappa = alpha/10, - returnLength = F, postPeriodMomentsOnly = T, + returnLength = FALSE, postPeriodMomentsOnly = TRUE, gridPoints = 10^3, grid.ub = NA, grid.lb = NA) { # This function computes the ARP CI that includes nuisance parameters # for Delta^{SDRM}(Mbar). This functions uses ARP_computeCI for all @@ -283,7 +283,7 @@ computeConditionalCS_DeltaSDRM <- function(betahat, sigma, numPrePeriods, numPos CIs_SDRM_minus_allS = base::matrix(0, nrow = gridPoints, ncol = base::length(s_indices)) for (s_i in 1:base::length(s_indices)) { # Compute CI for s, (+) and bind it to all CI's for (+) - CI_s_plus = .computeConditionalCS_DeltaSDRM_fixedS(s = s_indices[s_i], max_positive = T, Mbar = Mbar, + CI_s_plus = .computeConditionalCS_DeltaSDRM_fixedS(s = s_indices[s_i], max_positive = TRUE, Mbar = Mbar, betahat = betahat, sigma = sigma, numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, hybrid_flag = hybrid_flag, hybrid_kappa = hybrid_kappa, @@ -292,7 +292,7 @@ computeConditionalCS_DeltaSDRM <- function(betahat, sigma, numPrePeriods, numPos CIs_SDRM_plus_allS[,s_i] = CI_s_plus$accept # Compute CI for s, (-) and bind it to all CI's for (-) - CI_s_minus = .computeConditionalCS_DeltaSDRM_fixedS(s = s_indices[s_i], max_positive = F, Mbar = Mbar, + CI_s_minus = .computeConditionalCS_DeltaSDRM_fixedS(s = s_indices[s_i], max_positive = FALSE, Mbar = Mbar, betahat = betahat, sigma = sigma, numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, hybrid_flag = hybrid_flag, hybrid_kappa = hybrid_kappa, @@ -308,7 +308,7 @@ computeConditionalCS_DeltaSDRM <- function(betahat, sigma, numPrePeriods, numPos accept = base::pmax(CIs_SDRM_plus_maxS, CIs_SDRM_minus_maxS)) # Compute length, else return grid - if (returnLength == T) { + if (returnLength == TRUE) { gridLength <- 0.5 * ( base::c(0, base::diff(CI_SDRM$grid)) + base::c(base::diff(CI_SDRM$grid), 0 ) ) base::return(base::sum(CI_SDRM$accept*gridLength)) } else { diff --git a/R/deltasdrmb.R b/R/deltasdrmb.R index a53ce87..e0073c5 100644 --- a/R/deltasdrmb.R +++ b/R/deltasdrmb.R @@ -14,9 +14,9 @@ # In this section, we implement helper functions to place testing with # Delta^{SDRMB}(Mbar) into the form needed to use the ARP functions. .create_A_SDRMB <- function(numPrePeriods, numPostPeriods, - Mbar = 1, s, max_positive = T, - dropZero = T, biasDirection) { - # This function creates a matrix for the linear constraints that \delta \in Delta^SDRMB_{s,.}(Mbar), where . is + if max_positve = T and - if max_positive = F. + Mbar = 1, s, max_positive = TRUE, + dropZero = TRUE, biasDirection) { + # This function creates a matrix for the linear constraints that \delta \in Delta^SDRMB_{s,.}(Mbar), where . is + if max_positve = TRUE and - if max_positive = FALSE. # # Inputs: # numPrePeriods = number of pre-periods. This is an element of resultsObjects. @@ -31,11 +31,11 @@ Atilde[r, r:(r+2)] = c(1, -2, 1) } - # Create a vector to extract the max second dif, which corresponds with the second dif for period s, or minus this if max_positive == F + # Create a vector to extract the max second dif, which corresponds with the second dif for period s, or minus this if max_positive == FALSE v_max_dif <- base::matrix(0, nrow = 1, ncol = numPrePeriods + numPostPeriods + 1) v_max_dif[(numPrePeriods+1+s-2):(numPrePeriods+1+s)] <- c(1,-2, 1) - if(max_positive == F){ + if(max_positive == FALSE){ v_max_dif <- -v_max_dif } @@ -64,8 +64,8 @@ } } -.create_d_SDRMB <- function(numPrePeriods, numPostPeriods, dropZero = T){ - # This function creates a vector for the linear constraints that delt is in Delta^SDRM_{s,.}(Mbar), where . is + if max_positve = T and - if max_positive = F. +.create_d_SDRMB <- function(numPrePeriods, numPostPeriods, dropZero = TRUE){ + # This function creates a vector for the linear constraints that delt is in Delta^SDRM_{s,.}(Mbar), where . is + if max_positve = TRUE and - if max_positive = FALSE. # It implements this using the general characterization of d, NOT the sharp # characterization of the identified set. # @@ -252,8 +252,8 @@ computeConditionalCS_DeltaSDRMB <- function(betahat, sigma, numPrePeriods, numPostPeriods, l_vec = .basisVector(index = 1, size = numPostPeriods), Mbar = 0, alpha = 0.05, hybrid_flag = "LF", - hybrid_kappa = alpha/10, returnLength = F, - postPeriodMomentsOnly = T, biasDirection = "positive", + hybrid_kappa = alpha/10, returnLength = FALSE, + postPeriodMomentsOnly = TRUE, biasDirection = "positive", gridPoints = 10^3, grid.ub = NA, grid.lb = NA) { # This function computes the ARP CI that includes nuisance parameters # for Delta^{SDRMB}(Mbar). This functions uses ARP_computeCI for all @@ -298,7 +298,7 @@ computeConditionalCS_DeltaSDRMB <- function(betahat, sigma, numPrePeriods, numPo CIs_SDRMB_minus_allS = base::matrix(0, nrow = gridPoints, ncol = base::length(s_indices)) for (s_i in 1:base::length(s_indices)) { # Compute CI for s, (+) and bind it to all CI's for (+) - CI_s_plus = .computeConditionalCS_DeltaSDRMB_fixedS(s = s_indices[s_i], max_positive = T, Mbar = Mbar, + CI_s_plus = .computeConditionalCS_DeltaSDRMB_fixedS(s = s_indices[s_i], max_positive = TRUE, Mbar = Mbar, betahat = betahat, sigma = sigma, numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, hybrid_flag = hybrid_flag, hybrid_kappa = hybrid_kappa, @@ -307,7 +307,7 @@ computeConditionalCS_DeltaSDRMB <- function(betahat, sigma, numPrePeriods, numPo CIs_SDRMB_plus_allS[,s_i] = CI_s_plus$accept # Compute CI for s, (-) and bind it to all CI's for (-) - CI_s_minus = .computeConditionalCS_DeltaSDRMB_fixedS(s = s_indices[s_i], max_positive = F, Mbar = Mbar, + CI_s_minus = .computeConditionalCS_DeltaSDRMB_fixedS(s = s_indices[s_i], max_positive = FALSE, Mbar = Mbar, betahat = betahat, sigma = sigma, numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, hybrid_flag = hybrid_flag, hybrid_kappa = hybrid_kappa, @@ -323,7 +323,7 @@ computeConditionalCS_DeltaSDRMB <- function(betahat, sigma, numPrePeriods, numPo accept = base::pmax(CIs_SDRMB_plus_maxS, CIs_SDRMB_minus_maxS)) # Compute length, else return grid - if (returnLength == T) { + if (returnLength == TRUE) { gridLength <- 0.5 * ( base::c(0, base::diff(CI_SDRMB$grid)) + base::c(base::diff(CI_SDRMB$grid), 0 ) ) base::return(base::sum(CI_SDRMB$accept*gridLength)) } else { diff --git a/R/deltasdrmm.R b/R/deltasdrmm.R index e236aef..77fb8a4 100644 --- a/R/deltasdrmm.R +++ b/R/deltasdrmm.R @@ -13,9 +13,9 @@ # In this section, we implement helper functions to place testing with # Delta^{SDRMM}(Mbar) into the form needed to use the ARP functions. .create_A_SDRMM <- function(numPrePeriods, numPostPeriods, - Mbar = 1, s, max_positive = T, dropZero = T, + Mbar = 1, s, max_positive = TRUE, dropZero = TRUE, monotonicityDirection) { - # This function creates a matrix for the linear constraints that \delta \in Delta^SDRM_{s,.}(Mbar), where . is + if max_positve = T and - if max_positive = F. + # This function creates a matrix for the linear constraints that \delta \in Delta^SDRM_{s,.}(Mbar), where . is + if max_positve = TRUE and - if max_positive = FALSE. # # Inputs: # numPrePeriods = number of pre-periods. This is an element of resultsObjects. @@ -29,11 +29,11 @@ Atilde[r, r:(r+2)] = base::c(1, -2, 1) } - # Create a vector to extract the max second dif, which corresponds with the second dif for period s, or minus this if max_positive == F + # Create a vector to extract the max second dif, which corresponds with the second dif for period s, or minus this if max_positive == FALSE v_max_dif <- base::matrix(0, nrow = 1, ncol = numPrePeriods + numPostPeriods + 1) v_max_dif[(numPrePeriods+1+s-2):(numPrePeriods+1+s)] <- base::c(1,-2, 1) - if(max_positive == F){ + if(max_positive == FALSE){ v_max_dif <- -v_max_dif } @@ -63,8 +63,8 @@ } } -.create_d_SDRMM <- function(numPrePeriods, numPostPeriods, dropZero = T){ - # This function creates a vector for the linear constraints that delt is in Delta^SDRM_{s,.}(Mbar), where . is + if max_positve = T and - if max_positive = F. +.create_d_SDRMM <- function(numPrePeriods, numPostPeriods, dropZero = TRUE){ + # This function creates a vector for the linear constraints that delt is in Delta^SDRM_{s,.}(Mbar), where . is + if max_positve = TRUE and - if max_positive = FALSE. # It implements this using the general characterization of d, NOT the sharp # characterization of the identified set. # @@ -254,7 +254,7 @@ computeConditionalCS_DeltaSDRMM <- function(betahat, sigma, numPrePeriods, numPostPeriods, l_vec = .basisVector(index = 1, size = numPostPeriods), Mbar = 0, alpha = 0.05, hybrid_flag = "LF", hybrid_kappa = alpha/10, - returnLength = F, postPeriodMomentsOnly = T, monotonicityDirection = "increasing", + returnLength = FALSE, postPeriodMomentsOnly = TRUE, monotonicityDirection = "increasing", gridPoints = 10^3, grid.ub = NA, grid.lb = NA) { # This function computes the ARP CI that includes nuisance parameters # for Delta^{SDRMM}(Mbar). This functions uses ARP_computeCI for all @@ -299,7 +299,7 @@ computeConditionalCS_DeltaSDRMM <- function(betahat, sigma, numPrePeriods, numPo CIs_SDRMM_minus_allS = base::matrix(0, nrow = gridPoints, ncol = base::length(s_indices)) for (s_i in 1:base::length(s_indices)) { # Compute CI for s, (+) and bind it to all CI's for (+) - CI_s_plus = .computeConditionalCS_DeltaSDRMM_fixedS(s = s_indices[s_i], max_positive = T, Mbar = Mbar, + CI_s_plus = .computeConditionalCS_DeltaSDRMM_fixedS(s = s_indices[s_i], max_positive = TRUE, Mbar = Mbar, betahat = betahat, sigma = sigma, numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, hybrid_flag = hybrid_flag, hybrid_kappa = hybrid_kappa, @@ -308,7 +308,7 @@ computeConditionalCS_DeltaSDRMM <- function(betahat, sigma, numPrePeriods, numPo CIs_SDRMM_plus_allS[,s_i] = CI_s_plus$accept # Compute CI for s, (-) and bind it to all CI's for (-) - CI_s_minus = .computeConditionalCS_DeltaSDRMM_fixedS(s = s_indices[s_i], max_positive = F, Mbar = Mbar, + CI_s_minus = .computeConditionalCS_DeltaSDRMM_fixedS(s = s_indices[s_i], max_positive = FALSE, Mbar = Mbar, betahat = betahat, sigma = sigma, numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, l_vec = l_vec, alpha = alpha, hybrid_flag = hybrid_flag, hybrid_kappa = hybrid_kappa, @@ -324,7 +324,7 @@ computeConditionalCS_DeltaSDRMM <- function(betahat, sigma, numPrePeriods, numPo accept = base::pmax(CIs_SDRMM_plus_maxS, CIs_SDRMM_minus_maxS)) # Compute length, else return grid - if (returnLength == T) { + if (returnLength == TRUE) { gridLength <- 0.5 * ( base::c(0, base::diff(CI_SDRMM$grid)) + base::c(base::diff(CI_SDRMM$grid), 0 ) ) base::return(base::sum(CI_SDRMM$accept*gridLength)) } else { diff --git a/R/flci.R b/R/flci.R index ba49299..3150b46 100644 --- a/R/flci.R +++ b/R/flci.R @@ -134,7 +134,7 @@ } # FLCI FUNCTIONS ------------------------------------------------------ -.findWorstCaseBiasGivenH <- function(h, sigma, numPrePeriods, numPostPeriods, l_vec, M = 1, returnDF = F) { +.findWorstCaseBiasGivenH <- function(h, sigma, numPrePeriods, numPostPeriods, l_vec, M = 1, returnDF = FALSE) { # This function minimizes worst-case bias over Delta^{SD}(M) subject to the constraint # that the SD of the estimator is <= h # Note: this function assumes M = 1 unless specified otherwise. @@ -157,7 +157,7 @@ optimal.w <- optimal.x[ (base::length(optimal.x)/2 + 1):base::length(optimal.x) ] optimal.l <- .wToLFn(optimal.w) - if(returnDF == F){ + if(returnDF == FALSE){ base::return(base::list(status = biasResult$status, value = biasResult$value, optimal.x = optimal.x, @@ -218,14 +218,14 @@ l_vec, numPoints = 100, alpha){ 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, T) + hstar <- .findOptimalCIDerivativeBisection(hMin, h0, M, numPoints, alpha, sigma, numPrePeriods, numPostPeriods, l_vec, TRUE) if ( base::is.na(hstar) ) { # Numerical derivatives will occasionally fail; fall back into grid # search in that case hGrid <- base::seq(from = hMin, to = h0, length.out = numPoints) biasDF <- purrr::map_dfr(.x = hGrid, - .f = function(h){ .findWorstCaseBiasGivenH(h, sigma = sigma, numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, l_vec = l_vec, returnDF = T) %>% dplyr::mutate(h = h) } ) + .f = function(h){ .findWorstCaseBiasGivenH(h, sigma = sigma, numPrePeriods = numPrePeriods, numPostPeriods = numPostPeriods, l_vec = l_vec, returnDF = TRUE) %>% dplyr::mutate(h = h) } ) biasDF <- biasDF %>% dplyr::rename(bias = .data$value) biasDF <- dplyr::left_join( @@ -244,7 +244,7 @@ dplyr::filter(.data$status == "optimal" | .data$status == "optimal_inaccurate") %>% dplyr::filter(.data$CI.halflength == min(.data$CI.halflength)) } else { - optimalCIDF <- .findWorstCaseBiasGivenH(hstar, sigma, numPrePeriods, numPostPeriods, l_vec, T) + optimalCIDF <- .findWorstCaseBiasGivenH(hstar, sigma, numPrePeriods, numPostPeriods, l_vec, TRUE) optimalCIDF$m <- M optimalCIDF$CI.halflength <- .qfoldednormal(p = 1-alpha, mu = (M * optimalCIDF$value)/hstar) * hstar } diff --git a/R/sensitivityresults.R b/R/sensitivityresults.R index ff9ce59..bbe6888 100644 --- a/R/sensitivityresults.R +++ b/R/sensitivityresults.R @@ -739,7 +739,7 @@ createEventStudyPlot <- function(betahat, stdErrors = NULL, sigma = NULL, stdErrors = base::sqrt(base::diag(sigma)) } - if (useRelativeEventTime == T) { + if (useRelativeEventTime == TRUE) { timeVec = timeVec - referencePeriod referencePeriod = 0 } diff --git a/README.Rmd b/README.Rmd index 3cc357a..ab520bb 100644 --- a/README.Rmd +++ b/README.Rmd @@ -4,7 +4,7 @@ output: github_document --- ```{r setup, include=FALSE} -knitr::opts_chunk$set(echo = TRUE, warning = F) +knitr::opts_chunk$set(echo = TRUE, warning = FALSE) ``` diff --git a/man/DeltaSD_lowerBound_Mpre.Rd b/man/DeltaSD_lowerBound_Mpre.Rd index b059c86..378f503 100644 --- a/man/DeltaSD_lowerBound_Mpre.Rd +++ b/man/DeltaSD_lowerBound_Mpre.Rd @@ -42,7 +42,3 @@ Rambachan, Ashesh and Jonathan Roth. "An Honest Approach to Parallel Trends." 20 \author{ Ashesh Rambachan } -% Add one or more standard keywords, see file 'KEYWORDS' in the -% R documentation directory. -% \keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS") -% \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line diff --git a/man/DeltaSD_upperBound_Mpre.Rd b/man/DeltaSD_upperBound_Mpre.Rd index 13f2c09..8313b09 100644 --- a/man/DeltaSD_upperBound_Mpre.Rd +++ b/man/DeltaSD_upperBound_Mpre.Rd @@ -36,7 +36,3 @@ Rambachan, Ashesh and Jonathan Roth. "An Honest Approach to Parallel Trends." 20 \author{ Ashesh Rambachan } -% Add one or more standard keywords, see file 'KEYWORDS' in the -% R documentation directory. -% \keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS") -% \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line diff --git a/man/basisVector.Rd b/man/basisVector.Rd index 9845dcd..5c73880 100644 --- a/man/basisVector.Rd +++ b/man/basisVector.Rd @@ -5,30 +5,27 @@ Creates a standard basis vector. } \description{ -%% ~~ A concise (1-5 lines) description of what the function does. ~~ Creates a basis vector of length \code{size} with a 1 in the \code{index} position. } \usage{ -# Create the third basis vector in R^6 -basisVector(index = 1, size = 1) +# Create the index basis vector in R^size +basisVector(index, size) } %- maybe also 'usage' for other objects documented here. \arguments{ -%% ~~Describe \code{index} here~~ - \item{index}{ The index at which there should be a one. Default equals one. - -} + \item{index}{ + The index at which there should be a one. Default equals one. + } \item{size}{ -%% ~~Describe \code{size} here~~ -The length of the vector. Default equals one. -} + The length of the vector. Default equals one. + } } \value{ -%% ~Describe the value returned -%% If it is a LIST, use -%% \item{comp1 }{Description of 'comp1'} -%% \item{comp2 }{Description of 'comp2'} -%% ... Returns a basis vector of length \code{size} with a 1 in the \code{index} position. } - +\examples{ + # Create the first basis vector in R^2 + basisVector(index = 1, size = 2) + # Create the third basis vector in R^6 + basisVector(index = 3, size = 6) +} diff --git a/man/computeConditionalCS_DeltaRM.Rd b/man/computeConditionalCS_DeltaRM.Rd index 294604a..19760d5 100644 --- a/man/computeConditionalCS_DeltaRM.Rd +++ b/man/computeConditionalCS_DeltaRM.Rd @@ -11,7 +11,7 @@ Computes the conditional confidence set and hybridized confidence set for Delta 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 = F, postPeriodMomentsOnly = T, + returnLength = FALSE, postPeriodMomentsOnly = TRUE, gridPoints=10^3, grid.ub = NA, grid.lb = NA) } %- maybe also 'usage' for other objects documented here. diff --git a/man/computeConditionalCS_DeltaRMB.Rd b/man/computeConditionalCS_DeltaRMB.Rd index ed03e2b..d13f6d6 100644 --- a/man/computeConditionalCS_DeltaRMB.Rd +++ b/man/computeConditionalCS_DeltaRMB.Rd @@ -12,8 +12,8 @@ computeConditionalCS_DeltaRMB(betahat, sigma, numPrePeriods, numPostPeriods, l_vec = .basisVector(index = 1, size = numPostPeriods), Mbar = 0, alpha = 0.05, hybrid_flag = "LF", - hybrid_kappa = alpha/10, returnLength = F, - biasDirection = "positive", postPeriodMomentsOnly = T, + hybrid_kappa = alpha/10, returnLength = FALSE, + biasDirection = "positive", postPeriodMomentsOnly = TRUE, gridPoints=10^3, grid.ub = NA, grid.lb = NA) } %- maybe also 'usage' for other objects documented here. diff --git a/man/computeConditionalCS_DeltaRMM.Rd b/man/computeConditionalCS_DeltaRMM.Rd index fa41590..5cd3631 100644 --- a/man/computeConditionalCS_DeltaRMM.Rd +++ b/man/computeConditionalCS_DeltaRMM.Rd @@ -13,7 +13,7 @@ computeConditionalCS_DeltaRMM(betahat, sigma, numPrePeriods, numPostPeriods, size = numPostPeriods), Mbar = 0, alpha = 0.05, hybrid_flag = "LF", hybrid_kappa = alpha/10, - returnLength = F, postPeriodMomentsOnly = T, + returnLength = FALSE, postPeriodMomentsOnly = TRUE, monotonicityDirection = "increasing", gridPoints=10^3, grid.ub = NA, grid.lb = NA) } diff --git a/man/computeConditionalCS_DeltaSD.Rd b/man/computeConditionalCS_DeltaSD.Rd index 0918325..bbda2a8 100644 --- a/man/computeConditionalCS_DeltaSD.Rd +++ b/man/computeConditionalCS_DeltaSD.Rd @@ -11,8 +11,8 @@ Computes conditional and hybridized confidence set for Delta = Delta^{SD}(M). computeConditionalCS_DeltaSD(betahat, sigma, numPrePeriods, numPostPeriods, l_vec = .basisVector(index = 1, size = numPostPeriods), M = 0, alpha = 0.05, hybrid_flag = "FLCI", - hybrid_kappa = alpha/10, returnLength = F, - postPeriodMomentsOnly = T, + hybrid_kappa = alpha/10, returnLength = FALSE, + postPeriodMomentsOnly = TRUE, gridPoints =10^3, grid.ub = NA, grid.lb = NA) } %- maybe also 'usage' for other objects documented here. diff --git a/man/computeConditionalCS_DeltaSDB.Rd b/man/computeConditionalCS_DeltaSDB.Rd index da9b36a..5e310cf 100644 --- a/man/computeConditionalCS_DeltaSDB.Rd +++ b/man/computeConditionalCS_DeltaSDB.Rd @@ -11,8 +11,8 @@ Computes the conditional confidence set and hybridized confidence set for Delta computeConditionalCS_DeltaSDB(betahat, sigma, numPrePeriods, numPostPeriods, M = 0, l_vec = .basisVector(index = 1, size=numPostPeriods), alpha = 0.05, hybrid_flag = "FLCI", hybrid_kappa = alpha/10, - returnLength = F, biasDirection = "positive", - postPeriodMomentsOnly = T, + returnLength = FALSE, biasDirection = "positive", + postPeriodMomentsOnly = TRUE, gridPoints = 10^3, grid.lb = NA, grid.ub = NA) } %- maybe also 'usage' for other objects documented here. diff --git a/man/computeConditionalCS_DeltaSDM.Rd b/man/computeConditionalCS_DeltaSDM.Rd index 5977bf0..83eea2e 100644 --- a/man/computeConditionalCS_DeltaSDM.Rd +++ b/man/computeConditionalCS_DeltaSDM.Rd @@ -12,7 +12,7 @@ computeConditionalCS_DeltaSDM(betahat, sigma, numPrePeriods, numPostPeriods, M = 0, l_vec = .basisVector(index = 1, size=numPostPeriods), alpha = 0.05, monotonicityDirection = "increasing", hybrid_flag = "FLCI", hybrid_kappa = alpha/10, - returnLength = F, postPeriodMomentsOnly = T, + returnLength = FALSE, postPeriodMomentsOnly = TRUE, gridPoints = 10^3, grid.lb = NA, grid.ub = NA) } %- maybe also 'usage' for other objects documented here. diff --git a/man/computeConditionalCS_DeltaSDRM.Rd b/man/computeConditionalCS_DeltaSDRM.Rd index bb69274..10d3842 100644 --- a/man/computeConditionalCS_DeltaSDRM.Rd +++ b/man/computeConditionalCS_DeltaSDRM.Rd @@ -11,7 +11,7 @@ Computes the conditional confidence set and hybridized confidence set for Delta 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 = F, postPeriodMomentsOnly = T, + returnLength = FALSE, postPeriodMomentsOnly = TRUE, gridPoints=10^3, grid.ub = NA, grid.lb = NA) } %- maybe also 'usage' for other objects documented here. diff --git a/man/computeConditionalCS_DeltaSDRMB.Rd b/man/computeConditionalCS_DeltaSDRMB.Rd index ce86735..0dc5654 100644 --- a/man/computeConditionalCS_DeltaSDRMB.Rd +++ b/man/computeConditionalCS_DeltaSDRMB.Rd @@ -11,8 +11,8 @@ Computes the conditional confidence set and hybridized confidence set for Delta computeConditionalCS_DeltaSDRMB(betahat, sigma, numPrePeriods, numPostPeriods, l_vec = .basisVector(index = 1, size = numPostPeriods), Mbar = 0, alpha = 0.05, hybrid_flag = "LF", - hybrid_kappa = alpha/10, returnLength = F, - postPeriodMomentsOnly = T, biasDirection = "positive", + hybrid_kappa = alpha/10, returnLength = FALSE, + postPeriodMomentsOnly = TRUE, biasDirection = "positive", gridPoints=10^3, grid.ub = NA, grid.lb = NA) } %- maybe also 'usage' for other objects documented here. diff --git a/man/computeConditionalCS_DeltaSDRMM.Rd b/man/computeConditionalCS_DeltaSDRMM.Rd index dc93e0d..5fc75bf 100644 --- a/man/computeConditionalCS_DeltaSDRMM.Rd +++ b/man/computeConditionalCS_DeltaSDRMM.Rd @@ -12,8 +12,8 @@ computeConditionalCS_DeltaSDRMM(betahat, sigma, numPrePeriods, numPostPeriods, l_vec = .basisVector(index = 1, size = numPostPeriods), Mbar = 0, alpha = 0.05, hybrid_flag = "LF", - hybrid_kappa = alpha/10, returnLength = F, - postPeriodMomentsOnly = T, monotonicityDirection = "increasing", + hybrid_kappa = alpha/10, returnLength = FALSE, + postPeriodMomentsOnly = TRUE, monotonicityDirection = "increasing", gridPoints=10^3, grid.ub = NA, grid.lb = NA) } %- maybe also 'usage' for other objects documented here. diff --git a/man/constructOriginalCS.Rd b/man/constructOriginalCS.Rd index 959814b..16218ab 100644 --- a/man/constructOriginalCS.Rd +++ b/man/constructOriginalCS.Rd @@ -34,7 +34,26 @@ constructOriginalCS(betahat, sigma, Desired size of the robust confidence sets. Default equals 0.05 (corresponding to 95\% confidence interval) } } -% Add one or more standard keywords, see file 'KEYWORDS' in the -% R documentation directory. -% \keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS") -% \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line +\value{ +Returns a dataframe with columns + \item{lb}{ + Lower bound of original confidence set (based on asymptotic normality). + } + \item{ub}{ + Upper bound of original confidence set (based on asymptotic normality). + } + \item{method}{ + Method for constructing confidence set; set to "Original". + } + \item{Delta}{ + The set Delta that was specified; set to NA. + } +} +\examples{ + # Simple use case; for more detailed examples, see + constructOriginalCS(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = length(BCdata_EventStudy$prePeriodIndices), + numPostPeriods = length(BCdata_EventStudy$postPeriodIndices), + alpha = 0.05) +} diff --git a/man/createEventStudyPlot.Rd b/man/createEventStudyPlot.Rd index e072977..fa8a7ca 100644 --- a/man/createEventStudyPlot.Rd +++ b/man/createEventStudyPlot.Rd @@ -10,7 +10,7 @@ Constructs event study plot using the estimated event study coefficients and sta \usage{ createEventStudyPlot(betahat, stdErrors = NULL, sigma = NULL, numPrePeriods, numPostPeriods, alpha, timeVec, - referencePeriod, useRelativeEventTime = F) + referencePeriod, useRelativeEventTime = FALSE) } %- maybe also 'usage' for other objects documented here. \arguments{ @@ -51,7 +51,14 @@ Rambachan, Ashesh and Jonathan Roth. "An Honest Approach to Parallel Trends." 20 \author{ Ashesh Rambachan } -% Add one or more standard keywords, see file 'KEYWORDS' in the -% R documentation directory. -% \keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS") -% \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line +\examples{ + # Simple use case; for more detailed examples, see + + createEventStudyPlot(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = length(BCdata_EventStudy$prePeriodIndices), + numPostPeriods = length(BCdata_EventStudy$postPeriodIndices), + alpha = 0.05, + timeVec = BCdata_EventStudy$timeVec, + referencePeriod = BCdata_EventStudy$referencePeriod) +} diff --git a/man/createSensitivityPlot.Rd b/man/createSensitivityPlot.Rd index 5373b5b..40ec49f 100644 --- a/man/createSensitivityPlot.Rd +++ b/man/createSensitivityPlot.Rd @@ -38,7 +38,19 @@ Returns ggplot object of the sensitivity plot. \author{ Ashesh Rambachan } -% Add one or more standard keywords, see file 'KEYWORDS' in the -% R documentation directory. -% \keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS") -% \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line +\examples{ + # Simple use case; for more detailed examples, see + robustResults <- + createSensitivityResults(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = length(BCdata_EventStudy$prePeriodIndices), + numPostPeriods = length(BCdata_EventStudy$postPeriodIndices), + alpha = 0.05) + originalResults <- + constructOriginalCS(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = length(BCdata_EventStudy$prePeriodIndices), + numPostPeriods = length(BCdata_EventStudy$postPeriodIndices), + alpha = 0.05) + createSensitivityPlot(robustResults, originalResults) +} diff --git a/man/createSensitivityPlot_relativeMagnitudes.Rd b/man/createSensitivityPlot_relativeMagnitudes.Rd index 0816294..378f143 100644 --- a/man/createSensitivityPlot_relativeMagnitudes.Rd +++ b/man/createSensitivityPlot_relativeMagnitudes.Rd @@ -39,7 +39,19 @@ Returns ggplot object of the sensitivity plot. \author{ Ashesh Rambachan } -% Add one or more standard keywords, see file 'KEYWORDS' in the -% R documentation directory. -% \keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS") -% \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line +\examples{ + # Simple use case; for more detailed examples, see + robustResults <- + createSensitivityResults_relativeMagnitudes(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = length(BCdata_EventStudy$prePeriodIndices), + numPostPeriods = length(BCdata_EventStudy$postPeriodIndices), + alpha = 0.05) + originalResults <- + constructOriginalCS(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = length(BCdata_EventStudy$prePeriodIndices), + numPostPeriods = length(BCdata_EventStudy$postPeriodIndices), + alpha = 0.05) + createSensitivityPlot_relativeMagnitudes(robustResults, originalResults) +} diff --git a/man/createSensitivityResults.Rd b/man/createSensitivityResults.Rd index 3b7a830..fccb89b 100644 --- a/man/createSensitivityResults.Rd +++ b/man/createSensitivityResults.Rd @@ -74,7 +74,11 @@ Rambachan, Ashesh and Jonathan Roth. "An Honest Approach to Parallel Trends." 20 \author{ Ashesh Rambachan } -% Add one or more standard keywords, see file 'KEYWORDS' in the -% R documentation directory. -% \keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS") -% \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line +\examples{ + # Simple use case; for more detailed examples, see + createSensitivityResults(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = length(BCdata_EventStudy$prePeriodIndices), + numPostPeriods = length(BCdata_EventStudy$postPeriodIndices), + alpha = 0.05) +} diff --git a/man/createSensitivityResults_relativeMagnitudes.Rd b/man/createSensitivityResults_relativeMagnitudes.Rd index 2d258f5..7534633 100644 --- a/man/createSensitivityResults_relativeMagnitudes.Rd +++ b/man/createSensitivityResults_relativeMagnitudes.Rd @@ -98,7 +98,11 @@ Rambachan, Ashesh and Jonathan Roth. "An Honest Approach to Parallel Trends." 20 \author{ Ashesh Rambachan } -% Add one or more standard keywords, see file 'KEYWORDS' in the -% R documentation directory. -% \keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS") -% \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line +\examples{ + # Simple use case; for more detailed examples, see + createSensitivityResults_relativeMagnitudes(betahat = BCdata_EventStudy$betahat, + sigma = BCdata_EventStudy$sigma, + numPrePeriods = length(BCdata_EventStudy$prePeriodIndices), + numPostPeriods = length(BCdata_EventStudy$postPeriodIndices), + alpha = 0.05) +}