Skip to contents

A generic method for calculating predictions for a given model. Further parameters must be passed to the S3 methods of each class (calculate_predictions.cox() and calculate_predictions.logreg())

Usage

calculate_predictions(model, data, .progress = TRUE)

Arguments

model

A model generated by the function mv_model_cox() or mv_model_logreg()

data

Data parameter for calculate_predictions.cox() or calculate_predictions.logreg()

.progress

TRUE to render the progress bar FALSE otherwise.

Value

A model with the parameters predictions_imp, predictions_agg.

Examples

set.seed(123)

model <- mv_model_logreg(formula = event ~ 0.5 * (x - 1) + 0.3 * (z - 2))

data <- data.frame(
  .imp = c(1, 1, 1, 2, 2, 2, 3, 3, 3),
  id = c(1, 2, 3, 1, 2, 3, 1, 2, 3),
  event = survival::Surv(rpois(9, 5), rbinom(n = 9, size = 1, prob = 0.2)),
  x = rnorm(9, 1, 0.25),
  z = rnorm(9, 2, 0.75)
)

model |> calculate_predictions(data)
#> 
#> ── <MiceExtVal/logreg> ─────────────────────────────────────────────────────────
#> 
#> ── formula ──
#> 
#> event ~ 0.5 * (x - 1) + 0.3 * (z - 2)
#> 
#> ── predictions_imp ──
#> 
#> # A tibble: 5 × 4
#>    .imp    id    betax prediction
#>   <dbl> <dbl>    <dbl>      <dbl>
#> 1     1     1  0.102        0.526
#> 2     1     2  0.0466       0.512
#> 3     1     3 -0.195        0.451
#> 4     2     1  0.00105      0.500
#> 5     2     2 -0.217        0.446
#> ── predictions_agg ──
#> 
#> # A tibble: 3 × 3
#>      id   betax prediction
#>   <dbl>   <dbl>      <dbl>
#> 1     1  0.0620      0.515
#> 2     2 -0.163       0.460
#> 3     3 -0.162       0.460