Skip to content

Commit

Permalink
corrections + precommit edits
Browse files Browse the repository at this point in the history
  • Loading branch information
nhejazi committed Mar 11, 2021
1 parent 80269a4 commit 17835fd
Show file tree
Hide file tree
Showing 27 changed files with 162 additions and 92 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
repos:
- repo: https://github.com/lorenzwalthert/precommit
rev: v0.1.3
hooks:
hooks:
- id: style-files
args: [--style_pkg=styler, --style_fun=tidyverse_style]
args: [--style_pkg=styler, --style_fun=tidyverse_style]
- id: roxygenize
# codemeta must be above use-tidy-description when both are used
# - id: codemeta-description-updated
- id: use-tidy-description
- id: spell-check
exclude: >
(?x)^(
data/.*|
data/.*|
(.*/|)\.Rprofile|
(.*/|)\.Renviron|
(.*/|)\.gitignore|
Expand All @@ -32,14 +32,14 @@ repos:
.*\.sh|
.*\.RData
)$
- id: lintr
#- id: lintr
- id: readme-rmd-rendered
- id: parsable-R
- id: no-browser-statement
- id: deps-in-desc
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
hooks:
- id: check-added-large-files
args: ['--maxkb=200']
- id: end-of-file-fixer
Expand Down
4 changes: 2 additions & 2 deletions 05-origami.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ washb_data <- fread(
washb_data <- washb_data[1:30, ]
head(washb_data) %>%
kable() %>%
kableExtra:::kable_styling(fixed_thead = TRUE) %>%
kableExtra::kable_styling(fixed_thead = TRUE) %>%
scroll_box(width = "100%", height = "300px")
```

Expand Down Expand Up @@ -655,7 +655,7 @@ covars <- colnames(washb_data)[-which(names(washb_data) == outcome)]
head(washb_data) %>%
kable() %>%
kableExtra:::kable_styling(fixed_thead = TRUE) %>%
kableExtra::kable_styling(fixed_thead = TRUE) %>%
scroll_box(width = "100%", height = "300px")
```

Expand Down
8 changes: 4 additions & 4 deletions 06-sl3.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ washb_data <- fread(
)
head(washb_data) %>%
kable() %>%
kableExtra:::kable_styling(fixed_thead = T) %>%
kableExtra::kable_styling(fixed_thead = T) %>%
scroll_box(width = "100%", height = "300px")
```

Expand Down Expand Up @@ -800,7 +800,7 @@ CVsl <- CV_lrnr_sl(
)
CVsl %>%
kable(digits = 4) %>%
kableExtra:::kable_styling(fixed_thead = TRUE) %>%
kableExtra::kable_styling(fixed_thead = TRUE) %>%
scroll_box(width = "100%", height = "300px")
```
<!-- Explain summary!!!! -->
Expand Down Expand Up @@ -838,7 +838,7 @@ Let's explore the `sl3` variable importance measurements for the `washb` data.
washb_varimp <- importance(sl_fit, loss = loss_squared_error, type = "permute")
washb_varimp %>%
kable(digits = 4) %>%
kableExtra:::kable_styling(fixed_thead = TRUE) %>%
kableExtra::kable_styling(fixed_thead = TRUE) %>%
scroll_box(width = "100%", height = "300px")
```

Expand Down Expand Up @@ -872,7 +872,7 @@ chspred <- read_csv(file = db_data, col_names = TRUE)
# take a quick peek
head(chspred) %>%
kable(digits = 4) %>%
kableExtra:::kable_styling(fixed_thead = TRUE) %>%
kableExtra::kable_styling(fixed_thead = TRUE) %>%
scroll_box(width = "100%", height = "300px")
```

Expand Down
41 changes: 26 additions & 15 deletions 11-tmle3survival.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ library(sl3)

```{r}
vet_data <- read.csv(
paste0("https://raw.githubusercontent.com/tlverse/deming2019-workshop/",
"master/data/veteran.csv")
paste0(
"https://raw.githubusercontent.com/tlverse/deming2019-workshop/",
"master/data/veteran.csv"
)
)
vet_data$trt <- vet_data$trt - 1
# make fewer times for illustration
vet_data$time <- ceiling(vet_data$time / 20)
k_grid <- seq_len(:max(vet_data$time))
k_grid <- seq_len(max(vet_data$time))
head(vet_data)
```

Expand Down Expand Up @@ -70,14 +72,20 @@ speficy W (covariates), A (treatment/intervention), T_tilde (time-to-event
vector), Delta (censoring indicator vector), and row ids for the nodelist.

```{r}
var_types <- list(T_tilde = Variable_Type$new("continuous"),
t = Variable_Type$new("continuous"),
Delta = Variable_Type$new("binomial"))
survival_spec <- tmle_survival(treatment_level = 1, control_level = 0,
target_times = intersect(1:10, k_grid),
variable_types = var_types)
node_list <- list(W = c("celltype", "karno", "diagtime", "age", "prior"),
A = "trt", T_tilde = "time", Delta = "status", id ="X")
var_types <- list(
T_tilde = Variable_Type$new("continuous"),
t = Variable_Type$new("continuous"),
Delta = Variable_Type$new("binomial")
)
survival_spec <- tmle_survival(
treatment_level = 1, control_level = 0,
target_times = intersect(1:10, k_grid),
variable_types = var_types
)
node_list <- list(
W = c("celltype", "karno", "diagtime", "age", "prior"),
A = "trt", T_tilde = "time", Delta = "status", id = "X"
)
long_data_tuple <- survival_spec$transform_data(vet_data, node_list)
df_long <- long_data_tuple$long_data
Expand All @@ -98,8 +106,10 @@ learner_list <- list(A = sl_A, N = sl_A, A_c = sl_A)

```{r}
tmle_task <- survival_spec$make_tmle_task(df_long, long_node_list)
initial_likelihood <- survival_spec$make_initial_likelihood(tmle_task,
learner_list)
initial_likelihood <- survival_spec$make_initial_likelihood(
tmle_task,
learner_list
)
```

### Perform TMLE adjustment of the initial conditional survival estimate
Expand All @@ -116,11 +126,12 @@ up <- tmle3_Update_survival$new(
delta_epsilon = 1e-2,
fit_method = "l2",
use_best = TRUE,
verbose=FALSE
verbose = FALSE
)
targeted_likelihood <- Targeted_Likelihood$new(initial_likelihood,
updater = up)
updater = up
)
tmle_params <- survival_spec$make_params(tmle_task, targeted_likelihood)
tmle_fit_manual <- fit_tmle3(
tmle_task, targeted_likelihood, tmle_params,
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ style:
Rscript -e "styler::style_dir(filetype = 'rmd')"

code:
rm R/*.R
rm -f R_code/*.R
R CMD BATCH purl.R
rm purl.Rout .RData
1 change: 0 additions & 1 deletion R/01-preface.R

This file was deleted.

1 change: 0 additions & 1 deletion R/10-tmle3mediate.R

This file was deleted.

1 change: 0 additions & 1 deletion R/99-primer_R6.R

This file was deleted.

File renamed without changes.
Empty file added R_code/01-preface.R
Empty file.
1 change: 0 additions & 1 deletion R/02-roadmap.R → R_code/02-roadmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ tidy_dag <- tidy_dagitty(dag)
# visualize DAG
ggdag(tidy_dag) +
theme_dag()

5 changes: 2 additions & 3 deletions R/03-tlverse.R → R_code/03-tlverse.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
## ----installation, eval=FALSE-------------------------------------------------
## install.packages("usethis")
## usethis::install_github("tlverse/tlverse")

## install.packages("devtools")
## devtools::install_github("tlverse/tlverse")
1 change: 0 additions & 1 deletion R/04-data.R → R_code/04-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@ if (knitr::is_latex_output()) {
} else {
skim(nhefs_data)
}

5 changes: 2 additions & 3 deletions R/05-origami.R → R_code/05-origami.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ washb_data <- fread(
washb_data <- washb_data[1:30, ]
head(washb_data) %>%
kable() %>%
kableExtra:::kable_styling(fixed_thead = TRUE) %>%
kableExtra::kable_styling(fixed_thead = TRUE) %>%
scroll_box(width = "100%", height = "300px")


Expand Down Expand Up @@ -122,7 +122,7 @@ covars <- colnames(washb_data)[-which(names(washb_data) == outcome)]

head(washb_data) %>%
kable() %>%
kableExtra:::kable_styling(fixed_thead = TRUE) %>%
kableExtra::kable_styling(fixed_thead = TRUE) %>%
scroll_box(width = "100%", height = "300px")


Expand Down Expand Up @@ -285,4 +285,3 @@ mses <- cross_validate(
)
mses$mse
colMeans(mses$mse[, c("arima", "arima2")])

Loading

0 comments on commit 17835fd

Please sign in to comment.