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

Supports general submodels and a bunch of new parameters #75

Open
wants to merge 66 commits into
base: devel
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
5552f70
submodels
Sep 5, 2021
15d0089
submodels
Sep 5, 2021
8d86c53
supports general submodels. Tests pass
Sep 5, 2021
4ceae2c
supports general submodel and weights. JK on previous commit
Sep 5, 2021
97b765e
supports general submodel and weights. JK on previous commit
Sep 5, 2021
3d252ac
supports general submodel and weights. JK on previous commit
Sep 5, 2021
a7a1dda
fix ATT and ATC submodels
Sep 5, 2021
742f1c9
REFERENCE CHANGES HERE
Sep 5, 2021
64583b0
towards spCATE
Sep 6, 2021
5a80be0
implemented spCATE PARAM
Sep 6, 2021
870e1a1
added more sp params
Sep 6, 2021
ceac71b
causalGLM seems to work
Sep 6, 2021
ec88bb9
hi
Sep 6, 2021
7ba9492
Update tmle3_Update.R
Larsvanderlaan Sep 6, 2021
9b64c82
Remove built in submodels/losses
Larsvanderlaan Sep 6, 2021
01b1116
Delete submodels_semiparametric.R
Larsvanderlaan Sep 6, 2021
a22e578
np params
Sep 6, 2021
a8ca892
Merge branch 'general_submodels_devel' of https://github.com/tlverse/…
Sep 6, 2021
1142b6b
more np
Sep 6, 2021
a4584d1
minr bug fixes to npOR
Sep 6, 2021
6bd79b4
testing
Sep 6, 2021
0f15fc0
hi
Sep 6, 2021
b017418
more tests
Sep 6, 2021
eaff276
more tests
Sep 6, 2021
d9f2ee3
ran make style
Sep 6, 2021
e97a39f
ran make style
Sep 6, 2021
667e24c
wait
Sep 6, 2021
2d3aa6e
fix bug
Sep 6, 2021
e349397
format
Sep 6, 2021
de1a3f1
format
Sep 6, 2021
759dca0
fix documentation bug
Sep 6, 2021
d90cb6e
remove glm_sp docs
Sep 6, 2021
63a41a1
changes
Sep 6, 2021
fca50f6
changes
Sep 6, 2021
7253a6c
changes
Sep 6, 2021
436581f
change to default for spCausal
Sep 6, 2021
03f22c7
change to default for spCausal
Sep 6, 2021
c19995e
change to default for spCausal
Sep 6, 2021
e4ee0f5
change to default for spCausal
Sep 6, 2021
da0e4a8
change to default for spCausal
Sep 7, 2021
fc438e4
change to default for spCausal
Sep 7, 2021
e218916
fix bug tmle3_fit initial est if no full fit
Sep 7, 2021
e094a76
fix
Sep 7, 2021
701b5a5
fix
Sep 7, 2021
2fff29b
fix
Sep 7, 2021
2244687
fix
Sep 7, 2021
59a9301
fix
Sep 7, 2021
9808493
add npTSM
Sep 7, 2021
3f5b0f7
npRR
Sep 7, 2021
9c55096
bounded outcomes
Sep 7, 2021
d75be43
bounded outcomes
Sep 7, 2021
ed89de8
bounded outcomes
Sep 7, 2021
469e7f8
bounded outcomes
Sep 7, 2021
4d4fb2f
plz
Sep 7, 2021
48324de
small
Sep 7, 2021
ab16187
added Param_coxph
Sep 8, 2021
f019a0f
added Param_coxph
Sep 8, 2021
1fcd721
added Param_coxph
Sep 8, 2021
a6b3587
change OR default submodel
Sep 8, 2021
7969124
sort of fixed coxph
Sep 9, 2021
e9d587f
sort of fixed coxph
Sep 9, 2021
3a3bfa8
hi
Sep 9, 2021
d340dc9
hi
Sep 9, 2021
fef3613
plz dont break
Sep 9, 2021
0787f9b
ATE weights
Larsvanderlaan Apr 7, 2022
dd189d8
ATE weights
Larsvanderlaan Apr 7, 2022
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
Prev Previous commit
Next Next commit
hi
Lars van der Laan committed Sep 9, 2021
commit 3a3bfa8ac466c276d29dad3504ecc7e08a697a74
23 changes: 10 additions & 13 deletions R/Param_coxph.R
Original file line number Diff line number Diff line change
@@ -53,7 +53,6 @@ Param_coxph <- R6Class(
inherit = Param_base,
public = list(
initialize = function(observed_likelihood, formula_coxph = ~1, intervention_list_treatment, intervention_list_control, family_fluctuation = c("binomial"), outcome_node = "N") {

super$initialize(observed_likelihood, list(), outcome_node = outcome_node)
family_fluctuation <- match.arg(family_fluctuation)
training_task <- self$observed_likelihood$training_task
@@ -123,7 +122,7 @@ Param_coxph <- R6Class(
pC_mat <- self$long_to_mat(pC, id, time)
S_censor_mat <- self$hm_to_sm(pC_mat)
S_censor_mat <- cbind(1, S_censor_mat[, -ncol(S_censor_mat)])
S_censor <- pmax(as.vector(S_censor_mat), 0.005)# Back to long, CHECK
S_censor <- pmax(as.vector(S_censor_mat), 0.005) # Back to long, CHECK
pN_mat <- self$long_to_mat(pN, id, time)
S_surv_mat <- self$hm_to_sm(pN_mat)
S_surv_mat <- cbind(1, S_surv_mat[, -ncol(S_surv_mat)])
@@ -136,9 +135,9 @@ Param_coxph <- R6Class(
t_grid <- sort(unique(time))


H <- as.matrix(Vt * (prefailure / S_censor / S_surv) * (A / g1 * HR - (1 - A) / g0))
H <- as.matrix(Vt * (prefailure / S_censor) * (A / g1 * HR - (1 - A) / g0))

#print(quantile(H))
# print(quantile(H))

EIF_N <- NULL

@@ -151,23 +150,20 @@ Param_coxph <- R6Class(


scaleinv <- solve(scale)
EIF_N <- self$weights * (H %*% scaleinv) * as.vector(dNt - pN)
EIF_N <- self$weights * (H) * as.vector(dNt - pN)
EIF_WA <- apply(Vt, 2, function(v) {
long_vec <- self$weights * (v * (HR * pN0 - pN1))
wide_vec <- self$long_to_mat(long_vec, id, time)
means <- colMeans(wide_vec)
as.vector(t(t(wide_vec) - means))
}) %*% scaleinv



})
}





return(list(N = H, EIF = list(N = EIF_N, WA = EIF_WA)))
return(list(N = H, EIF = list(N = EIF_N, WA = EIF_WA, scaleinv = scaleinv)))
},
estimates = function(tmle_task = NULL, fold_number = "full") {
if (is.null(tmle_task)) {
@@ -188,12 +184,13 @@ Param_coxph <- R6Class(
id <- tmle_task$id
long_order <- order(id, time)
# clever_covariates happen here (for this param) only, but this is repeated computation
EIF <- self$clever_covariates(tmle_task, fold_number, is_training_task = TRUE)$EIF
EIFs <- self$clever_covariates(tmle_task, fold_number, is_training_task = TRUE)$EIF
EIF <- EIFs
EIF <- EIF$N + EIF$WA

EIF <- apply(EIF, 2, function(col) {
rowSums(self$long_to_mat(col, id, time))
})
}) %*% EIFs$scaleinv

pN <- self$observed_likelihood$get_likelihoods(tmle_task, "N", fold_number)
pC <- self$observed_likelihood$get_likelihoods(tmle_task, "A_c", fold_number)
@@ -209,7 +206,7 @@ Param_coxph <- R6Class(



beta <- suppressWarnings(coef(glm.fit(Vt, pN1, offset = log(pN0), family = poisson(), weights = self$weights )))
beta <- suppressWarnings(coef(glm.fit(Vt, pN1, offset = log(pN0), family = poisson(), weights = self$weights)))


HR <- exp(Vt %*% beta)
4 changes: 2 additions & 2 deletions R/helpers_survival.R
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
#' @param ... extra arguments.
#' @export
#' @rdname survival_tx
survival_tx_npsem <- function(node_list, variable_types = NULL ) {
survival_tx_npsem <- function(node_list, variable_types = NULL) {
# make the tmle task

# define censoring (lost to followup node)
@@ -38,7 +38,7 @@ survival_tx_npsem <- function(node_list, variable_types = NULL ) {
survival_tx_task <- function(data, node_list, variable_types = NULL, ...) {
setDT(data)

npsem <- survival_tx_npsem(node_list, variable_types )
npsem <- survival_tx_npsem(node_list, variable_types)

if (!is.null(node_list$id)) {
tmle_task <- tmle3_Task$new(data, npsem = npsem, id = node_list$id, time = node_list$time, ...)
2 changes: 1 addition & 1 deletion R/tmle3_Spec_coxph.R
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ tmle3_Spec_coxph <- R6Class(
make_tmle_task = function(data, node_list, ...) {
variable_types <- self$options$variable_types
data_list <- self$transform_data(data, node_list)
tmle_task <- survival_tx_task(data_list$long_data, data_list$long_node_list, variable_types )
tmle_task <- survival_tx_task(data_list$long_data, data_list$long_node_list, variable_types)

return(tmle_task)
},
15 changes: 8 additions & 7 deletions vignettes/testing.Rmd
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ library(sl3)
```{r}
passes<-c()
for(i in 1:200){
tmax <- 4
tmax <- 5
print(i)
D <- DAG.empty()
D <- D + node("W1", distr = "runif", min = -1, max = 1) +
@@ -27,20 +27,21 @@ D <- set.DAG(D)
data <- sim(D, n = 1000)
data

data_N <- data[, grep("[d][N].+", colnames(data))]
data_C <- data[, grep("[d][C].+", colnames(data))]
data_N <- data[, grep("[d][N].+", colnames(data)), drop = F]
data_C <- data[, grep("[d][C].+", colnames(data)), drop = F]

data_surv <- as.data.frame(do.call(rbind, lapply(1:nrow(data), function(i) {
rowN <- data_N[i,]
rowC <- data_C[i,]
t <- which(rowN==1)
tc <- which(rowC==1)
if(length(tc)==0){
tc <- tmax
}
if(length(t)==0){
t <- tmax+2
}
if(length(tc)==0){
tc <- tmax + 1
}

Ttilde <- min(t,tc)
Delta <- t <= tc
return(matrix(c(Ttilde,Delta), nrow=1))
@@ -62,7 +63,7 @@ data$Ttilde <- data_surv$Ttilde

tmle3_fit <- suppressMessages(suppressWarnings(tmle3(tmle_spec_np, data, node_list, learner_list)))


print(tmle3_fit$summary)
passes <- c(passes, tmle3_fit$summary$lower <= 0.5 & tmle3_fit$summary$upper >= 0.5 )
print(mean(passes))
}