Skip to content

Commit

Permalink
make PR + option out tmle3shift dep
Browse files Browse the repository at this point in the history
  • Loading branch information
nhejazi committed Mar 13, 2021
1 parent b0d2c22 commit 00bbeb4
Show file tree
Hide file tree
Showing 95 changed files with 3,892 additions and 1,703 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ r_github_packages:
- r-lib/sessioninfo
- r-lib/covr
- tlverse/sl3
- tlverse/tmle3shift

after_success:
- travis_wait 80 Rscript -e 'covr::codecov()'
Expand Down
10 changes: 4 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ Description: A general framework supporting the implementation of targeted
target parameters through a unified interface. The goal is that the exposed
framework be as general as the mathematical framework upon which it draws.
Depends:
R (>= 3.2.2),
R (>= 3.6.0),
graphics
Imports:
sl3 (>= 1.3.7),
sl3 (>= 1.4.2),
delayed,
data.table,
assertthat,
Expand All @@ -27,7 +27,6 @@ Imports:
methods,
ggplot2,
stats,
Rsolnp,
foreach,
mvtnorm,
magrittr,
Expand All @@ -40,15 +39,14 @@ Suggests:
tableone,
speedglm,
rmarkdown,
Rsolnp,
nnls,
tmle,
tmle3shift,
future,
future.apply,
xgboost
Remotes:
github::tlverse/sl3,
github::tlverse/tmle3shift
github::tlverse/sl3
License: GPL-3
URL: https://tlverse.org/tmle3
BugReports: https://github.com/tlverse/tmle3/issues
Expand Down
8 changes: 4 additions & 4 deletions R/Param_MSM.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ Param_MSM <- R6Class(
inherit = Param_base,
public = list(
initialize = function(observed_likelihood, strata_variable, strata_name = "V",
msm = "A + V", weight = "Cond.Prob.", weight_ub = 1 / 0.025,
continuous_treatment = FALSE, treatment_values = NULL, n_samples = 30,
...,
covariate_node = "W", treatment_node = "A", outcome_node = "Y") {
msm = "A + V", weight = "Cond.Prob.", weight_ub = 1 / 0.025,
continuous_treatment = FALSE, treatment_values = NULL, n_samples = 30,
...,
covariate_node = "W", treatment_node = "A", outcome_node = "Y") {
super$initialize(observed_likelihood, ..., outcome_node = outcome_node)
private$.strata_variable <- strata_variable
private$.strata_name <- strata_name
Expand Down
2 changes: 1 addition & 1 deletion R/Param_delta.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Param_delta <- R6Class(
inherit = Param_base,
public = list(
initialize = function(observed_likelihood, delta_param, parent_parameters,
..., outcome_node = NA) {
..., outcome_node = NA) {
super$initialize(observed_likelihood, ..., outcome_node = outcome_node)
private$.delta_param <- delta_param
private$.parent_parameters <- parent_parameters
Expand Down
2 changes: 1 addition & 1 deletion R/tmle3_Fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ tmle3_Fit <- R6Class(
print(self$summary)
},
set_timings = function(start_time, task_time, likelihood_time, params_time,
fit_time) {
fit_time) {
timings <- list(
make_tmle_task = task_time - start_time,
fit_likelihood = likelihood_time - task_time,
Expand Down
2 changes: 1 addition & 1 deletion R/tmle3_Node.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ tmle3_Node <- R6Class(
class = TRUE,
public = list(
initialize = function(name, variables, parents = c(),
variable_type = NULL, censoring_node = NULL, scale = FALSE) {
variable_type = NULL, censoring_node = NULL, scale = FALSE) {
private$.name <- name
private$.variables <- variables
private$.parents <- parents
Expand Down
2 changes: 1 addition & 1 deletion R/tmle3_Spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tmle3_Spec <- R6Class(
class = TRUE,
public = list(
initialize = function(likelihood_override = NULL,
variable_types = NULL, ...) {
variable_types = NULL, ...) {
private$.options <- list(
likelihood_override = likelihood_override,
variable_types = variable_types, ...
Expand Down
2 changes: 1 addition & 1 deletion R/tmle3_Spec_MSM.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tmle3_Spec_MSM <- R6Class(
inherit = tmle3_Spec,
public = list(
initialize = function(msm = "A + V", weight = "Cond.Prob.", weight_ub = 1 / 0.025,
n_samples = 30, ...) {
n_samples = 30, ...) {
super$initialize(
msm = msm, weight = weight, weight_ub = weight_ub, n_samples = n_samples, ...
)
Expand Down
18 changes: 9 additions & 9 deletions R/tmle3_Update.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ tmle3_Update <- R6Class(
public = list(
# TODO: change maxit for test
initialize = function(maxit = 100, cvtmle = TRUE, one_dimensional = FALSE,
constrain_step = FALSE, delta_epsilon = 1e-4,
convergence_type = c("scaled_var", "sample_size"),
fluctuation_type = c("standard", "weighted"),
optim_delta_epsilon = TRUE,
use_best = FALSE,
verbose = FALSE) {
constrain_step = FALSE, delta_epsilon = 1e-4,
convergence_type = c("scaled_var", "sample_size"),
fluctuation_type = c("standard", "weighted"),
optim_delta_epsilon = TRUE,
use_best = FALSE,
verbose = FALSE) {
private$.maxit <- maxit
private$.cvtmle <- cvtmle
private$.one_dimensional <- one_dimensional
Expand Down Expand Up @@ -110,9 +110,9 @@ tmle3_Update <- R6Class(
private$.step_number <- current_step
},
generate_submodel_data = function(likelihood, tmle_task,
fold_number = "full",
update_node = "Y",
drop_censored = FALSE) {
fold_number = "full",
update_node = "Y",
drop_censored = FALSE) {

# TODO: change clever covariates to allow only calculating some nodes
clever_covariates <- lapply(self$tmle_params, function(tmle_param) {
Expand Down
91 changes: 47 additions & 44 deletions R/tmle3_Update_survival.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ tmle3_Update_survival <- R6Class(
inherit = tmle3_Update,
public = list(
initialize = function(maxit = 100, cvtmle = TRUE, one_dimensional = FALSE,
constrain_step = FALSE, delta_epsilon = 1e-4,
convergence_type = c("scaled_var", "sample_size"),
fluctuation_type = c("standard", "weighted"),
use_best = FALSE,
verbose = FALSE,
fit_method = "l2") {
constrain_step = FALSE, delta_epsilon = 1e-4,
convergence_type = c("scaled_var", "sample_size"),
fluctuation_type = c("standard", "weighted"),
use_best = FALSE,
verbose = FALSE,
fit_method = "l2") {
super$initialize(
maxit = maxit, cvtmle = cvtmle,
one_dimensional = one_dimensional,
Expand All @@ -74,49 +74,52 @@ tmle3_Update_survival <- R6Class(
# TODO: check
# print("l2")
# mean_eic <- self$get_mean_eic(self$update_fold)
epsilon_n <- tryCatch({
alpha <- 0
norm_func <- self$norm_l2
lambda.min.ratio <- 1e-2
epsilon_n <- tryCatch(
{
alpha <- 0
norm_func <- self$norm_l2
lambda.min.ratio <- 1e-2

ind <- 1
while (ind == 1) {
submodel_fit <- glmnet::glmnet(
x = submodel_data$H,
y = submodel_data$observed,
offset = qlogis(submodel_data$initial),
family = "binomial",
alpha = alpha,
standardize = FALSE,
intercept = FALSE,
lambda.min.ratio = lambda.min.ratio,
# nlambda = 2e2
nlambda = 1e2
# TODO: check
# penalty.factor = 1/abs(mean_eic)
)
norms <- apply(submodel_fit$beta, 2, norm_func)
ind <- max(which(norms <= self$delta_epsilon))
if (ind > 1) break
ind <- 1
while (ind == 1) {
submodel_fit <- glmnet::glmnet(
x = submodel_data$H,
y = submodel_data$observed,
offset = qlogis(submodel_data$initial),
family = "binomial",
alpha = alpha,
standardize = FALSE,
intercept = FALSE,
lambda.min.ratio = lambda.min.ratio,
# nlambda = 2e2
nlambda = 1e2
# TODO: check
# penalty.factor = 1/abs(mean_eic)
)
norms <- apply(submodel_fit$beta, 2, norm_func)
ind <- max(which(norms <= self$delta_epsilon))
if (ind > 1) break

fit_lambda <- submodel_fit$lambda
fit_lambda <- submodel_fit$lambda

if (fit_lambda == 1) {
stop("only one lambda could be fit")
}
if (fit_lambda == 1) {
stop("only one lambda could be fit")
}

# try to estimate what the correct lambda value is and go a bit beyond that
norm_ratio <- self$delta_epsilon / norms[2]
lambda_guess <- fit_lambda[1] - norm_ratio * (fit_lambda[1] - fit_lambda[2])
lambda_min_ratio <- 0.8 * lambda_guess / fit_lambda[1]
# lambda.min.ratio <- sort(submodel_fit$lambda, decreasing = TRUE)[2] / max(submodel_fit$lambda)
# try to estimate what the correct lambda value is and go a bit beyond that
norm_ratio <- self$delta_epsilon / norms[2]
lambda_guess <- fit_lambda[1] - norm_ratio * (fit_lambda[1] - fit_lambda[2])
lambda_min_ratio <- 0.8 * lambda_guess / fit_lambda[1]
# lambda.min.ratio <- sort(submodel_fit$lambda, decreasing = TRUE)[2] / max(submodel_fit$lambda)
}
epsilon_n <- submodel_fit$beta[, ind]
},
error = function(e) {
# TODO: check
print(e)
return(rep(0, ncol(submodel_data$H)))
}
epsilon_n <- submodel_fit$beta[, ind]
}, error = function(e) {
# TODO: check
print(e)
return(rep(0, ncol(submodel_data$H)))
})
)
epsilon <- epsilon_n
# TODO: check if necessary
# NOTE: this protects against collinear covariates
Expand Down
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ remotes::install_github("tlverse/tmle3")

-----

## Issues

If you encounter any bugs or have any specific feature requests, please
[file an issue](https://github.com/tlverse/tmle3/issues).

-----

## Getting Started

The best place to get started is the “Framework Overview” document,
Expand All @@ -65,16 +72,36 @@ may be found at <https://tlverse.org/tmle3/articles/framework.html>.

-----

## Issues
## Contributions

If you encounter any bugs or have any specific feature requests, please
[file an issue](https://github.com/tlverse/tmle3/issues).
Contributions are very welcome. Interested contributors should consult
our [contribution
guidelines](https://github.com/tlverse/tmle3/blob/master/CONTRIBUTING.md)
prior to submitting a pull request.

-----

## Citation

After using the `tmle3` R package, please cite the following:

```
@software{coyle2021tmle3-rpkg,
author = {Coyle, Jeremy R},
title = {{tmle3}: The Extensible {TMLE} Framework},
year = {2021},
howpublished = {\url{https://github.com/tlverse/tmle3}},
note = {{R} package version 0.2.0},
url = {https://doi.org/},
doi = {}
}
```

-----

## License

© 2017-2020 [Jeremy R. Coyle](https://github.com/jeremyrcoyle)
© 2017-2021 [Jeremy R. Coyle](https://github.com/jeremyrcoyle)

The contents of this repository are distributed under the GPL-3 license.
See file `LICENSE` for details.
Expand Down
34 changes: 22 additions & 12 deletions docs/404.html

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

Loading

0 comments on commit 00bbeb4

Please sign in to comment.