Data for TMB Fit
Usage
h_mmrm_tmb_data(
formula_parts,
data,
weights,
reml,
singular = c("drop", "error", "keep"),
drop_visit_levels,
allow_na_response = FALSE,
drop_levels = TRUE,
xlev = NULL,
contrasts = NULL,
emmeans_gcomp_vars = NULL
)Arguments
- formula_parts
(
mmrm_tmb_formula_parts)
list with formula parts fromh_mmrm_tmb_formula_parts().- data
(
data.frame)
which contains variables used informula_parts.- weights
(
vector)
weights to be used in the fitting process.- reml
(
flag)
whether restricted maximum likelihood (REML) estimation is used, otherwise maximum likelihood (ML) is used.- singular
(
string)
choices of method deal with rank-deficient matrices. "error" to stop the function return the error, "drop" to drop these columns, and "keep" to keep all the columns.- drop_visit_levels
(
flag)
whether to drop levels for visit variable, if visit variable is a factor.- allow_na_response
(
flag)
whether NA in response is allowed.- drop_levels
(
flag)
whether drop levels for covariates. If not dropped could lead to singular matrix.- xlev
(
listorNULL)
list of X levels produced by stats::.getXlevels- contrasts
(
listorNULL)
an optional named list of contrast matrices or contrast functions (like stats::contr.sum or stats::contr.poly) for specific factor variables, matching thecontrastsargument instats::lm(). The list names must correspond to factor variable names in the model formula. WhenNULL(the default), the contrasts set on the factor variables indataare used. If a contrast matrix has rownames that include levels not present indata, those levels are preserved and the corresponding model matrix columns are marked as aliased (not estimable), enabling prediction on new data containing those levels.- emmeans_gcomp_vars
(
characterorNULL) treated as fixed for G-computation correction. Stored as a character vector in the returned list for downstream use in the emmeans hook.
Value
List of class mmrm_tmb_data with elements:
full_frame:data.framewithnrows containing all variables needed in the model.data:data.frameof input dataset.x_matrix:matrixwithnrows andpcolumns specifying the overall design matrix.x_cols_aliased:logicalwith potentially more thanpelements indicating which columns in the original design matrix have been left out to obtain a full rankx_matrix.y_vector: lengthnnumericspecifying the overall response vector.weights_vector: lengthnnumericspecifying the weights vector.n_visits:intwith the number of visits, which is the dimension of the covariance matrix.n_subjects:intwith the number of subjects.subject_zero_inds: lengthn_subjectsintegercontaining the zero-based start indices for each subject.subject_n_visits: lengthn_subjectsintegercontaining the number of observed visits for each subjects. So the sum of this vector equalsn.cov_type:stringvalue specifying the covariance type.is_spatial_int:intspecifying whether the covariance structure is spatial(1) or not(0).reml:intspecifying whether REML estimation is used (1), otherwise ML (0).subject_groups:factorspecifying the grouping for each subject.n_groups:intwith the number of total groupsemmeans_gcomp_vars:characterorNULLwith the G-computation variable names.
Details
Note that the subject_var must not be factor but can also be character.
If it is character, then it will be converted to factor internally. Here
the levels will be the unique values, sorted alphabetically and numerically if there
is a common string prefix of numbers in the character elements. For full control
on the order please use a factor.