Skip to content

Commit

Permalink
correct codes
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleBeannie committed Apr 9, 2024
1 parent a018106 commit 8569ee4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
3 changes: 2 additions & 1 deletion R/maxcombo.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ maxcombo <- function(data = sim_pw_surv(n = 200) |> cut_data_by_event(150),
# Tidy outputs ----
ans <- list()
ans$method <- "Maxcombo"
temp <- data.frame(rho = rho, gamma = gamma) %>% mutate(x= paste0("FH(", rho, ", ", gamma, ")"))
temp <- data.frame(rho = rho, gamma = gamma)
temp$x <- paste0("FH(", temp$rho, ", ", temp$gamma, ")")
ans$parameter <- paste(temp$x, collapse = " + ")
ans$estimation <- NULL
ans$se <- NULL
Expand Down
20 changes: 7 additions & 13 deletions R/wlr.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,25 @@ wlr <- function(data, weight, return_variance = FALSE) {
if (inherits(weight, "fh")) {
x <- x |> fh_weight(rho = weight$rho, gamma = weight$gamma)

x$weighted_o_minus_e <- x$weight * x$o_minus_e
x$weighted_var <- x$weight^2 * x$var_o_minus_e

weighted_var_total <- sum(x$weighted_var)
weighted_o_minus_e_total <- sum(x$weighted_o_minus_e)

ans$parameter <- paste0("FH(rho=", weight$rho, ", gamma =", weight$gamma, ")")
ans$estimation <- weighted_o_minus_e_total
ans$se <- sqrt(weighted_var_total)
ans$estimation <- sum(x$weight * x$o_minus_e)
ans$se <- sqrt(sum(x$weight^2 * x$var_o_minus_e))
ans$z <- ans$estimation / ans$se

} else if (inherits(weight, "mb")) {
x <- x |> mb_weight(delay = weight$delay, w_max = weight$w_max)

ans$parameter <- paste0("MB(delay = ", delay, ", max_weight = ", w_max, ")")
ans$estimate <- sum(res$o_minus_e * res$mb_weight)
ans$se <- sqrt(sum(res$var_o_minus_e * res$mb_weight^2))
ans$estimate <- sum(x$o_minus_e * x$mb_weight)
ans$se <- sqrt(sum(x$var_o_minus_e * x$mb_weight^2))
ans$z <- ans$estimate / ans$se

} else if (inherits(weight, "early_period")) {
x <- x |> early_zero_weight(early_period = weight$early_period)

ans$parameter <- paste0("Xu 2017 with first ", early_period, " months of 0 weights")
ans$estimate <- sum(res$o_minus_e * res$weight)
ans$se <- sqrt(sum(res$var_o_minus_e * res$weight^2))
ans$parameter <- paste0("Xu 2017 with first ", weight$early_period, " months of 0 weights")
ans$estimate <- sum(x$o_minus_e * x$weight)
ans$se <- sqrt(sum(x$var_o_minus_e * x$weight^2))
ans$z <- ans$estimate / ans$se

}
Expand Down
2 changes: 1 addition & 1 deletion R/wlr_weight.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,6 @@ mb <- function(delay = 4, w_max = Inf) {
#' ) |>
#' cut_data_by_event(125) |>
#' wlr(weight = early_zero(early_period = 2, fail_rate = fail_rate))
early_zero <- function(early_period, fail_rate) {
early_zero <- function(early_period, fail_rate = NULL) {
structure(list(early_period = early_period, fail_rate = fail_rate), class = c("list", "early_period", "wlr"))
}
9 changes: 5 additions & 4 deletions tests/testthat/test-unvalidated-early_zero_weight.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
test_that("early_zero_weight() with unstratified data", {
# Example 1: Unstratified
set.seed(123)
input <- sim_pw_surv(n = 200)
input <- cut_data_by_event(input, 125)
input <- counting_process(input, arm = "experimental")
output <- early_zero_weight(input, early_period = 2)

output <- sim_pw_surv(n = 200) |>
cut_data_by_event(125) |>
counting_process(arm = "experimental") |>
early_zero_weight(early_period = 2)

observed <- output$weight
expected <- rep(c(0, 1), c(15L, 110L))
Expand Down
15 changes: 11 additions & 4 deletions vignettes/pvalue-maxcombo.Rmd → vignettes/maxcombo.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ library(dplyr)
library(gt)
```

```{r}
```{r, eval=FALSE}
set.seed(123)
x <- sim_fixed_n(
n_sim = 1,
timing_type = 5,
Expand All @@ -66,6 +68,8 @@ We begin with another simulation generated by `sim_pw_surv()`.
Again, we use defaults for that routine.

```{r, message=FALSE, warning=FALSE, cache=FALSE}
set.seed(123)
s <- sim_pw_surv(n = 100)
s |>
Expand Down Expand Up @@ -133,15 +137,16 @@ x |> head() |> gt()
Now we analyze the data with a MaxCombo with the logrank and FH(0, 1) and compute a $p$-value.

```{r, warning=FALSE, message=FALSE}
x |>
maxcombo(rho = c(0, 0), gamma = c(0, 1))
x |> maxcombo(rho = c(0, 0), gamma = c(0, 1))
```

## Simulation

We now consider the example simulation from the `pvalue_maxcombo()` help file to demonstrate how to simulate power for the MaxCombo test. However, we increase the number of simulations to 100 in this case; a larger number should be used (e.g., 1000) for a better estimate of design properties. Here we will test at the $\alpha=0.001$ level.

```{r, cache=FALSE, warning=FALSE, message=FALSE, eval=FALSE}
set.seed(123)
# Only use cut events + min follow-up
xx <- sim_fixed_n(
n_sim = 100,
Expand All @@ -161,8 +166,10 @@ We note the use of `group_map` in the above produces a list of $p$-values for ea
It would be nice to have something that worked more like `dplyr::summarize()` to avoid `unlist()` and to allow evaluating, say, multiple data cutoff methods.
The latter can be done without having to re-run all simulations as follows, demonstrated with a smaller number of simulations.

```{r, cache=FALSE, warning=FALSE, message=FALSE}
```{r, cache=FALSE, warning=FALSE, message=FALSE, eval=FALSE}
# Only use cuts for events and events + min follow-up
set.seed(123)
xx <- sim_fixed_n(
n_sim = 100,
timing_type = c(2, 5),
Expand Down

0 comments on commit 8569ee4

Please sign in to comment.