Skip to contents

Generate a new, resampled dataset of the same shape as data following the given model. The covariates X are kept the same. Survival times Y are drawn according to model$sample_yx() and censoring times C according to the KM estimator.

Usage

resample_param_cens(data, model)

Arguments

data

data.frame() with columns x, z and delta containing the original data

model

ParamRegrModel to use for the resampling

Value

data.frame() with columns x, z and delta containing the resampled data

Examples

# Create an example dataset
n <- 10
x <- cbind(runif(n), rbinom(n, 1, 0.5))
model <- NormalGLM$new()
params <- list(beta = c(2, 3), sd = 1)
y <- model$sample_yx(x, params = params)
c <- rnorm(n, mean(y) * 1.2, sd(y) * 0.5)
z <- pmin(y, c)
delta <- as.numeric(y <= c)
data <- dplyr::tibble(x = x, z = z, delta = delta)

# Fit the model to the data
model$fit(data, params_init = params, inplace = TRUE, loglik = loglik_xzd)

# Resample from the model given data
resample_param_cens(data, model)
#> # A tibble: 10 × 3
#>     x[,1]  [,2]      z delta
#>     <dbl> <dbl>  <dbl> <dbl>
#>  1 0.0979     0 -0.111     1
#>  2 0.700      0  0.642     1
#>  3 0.214      1  1.33      1
#>  4 0.277      1  1.74      0
#>  5 0.747      1  3.46      0
#>  6 0.118      1  2.83      1
#>  7 0.296      0  1.18      1
#>  8 0.885      0  1.31      1
#>  9 0.0982     1  2.85      0
#> 10 0.182      1  1.76      0