diff --git a/DESCRIPTION b/DESCRIPTION index 1639eff..d0ab853 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -6,6 +6,7 @@ Depends: R (>= 3.6.0) Imports: stats, + rlang, foreach (>= 1.4.7), matrixStats (>= 0.63.0), CVXR (>= 0.99-6), diff --git a/NAMESPACE b/NAMESPACE index 3fa3e25..9d290bf 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,7 @@ importFrom(dplyr, "%>%") importFrom(foreach, "%dopar%") importFrom(foreach, "%do%") +importFrom(rlang, ".data") export(computeConditionalCS_DeltaRM) export(computeConditionalCS_DeltaRMB) export(computeConditionalCS_DeltaRMM) diff --git a/R/flci.R b/R/flci.R index ff22d33..ba49299 100644 --- a/R/flci.R +++ b/R/flci.R @@ -226,23 +226,23 @@ 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) } ) - biasDF <- biasDF %>% dplyr::rename(bias = value) + biasDF <- biasDF %>% dplyr::rename(bias = .data$value) biasDF <- dplyr::left_join( biasDF %>% dplyr::mutate(id = 1), data.frame(m = M, id = 1), - by = "id") %>% dplyr::select(-id) + by = "id") %>% dplyr::select(-.data$id) biasDF <- biasDF %>% - dplyr::rename(maxBias = bias) %>% dplyr::filter(maxBias < Inf) + dplyr::rename(maxBias = .data$bias) %>% dplyr::filter(.data$maxBias < Inf) biasDF <- biasDF %>% - dplyr::mutate(maxBias = maxBias * m) %>% - dplyr::mutate(CI.halflength = .qfoldednormal(p = 1-alpha, mu = maxBias/h) * h) + dplyr::mutate(maxBias = .data$maxBias * .data$m) %>% + dplyr::mutate(CI.halflength = .qfoldednormal(p = 1-alpha, mu = .data$maxBias/.data$h) * .data$h) optimalCIDF <- biasDF %>% - dplyr::group_by(m) %>% - dplyr::filter(status == "optimal" | status == "optimal_inaccurate") %>% - dplyr::filter(CI.halflength == min(CI.halflength)) + dplyr::group_by(.data$m) %>% + 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$m <- M diff --git a/R/sensitivityresults.R b/R/sensitivityresults.R index 62e8669..ff9ce59 100644 --- a/R/sensitivityresults.R +++ b/R/sensitivityresults.R @@ -21,6 +21,7 @@ createSensitivityResults <- function(betahat, sigma, .stopIfNotConformable(betahat, sigma, numPrePeriods, numPostPeriods, l_vec) .warnIfNotSymmPSD(sigma) + m <- NULL # If Mvec is null, construct default Mvec if (base::is.null(Mvec)) { @@ -389,10 +390,10 @@ createSensitivityPlot <- function(robustResults, originalResults, rescaleFactor df <- df %>% dplyr::mutate_at( c("M", "ub", "lb"), ~ .x * rescaleFactor) # Filter out observations above maxM (after rescaling) - df <- df %>% dplyr::filter(M <= maxM) + df <- df %>% dplyr::filter(.data$M <= maxM) - p <- ggplot2::ggplot(data = df, ggplot2::aes(x=M)) + - ggplot2::geom_errorbar(ggplot2::aes(ymin = lb, ymax = ub, color = base::factor(method)), + p <- ggplot2::ggplot(data = df, ggplot2::aes(x=.data$M)) + + ggplot2::geom_errorbar(ggplot2::aes(ymin = .data$lb, ymax = .data$ub, color = base::factor(.data$method)), width = Mgap * rescaleFactor / 2) + ggplot2::scale_color_manual(values = base::c("red", '#01a2d9')) + ggplot2::theme(legend.title=ggplot2::element_blank(), legend.position="bottom") + @@ -421,6 +422,7 @@ createSensitivityResults_relativeMagnitudes <- function(betahat, sigma, .stopIfNotConformable(betahat, sigma, numPrePeriods, numPostPeriods, l_vec) .warnIfNotSymmPSD(sigma) + m <- NULL # If Mbarvec is null, construct default Mbarvec to be 10 values on [0,2]. if (base::is.null(Mbarvec)) { @@ -694,10 +696,10 @@ createSensitivityPlot_relativeMagnitudes <- function(robustResults, originalResu df <- df %>% dplyr::mutate_at( base::c("Mbar", "ub", "lb"), ~ .x * rescaleFactor) # Filter out observations above maxM (after rescaling) - df <- df %>% dplyr::filter(Mbar <= maxMbar) + df <- df %>% dplyr::filter(.data$Mbar <= maxMbar) - p <- ggplot2::ggplot(data = df, ggplot2::aes(x=Mbar)) + - ggplot2::geom_errorbar(ggplot2::aes(ymin = lb, ymax = ub, color = base::factor(method)), + p <- ggplot2::ggplot(data = df, ggplot2::aes(x=.data$Mbar)) + + ggplot2::geom_errorbar(ggplot2::aes(ymin = .data$lb, ymax = .data$ub, color = base::factor(.data$method)), width = Mbargap * rescaleFactor / 2) + ggplot2::scale_color_manual(values = base::c("red", '#01a2d9')) + ggplot2::theme(legend.title=ggplot2::element_blank(), legend.position="bottom") + @@ -747,7 +749,7 @@ createEventStudyPlot <- function(betahat, stdErrors = NULL, sigma = NULL, se = base::c(stdErrors[1:numPrePeriods], NA, stdErrors[(numPrePeriods+1):(numPrePeriods+numPostPeriods)])), ggplot2::aes(x = t)) + ggplot2::geom_point(ggplot2::aes(y = beta), color = "red") + - ggplot2::geom_errorbar(ggplot2::aes(ymin = beta - stats::qnorm(1-alpha/2)*se, ymax = beta + stats::qnorm(1-alpha/2)*se), width = 0.5, colour = "#01a2d9") + + ggplot2::geom_errorbar(ggplot2::aes(ymin = beta - stats::qnorm(1-alpha/2)*.data$se, ymax = beta + stats::qnorm(1-alpha/2)*.data$se), width = 0.5, colour = "#01a2d9") + ggplot2::theme(legend.position = "none") + ggplot2::labs(x = "Event time", y = "") + ggplot2::scale_x_continuous(breaks = base::seq(from = base::min(timeVec), to = base::max(timeVec), by = 1),