Skip to content

Commit 930907f

Browse files
committed
Renamed package to apm and edited all functions names
1 parent b19eb9b commit 930907f

17 files changed

+197
-197
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Package: eepd
1+
Package: apm
22
Title: What the Package Does (One Line, Title Case)
33
Version: 0.0.0.9001
44
Authors@R:

NAMESPACE

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# Generated by roxygen2: do not edit by hand
22

3-
S3method(`[[`,eepd_models)
4-
S3method(`[`,eepd_models)
5-
S3method(c,eepd_models)
6-
S3method(plot,eepd_est)
7-
S3method(plot,eepd_pre_fits)
8-
S3method(print,eepd_est)
9-
S3method(print,eepd_models)
10-
S3method(print,eepd_pre_fits)
11-
S3method(print,summary.eepd_est)
12-
S3method(print,summary.eepd_pre_fits)
13-
S3method(summary,eepd_est)
14-
S3method(summary,eepd_pre_fits)
15-
export(eepd_est)
16-
export(eepd_mod)
17-
export(eepd_pre)
3+
S3method(`[[`,apm_models)
4+
S3method(`[`,apm_models)
5+
S3method(c,apm_models)
6+
S3method(plot,apm_est)
7+
S3method(plot,apm_pre_fits)
8+
S3method(print,apm_est)
9+
S3method(print,apm_models)
10+
S3method(print,apm_pre_fits)
11+
S3method(print,summary.apm_est)
12+
S3method(print,summary.apm_pre_fits)
13+
S3method(summary,apm_est)
14+
S3method(summary,apm_pre_fits)
15+
export(apm_est)
16+
export(apm_mod)
17+
export(apm_pre)
1818
export(robustness_bound)
1919
import(ggh4x)
2020
import(ggplot2)

R/eepd-package.R R/apm-package.R

File renamed without changes.

R/eepd_est.R R/apm_est.R

+29-29
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
#' Estimate ATTS from models fits
22
#'
3-
#' @description `eepd_est()` computes the ATTs from the models previously fit by [eepd_pre()], choosing the optimal one by minimizing the largest absolute average prediction error across validation times. Optionally, this process can be simulated to arrive at a distribution of ATTs that accounts for the uncertainty in selecting the optimal model. `plot()` plots the resulting ATT(s).
3+
#' @description `apm_est()` computes the ATTs from the models previously fit by [apm_pre()], choosing the optimal one by minimizing the largest absolute average prediction error across validation times. Optionally, this process can be simulated to arrive at a distribution of ATTs that accounts for the uncertainty in selecting the optimal model. `plot()` plots the resulting ATT(s).
44
#'
5-
#' @inheritParams eepd_pre
6-
#' @param fits an `eepd_pre_fits` object; the output of a call to [eepd_pre()].
5+
#' @inheritParams apm_pre
6+
#' @param fits an `apm_pre_fits` object; the output of a call to [apm_pre()].
77
#' @param post_time the value of the time variable considered post-treatment, for which the ATT is to be estimated.
8-
#' @param M the sensitivity parameter for set identification. For `eepd_est()`, the default is 0, i.e., under point identification. For `summary()`, this can be set to one or more positive values to produce uncertainty bounds for each value. Only allowed when not set to 0 in the call to `eepd_est()`. See Details.
8+
#' @param M the sensitivity parameter for set identification. For `apm_est()`, the default is 0, i.e., under point identification. For `summary()`, this can be set to one or more positive values to produce uncertainty bounds for each value. Only allowed when not set to 0 in the call to `apm_est()`. See Details.
99
#' @param R the number of bootstrap iterations used to compute the sampling variance of the ATT. Default is 1000. More is better but takes longer.
1010
#' @param all_models `logical`; whether to compute ATTs for all models (`TRUE`) or just those with BMA weights greater than 0 (`FALSE`, default). This will not effect the final estimates but leaving as `FALSE` can speed up computation when some models have BMA weights of 0.
11-
#' @param x,object an `eepd_est` object; the output of a call to `eepd_est()`.
11+
#' @param x,object an `apm_est` object; the output of a call to `apm_est()`.
1212
#' @param level the desired confidence level. Set to 0 to ignore sampling variation in computing the interval bounds. Default is .95.
1313
#' @param label `logical`; whether to label the ATT estimates. Requires \pkg{ggrepel} to be installed. Default is `TRUE`.
1414
#' @param size.weights `logicsl`; whether to size the points based on their BMA weights. Default is `TRUE`.
1515
#'
1616
#' @returns
17-
#' `eepd_est()` returns an `eepd_est` object, which contains the ATT estimates and their variance estimates. The following components are included:
17+
#' `apm_est()` returns an `apm_est` object, which contains the ATT estimates and their variance estimates. The following components are included:
1818
#' \describe{
1919
#' \item{BMA_att}{the BMA-weighted ATT}
2020
#' \item{atts}{a matrix containing the ATT estimates from each model (when `all_models = FALSE`, only models with positive BMA weights are included)}
@@ -24,7 +24,7 @@
2424
#' \item{M}{the value of the sensitivity parameter `M`}
2525
#' \item{post_time}{the value supplied to `post_time`}
2626
#' \item{pred_errors}{a matrix containing the difference in average prediction errors for each model and each pre-treatment validation period}
27-
#' \item{BMA_weights}{the BMA weights computed by `eepd_pre()` (when `all_models = FALSE`, only positive BMA weights are included)}
27+
#' \item{BMA_weights}{the BMA weights computed by `apm_pre()` (when `all_models = FALSE`, only positive BMA weights are included)}
2828
#' \item{boot_out}{an `fwb` object containing the bootstrap results}
2929
#' }
3030
#'
@@ -33,35 +33,35 @@
3333
#' `summary()` produces a table with the BMA-weighted ATT, it's estimated standard error, and confidence interval limits. When `M` is greater than 0, additional rows for each value of `M` are included with the lower and upper bound. When `level` is greater than 0, these bounds include the uncertainty due to sampling and model selection; otherwise, they correspond to the set identification bounds for the ATT.
3434
#'
3535
#' @details
36-
#' `eepd_est()` estimates the ATT from each model and combines them to form the BMA-weighted estimate of the ATT. Uncertainty for the BMA-weighted ATT is computed by combining two variance components, one that account for sampling and another that accounts for model selection. The component due to sampling is computed by bootstrapping the process of fitting the outcome model for the post-treatment outcome identified by `post_time` and computing the difference between the observed outcome mean difference and the model-predicted outcome mean difference. The fractional weighted bootstrap as implemented in [fwb::fwb()] is used to ensure no units are dropped from the analysis. In each bootstrap sample, the BMA-weighted ATT estimate is computed as the weighted average of the ATTs computed from the models using the fixed BMA weights computed by [eepd_pre()], and the variance is computed as the empirical variance over the bootstrapped estimates. The variance component due to model selection is computed as the BMA-weighted variance of the original ATTs.
36+
#' `apm_est()` estimates the ATT from each model and combines them to form the BMA-weighted estimate of the ATT. Uncertainty for the BMA-weighted ATT is computed by combining two variance components, one that account for sampling and another that accounts for model selection. The component due to sampling is computed by bootstrapping the process of fitting the outcome model for the post-treatment outcome identified by `post_time` and computing the difference between the observed outcome mean difference and the model-predicted outcome mean difference. The fractional weighted bootstrap as implemented in [fwb::fwb()] is used to ensure no units are dropped from the analysis. In each bootstrap sample, the BMA-weighted ATT estimate is computed as the weighted average of the ATTs computed from the models using the fixed BMA weights computed by [apm_pre()], and the variance is computed as the empirical variance over the bootstrapped estimates. The variance component due to model selection is computed as the BMA-weighted variance of the original ATTs.
3737
#'
3838
#' When `M` is greater than 0, bounds for set identification and their uncertainty are additionally computed. This involves bootstrapping the fitting of the pre-period models along with post-treatment models on order to compute the maximum absolute difference in average prediction errors for each model across validation periods. Each bootstrap sample produces a margin of error for each model computed as \eqn{M \times \delta_m} where \eqn{\delta_m} is the maximum absolute difference in average prediction errors for model \eqn{m}. Upper and lower bounds for the set-identified BMA-weighted ATT are computed as \eqn{\text{ATT}_m \pm M \times \delta_m}. The same procedure as above is then used to compute the variance of these bounds.
3939
#'
4040
#' `summary()` displays the BMA-weighted ATT estimate, its standard error, and Wald confidence intervals. When `M` is greater than 0, bounds for the set-identified ATT are displayed in the confidence interval bound columns. The lower bound is computed as \eqn{\text{LB} - \sigma_{LB}Z_{l}} and the upper bound as \eqn{\text{UB} + \sigma_{UB}Z_{l}}, where \eqn{\text{LB}} and \eqn{\text{UB}} are the lower and upper bounds, \eqn{\sigma_{LB}} and \eqn{\sigma_{UB}} are their variances accounting for sampling and model selection, and \eqn{Z_{l}} is the critical Z-statistic for confidence level \eqn{l}. To display the set-identification bounds themselves, one should set `level = 0`.
4141
#'
42-
#' @seealso [eepd_pre()] for computing the BMA weights; [fwb::fwb()] for the fractional weighted bootstrap.
42+
#' @seealso [apm_pre()] for computing the BMA weights; [fwb::fwb()] for the fractional weighted bootstrap.
4343
#'
4444
#'
4545
#' @examples
4646
#' data("ptpdata")
4747
#'
4848
#' # Combination of 4 models: 2 time trends, 2 lags
49-
#' models <- eepd_mod(list(crude_rate ~ 1),
49+
#' models <- apm_mod(list(crude_rate ~ 1),
5050
#' lag = 0:1,
5151
#' time_trend = 0:1)
5252
#' models
5353
#'
5454
#' # Fit the models to data; unit_var must be supplied for
5555
#' # fixed effects
56-
#' fits <- eepd_pre(models,
56+
#' fits <- apm_pre(models,
5757
#' data = ptpdata,
5858
#' group_var = "group",
5959
#' time_var = "year",
6060
#' val_times = 2004:2007,
6161
#' unit_var = "state",
6262
#' nsim = 100)
6363
#'
64-
#' est <- eepd_est(fits,
64+
#' est <- apm_est(fits,
6565
#' post_time = 2008,
6666
#' M = 1,
6767
#' R = 20)
@@ -80,8 +80,8 @@
8080
#' plot(est)
8181

