Learn R Programming

mmrm (version 0.3.16)

Mixed Models for Repeated Measures

Description

Mixed models for repeated measures (MMRM) are a popular choice for analyzing longitudinal continuous outcomes in randomized clinical trials and beyond; see Cnaan, Laird and Slasor (1997) for a tutorial and Mallinckrodt, Lane, Schnell, Peng and Mancuso (2008) for a review. This package implements MMRM based on the marginal linear model without random effects using Template Model Builder ('TMB') which enables fast and robust model fitting. Users can specify a variety of covariance matrices, weight observations, fit models with restricted or standard maximum likelihood inference, perform hypothesis testing with Satterthwaite or Kenward-Roger adjustment, and extract least square means estimates by using 'emmeans'.

Copy Link

Version

Install

install.packages('mmrm')

Monthly Downloads

6,214

Version

0.3.16

License

Apache License 2.0

Maintainer

Daniel Sabanes Bove

Last Published

December 9th, 2025

Functions in mmrm (0.3.16)

emit_tidymodels_register_msg

Format a Message to Emit When Tidymodels is Loaded
emp_start

Empirical Starting Value
emmeans_support

Support for emmeans
df_md

Calculation of Degrees of Freedom for Multi-Dimensional Contrast
format_symbols

Format Symbol Objects
h_add_covariance_terms

Add Individual Covariance Variables As Terms to Formula
fit_mmrm

Low-Level Fitting Function for MMRM
covariance_types

Covariance Types
h_dataset_sort_all

Sort a Data Frame by All Its Columns in Ascending Order
h_confirm_large_levels

Ask for Confirmation on Large Visit Levels
h_anova_single_mmrm_model

Calculate the Significance of Each Term in an mmrm Fit.
h_default_value

Default Value on NULL Return default value when first argument is NULL.
h_assert_lrt_suitability

Ensure LRT Is Appropriate for list of mmrm Fits
h_df_bw_calc

Calculation of Between-Within Degrees of Freedom
cov_type_name

Retrieve Associated Full Covariance Structure Type Name
h_construct_model_frame_inputs

Construction of Model Frame Formula and Data Inputs
h_add_terms

Add Formula Terms with Character
h_contr_sum_type3_contrasts

Construct Preliminary Contrast Matrices for Type III Tests Assuming Sum Contrasts
formula_rhs

Extract Right-Hand-Side (rhs) from Formula
h_df_1d_bw

Calculation of Between-Within Degrees of Freedom for One-Dimensional Contrast
h_df_md_sat

Calculation of Satterthwaite Degrees of Freedom for Multi-Dimensional Contrast
h_df_md_res

Calculation of Residual Degrees of Freedom for Multi-Dimensional Contrast
flat_expr

Flatten Expressions for Non-standard Evaluation
h_drop_covariance_terms

Drop Formula Terms used for Covariance Structure Definition
h_drop_levels

Drop Levels from Dataset
h_df_md_bw

Calculation of Between-Within Degrees of Freedom for Multi-Dimensional Contrast
fit_single_optimizer

Fitting an MMRM with Single Optimizer
h_get_na_action

Obtain na.action as Function
h_get_optimizers

Obtain Optimizer according to Optimizer String Value
h_df_1d_sat

Calculation of Satterthwaite Degrees of Freedom for One-Dimensional Contrast
h_gradient

Computation of a Gradient Given Jacobian and Contrast Vector
h_mmrm_tmb_fit

Build TMB Fit Result List
h_jac_list

Obtain List of Jacobian Matrix Entries for Covariance Matrix
h_get_empirical

Obtain Empirical/Jackknife/Bias-Reduced Covariance
h_df_1d_res

Calculation of Residual Degrees of Freedom for One-Dimensional Contrast
h_check_cov_struct_nesting

Ensure Two Models' Covariance Structures Are Nested
h_mmrm_tmb_data

Data for TMB Fit
h_check_columns_nested

Predicate Indicating Whether Two Datasets Contain the Same Observations
h_df_1d_kr

Calculation of Kenward-Roger Degrees of Freedom for One-Dimensional Contrast
h_generate_new_name

Generate a Name Not Already In an Environment nor Its Parents
h_get_cov_default

Obtain Default Covariance Method
h_assert_nested_models

Ensure Two Models Are Nested
h_check_covar_nesting

Ensure Two Models' Covariates Are Nested
h_df_md_kr

Calculation of Kenward-Roger Degrees of Freedom for Multi-Dimensional Contrast
h_first_term_containing_categ

Identify the First Term in a Model to Contain a Categorical Variable
h_df_md_from_1d

Creating F-Statistic Results from One-Dimensional Contrast
h_mmrm_tmb_extract_cov

Extract covariance matrix from TMB report and input data
h_mmrm_tmb_parameters

Start Parameters for TMB Fit
h_newdata_add_pred

Add Prediction Results to New Data
h_df_1d_sat_empirical

Helper for Calculation of Satterthwaite with Empirical Covariance Matrix
h_extra_levels

