mmcif_pd_univariate function

Computes Marginal Measures for One Observation

Computes Marginal Measures for One Observation

Computes the marginal cumulative incidence functions (CIF), marginal survival function or the derivative of the CIF.

mmcif_pd_univariate( par, object, newdata, cause, time, left_trunc = NULL, ghq_data = object$ghq_data, strata = NULL, use_log = FALSE, type = "cumulative" )

Arguments

  • par: numeric vector with the model parameters.

  • object: an object from mmcif_data.

  • newdata: a data.frame with data for the observation. It needs to have one row.

  • cause: an integer vector with the cause of each outcome. If there are n_causes of outcome, then the vector should have values in 1:(n_causes + 1) with n_causes + 1 indicating censoring.

  • time: a numeric vector with the observed times.

  • left_trunc: numeric vector with left-truncation times. NULL

    implies that there are not any individuals with left-truncation.

  • ghq_data: the Gauss-Hermite quadrature nodes and weights to use. It should be a list with two elements called "node"

    and "weight". A default is provided if NULL is passed.

  • strata: an integer vector or a factor vector with the strata of each individual. NULL implies that there are no strata.

  • use_log: a logical for whether the returned output should be on the log scale.

  • type: a character for the type of measures for the observation. It can have value "derivative" for the derivative of a CIF or "cumulative" for a CIF or the survival probability.

Returns

A numeric scalar with the requested quantity.

Examples

if(require(mets)){ data(prt) # truncate the time max_time <- 90 prt <- within(prt, { status[time >= max_time] <- 0 time <- pmin(time, max_time) }) # select the DZ twins and re-code the status prt_use <- subset(prt, zyg == "DZ") |> transform(status = ifelse(status == 0, 3L, status)) # Gauss Hermite quadrature nodes and weights from fastGHQuad::gaussHermiteData ghq_data <- list( node = c(-3.43615911883774, -2.53273167423279, -1.75668364929988, -1.03661082978951, -0.342901327223705, 0.342901327223705, 1.03661082978951, 1.75668364929988, 2.53273167423279, 3.43615911883774), weight = c(7.6404328552326e-06, 0.00134364574678124, 0.0338743944554811, 0.240138611082314, 0.610862633735326,0.610862633735326, 0.240138611082315, 0.033874394455481, 0.00134364574678124, 7.64043285523265e-06)) # setup the object for the computation mmcif_obj <- mmcif_data( ~ country - 1, prt_use, status, time, id, max_time, 2L, strata = country, ghq_data = ghq_data) # previous estimates par <- c(0.727279974859164, 0.640534073288067, 0.429437766165371, 0.434367104339573, -2.4737847536253, -1.49576564624673, -1.89966050143904, -1.58881346649412, -5.5431198001029, -3.5328359024178, -5.82305147022587, -3.4531896212114, -5.29132887832377, -3.36106297109548, -6.03690322125729, -3.49516746825624, 2.55000711185704, 2.71995985605891, 2.61971498736444, 3.05976391058032, -5.97173564860957, -3.37912051983482, -5.14324860374941, -3.36396780694965, -6.02337246348561, -3.03754644968859, -5.51267338700737, -3.01148582224673, 2.69665543753264, 2.59359057553995, 2.7938341786374, 2.70689750644755, -0.362056555418564, 0.24088005091276, 0.124070380635372, -0.246152029808377, -0.0445628476462479, -0.911485513197845, -0.27911988106887, -0.359648419277058, -0.242711959678559, -6.84897302527358) # the test data we will use test_dat <- data.frame(country = factor("Norway", levels(prt_use$country)), status = 2L) # compute the CIF mmcif_pd_univariate( par = par, object = mmcif_obj, newdata = test_dat, cause = status, strata = country, ghq_data = ghq_data, time = 75, type = "cumulative") |> print() # compute the derivative of the CIF mmcif_pd_univariate( par = par, object = mmcif_obj, newdata = test_dat, cause = status, strata = country, ghq_data = ghq_data, time = 75, type = "derivative") |> print() # compute the survival probability mmcif_pd_univariate( par = par, object = mmcif_obj, newdata = test_dat, cause = 3L, strata = country, ghq_data = ghq_data, time = 75, type = "cumulative") |> print() }

See Also

mmcif_pd_bivariate and mmcif_pd_cond.

  • Maintainer: Benjamin Christoffersen
  • License: GPL (>= 3)
  • Last published: 2022-07-17

Downloads (last 30 days):