mmm_predictions: Predictions from the multivariate mixed model using a...

mmm_predictionsR Documentation

Predictions from the multivariate mixed model using a disciminant analysis framework.

Description

Calculate the posterior predictions from the likelihood profiles and priors. Implements equation 7.1 (p154) from Steffen's thesis.

Usage

mmm_predictions(
  data,
  outcomes,
  fixed_formula_nofail,
  random_formula_nofail,
  random_effects_nofail,
  parameters_nofail,
  fixed_formula_fail,
  random_formula_fail,
  random_effects_fail,
  parameters_fail,
  time,
  failure,
  failure_time,
  prior,
  id,
  landmark = 0,
  horizon,
  interval,
  ...
)

Arguments

data

a data.frame with the data for which to predict in the long format (input should be the same as likelihood_profiles)

outcomes

character vector with the outcomes

fixed_formula_nofail

formula for the fixed effects of the nofail model

random_formula_nofail

formula for the random effects of the nofail model,

random_effects_nofail

random effect estimates for the no fail model (see MASS::mvnorm)

parameters_nofail

parameter estimates from the non-failures model (see mmm_model)

fixed_formula_fail

formula for the fixed effects of the fail model,

random_formula_fail

formula for the random effects of the fail model,

random_effects_fail

random effect estimates for the fail model (see MASS::mvnorm),

parameters_fail

parameter estimates from the non-failures model (see mmm_model)

time

a character string with the time variable name in data

failure

a character string with the failure variable name in data

failure_time

a character string with the failure time variable in data

prior

the priors returned by get_priors().

id

a character string with the subject id

landmark

a numeric value indicating the prediction landmark until which data is available for prediction.

horizon

the prediction horizon (maximum follow-up time)

interval

the intervals relative to the horizon (e.g. 1/12 for monthly intervals and horizon is in years)

Value

a data.frame with the posterior predictions for each subject at every landmark up to the horizon

Examples

## Not run: 
# First retrieve random effects samples from a fitted model
mu <- setNames(rep(0, length(outcomes)), outcomes)
re_samples_nofail <- MASS:mvrnorm(1e3,mu = mu, Sigma = model_nofail$vcov)
re_samples_fail <- MASS:mvrnorm(1e3,mu = mu, Sigma = model_fail$vcov)

# Get the priors
prior <- get_priors(data = df,
time_failure = "time_failure",
failure = "failure",
horizon = 5,
interval = 1/12)

# get the outcomes types
outcome_types <- get_outcome_type(data = df, outcomes)

# Select a single subject
df_pred <- df %>% filter(id == 10)

mmm_predictions(
  data=df,
  outcomes=outcome_types,
  fixed_formula_nofail="~ y1 + y2 + y3 + y4 + time + sex",
  random_formula_nofail="~ 1| id",
  random_effects_nofail=re_samples_nofail,
  parameters_nofail=model_nofail$estimates,
  fixed_formula_fail="~ y1 + y2 + y3 + y4 + time + sex + time_failure",
  random_formula_fail="~ 1 | id",
  random_effects_fail=re_samples_fail,
  parameters_fail=model_fail$estimates,
  time="time",
  failure="failure",
  failure_time="time_failure",
  prior=prior,
  id="id",
  landmark=1,
  horizon=5,
  interval=1/4
)

## End(Not run)

JanvandenBrand/jmmm documentation built on May 30, 2022, 9:37 a.m.