Check if a Factor Should Drop Levels
h_obtain_lvls

Obtain Levels Prior and Posterior
h_mmrm_tmb_assert_start

Asserting Sane Start Values for TMB Fit
h_mmrm_tmb_check_conv

Checking the TMB Optimization Result
h_get_kr_comp

Obtain Kenward-Roger Adjustment Components
h_get_theta_from_cov

Obtain Theta from Covariance Matrix
h_get_index

Test if the First Vector is Subset of the Second Vector
h_fits_common_data

Combine the Datasets from mmrm Fits
h_optimizer_fun

Obtain Optimizer Function with Character
h_print_aic_list

Printing AIC and other Model Fit Criteria
h_get_minimal_fit_data

Obtain the Minimal Dataset Needed for an mmrm Fit
h_partial_fun_args

Create Partial Functions
h_get_sim_per_subj

Get simulated values by patient.
h_quad_form

Quadratic Form Calculations
h_extract_covariance_terms

Extract Formula Terms used for Covariance Structure Definition
h_var_adj

Obtain the Adjusted Covariance Matrix
h_valid_formula

Validate mmrm Formula
h_register_s3

Register S3 Method Register S3 method to a generic.
h_residuals_pearson

Calculate Pearson Residuals
h_residuals_normalized

Calculate normalized residuals
h_mmrm_tmb_formula_parts

Processing the Formula for TMB Fit
h_warn_na_action

Warn on na.action
position_symbol

Search For the Position of a Symbol
h_within_or_between

Determine Within or Between for each Design Matrix Column
h_residuals_response

Calculate response residuals.
h_tmb_warn_non_deterministic

Warn if TMB is Configured to Use Non-Deterministic Hash for Tape Optimizer
h_test_md

Creating F- or Chi-squared-statistic Test Results For Multi-Dimensional Contrast
h_reconcile_cov_struct

Reconcile Possible Covariance Structure Inputs
h_tr

Trace of a Matrix
mmrm

Fit an MMRM
h_tmb_version_sufficient

Predicate if the TMB Version Used to Compile the Package is Sufficient
h_print_call

Printing MMRM Function Call
h_check_fits_all_data_same

Predicate Indicating Whether mmrm Fits' Datasets Contain the Same Observations
format.cov_struct

Format Covariance Structure Object
print.cov_struct

Print a Covariance Structure Object
h_coef_table

Coefficients Table for MMRM Fit
h_print_cov

Printing MMRM Covariance Type
h_split_control

Split Control List
h_summarize_all_fits

Summarizing List of Fits
h_type2_contrast

Obtain Type 2 Contrast for One Specified Effect
mmrm_control

Control Parameters for Fitting an MMRM
mmrm_tmb_methods

Methods for mmrm_tmb Objects
mmrm-package

mmrm Package
is_infix

Test Whether a Symbol is an Infix Operator
h_type3_contrasts

Obtain Type 3 Contrast for All Effects
parsnip_add_mmrm

Register mmrm For Use With tidymodels
refit_multiple_optimizers

Refitting MMRM with Multiple Optimizers
h_df_min_bw

Assign Minimum Degrees of Freedom Given Involved Coefficients
reexports

Objects exported from other packages
h_md_denom_df

Calculating Denominator Degrees of Freedom for the Multi-Dimensional Case
h_get_prediction_variance

Get Prediction Variance
h_df_to_tibble

Coerce a Data Frame to a tibble
mmrm_methods

Methods for mmrm Objects
mmrm_tidiers

Tidying Methods for mmrm Objects
h_kr_df

Obtain the Adjusted Kenward-Roger degrees of freedom
h_get_prediction

Get Prediction
stats_anova

Analysis of Variance for mmrm Fits
validate_cov_struct

Validate Covariance Structure Data
register_on_load

Helper Function for Registering Functionality With Suggests Packages
h_record_all_output

Capture all Output
h_refit_mmrm

Refit an mmrm Model Using a New Dataset
h_tbl_confint_terms

Extract tibble with Confidence Intervals and Term Names
tmb_cov_type

Produce A Covariance Identifier Passing to TMB
std_start

Standard Starting Value
h_test_1d

Creating T-Statistic Test Results For One-Dimensional Contrast
as.cov_struct

Coerce into a Covariance Structure Definition
cov_type_abbr

Retrieve Associated Abbreviated Covariance Structure Type Name
cov_struct

Define a Covariance Structure
component

Component Access for mmrm_tmb Objects
df_1d

Calculation of Degrees of Freedom for One-Dimensional Contrast
COV_TYPES

Covariance Type Database
drop_elements

Drop Items from an Indexible
fev_data

Example Data on FEV1
cached_mmrm_results

Cache Data for mmrm Model Comparison
fill_names

Complete character Vector Names From Values
bcva_data

Example Data on BCVA
Anova.mmrm

Conduct type II/III hypothesis testing on the MMRM fit results.
check_package_version

Check Suggested Dependency Against Version Requirements
car_add_mmrm

Register mmrm For Use With car::Anova