Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

truncated censoring #72

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# txshift 0.3.9

As of October 2023:
* A new argument `bound` has been added to `est_g_cens()` to specify the lower
tolerated limit of the censoring mechanism estimates. This is used to allow
for stable inverse probability of censoring weights to be applied. This bound
has been given a default value of 0.02.
* The default value of `bound` in `bound_propensity()` has been changed from
0.005 to 0.01, as has the default value of `gps_bound` in `txshift()`.

As of May 2023:
* A new argument `bound` has been added to `bound_propensity()` to specify the
lower tolerated limit of generalized propensity score estimates. Estimates
Expand Down
4 changes: 2 additions & 2 deletions R/bound.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ bound_precision <- function(vals) {
#' should only be bounded/truncated away from zero.
#' @param bound \code{numeric} atomic giving the lower limit of the generalized
#' propensity score estimates to be tolerated. Estimates less than this will
#' be truncated to this value (default = 0.005). Note that the default may be
#' be truncated to this value (default = 0.01). Note that the default may be
#' internally overwritten by reference to the sample size (n), so the lower
#' bound used is the greater of the specified value and 1/n.
#'
#' @return A \code{numeric} vector of the same length as \code{vals}, where the
#' returned values are bounded such that the minimum is no lower than 1/n, for
#' the sample size n.
bound_propensity <- function(vals, bound = 0.005) {
bound_propensity <- function(vals, bound = 0.01) {
# bound generalized propensity score g(a|w) away from 0 only
propensity_bound <- max(1 / length(vals), bound)
vals_bounded <- pmax(vals, propensity_bound)
Expand Down
7 changes: 6 additions & 1 deletion R/fit_mechanisms.R
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ est_g_exp <- function(A,
#' for fitting a (generalized) linear model via \code{\link[stats]{glm}}.
#' @param sl_learners Object containing a set of instantiated learners from the
#' \pkg{sl3}, to be used in fitting an ensemble model.
#' @param bound \code{numeric} giving the lower limit of censoring mechanism
#' estimates to be tolerated (default = 0.02). Estimates below this value are
#' truncated to this or 1/n. See \code{\link{bound_propensity}} for details.
#'
#' @importFrom stats glm as.formula predict
#' @importFrom data.table as.data.table setnames copy set
Expand All @@ -237,7 +240,8 @@ est_g_cens <- function(C_cens,
samp_weights = rep(1, length(C_cens)),
fit_type = c("sl", "glm"),
glm_formula = "C_cens ~ .",
sl_learners = NULL) {
sl_learners = NULL,
bound = 0.02) {
# set defaults and check arguments
fit_type <- match.arg(fit_type)
if (fit_type == "sl") {
Expand Down Expand Up @@ -301,6 +305,7 @@ est_g_cens <- function(C_cens,
}

# generate output
pred_g_cens <- bound_propensity(vals = pred_g_cens, bound = bound)
return(pred_g_cens)
}

Expand Down
5 changes: 4 additions & 1 deletion R/onestep_txshift.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
#' @param samp_estim An object providing the value of the censoring mechanism
#' evaluated across the full data. This object is passed in after being
#' constructed by a call to the internal function \code{\link{est_samp}}.
#' @param gn_cens_weights TODO: document
#' @param gn_cens_weights An object providing the value of inverse probability
#' of censoring weights, the inverse of the censoring mechanism estimate. The
#' weights are used as part of the IPCW-EIF procedure to implement a joint
#' intervention that removes the contribution of the censoring process.
#' @param Qn_estim An object providing the value of the outcome evaluated after
#' imposing a shift in the treatment. This object is passed in after being
#' constructed by a call to the internal function \code{est_Q}.
Expand Down
5 changes: 4 additions & 1 deletion R/tmle_txshift.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
#' @param samp_estim An object providing the value of the sampling mechanism
#' evaluated across the full data. This object is passed in after being
#' constructed by a call to the internal function \code{\link{est_samp}}.
#' @param gn_cens_weights TODO: document
#' @param gn_cens_weights An object providing the value of inverse probability
#' of censoring weights, the inverse of the censoring mechanism estimate. The
#' weights are used as part of the IPCW-TMLE procedure to implement a joint
#' intervention that removes the contribution of the censoring process.
#' @param Qn_estim An object providing the value of the outcome evaluated after
#' imposing a shift in the treatment. This object is passed in after being
#' constructed by a call to the internal function \code{\link{est_Q}}.
Expand Down
8 changes: 4 additions & 4 deletions R/txshift.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
#' @param max_iter A \code{numeric} integer giving the maximum number of steps
#' to be taken in iterating to a solution of the efficient influence function.
#' @param gps_bound \code{numeric} giving the lower limit of the generalized
#' propensity score estimates to be tolerated (default = 0.05). Estimates less
#' than this are truncated to this or 1/n. See \code{\link{bound_propensity}}
#' for details.
#' propensity score estimates to be tolerated (default = 0.01). Estimates
#' falling below this value are truncated to this or 1/n. For details, see
#' \code{\link{bound_propensity}}.
#' @param samp_fit_args A \code{list} of arguments, all but one of which are
#' passed to \code{\link{est_samp}}. For details, consult the documentation of
#' \code{\link{est_samp}}. The first element (i.e., \code{fit_type}) is used
Expand Down Expand Up @@ -203,7 +203,7 @@ txshift <- function(W,
estimator = c("tmle", "onestep"),
fluctuation = c("standard", "weighted"),
max_iter = 10,
gps_bound = 0.005,
gps_bound = 0.01,
samp_fit_args = list(
fit_type = c("glm", "sl", "external"),
sl_learners = NULL
Expand Down
4 changes: 2 additions & 2 deletions man/bound_propensity.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion man/est_g_cens.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/onestep_txshift.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/tmle_txshift.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/txshift.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading