Skip to content

Commit

Permalink
Merge pull request #45 from nhejazi/44-missing-obs-weights
Browse files Browse the repository at this point in the history
add back obs_weights to est_tml()
  • Loading branch information
nhejazi authored Mar 4, 2024
2 parents 15f938f + fc1f674 commit a7cecb5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: medoutcon
Title: Efficient Natural and Interventional Causal Mediation Analysis
Version: 0.2.0
Version: 0.2.1
Authors@R: c(
person("Nima", "Hejazi", email = "nh@nimahejazi.org",
role = c("aut", "cre", "cph"),
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# medoutcon 0.2.1

* Fixes issue affecting weighted TMLEs that introduced itself during
previous update to `est_tml()`.

# medoutcon 0.2.0

* Added support for a semiparametric correction for outcome-dependent two-phase
Expand Down
13 changes: 9 additions & 4 deletions R/estimators.R
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ est_tml <- function(data,
weights_b_tilt <- as.numeric(data[R == 1, A] == contrast[1]) / g_prime *
as.numeric(data[R == 1, two_phase_weights])
} else {
weights_b_tilt <- (data$A == contrast[1]) / g_prime
weights_b_tilt <- data$obs_weights * (data$A == contrast[1]) / g_prime
}

suppressWarnings(
Expand Down Expand Up @@ -829,7 +829,7 @@ est_tml <- function(data,
weights_q_tilt <- as.numeric(data[R == 1, A] == contrast[1]) /
g_prime * as.numeric(data[R == 1, two_phase_weights])
} else {
weights_q_tilt <- (data$A == contrast[1]) / g_prime
weights_q_tilt <- data$obs_weights * (data$A == contrast[1]) / g_prime
}
suppressWarnings(
q_tilt_fit <- stats::glm(
Expand Down Expand Up @@ -906,15 +906,20 @@ est_tml <- function(data,
stats::qlogis()

# fit tilting model for substitution estimator
if (tilt_two_phase_weights) {
weights_v_tilt <- (as.numeric(data[R == 1, A]) == contrast[2]) / g_star *
(as.numeric(data[R == 1, two_phase_weights]))
} else {
weights_v_tilt <- data$obs_weights * (data$A == contrast[2]) / g_star
}
suppressWarnings(
v_tilt_fit <- stats::glm(
stats::as.formula("v_pseudo ~ offset(v_star_logit)"),
data = data.table::as.data.table(list(
v_pseudo = v_pseudo,
v_star_logit = v_star_logit
)),
weights = (as.numeric(data[R == 1, A]) == contrast[2]) / g_star *
(as.numeric(data[R == 1, two_phase_weights])),
weights = weights_v_tilt,
family = "binomial",
start = 0
)
Expand Down

0 comments on commit a7cecb5

Please sign in to comment.