8282
#' @export
83-
eepd_est <- function(fits, post_time, M = 0, R = 1000L, all_models = FALSE, cl = NULL, verbose = TRUE, ...) {
84-
chk::chk_is(fits, "eepd_pre_fits")
83+
apm_est <- function(fits, post_time, M = 0, R = 1000L, all_models = FALSE, cl = NULL, verbose = TRUE, ...) {
84+
chk::chk_is(fits, "apm_pre_fits")
8585

8686
time_var <- attr(fits, "time_var")
8787
data <- fits$data
@@ -286,14 +286,14 @@ eepd_est <- function(fits, post_time, M = 0, R = 1000L, all_models = FALSE, cl =
286286
attr(out, "unit_var") <- unit_var
287287
attr(out, "group_var") <- group_var
288288

289-
class(out) <- "eepd_est"
289+
class(out) <- "apm_est"
290290

291291
out
292292
}
293293

294-
#' @exportS3Method print eepd_est
295-
print.eepd_est <- function(x, ...) {
296-
cat("An `eepd_est` object\n")
294+
#' @exportS3Method print apm_est
295+
print.apm_est <- function(x, ...) {
296+
cat("An `apm_est` object\n")
297297
cat("\n")
298298
cat(sprintf(" - grouping variable: %s\n", attr(x, "group_var")))
299299
cat(sprintf(" - unit variable: %s\n", attr(x, "unit_var")))
@@ -308,9 +308,9 @@ print.eepd_est <- function(x, ...) {
308308
invisible(x)
309309
}
310310

311-
#' @exportS3Method summary eepd_est
312-
#' @rdname eepd_est
313-
summary.eepd_est <- function(object, level = .95, M = NULL, ...) {
311+
#' @exportS3Method summary apm_est
312+
#' @rdname apm_est
313+
summary.apm_est <- function(object, level = .95, M = NULL, ...) {
314314

315315
res <- data.frame(
316316
object[["BMA_att"]]["ATT"],
@@ -339,7 +339,7 @@ summary.eepd_est <- function(object, level = .95, M = NULL, ...) {
339339

340340
if (length(M) > 0) {
341341
if (object[["M"]] == 0) {
342-
chk::err("`M` cannot be nonzero when `M` was 0 in the call to `eepd_est()`")
342+
chk::err("`M` cannot be nonzero when `M` was 0 in the call to `apm_est()`")
343343
}
344344

345345
res2 <- do.call("rbind", lapply(M, function(m) {
@@ -396,13 +396,13 @@ summary.eepd_est <- function(object, level = .95, M = NULL, ...) {
396396
res <- rbind(res, res2)
397397
}
398398

399-
class(res) <- c("summary.eepd_est", class(res))
399+
class(res) <- c("summary.apm_est", class(res))
400400

401401
res
402402
}
403403

404-
#' @exportS3Method print summary.eepd_est
405-
print.summary.eepd_est <- function(x, digits = max(3, getOption("digits") - 3), ...) {
404+
#' @exportS3Method print summary.apm_est
405+
print.summary.apm_est <- function(x, digits = max(3, getOption("digits") - 3), ...) {
406406
printCoefmat(x, digits = digits, cs.ind = 1:4,
407407
tst.ind = 5,
408408
P.values = TRUE,
@@ -413,9 +413,9 @@ print.summary.eepd_est <- function(x, digits = max(3, getOption("digits") - 3),
413413
invisible(x)
414414
}
415415

416-
#' @exportS3Method plot eepd_est
417-
#' @rdname eepd_est
418-
plot.eepd_est <- function(x, label = TRUE, size.weights = TRUE, ...) {
416+
#' @exportS3Method plot apm_est
417+
#' @rdname apm_est
418+
plot.apm_est <- function(x, label = TRUE, size.weights = TRUE, ...) {
419419
chk::chk_flag(label)
420420

421421
max_abs_pred_error <- apply(abs(x[["pred_errors"]]), 2, max)
@@ -451,4 +451,4 @@ plot.eepd_est <- function(x, label = TRUE, size.weights = TRUE, ...) {
451451
}
452452

453453
p
454-
}
454+
}

R/eepd_mod.R R/apm_mod.R

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#' Generate models used to fit outcomes
22
#'
3-
#' @description `eepd_mod()` generates a list of models characterized by a basic model formulas and other options (e.g., lags, families, etc.) that are supplied to [eepd_pre()]. These values are completely crossed to create a grid of model specifications, and multiple sets of model specifications can be combined using `c()` (see Examples).
3+
#' @description `apm_mod()` generates a list of models characterized by a basic model formulas and other options (e.g., lags, families, etc.) that are supplied to [apm_pre()]. These values are completely crossed to create a grid of model specifications, and multiple sets of model specifications can be combined using `c()` (see Examples).
44
#'
55
#' @param formula_list a list of model formulas with the outcome on the left side and predictions (or just an intercept) on the right side.
6-
#' @param family a list of family specifications; see [family()] for allowable options. These will eventually be passed to [glm()] when fitting the models in [eepd_pre()]. `"negbin"` can also be supplied to request a negative binomial model with a log link fit using [MASS::glm.nb()]. Default is `"gaussian"` to specify a linear model.
6+
#' @param family a list of family specifications; see [family()] for allowable options. These will eventually be passed to [glm()] when fitting the models in [apm_pre()]. `"negbin"` can also be supplied to request a negative binomial model with a log link fit using [MASS::glm.nb()]. Default is `"gaussian"` to specify a linear model.
77
#' @param lag a vector of integers indicating the desired outcome lags to be used as predictors. For example, a `lag` value of 3 means the outcome lagged once, twice, and three times will be included as predictors. Default is 0 for no lags.
8-
#' @param diff_k a vector of integers indicating the desired outcome lag to be used a an offset For example, a `diff_k` value of 1 means the prior time point's outcome will be included as an offset, equivalent to using the outcome minus its corresponding lag as the outcome of the corresponding model. Default is 0 for no lags. Any models with a `diff_k` value less than a `lag` value will be removed automatically. When used with a family with a log link, the lags are automatically log-transformed; an error will be thrown by `eepd_pre()` if nonpositive values are present in the outcome.
8+
#' @param diff_k a vector of integers indicating the desired outcome lag to be used a an offset For example, a `diff_k` value of 1 means the prior time point's outcome will be included as an offset, equivalent to using the outcome minus its corresponding lag as the outcome of the corresponding model. Default is 0 for no lags. Any models with a `diff_k` value less than a `lag` value will be removed automatically. When used with a family with a log link, the lags are automatically log-transformed; an error will be thrown by `apm_pre()` if nonpositive values are present in the outcome.
99
#' @param log a logical vector indicating whether the outcome should be log-transformed. Default is `FALSE` to use the original outcome. When `lag` or `diff_k` are greater than 0, the outcome lags will also be log-transformed if `TRUE`. When the family has a log link and `diff_k` is greater than zero, the lag in the offset will be log transformed.
1010
#' @param time_trend a vector of integers indicating the desired powers to be included in a time trend. For example, a `time_trend` value of 2 means the time variable and its square will be included as predictors in the model. A value of 0 (the default) means time is not included as a predictor.
1111
#' @param fixef a logical vector indicating whether unit fixed effects should be included as predictors. Default is `FALSE` to omit unit fixed effects.
1212
#' @param identiy_only_log `logical`; whether to omit any models in which `log` is `TRUE` but the link in the `family` specification corresponds to something other than `"identity"`. Default is `TRUE`, and this should probably not be changed.
1313
#'
1414
#' @returns
15-
#' An `eepd_models` object, which is a list containing the full cross (less any omitted combinations) of the model features specified in the arguments, with each combination a list. These have a `print()` method and can be combined using `c()`. Each model is named automatically, but these can be set manually using [names()] as well. Models can be removed by setting their value to `NULL`; see Examples.
15+
#' An `apm_models` object, which is a list containing the full cross (less any omitted combinations) of the model features specified in the arguments, with each combination a list. These have a `print()` method and can be combined using `c()`. Each model is named automatically, but these can be set manually using [names()] as well. Models can be removed by setting their value to `NULL`; see Examples.
1616
#'
1717
#' @seealso [formula], [family]
1818
#'
@@ -21,14 +21,14 @@
2121
#'
2222
#' # Combination of 8 models: 1 baseline formulas,
2323
#' # 2 families, 2 lags, 2 time trends
24-
#' models1 <- eepd_mod(crude_rate ~ 1,
24+
#' models1 <- apm_mod(crude_rate ~ 1,
2525
#' family = list("gaussian", "quasipoisson"),
2626
#' time_trend = 0:1,
2727
#' lag = 0:1, fixef = TRUE)
2828
#' models1
2929
#'
3030
#' # Add a single other model with a square time trend
31-
#' models2 <- eepd_mod(crude_rate ~ 1,
31+
#' models2 <- apm_mod(crude_rate ~ 1,
3232
#' family = "gaussian",
3333
#' time_trend = 2,
3434
#' fixef = FALSE)
@@ -42,7 +42,7 @@
4242

4343

4444
#' @export
45-
eepd_mod <- function(formula_list, family = "gaussian", lag = 0, diff_k = 0,
45+
apm_mod <- function(formula_list, family = "gaussian", lag = 0, diff_k = 0,
4646
log = FALSE, time_trend = 0, fixef = FALSE, identiy_only_log = TRUE) {
4747
# Check arguments
4848

@@ -171,13 +171,13 @@ eepd_mod <- function(formula_list, family = "gaussian", lag = 0, diff_k = 0,
171171

172172
names(out) <- .name_mods(out)
173173

174-
class(out) <- "eepd_models"
174+
class(out) <- "apm_models"
175175

176176
out
177177
}
178178

179-
#' @exportS3Method print eepd_models
180-
print.eepd_models <- function(x, ...) {
179+
#' @exportS3Method print apm_models
180+
print.apm_models <- function(x, ...) {
181181
for (i in seq_along(x)) {
182182
cat(sprintf("- Model %s: %s\n", i, names(x)[i]))
183183
cat(deparse1(x[[i]]$formula), "\n", sep = "")
@@ -200,8 +200,8 @@ print.eepd_models <- function(x, ...) {
200200
invisible(x)
201201
}
202202

203-
#' @exportS3Method c eepd_models
204-
c.eepd_models <- function(..., recursive = TRUE) {
203+
#' @exportS3Method c apm_models
204+
c.apm_models <- function(..., recursive = TRUE) {
205205
out <- NextMethod("c")
206206

207207
for (i in which(duplicated(out))) {
@@ -210,22 +210,22 @@ c.eepd_models <- function(..., recursive = TRUE) {
210210

211211
names(out) <- .name_mods(out)
212212

213-
class(out) <- "eepd_models"
213+
class(out) <- "apm_models"
214214

215215
out
216216
}
217217

218-
#' @exportS3Method `[` eepd_models
219-
`[.eepd_models` <- function(..., recursive = TRUE) {
218+
#' @exportS3Method `[` apm_models
219+
`[.apm_models` <- function(..., recursive = TRUE) {
220220
out <- NextMethod("[")
221221

222-
class(out) <- "eepd_models"
222+
class(out) <- "apm_models"
223223

224224
out
225225
}
226226

227-
#' @exportS3Method `[[` eepd_models
228-
`[[.eepd_models` <- function(..., recursive = TRUE) {
227+
#' @exportS3Method `[[` apm_models
228+
`[[.apm_models` <- function(..., recursive = TRUE) {
229229
NextMethod("[[")
230230
}
231231

0 commit comments

Comments
 (0)