├── .Rbuildignore ├── .github ├── CODEOWNERS ├── CONTRIBUTING.Rmd ├── CONTRIBUTING.md ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── add_function.md │ ├── bug_report.md │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── check.yaml │ ├── docs.yaml │ ├── release.yaml │ ├── rhub.yaml │ └── scheduled.yaml ├── .gitignore ├── .lintr ├── .pre-commit-config.yaml ├── DESCRIPTION ├── NAMESPACE ├── NEWS.md ├── R ├── between-within.R ├── catch-routine-registration.R ├── component.R ├── cov_struct.R ├── data.R ├── empirical.R ├── fit.R ├── interop-car.R ├── interop-emmeans.R ├── interop-parsnip.R ├── kenwardroger.R ├── mmrm-methods.R ├── mmrm-package.R ├── residual.R ├── satterthwaite.R ├── skipping.R ├── testing.R ├── tidiers.R ├── tmb-methods.R ├── tmb.R ├── utils-formula.R ├── utils-nse.R ├── utils.R └── zzz.R ├── README.Rmd ├── README.md ├── _pkgdown.yml ├── data-raw ├── bcva-helpers.R ├── bcva_data.R └── mmrm_review.R ├── data ├── bcva_data.rda ├── cached_mmrm_results.rda └── fev_data.rda ├── design ├── R │ ├── R_weighted.R │ ├── R_weighted_mmrm.txt │ ├── R_weighted_nlme.txt │ ├── mmrm_ad.R │ ├── mmrm_ad_ml.txt │ └── mmrm_ad_reml.txt ├── Robust │ ├── empirical.Rmd │ ├── empirical_adh.txt │ ├── empirical_adh_covb.csv │ ├── empirical_adh_lsmean.csv │ ├── empirical_adh_weighted.txt │ ├── empirical_adh_weighted_covb.csv │ ├── empirical_adh_weighted_lsmean.csv │ ├── empirical_ar1.txt │ ├── empirical_ar1_covb.csv │ ├── empirical_ar1_lsmean.csv │ ├── empirical_ar1_weighted.txt │ ├── empirical_ar1_weighted_covb.csv │ ├── empirical_ar1_weighted_lsmean.csv │ ├── empirical_arh1.txt │ ├── empirical_arh1_covb.csv │ ├── empirical_arh1_lsmean.csv │ ├── empirical_arh1_weighted.txt │ ├── empirical_arh1_weighted_covb.csv │ ├── empirical_arh1_weighted_lsmean.csv │ ├── empirical_cs.txt │ ├── empirical_cs_covb.csv │ ├── empirical_cs_lsmean.csv │ ├── empirical_cs_weighted.txt │ ├── empirical_cs_weighted_covb.csv │ ├── empirical_cs_weighted_lsmean.csv │ ├── empirical_csh.txt │ ├── empirical_csh_covb.csv │ ├── empirical_csh_lsmean.csv │ ├── empirical_csh_weighted.txt │ ├── empirical_csh_weighted_covb.csv │ ├── empirical_csh_weighted_lsmean.csv │ ├── empirical_spexp.txt │ ├── empirical_spexp_covb.csv │ ├── empirical_spexp_lsmean.csv │ ├── empirical_spexp_weighted.txt │ ├── empirical_spexp_weighted_covb.csv │ ├── empirical_spexp_weighted_lsmean.csv │ ├── empirical_toep.txt │ ├── empirical_toep_covb.csv │ ├── empirical_toep_lsmean.csv │ ├── empirical_toep_weighted.txt │ ├── empirical_toep_weighted_covb.csv │ ├── empirical_toep_weighted_lsmean.csv │ ├── empirical_toeph.txt │ ├── empirical_toeph_covb.csv │ ├── empirical_toeph_lsmean.csv │ ├── empirical_toeph_weighted.txt │ ├── empirical_toeph_weighted_covb.csv │ ├── empirical_toeph_weighted_lsmean.csv │ ├── empirical_us.txt │ ├── empirical_us_covb.csv │ ├── empirical_us_lsmean.csv │ ├── empirical_us_weighted.txt │ ├── empirical_us_weighted_covb.csv │ ├── empirical_us_weighted_lsmean.csv │ └── robust.R ├── SAS │ ├── estimates.R │ ├── sas.R │ ├── sas_adh.R │ ├── sas_adh_ml.txt │ ├── sas_adh_reml.txt │ ├── sas_ar1.R │ ├── sas_ar1_ml.txt │ ├── sas_ar1_reml.txt │ ├── sas_ar1h.R │ ├── sas_ar1h_ml.txt │ ├── sas_ar1h_reml.txt │ ├── sas_coef_ci_ml_ar1.txt │ ├── sas_coef_ci_ml_un.txt │ ├── sas_coef_ci_reml_ar1.txt │ ├── sas_coef_ci_reml_un.txt │ ├── sas_cs.R │ ├── sas_cs_ml.txt │ ├── sas_cs_reml.txt │ ├── sas_csh.R │ ├── sas_csh_ml.txt │ ├── sas_csh_reml.txt │ ├── sas_group_adh_ml.txt │ ├── sas_group_adh_reml.txt │ ├── sas_group_ar1_ml.txt │ ├── sas_group_ar1_reml.txt │ ├── sas_group_ar1h_ml.txt │ ├── sas_group_ar1h_reml.txt │ ├── sas_group_cs_ml.txt │ ├── sas_group_cs_reml.txt │ ├── sas_group_csh_ml.txt │ ├── sas_group_csh_reml.txt │ ├── sas_group_toeph_ml.txt │ ├── sas_group_toeph_reml.txt │ ├── sas_log.txt │ ├── sas_log_nonconvergence.txt │ ├── sas_log_nonconvergence_reml.txt │ ├── sas_log_reml.txt │ ├── sas_log_simple.txt │ ├── sas_log_simple_reml.txt │ ├── sas_resid_spatial.txt │ ├── sas_resid_un.txt │ ├── sas_resid_un_grp.txt │ ├── sas_resid_un_weighted.txt │ ├── sas_sp_exp.R │ ├── sas_sp_exp2_ml.txt │ ├── sas_sp_exp2_reml.txt │ ├── sas_sp_exp_ml.txt │ ├── sas_sp_exp_reml.txt │ ├── sas_toep.sas │ ├── sas_toep_ml.rtf │ ├── sas_toep_reml.rtf │ ├── sas_toeph.R │ ├── sas_toeph_ml.txt │ ├── sas_toeph_reml.txt │ ├── sas_weighted.R │ ├── sas_weighted.txt │ ├── sas_weighted_mmrm.sas │ ├── sas_weighted_mmrm_ml.rtf │ └── sas_weighted_mmrm_reml.rtf ├── SAT_autodiff │ └── efficiency_compare.Rmd ├── TMB │ ├── TMB_mixed.R │ ├── TMB_mixed.cpp │ ├── TMB_mmrm.Rmd │ ├── TMB_mmrm.cpp │ ├── TMB_mmrm2.cpp │ ├── TMB_mmrm3.cpp │ ├── check_autodiff.R │ ├── check_autodiff.cpp │ └── sas_log.txt ├── anova │ ├── anova.Rmd │ ├── anova.sas │ ├── test2_1.csv │ ├── test2_2.csv │ ├── test3_1.csv │ └── test3_2.csv ├── ddfm_covtype │ ├── ddfm_covtype.R │ ├── kr1_adh.csv │ ├── kr1_adh.txt │ ├── kr1_ar1.csv │ ├── kr1_ar1.txt │ ├── kr1_arh1.csv │ ├── kr1_arh1.txt │ ├── kr1_cs.csv │ ├── kr1_cs.txt │ ├── kr1_csh.csv │ ├── kr1_csh.txt │ ├── kr1_spexp.csv │ ├── kr1_spexp.txt │ ├── kr1_toep.csv │ ├── kr1_toep.txt │ ├── kr1_toeph.csv │ ├── kr1_toeph.txt │ ├── kr1_us.csv │ ├── kr1_us.txt │ ├── kr_adh.csv │ ├── kr_adh.txt │ ├── kr_ar1.csv │ ├── kr_ar1.txt │ ├── kr_arh1.csv │ ├── kr_arh1.txt │ ├── kr_cs.csv │ ├── kr_cs.txt │ ├── kr_csh.csv │ ├── kr_csh.txt │ ├── kr_numderiv.R │ ├── kr_spexp.csv │ ├── kr_spexp.txt │ ├── kr_toep.csv │ ├── kr_toep.txt │ ├── kr_toeph.csv │ ├── kr_toeph.txt │ ├── kr_us.csv │ └── kr_us.txt ├── design_fit.Rmd ├── predict_interval │ ├── ar(1)_kenwardroger.csv │ ├── ar(1)_satterthwaite.csv │ ├── cs_kenwardroger.csv │ ├── cs_satterthwaite.csv │ ├── predict_interval.Rmd │ ├── sp(exp)(VISITN VISITN2)_kenwardroger.csv │ ├── sp(exp)(VISITN VISITN2)_satterthwaite.csv │ ├── toep_kenwardroger.csv │ ├── toep_satterthwaite.csv │ ├── un_kenwardroger_linear.csv │ └── un_satterthwaite.csv └── unstructured_optimization.Rmd ├── inst ├── REFERENCES.bib ├── WORDLIST └── jss.csl ├── man ├── Anova.mmrm.Rd ├── COV_TYPES.Rd ├── as.cov_struct.Rd ├── bcva_data.Rd ├── cached_mmrm_results.Rd ├── car_add_mmrm.Rd ├── check_package_version.Rd ├── component.Rd ├── cov_struct.Rd ├── cov_type_abbr.Rd ├── cov_type_name.Rd ├── covariance_types.Rd ├── df_1d.Rd ├── df_md.Rd ├── drop_elements.Rd ├── emit_tidymodels_register_msg.Rd ├── emmeans_support.Rd ├── emp_start.Rd ├── fev_data.Rd ├── figures │ ├── lifecycle-archived.svg │ ├── lifecycle-defunct.svg │ ├── lifecycle-deprecated.svg │ ├── lifecycle-experimental.svg │ ├── lifecycle-maturing.svg │ ├── lifecycle-questioning.svg │ ├── lifecycle-stable.svg │ ├── lifecycle-superseded.svg │ ├── logo.png │ └── logo.svg ├── fill_names.Rd ├── fit_mmrm.Rd ├── fit_single_optimizer.Rd ├── flat_expr.Rd ├── format.cov_struct.Rd ├── format_symbols.Rd ├── formula_rhs.Rd ├── h_add_covariance_terms.Rd ├── h_add_terms.Rd ├── h_coef_table.Rd ├── h_confirm_large_levels.Rd ├── h_construct_model_frame_inputs.Rd ├── h_default_value.Rd ├── h_df_1d_bw.Rd ├── h_df_1d_kr.Rd ├── h_df_1d_res.Rd ├── h_df_1d_sat.Rd ├── h_df_1d_sat_empirical.Rd ├── h_df_bw_calc.Rd ├── h_df_md_bw.Rd ├── h_df_md_from_1d.Rd ├── h_df_md_kr.Rd ├── h_df_md_res.Rd ├── h_df_md_sat.Rd ├── h_df_min_bw.Rd ├── h_df_to_tibble.Rd ├── h_drop_covariance_terms.Rd ├── h_drop_levels.Rd ├── h_extra_levels.Rd ├── h_extract_covariance_terms.Rd ├── h_first_contain_categorical.Rd ├── h_get_contrast.Rd ├── h_get_cov_default.Rd ├── h_get_empirical.Rd ├── h_get_index.Rd ├── h_get_kr_comp.Rd ├── h_get_na_action.Rd ├── h_get_optimizers.Rd ├── h_get_prediction.Rd ├── h_get_prediction_variance.Rd ├── h_get_sim_per_subj.Rd ├── h_get_theta_from_cov.Rd ├── h_gradient.Rd ├── h_jac_list.Rd ├── h_kr_df.Rd ├── h_md_denom_df.Rd ├── h_mmrm_tmb_assert_start.Rd ├── h_mmrm_tmb_check_conv.Rd ├── h_mmrm_tmb_data.Rd ├── h_mmrm_tmb_extract_cov.Rd ├── h_mmrm_tmb_fit.Rd ├── h_mmrm_tmb_formula_parts.Rd ├── h_mmrm_tmb_parameters.Rd ├── h_newdata_add_pred.Rd ├── h_obtain_lvls.Rd ├── h_optimizer_fun.Rd ├── h_partial_fun_args.Rd ├── h_print_aic_list.Rd ├── h_print_call.Rd ├── h_print_cov.Rd ├── h_quad_form.Rd ├── h_reconcile_cov_struct.Rd ├── h_record_all_output.Rd ├── h_register_s3.Rd ├── h_residuals_normalized.Rd ├── h_residuals_pearson.Rd ├── h_residuals_response.Rd ├── h_split_control.Rd ├── h_summarize_all_fits.Rd ├── h_tbl_confint_terms.Rd ├── h_test_1d.Rd ├── h_test_md.Rd ├── h_tmb_version_sufficient.Rd ├── h_tmb_warn_non_deterministic.Rd ├── h_tr.Rd ├── h_valid_formula.Rd ├── h_var_adj.Rd ├── h_warn_na_action.Rd ├── h_within_or_between.Rd ├── is_infix.Rd ├── mmrm-package.Rd ├── mmrm.Rd ├── mmrm_control.Rd ├── mmrm_methods.Rd ├── mmrm_tidiers.Rd ├── mmrm_tmb_methods.Rd ├── parsnip_add_mmrm.Rd ├── position_symbol.Rd ├── print.cov_struct.Rd ├── reexports.Rd ├── refit_multiple_optimizers.Rd ├── register_on_load.Rd ├── std_start.Rd ├── tmb_cov_type.Rd └── validate_cov_struct.Rd ├── mmrm.Rproj ├── simulations ├── chols │ └── README.Rmd ├── csh-benchmarks │ ├── .gitignore │ ├── R │ │ ├── dgp-functions.R │ │ ├── eval-functions.R │ │ ├── meal.R │ │ ├── method-functions.R │ │ ├── tests │ │ │ ├── evalulator-tests.R │ │ │ └── method-tests.R │ │ └── visualizer-functions.R │ ├── README.Rmd │ ├── results │ │ └── hom_rct-het_rct │ │ │ └── Varying num_part-num_part │ │ │ ├── .gitignore │ │ │ ├── eval_results.rds │ │ │ ├── experiment.rds │ │ │ └── viz_results.rds │ ├── slurm │ │ └── meal.sh │ └── vignette │ │ └── summary.Rmd └── missing-data-benchmarks │ ├── README.md │ ├── Snakefile │ ├── aggregate_all_results.R │ ├── config.yaml │ ├── process_sas.R │ ├── programs │ ├── analyze_data.R │ └── generate_data.R │ ├── run_analysis.R │ ├── run_analysis.sas │ └── simulate_data.R ├── src ├── .gitignore ├── Makevars ├── chol_cache.h ├── covariance.h ├── derivatives.h ├── empirical.cpp ├── exports.cpp ├── jacobian.cpp ├── kr_comp.cpp ├── mmrm.cpp ├── predict.cpp ├── test-chol_cache.cpp ├── test-covariance.cpp ├── test-derivatives.cpp ├── test-runner.cpp ├── test-utils.cpp ├── testthat-helpers.h ├── tmb.cpp ├── tmb_includes.h └── utils.h ├── tests ├── testthat.R └── testthat │ ├── _snaps │ ├── between-within.md │ ├── car.md │ ├── emmeans.md │ ├── empirical.md │ ├── fit.md │ ├── kenwardroger.md │ ├── mmrm-methods.md │ ├── testing.md │ └── tmb-methods.md │ ├── helper-examples.R │ ├── helper-skipping.R │ ├── test-between-within.R │ ├── test-car.R │ ├── test-component.R │ ├── test-cov-struct.R │ ├── test-cpp-covariance.R │ ├── test-cpp-utils.R │ ├── test-cpp.R │ ├── test-emmeans.R │ ├── test-empirical.R │ ├── test-fit.R │ ├── test-interop-parsnip.R │ ├── test-interop.R │ ├── test-kenwardroger.R │ ├── test-mmrm-methods.R │ ├── test-residual.R │ ├── test-satterthwaite.R │ ├── test-skipping.R │ ├── test-testing.R │ ├── test-tidiers.R │ ├── test-tmb-methods.R │ ├── test-tmb.R │ ├── test-utils-formula.R │ ├── test-utils-nse.R │ └── test-utils.R └── vignettes ├── .gitignore ├── algorithm.Rmd ├── between_within.Rmd ├── coef_vcov.Rmd ├── covariance.Rmd ├── empirical_wls.Rmd ├── hypothesis_testing.Rmd ├── introduction.Rmd ├── kenward.Rmd ├── methodological_introduction.Rmd ├── mmrm_review_methods.Rmd ├── mmrm_review_refs.bib ├── package_structure.Rmd ├── predict.Rmd ├── satterthwaite.Rmd └── subsections ├── _intro-acknowledgments.Rmd ├── _intro-customizations.Rmd ├── _intro-getting_started.Rmd ├── _intro-hypothesis_testing.Rmd ├── _intro-lower_level.Rmd ├── _intro-model_features.Rmd └── _intro-tidymodels.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^renv$ 2 | ^renv\.lock$ 3 | ^.*\.Rproj$ 4 | ^\.Rproj\.user$ 5 | ^_pkgdown\.yml$ 6 | ^vignettes/hello\.Rmd$ 7 | ^docs$ 8 | ^\.github$ 9 | README.* 10 | ^\.lintr$ 11 | ^staged_dependencies\.yaml$ 12 | coverage.* 13 | ^\.pre-commit-config\.yaml$ 14 | ^codemeta\.json$ 15 | design 16 | sascfg_personal\.py 17 | ^\.vscode$ 18 | simulations 19 | ^doc$ 20 | ^Meta$ 21 | ^data-raw$ 22 | ^cache$ 23 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @danielinteractive 2 | 3 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: inferential-biostatistics 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/add_function.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Add function 3 | about: Create a function in the package 4 | title: "" 5 | labels: "features" 6 | assignees: "" 7 | --- 8 | 9 | To do: 10 | 11 | - [ ] See design document ... 12 | - [ ] Add function ... in file `R/xyz.R` 13 | - [ ] Add unit tests in file `testthat/test-xyz.R` 14 | - [ ] If needed please improve the function code 15 | - [ ] Add `roxygen2` documentation chunks 16 | - [ ] Run Build > Document, Build > Load All, and check that documentation looks good 17 | - [ ] Add function name to `pkgdown.yaml` 18 | - [ ] Run Build > Check to ensure that checks pass 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "" 5 | labels: "bug" 6 | assignees: "" 7 | --- 8 | 9 | 19 | 20 | **Summary** 21 | 22 | 30 | 31 | Your brief description of the problem 32 | 33 | ```r 34 | 35 | # your reproducible example here 36 | 37 | ``` 38 | 39 | **R session info** 40 | 41 | 44 | 45 | ```sh 46 | 47 | # R -e "utils::sessionInfo()" output goes here 48 | 49 | ``` 50 | 51 | **OS / Environment** 52 | 53 | 56 | 57 | - OS: [e.g. Windows 10, Ubuntu 20.04, Centos 8] 58 | - Docker Image [e.g. rocker/verse:4.1.0] 59 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "" 5 | labels: "enhancement" 6 | assignees: "" 7 | --- 8 | 9 | **Summary** 10 | 11 | 30 | 31 | As a [persona], I [want to], [so that]. 32 | 33 | **Additional Information** 34 | 35 | 40 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Description 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.github/workflows/check.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Check 🛠 3 | 4 | on: 5 | pull_request: 6 | types: 7 | - opened 8 | - synchronize 9 | - ready_for_review 10 | branches: 11 | - main 12 | push: 13 | branches: 14 | - main 15 | workflow_dispatch: 16 | 17 | jobs: 18 | audit: 19 | name: Audit Dependencies 🕵️‍♂️ 20 | uses: insightsengineering/r.pkg.template/.github/workflows/audit.yaml@main 21 | r-cmd: 22 | name: R CMD Check 🧬 23 | uses: insightsengineering/r.pkg.template/.github/workflows/build-check-install.yaml@main 24 | secrets: 25 | REPO_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 26 | with: 27 | additional-r-cmd-check-params: --as-cran 28 | unit-test-report-brand: >- 29 | https://raw.githubusercontent.com/insightsengineering/hex-stickers/main/thumbs/mmrm.png 30 | coverage: 31 | name: Coverage 📔 32 | uses: insightsengineering/r.pkg.template/.github/workflows/test-coverage.yaml@main 33 | secrets: 34 | REPO_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 35 | linter: 36 | if: github.event_name == 'pull_request' 37 | name: SuperLinter 🦸‍♀️ 38 | uses: insightsengineering/r.pkg.template/.github/workflows/linter.yaml@main 39 | roxygen: 40 | name: Roxygen 🅾 41 | uses: insightsengineering/r.pkg.template/.github/workflows/roxygen.yaml@main 42 | secrets: 43 | REPO_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 44 | with: 45 | auto-update: true 46 | gitleaks: 47 | name: gitleaks 💧 48 | uses: insightsengineering/r.pkg.template/.github/workflows/gitleaks.yaml@main 49 | spelling: 50 | if: github.event_name == 'pull_request' 51 | name: Spell Check 🆎 52 | uses: insightsengineering/r.pkg.template/.github/workflows/spelling.yaml@main 53 | vbump: 54 | name: Version Bump 🤜🤛 55 | if: github.event_name == 'push' 56 | uses: insightsengineering/r.pkg.template/.github/workflows/version-bump.yaml@main 57 | secrets: 58 | REPO_GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }} 59 | version: 60 | name: Version Check 🏁 61 | uses: insightsengineering/r.pkg.template/.github/workflows/version.yaml@main 62 | licenses: 63 | name: License Check 🃏 64 | uses: insightsengineering/r.pkg.template/.github/workflows/licenses.yaml@main 65 | -------------------------------------------------------------------------------- /.github/workflows/docs.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Docs 📚 3 | 4 | on: 5 | push: 6 | branches: 7 | - main 8 | pull_request: 9 | branches: 10 | - main 11 | workflow_dispatch: 12 | 13 | jobs: 14 | docs: 15 | name: Pkgdown Docs 📚 16 | uses: insightsengineering/r.pkg.template/.github/workflows/pkgdown.yaml@main 17 | with: 18 | refs-order: c("latest-tag", "main") 19 | default-landing-page: latest-tag 20 | secrets: 21 | REPO_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 22 | -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Release 🎈 3 | 4 | on: 5 | push: 6 | tags: 7 | - "v*" 8 | workflow_dispatch: 9 | 10 | jobs: 11 | release: 12 | name: Create release 🎉 13 | uses: insightsengineering/r.pkg.template/.github/workflows/release.yaml@main 14 | permissions: 15 | contents: write 16 | r-cmd: 17 | name: R CMD Check 🧬 18 | needs: [release, docs] 19 | uses: insightsengineering/r.pkg.template/.github/workflows/build-check-install.yaml@main 20 | secrets: 21 | REPO_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 22 | with: 23 | additional-r-cmd-check-params: --as-cran 24 | unit-test-report-brand: >- 25 | https://raw.githubusercontent.com/insightsengineering/hex-stickers/main/thumbs/mmrm.png 26 | coverage: 27 | name: Coverage 📔 28 | needs: [release, docs] 29 | uses: insightsengineering/r.pkg.template/.github/workflows/test-coverage.yaml@main 30 | secrets: 31 | REPO_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 32 | build: 33 | name: Build package 🎁 34 | needs: release 35 | uses: insightsengineering/r.pkg.template/.github/workflows/build-check-install.yaml@main 36 | secrets: 37 | REPO_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 38 | with: 39 | skip-r-cmd-check: true 40 | skip-r-cmd-install: true 41 | docs: 42 | name: Pkgdown Docs 📚 43 | needs: release 44 | uses: insightsengineering/r.pkg.template/.github/workflows/pkgdown.yaml@main 45 | with: 46 | refs-order: c("latest-tag", "main") 47 | default-landing-page: latest-tag 48 | secrets: 49 | REPO_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 50 | -------------------------------------------------------------------------------- /.github/workflows/scheduled.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Scheduled 🕰️ 3 | 4 | on: 5 | schedule: 6 | - cron: '45 3 * * 0' 7 | workflow_dispatch: 8 | 9 | jobs: 10 | cran-status: 11 | name: CRAN Status Monitor 📺 12 | uses: insightsengineering/r.pkg.template/.github/workflows/cran-status.yaml@main 13 | with: 14 | issue-assignees: "danielinteractive,clarkliming" 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .httr-oauth 3 | .project 4 | .RData 5 | .Rhistory 6 | .Rproj.user 7 | .Ruserdata 8 | *.tar.gz 9 | .settings/** 10 | *.html 11 | *.Rcheck 12 | *.rprof 13 | *.sas.txt 14 | *~ 15 | /.project 16 | devel/* 17 | doc 18 | docs 19 | pkgdown 20 | inst/outputs/* 21 | logs 22 | Meta 23 | packrat/lib*/ 24 | temp 25 | temp_w 26 | templates/ 27 | tmp.* 28 | vignettes/*.html 29 | vignettes/*.md 30 | vignettes/*.R 31 | coverage.* 32 | design/TMB/*.o 33 | design/TMB/*.so 34 | src/*.o 35 | src/*.so 36 | .vscode 37 | src/*.dll 38 | testthat-problems.rds 39 | README.md 40 | .Rprofile 41 | /doc/ 42 | /Meta/ 43 | /vignettes/sascgf_personal.py 44 | simulations/chols/*chols 45 | renv 46 | renv.lock 47 | *.pyc 48 | nohup.out 49 | inst/doc 50 | -------------------------------------------------------------------------------- /.lintr: -------------------------------------------------------------------------------- 1 | linters: 2 | linters_with_defaults( 3 | line_length_linter = line_length_linter(120), 4 | object_usage_linter = NULL 5 | ) 6 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(AIC,mmrm_tmb) 4 | S3method(BIC,mmrm_tmb) 5 | S3method(VarCorr,mmrm_tmb) 6 | S3method(as.cov_struct,cov_struct) 7 | S3method(as.cov_struct,formula) 8 | S3method(augment,mmrm) 9 | S3method(coef,mmrm_tmb) 10 | S3method(confint,mmrm) 11 | S3method(deviance,mmrm_tmb) 12 | S3method(fitted,mmrm_tmb) 13 | S3method(format,cov_struct) 14 | S3method(formula,mmrm_tmb) 15 | S3method(glance,mmrm) 16 | S3method(logLik,mmrm_tmb) 17 | S3method(model.frame,mmrm_tmb) 18 | S3method(model.matrix,mmrm_tmb) 19 | S3method(predict,mmrm_tmb) 20 | S3method(print,cov_struct) 21 | S3method(print,mmrm_tmb) 22 | S3method(print,summary.mmrm) 23 | S3method(residuals,mmrm_tmb) 24 | S3method(simulate,mmrm_tmb) 25 | S3method(summary,mmrm) 26 | S3method(terms,mmrm_tmb) 27 | S3method(tidy,mmrm) 28 | S3method(vcov,mmrm_tmb) 29 | export(VarCorr) 30 | export(as.cov_struct) 31 | export(augment) 32 | export(component) 33 | export(cov_struct) 34 | export(cov_types) 35 | export(df_1d) 36 | export(df_md) 37 | export(emp_start) 38 | export(fit_mmrm) 39 | export(fit_single_optimizer) 40 | export(glance) 41 | export(mmrm) 42 | export(mmrm_control) 43 | export(refit_multiple_optimizers) 44 | export(std_start) 45 | export(tidy) 46 | import(checkmate) 47 | importFrom(Rcpp,evalCpp) 48 | importFrom(Rdpack,reprompt) 49 | importFrom(generics,augment) 50 | importFrom(generics,glance) 51 | importFrom(generics,tidy) 52 | importFrom(methods,is) 53 | importFrom(nlme,VarCorr) 54 | importFrom(stats,AIC) 55 | importFrom(stats,BIC) 56 | importFrom(stats,coef) 57 | importFrom(stats,deviance) 58 | importFrom(stats,drop.terms) 59 | importFrom(stats,fitted) 60 | importFrom(stats,formula) 61 | importFrom(stats,logLik) 62 | importFrom(stats,model.frame) 63 | importFrom(stats,predict) 64 | importFrom(stats,residuals) 65 | importFrom(stats,simulate) 66 | importFrom(stats,terms) 67 | importFrom(stats,vcov) 68 | useDynLib(mmrm, .registration = TRUE) 69 | -------------------------------------------------------------------------------- /R/catch-routine-registration.R: -------------------------------------------------------------------------------- 1 | # This dummy function definition is included with the package to ensure that 2 | # 'tools::package_native_routine_registration_skeleton()' generates the required 3 | # registration info for the 'run_testthat_tests' symbol. 4 | # Important: The function does not take any arguments, please adjust the 5 | # auto-generated content accordingly! 6 | (function() { 7 | .Call("run_testthat_tests", FALSE, PACKAGE = "mmrm") 8 | }) 9 | -------------------------------------------------------------------------------- /R/empirical.R: -------------------------------------------------------------------------------- 1 | #' Obtain Empirical/Jackknife/Bias-Reduced Covariance 2 | #' 3 | #' @description Obtain the empirical or Jackknife covariance for \eqn{\beta}. 4 | #' Used in `mmrm` fitting if method is "Empirical", "Empirical-Jackknife" or 5 | #' "Empirical-Bias-Reduced". 6 | #' 7 | #' @param tmb_data (`mmrm_tmb_data`)\cr produced by [h_mmrm_tmb_data()]. 8 | #' @param theta (`numeric`)\cr theta estimate. 9 | #' @param beta (`numeric`)\cr beta estimate. 10 | #' @param beta_vcov (`matrix`)\cr covariance of beta estimate. 11 | #' @param type (`string`)\cr type of empirical method, including "Empirical", "Empirical-Jackknife" 12 | #' and "Empirical-Bias-Reduced". 13 | #' 14 | #' @return Named list with elements: 15 | #' - `cov`: `matrix` empirical covariance. 16 | #' - `g_mat`: `matrix` to calculate Satterthwaite degrees of freedom. 17 | #' 18 | #' @note 19 | #' This function used to return `df_mat`, which was equivalent to `crossproduct(g_mat)`. However, 20 | #' executing the cross product in C++ was a costly matrix multiplication, in particular when the number of coefficients 21 | #' and/or the number of subjects was large. Therefore this is now avoided and `g_mat` is returned instead. 22 | #' 23 | #' @keywords internal 24 | h_get_empirical <- function(tmb_data, theta, beta, beta_vcov, type) { 25 | assert_class(tmb_data, "mmrm_tmb_data") 26 | assert_numeric(theta) 27 | n_beta <- ncol(tmb_data$x_matrix) 28 | assert_numeric(beta, finite = TRUE, any.missing = FALSE, len = n_beta) 29 | assert_matrix( 30 | beta_vcov, 31 | mode = "numeric", 32 | any.missing = FALSE, 33 | nrows = n_beta, 34 | ncols = n_beta 35 | ) 36 | assert_subset( 37 | type, 38 | c("Empirical", "Empirical-Jackknife", "Empirical-Bias-Reduced") 39 | ) 40 | .Call( 41 | `_mmrm_get_empirical`, 42 | PACKAGE = "mmrm", 43 | tmb_data, 44 | theta, 45 | beta, 46 | beta_vcov, 47 | type 48 | ) 49 | } 50 | -------------------------------------------------------------------------------- /R/interop-parsnip.R: -------------------------------------------------------------------------------- 1 | #' Register `mmrm` For Use With `tidymodels` 2 | #' 3 | #' @inheritParams base::requireNamespace 4 | #' @return A logical value indicating whether registration was successful. 5 | #' 6 | #' @details We can use `parsnip::show_model_info("linear_reg")` to check the 7 | #' registration with `parsnip` and thus the wider `tidymodels` ecosystem. 8 | #' 9 | #' @keywords internal 10 | parsnip_add_mmrm <- function(quietly = FALSE) { 11 | if (!requireNamespace("parsnip", quietly = quietly)) { 12 | return(FALSE) 13 | } 14 | 15 | parsnip::set_model_engine( 16 | model = "linear_reg", 17 | eng = "mmrm", 18 | mode = "regression" 19 | ) 20 | 21 | parsnip::set_dependency( 22 | pkg = "mmrm", 23 | model = "linear_reg", 24 | eng = "mmrm", 25 | mode = "regression" 26 | ) 27 | 28 | parsnip::set_encoding( 29 | model = "linear_reg", 30 | eng = "mmrm", 31 | mode = "regression", 32 | options = list( 33 | predictor_indicators = "none", 34 | compute_intercept = FALSE, 35 | remove_intercept = FALSE, 36 | allow_sparse_x = TRUE 37 | ) 38 | ) 39 | 40 | parsnip::set_fit( 41 | model = "linear_reg", 42 | eng = "mmrm", 43 | mode = "regression", 44 | value = list( 45 | interface = "formula", 46 | protect = c("formula", "data", "weights"), 47 | data = c(formula = "formula", data = "data", weights = "weights"), 48 | func = c(pkg = "mmrm", fun = "mmrm"), 49 | defaults = list() 50 | ) 51 | ) 52 | 53 | parsnip::set_pred( 54 | model = "linear_reg", 55 | eng = "mmrm", 56 | mode = "regression", 57 | type = "numeric", 58 | value = parsnip::pred_value_template( 59 | # This is boilerplate. 60 | func = c(fun = "predict"), 61 | object = quote(object$fit), 62 | newdata = quote(new_data) 63 | ) 64 | ) 65 | 66 | parsnip::set_pred( 67 | model = "linear_reg", 68 | eng = "mmrm", 69 | mode = "regression", 70 | # This type allows to pass arguments via `opts` to `parsnip::predict.model_fit`. 71 | type = "raw", 72 | value = parsnip::pred_value_template( 73 | # This is boilerplate. 74 | func = c(fun = "predict"), 75 | object = quote(object$fit), 76 | newdata = quote(new_data) 77 | # We don't specify additional argument defaults here since otherwise 78 | # the user is not able to change them (they will be fixed). 79 | ) 80 | ) 81 | 82 | TRUE 83 | } 84 | -------------------------------------------------------------------------------- /R/mmrm-package.R: -------------------------------------------------------------------------------- 1 | #' `mmrm` Package 2 | #' 3 | #' `mmrm` implements mixed models with repeated measures (MMRM) in R. 4 | #' 5 | #' @aliases mmrm-package 6 | "_PACKAGE" 7 | 8 | #' @useDynLib mmrm, .registration = TRUE 9 | #' @importFrom Rcpp evalCpp 10 | #' @import checkmate 11 | #' @importFrom methods is 12 | #' @importFrom Rdpack reprompt 13 | NULL 14 | 15 | #' @importFrom generics tidy 16 | #' @export 17 | generics::tidy 18 | #' @importFrom generics glance 19 | #' @export 20 | generics::glance 21 | #' @importFrom generics augment 22 | #' @export 23 | generics::augment 24 | -------------------------------------------------------------------------------- /R/residual.R: -------------------------------------------------------------------------------- 1 | #' Calculation of Residual Degrees of Freedom for One-Dimensional Contrast 2 | #' 3 | #' @description Used in [df_1d()] if method is 4 | #' "Residual". 5 | #' 6 | #' @inheritParams h_df_1d_sat 7 | #' @inherit h_df_1d_sat return 8 | #' @keywords internal 9 | h_df_1d_res <- function(object, contrast) { 10 | assert_class(object, "mmrm") 11 | assert_numeric(contrast, len = length(component(object, "beta_est"))) 12 | 13 | df <- component(object, "n_obs") - length(component(object, "beta_est")) 14 | 15 | h_test_1d(object, contrast, df) 16 | } 17 | 18 | #' Calculation of Residual Degrees of Freedom for Multi-Dimensional Contrast 19 | #' 20 | #' @description Used in [df_md()] if method is "Residual". 21 | #' 22 | #' @inheritParams h_df_md_sat 23 | #' @inherit h_df_md_sat return 24 | #' @keywords internal 25 | h_df_md_res <- function(object, contrast) { 26 | assert_class(object, "mmrm") 27 | assert_matrix(contrast, mode = "numeric", any.missing = FALSE, ncols = length(component(object, "beta_est"))) 28 | 29 | df <- component(object, "n_obs") - length(component(object, "beta_est")) 30 | 31 | h_test_md(object, contrast, df) 32 | } 33 | -------------------------------------------------------------------------------- /R/skipping.R: -------------------------------------------------------------------------------- 1 | # Internal functions used for skipping tests or examples. 2 | 3 | # Predicate whether currently running R version is under development. 4 | is_r_devel <- function() { 5 | grepl("devel", R.version$status) 6 | } 7 | 8 | # Predicate whether currently running on a Linux operating system. 9 | is_linux <- function() { 10 | tolower(Sys.info()[["sysname"]]) == "linux" 11 | } 12 | 13 | # Get the compiler information. Workaround for older R versions 14 | # where R_compiled_by() is not available. 15 | get_compiler <- function() { 16 | r_cmd <- file.path(R.home("bin"), "R") 17 | system2(r_cmd, args = "CMD config CC", stdout = TRUE) 18 | } 19 | 20 | # Predicate whether currently using a clang compiler. 21 | is_using_clang <- function() { 22 | grepl("clang", get_compiler()) 23 | } 24 | 25 | # Predicate whether an R-devel version is running on Linux Fedora or 26 | # Debian with a clang compiler. 27 | is_r_devel_linux_clang <- function() { 28 | is_r_devel() && 29 | is_linux() && 30 | is_using_clang() 31 | } 32 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | --- 2 | url: https://openpharma.github.io/mmrm 3 | 4 | template: 5 | bootstrap: 5 6 | params: 7 | ganalytics: UA-125641273-1 8 | 9 | navbar: 10 | structure: 11 | left: [intro, reference, articles, tutorials, news, reports] 12 | right: [search, github] 13 | components: 14 | reports: 15 | text: Reports 16 | menu: 17 | - text: Coverage report 18 | href: coverage-report/ 19 | - text: Unit test report 20 | href: unit-test-report/ 21 | github: 22 | icon: fa-github 23 | href: https://github.com/openpharma/mmrm 24 | 25 | articles: 26 | - title: Introduction 27 | navbar: Introduction 28 | contents: 29 | - introduction 30 | - methodological_introduction 31 | - mmrm_review_methods 32 | - title: Covariance Structures 33 | navbar: Covariance Structures 34 | contents: 35 | - covariance 36 | - title: Degrees of Freedom and Testing 37 | navbar: Degrees of Freedom and Testing 38 | contents: 39 | - hypothesis_testing 40 | - between_within 41 | - kenward 42 | - satterthwaite 43 | - title: Coefficient Covariance 44 | navbar: Coefficient Covariance 45 | contents: 46 | - coef_vcov 47 | - empirical_wls 48 | - title: Algorithm Details 49 | navbar: Algorithm Details 50 | contents: 51 | - algorithm 52 | - predict 53 | - title: Developers 54 | navbar: Developers 55 | contents: 56 | - package_structure 57 | reference: 58 | - title: Package 59 | contents: 60 | - mmrm-package 61 | - title: Functions 62 | contents: 63 | - mmrm 64 | - fit_mmrm 65 | - mmrm_control 66 | - fit_single_optimizer 67 | - refit_multiple_optimizers 68 | - df_1d 69 | - df_md 70 | - component 71 | - title: Start Values 72 | contents: 73 | - std_start 74 | - emp_start 75 | - title: Methods 76 | contents: 77 | - mmrm_methods 78 | - mmrm_tidiers 79 | - mmrm_tmb_methods 80 | - title: Covariance Structures 81 | contents: 82 | - cov_struct 83 | - as.cov_struct 84 | - format.cov_struct 85 | - print.cov_struct 86 | - covariance_types 87 | - title: Estimate Marginal Means 88 | contents: 89 | - emmeans_support 90 | - title: Datasets 91 | contents: 92 | - fev_data 93 | - bcva_data 94 | -------------------------------------------------------------------------------- /data-raw/bcva_data.R: -------------------------------------------------------------------------------- 1 | library(dplyr) 2 | library(usethis) 3 | 4 | # generate the BCVA dataset 5 | set.seed(510) 6 | bcva_data <- rct_dgp_fun() 7 | use_data(bcva_data, overwrite = TRUE) 8 | -------------------------------------------------------------------------------- /data/bcva_data.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openpharma/mmrm/ca604819431a6b43a3a227a122173a1e9b1a8fda/data/bcva_data.rda -------------------------------------------------------------------------------- /data/cached_mmrm_results.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openpharma/mmrm/ca604819431a6b43a3a227a122173a1e9b1a8fda/data/cached_mmrm_results.rda -------------------------------------------------------------------------------- /data/fev_data.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openpharma/mmrm/ca604819431a6b43a3a227a122173a1e9b1a8fda/data/fev_data.rda -------------------------------------------------------------------------------- /design/R/R_weighted.R: -------------------------------------------------------------------------------- 1 | # Weighted MMRM and LS means- 2 | library(mmrm) 3 | library(nlme) 4 | library(emmeans) 5 | 6 | # Note: set VIS4 as reference level to match with SAS 7 | fev_data <- within(fev_data, AVISIT <- relevel(AVISIT, ref = "VIS4")) 8 | 9 | ## mmrm package ---- 10 | formula <- FEV1 ~ RACE + SEX + ARMCD * AVISIT + us(AVISIT | USUBJID) 11 | fit <- mmrm(formula, fev_data, weights = fev_data$WEIGHT) 12 | 13 | sink(file = "R_weighted_mmrm.txt") 14 | summary(fit) 15 | cat("\n \n") 16 | emmeans(fit, pairwise ~ ARMCD*AVISIT) 17 | sink(file = NULL) 18 | 19 | ## nlme package ---- 20 | fev_data$INVW <- 1 / fev_data$WEIGHT 21 | fit <- gls(model = FEV1 ~ RACE + SEX + ARMCD * AVISIT, 22 | data = fev_data, 23 | correlation = corSymm(form = ~as.numeric(AVISIT)|USUBJID), 24 | weights = varComb(varIdent(form = ~1|AVISIT), varFixed(~ INVW)), 25 | control = glsControl(opt = "optim"), 26 | method = "REML", 27 | na.action = "na.omit") 28 | 29 | sink(file = "R_weighted_nlme.txt") 30 | summary(fit) 31 | cat("\n \n") 32 | emmeans(fit, pairwise ~ ARMCD*AVISIT) 33 | sink(file = NULL) 34 | -------------------------------------------------------------------------------- /design/R/mmrm_ad.R: -------------------------------------------------------------------------------- 1 | # Homogeneous Ante-dependence covariance structure ---- 2 | # Note: this covariance structure is not available in SAS, so use mmrm to produce test results 3 | formula <- FEV1 ~ ad(AVISIT | USUBJID) 4 | 5 | ## ML ---- 6 | result <- mmrm(formula, fev_data, reml = FALSE) 7 | 8 | sink(file = "mmrm_ad_ml.txt") 9 | result 10 | summary(result) 11 | cat("result$theta_est \n") 12 | result$theta_est 13 | cat("\n deviance(result) \n") 14 | print(deviance(result), 8) 15 | sink(file = NULL) 16 | 17 | ## REML ---- 18 | result <- mmrm(formula, fev_data, reml = TRUE) 19 | 20 | sink(file = "mmrm_ad_reml.txt") 21 | result 22 | summary(result) 23 | cat("result$theta_est \n") 24 | result$theta_est 25 | cat("\n deviance(result) \n") 26 | print(deviance(result), 8) 27 | sink(file = NULL) 28 | -------------------------------------------------------------------------------- /design/R/mmrm_ad_ml.txt: -------------------------------------------------------------------------------- 1 | mmrm fit 2 | 3 | Formula: FEV1 ~ ad(AVISIT | USUBJID) 4 | Data: fev_data (used 537 observations from 197 subjects with maximum 4 5 | timepoints) 6 | Covariance: ante-dependence (4 variance parameters) 7 | Method: ML 8 | Deviance: 3855.879 9 | 10 | Coefficients: 11 | (Intercept) 12 | 43.0574 13 | 14 | Model Inference Optimization: 15 | Converged with code 0 and message: convergence: rel_reduction_of_f <= factr*epsmchmmrm fit 16 | 17 | Formula: FEV1 ~ ad(AVISIT | USUBJID) 18 | Data: fev_data (used 537 observations from 197 subjects with maximum 4 19 | timepoints) 20 | Covariance: ante-dependence (4 variance parameters) 21 | 22 | Model selection criteria: 23 | AIC BIC logLik deviance 24 | 3863.9 3877.0 -1927.9 3855.9 25 | 26 | Coefficients: 27 | Estimate Std. Error df t value Pr(>|t|) 28 | (Intercept) 43.0574 0.5222 179.6600 82.46 <2e-16 *** 29 | --- 30 | Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 31 | 32 | Covariance estimate: 33 | VIS1 VIS2 VIS3 VIS4 34 | VIS1 93.6091 63.1818 37.0842 6.9117 35 | VIS2 63.1818 93.6091 54.9434 10.2402 36 | VIS3 37.0842 54.9434 93.6091 17.4467 37 | VIS4 6.9117 10.2402 17.4467 93.6091 38 | 39 | result$theta_est 40 | [1] 2.2695640 0.9147445 0.7249571 0.1897019 41 | 42 | deviance(result) 43 | [1] 3855.8794 44 | -------------------------------------------------------------------------------- /design/R/mmrm_ad_reml.txt: -------------------------------------------------------------------------------- 1 | mmrm fit 2 | 3 | Formula: FEV1 ~ ad(AVISIT | USUBJID) 4 | Data: fev_data (used 537 observations from 197 subjects with maximum 4 5 | timepoints) 6 | Covariance: ante-dependence (4 variance parameters) 7 | Method: REML 8 | Deviance: 3855.338 9 | 10 | Coefficients: 11 | (Intercept) 12 | 43.05599 13 | 14 | Model Inference Optimization: 15 | Converged with code 0 and message: convergence: rel_reduction_of_f <= factr*epsmchmmrm fit 16 | 17 | Formula: FEV1 ~ ad(AVISIT | USUBJID) 18 | Data: fev_data (used 537 observations from 197 subjects with maximum 4 19 | timepoints) 20 | Covariance: ante-dependence (4 variance parameters) 21 | 22 | Model selection criteria: 23 | AIC BIC logLik deviance 24 | 3863.3 3876.5 -1927.7 3855.3 25 | 26 | Coefficients: 27 | Estimate Std. Error df t value Pr(>|t|) 28 | (Intercept) 43.0560 0.5236 179.1800 82.23 <2e-16 *** 29 | --- 30 | Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 31 | 32 | Covariance estimate: 33 | VIS1 VIS2 VIS3 VIS4 34 | VIS1 93.9422 63.5120 37.4606 7.0603 35 | VIS2 63.5120 93.9422 55.4088 10.4430 36 | VIS3 37.4606 55.4088 93.9422 17.7055 37 | VIS4 7.0603 10.4430 17.7055 93.9422 38 | 39 | result$theta_est 40 | [1] 2.2713398 0.9175433 0.7303929 0.1919114 41 | 42 | deviance(result) 43 | [1] 3855.3383 44 | -------------------------------------------------------------------------------- /design/Robust/empirical_adh_covb.csv: -------------------------------------------------------------------------------- 1 | "","Row","Effect","ARMCD","Col1","Col2","Col3" 2 | "1",1,"Intercept","NaN",0.17350223093416,-0.17350223093416,0 3 | "2",2,"ARMCD","TRT",-0.17350223093416,0.41552647969341,0 4 | "3",3,"ARMCD","PBO",0,0,0 5 | -------------------------------------------------------------------------------- /design/Robust/empirical_adh_lsmean.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.72344028834729,0.64461343431037,195,5.7762374939187,2.9784578495727e-08,0.05,2.4521310616983,4.99474951499627 3 | -------------------------------------------------------------------------------- /design/Robust/empirical_adh_weighted_covb.csv: -------------------------------------------------------------------------------- 1 | "","Row","Effect","ARMCD","Col1","Col2","Col3" 2 | "1",1,"Intercept","NaN",0.19660064483548,-0.19660064483548,0 3 | "2",2,"ARMCD","TRT",-0.19660064483548,0.53908302126134,0 4 | "3",3,"ARMCD","PBO",0,0,0 5 | -------------------------------------------------------------------------------- /design/Robust/empirical_adh_weighted_lsmean.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.45014003160112,0.73422273273261,195,4.69903733266398,4.9289124613136e-06,0.05,2.00210298357247,4.89817707962976 3 | -------------------------------------------------------------------------------- /design/Robust/empirical_ar1_covb.csv: -------------------------------------------------------------------------------- 1 | "","Row","Effect","ARMCD","Col1","Col2","Col3" 2 | "1",1,"Intercept","NaN",0.27666930670945,-0.27666930670945,0 3 | "2",2,"ARMCD","TRT",-0.27666930670945,0.68196697308307,0 4 | "3",3,"ARMCD","PBO",0,0,0 5 | -------------------------------------------------------------------------------- /design/Robust/empirical_ar1_lsmean.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",4.22574315817874,0.82581291651503,195,5.11707079614537,7.4032420379073e-07,0.05,2.59707157863797,5.8544147377195 3 | -------------------------------------------------------------------------------- /design/Robust/empirical_ar1_weighted_covb.csv: -------------------------------------------------------------------------------- 1 | "","Row","Effect","ARMCD","Col1","Col2","Col3" 2 | "1",1,"Intercept","NaN",0.3741856039623,-0.3741856039623,0 3 | "2",2,"ARMCD","TRT",-0.3741856039623,0.95376377451164,0 4 | "3",3,"ARMCD","PBO",0,0,0 5 | -------------------------------------------------------------------------------- /design/Robust/empirical_ar1_weighted_lsmean.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.62838307125478,0.9766083014759,195,3.7152900152204,0.00026501407627,0.05,1.70231222258161,5.55445391992794 3 | -------------------------------------------------------------------------------- /design/Robust/empirical_arh1_covb.csv: -------------------------------------------------------------------------------- 1 | "","Row","Effect","ARMCD","Col1","Col2","Col3" 2 | "1",1,"Intercept","NaN",0.19106397930347,-0.19106397930347,0 3 | "2",2,"ARMCD","TRT",-0.19106397930347,0.46203608554929,0 4 | "3",3,"ARMCD","PBO",0,0,0 5 | -------------------------------------------------------------------------------- /design/Robust/empirical_arh1_lsmean.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.72674356244499,0.67973236317634,195,5.48266312498375,1.287059168672e-07,0.05,2.38617264201034,5.06731448287964 3 | -------------------------------------------------------------------------------- /design/Robust/empirical_arh1_weighted_covb.csv: -------------------------------------------------------------------------------- 1 | "","Row","Effect","ARMCD","Col1","Col2","Col3" 2 | "1",1,"Intercept","NaN",0.22611242154248,-0.22611242154248,0 3 | "2",2,"ARMCD","TRT",-0.22611242154248,0.60705140369159,0 4 | "3",3,"ARMCD","PBO",0,0,0 5 | -------------------------------------------------------------------------------- /design/Robust/empirical_arh1_weighted_lsmean.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.24391633584203,0.77913503559498,195,4.16348410435018,4.701782834e-05,0.05,1.70730306215642,4.78052960952764 3 | -------------------------------------------------------------------------------- /design/Robust/empirical_cs_covb.csv: -------------------------------------------------------------------------------- 1 | "","Row","Effect","ARMCD","Col1","Col2","Col3" 2 | "1",1,"Intercept","NaN",0.26910953746582,-0.26910953746582,0 3 | "2",2,"ARMCD","TRT",-0.26910953746582,0.6297163326325,0 4 | "3",3,"ARMCD","PBO",0,0,0 5 | -------------------------------------------------------------------------------- /design/Robust/empirical_cs_lsmean.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",4.19663617897035,0.79354667955483,195,5.28845534496419,3.2939546845416e-07,0.05,2.63160020268168,5.76167215525901 3 | -------------------------------------------------------------------------------- /design/Robust/empirical_cs_weighted_covb.csv: -------------------------------------------------------------------------------- 1 | "","Row","Effect","ARMCD","Col1","Col2","Col3" 2 | "1",1,"Intercept","NaN",0.32402882795093,-0.32402882795093,0 3 | "2",2,"ARMCD","TRT",-0.32402882795093,0.81526337857816,0 4 | "3",3,"ARMCD","PBO",0,0,0 5 | -------------------------------------------------------------------------------- /design/Robust/empirical_cs_weighted_lsmean.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.55589587492425,0.90291936438319,195,3.93822085912771,0.00011422599419,0.05,1.77515464651898,5.33663710332953 3 | -------------------------------------------------------------------------------- /design/Robust/empirical_csh_covb.csv: -------------------------------------------------------------------------------- 1 | "","Row","Effect","ARMCD","Col1","Col2","Col3" 2 | "1",1,"Intercept","NaN",0.19635239056617,-0.19635239056617,0 3 | "2",2,"ARMCD","TRT",-0.19635239056617,0.46038132267959,0 4 | "3",3,"ARMCD","PBO",0,0,0 5 | -------------------------------------------------------------------------------- /design/Robust/empirical_csh_lsmean.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.77090812499029,0.67851405488729,195,5.55759766187403,8.9015699248867e-08,0.05,2.43273995709899,5.10907629288159 3 | -------------------------------------------------------------------------------- /design/Robust/empirical_csh_weighted_covb.csv: -------------------------------------------------------------------------------- 1 | "","Row","Effect","ARMCD","Col1","Col2","Col3" 2 | "1",1,"Intercept","NaN",0.21754684649458,-0.21754684649458,0 3 | "2",2,"ARMCD","TRT",-0.21754684649458,0.5806529085649,0 4 | "3",3,"ARMCD","PBO",0,0,0 5 | -------------------------------------------------------------------------------- /design/Robust/empirical_csh_weighted_lsmean.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.22555420139968,0.76200584549261,195,4.23297829075638,3.549043071e-05,0.05,1.72272318582892,4.72838521697044 3 | -------------------------------------------------------------------------------- /design/Robust/empirical_spexp_covb.csv: -------------------------------------------------------------------------------- 1 | "","Row","Effect","ARMCD","Col1","Col2","Col3" 2 | "1",1,"Intercept","NaN",0.26947559034166,-0.26947559034166,0 3 | "2",2,"ARMCD","TRT",-0.26947559034166,0.65569217854087,0 4 | "3",3,"ARMCD","PBO",0,0,0 5 | -------------------------------------------------------------------------------- /design/Robust/empirical_spexp_lsmean.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",4.21488979997259,0.80974821922674,195,5.20518563658905,4.8933014434658e-07,0.05,2.61790108150621,5.81187851843897 3 | -------------------------------------------------------------------------------- /design/Robust/empirical_spexp_weighted_covb.csv: -------------------------------------------------------------------------------- 1 | "","Row","Effect","ARMCD","Col1","Col2","Col3" 2 | "1",1,"Intercept","NaN",0.34876862866685,-0.34876862866685,0 3 | "2",2,"ARMCD","TRT",-0.34876862866685,0.88037866993301,0 4 | "3",3,"ARMCD","PBO",0,0,0 5 | -------------------------------------------------------------------------------- /design/Robust/empirical_spexp_weighted_lsmean.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.55339913699551,0.93828496200941,195,3.78712148320656,0.00020288925063,0.05,1.70290973367629,5.40388854031474 3 | -------------------------------------------------------------------------------- /design/Robust/empirical_toep_covb.csv: -------------------------------------------------------------------------------- 1 | "","Row","Effect","ARMCD","Col1","Col2","Col3" 2 | "1",1,"Intercept","NaN",0.30022945455349,-0.30022945455349,0 3 | "2",2,"ARMCD","TRT",-0.30022945455349,0.76371849328831,0 4 | "3",3,"ARMCD","PBO",0,0,0 5 | -------------------------------------------------------------------------------- /design/Robust/empirical_toep_lsmean.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",4.47051860580552,0.87390988854018,195,5.11553727040814,7.4564570361374e-07,0.05,2.74698998318302,6.19404722842802 3 | -------------------------------------------------------------------------------- /design/Robust/empirical_toep_weighted_covb.csv: -------------------------------------------------------------------------------- 1 | "","Row","Effect","ARMCD","Col1","Col2","Col3" 2 | "1",1,"Intercept","NaN",0.39272956491025,-0.39272956491025,0 3 | "2",2,"ARMCD","TRT",-0.39272956491025,1.00563551122259,0 4 | "3",3,"ARMCD","PBO",0,0,0 5 | -------------------------------------------------------------------------------- /design/Robust/empirical_toep_weighted_lsmean.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.89892091409498,1.00281379688484,195,3.88798092547854,0.00013852817765,0.05,1.9211674812108,5.87667434697915 3 | -------------------------------------------------------------------------------- /design/Robust/empirical_toeph_covb.csv: -------------------------------------------------------------------------------- 1 | "","Row","Effect","ARMCD","Col1","Col2","Col3" 2 | "1",1,"Intercept","NaN",0.18350201218893,-0.18350201218893,0 3 | "2",2,"ARMCD","TRT",-0.18350201218893,0.46360435395588,0 4 | "3",3,"ARMCD","PBO",0,0,0 5 | -------------------------------------------------------------------------------- /design/Robust/empirical_toeph_lsmean.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.92287746213894,0.68088497850656,195,5.7614392826572,3.2103694414398e-08,0.05,2.58003334908046,5.26572157519741 3 | -------------------------------------------------------------------------------- /design/Robust/empirical_toeph_weighted_covb.csv: -------------------------------------------------------------------------------- 1 | "","Row","Effect","ARMCD","Col1","Col2","Col3" 2 | "1",1,"Intercept","NaN",0.22472893956932,-0.22472893956932,0 3 | "2",2,"ARMCD","TRT",-0.22472893956932,0.60262173501823,0 4 | "3",3,"ARMCD","PBO",0,0,0 5 | -------------------------------------------------------------------------------- /design/Robust/empirical_toeph_weighted_lsmean.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.41120066426548,0.77628714727105,195,4.39425111733094,1.823396069e-05,0.05,1.88020400746989,4.94219732106108 3 | -------------------------------------------------------------------------------- /design/Robust/empirical_us_covb.csv: -------------------------------------------------------------------------------- 1 | "","Row","Effect","ARMCD","Col1","Col2","Col3" 2 | "1",1,"Intercept","NaN",0.16725909903518,-0.16725909903518,0 3 | "2",2,"ARMCD","TRT",-0.16725909903518,0.40908637028234,0 4 | "3",3,"ARMCD","PBO",0,0,0 5 | -------------------------------------------------------------------------------- /design/Robust/empirical_us_lsmean.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.81972492174648,0.63959860090712,195,5.97206578677483,1.091355954343e-08,0.05,2.55830596985182,5.08114387364113 3 | -------------------------------------------------------------------------------- /design/Robust/empirical_us_weighted_covb.csv: -------------------------------------------------------------------------------- 1 | "","Row","Effect","ARMCD","Col1","Col2","Col3" 2 | "1",1,"Intercept","NaN",0.198001710472,-0.198001710472,0 3 | "2",2,"ARMCD","TRT",-0.198001710472,0.53420413502786,0 4 | "3",3,"ARMCD","PBO",0,0,0 5 | -------------------------------------------------------------------------------- /design/Robust/empirical_us_weighted_lsmean.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.49283663375976,0.73089269734199,195,4.77886377365925,3.4626194794307e-06,0.05,2.05136709501936,4.93430617250017 3 | -------------------------------------------------------------------------------- /design/Robust/robust.R: -------------------------------------------------------------------------------- 1 | library(sasr) 2 | library(mmrm) 3 | df2sd(fev_data, "fev") 4 | 5 | sas_code <- function(covtype, weight) { 6 | sprintf("ods output diffs = diff covb = vcov; 7 | PROC MIXED DATA = fev empirical cl method=reml; 8 | CLASS RACE(ref = 'Asian') AVISIT(ref = 'VIS4') SEX(ref = 'Male') ARMCD(ref = 'PBO') USUBJID; 9 | MODEL FEV1 = ARMCD /solution chisq covb; 10 | REPEATED AVISIT / subject=USUBJID type=%s r rcorr; 11 | LSMEANS ARMCD / pdiff=all cl alpha=0.05 slice=AVISIT; 12 | %s 13 | RUN;", covtype, if (weight) "WEIGHT WEIGHT;" else "") 14 | } 15 | 16 | 17 | sas_wrapper <- function(ddfm, result_name, weight = FALSE) { 18 | sas_result <- run_sas(sas_code(ddfm, weight)) 19 | result_lsmean <- sd2df("diff") 20 | result_vcov <- sd2df("vcov") 21 | cat(sas_result$LST, file = sprintf("design/Robust/%s.txt", result_name)) 22 | write.csv(result_lsmean, file = sprintf("design/Robust/%s_lsmean.csv", result_name)) 23 | result_vcov$ARMCD <- as.character(result_vcov$ARMCD) 24 | write.csv(result_vcov, file = sprintf("design/Robust/%s_covb.csv", result_name)) 25 | } 26 | 27 | sas_wrapper("ar(1)", "empirical_ar1") 28 | sas_wrapper("arh(1)", "empirical_arh1") 29 | sas_wrapper("cs", "empirical_cs") 30 | sas_wrapper("csh", "empirical_csh") 31 | sas_wrapper("ante(1)", "empirical_adh") 32 | sas_wrapper("toep", "empirical_toep") 33 | sas_wrapper("toeph", "empirical_toeph") 34 | sas_wrapper("un", "empirical_us") 35 | sas_wrapper("sp(exp)(VISITN VISITN2)", "empirical_spexp") 36 | 37 | sas_wrapper("ar(1)", "empirical_ar1_weighted", TRUE) 38 | sas_wrapper("arh(1)", "empirical_arh1_weighted", TRUE) 39 | sas_wrapper("cs", "empirical_cs_weighted", TRUE) 40 | sas_wrapper("csh", "empirical_csh_weighted", TRUE) 41 | sas_wrapper("ante(1)", "empirical_adh_weighted", TRUE) 42 | sas_wrapper("toep", "empirical_toep_weighted", TRUE) 43 | sas_wrapper("toeph", "empirical_toeph_weighted", TRUE) 44 | sas_wrapper("un", "empirical_us_weighted", TRUE) 45 | sas_wrapper("sp(exp)(VISITN VISITN2)", "empirical_spexp_weighted", TRUE) 46 | -------------------------------------------------------------------------------- /design/SAS/estimates.R: -------------------------------------------------------------------------------- 1 | library(sasr) 2 | df2sd(fev_data, "data") 3 | 4 | run_sas_mmrm <- function(method = c("ml", "reml"), cov = "UN") { 5 | sascode <- sprintf(" 6 | PROC MIXED DATA = data cl method=%s; 7 | CLASS ARMCD(ref = 'PBO') AVISIT(ref = 'VIS4') SEX(ref='Male') USUBJID; 8 | MODEL FEV1 = ARMCD SEX/ ddfm=satterthwaite chisq solution cl ; 9 | REPEATED AVISIT / subject=USUBJID type=%s r rcorr; 10 | RUN;", method, cov) 11 | run_sas(sascode) 12 | } 13 | 14 | result <- run_sas_mmrm("ml", "un") 15 | cat(result$LST, file = "design/SAS/sas_coef_ci_ml_un.txt") 16 | 17 | result <- run_sas_mmrm("reml", "un") 18 | cat(result$LST, file = "design/SAS/sas_coef_ci_reml_un.txt") 19 | 20 | result <- run_sas_mmrm("ml", "ar(1)") 21 | cat(result$LST, file = "design/SAS/sas_coef_ci_ml_ar1.txt") 22 | 23 | result <- run_sas_mmrm("reml", "ar(1)") 24 | cat(result$LST, file = "design/SAS/sas_coef_ci_reml_ar1.txt") 25 | -------------------------------------------------------------------------------- /design/SAS/sas_adh.R: -------------------------------------------------------------------------------- 1 | # Heterogeneous Ante-dependence covariance structure ---- 2 | formula <- FEV1 ~ adh(AVISIT | USUBJID) 3 | data <- fev_data 4 | 5 | ## ML ---- 6 | sascode <- list( 7 | # "show" = " 8 | # PROC CONTENTS DATA = ana.dat; 9 | # RUN; 10 | # " 11 | "test" = " 12 | PROC MIXED DATA = ana.dat cl method=ml; 13 | CLASS AVISIT(ref = 'VIS4') USUBJID; 14 | MODEL FEV1 = / ddfm=satterthwaite solution chisq; 15 | REPEATED AVISIT / subject=USUBJID type=ANTE(1) r rcorr; 16 | RUN; 17 | " 18 | ) 19 | result <- r2stream::bee_sas(data = list("dat" = data), sascode = sascode) 20 | result$test$sas_log 21 | writeLines(result$test$sas_out, con = "sas_adh_ml.txt") 22 | 23 | ## REML ---- 24 | sascode <- list( 25 | # "show" = " 26 | # PROC CONTENTS DATA = ana.dat; 27 | # RUN; 28 | # " 29 | "test" = " 30 | PROC MIXED DATA = ana.dat cl method=reml; 31 | CLASS AVISIT(ref = 'VIS4') USUBJID; 32 | MODEL FEV1 = / ddfm=satterthwaite solution chisq; 33 | REPEATED AVISIT / subject=USUBJID type=ANTE(1) r rcorr; 34 | RUN; 35 | " 36 | ) 37 | result <- r2stream::bee_sas(data = list("dat" = data), sascode = sascode) 38 | result$test$sas_log 39 | writeLines(result$test$sas_out, con = "sas_adh_reml.txt") 40 | 41 | 42 | # Heterogeneous Ante-dependence covariance structure ---- 43 | formula <- FEV1 ~ adh(AVISIT | ARMCD / USUBJID) 44 | data <- fev_data 45 | 46 | ## ML ---- 47 | sascode <- list( 48 | # "show" = " 49 | # PROC CONTENTS DATA = ana.dat; 50 | # RUN; 51 | # " 52 | "test" = " 53 | PROC MIXED DATA = ana.dat cl method=ml; 54 | CLASS AVISIT(ref = 'VIS4') USUBJID ARMCD; 55 | MODEL FEV1 = / ddfm=satterthwaite solution chisq; 56 | REPEATED AVISIT / subject=USUBJID type=ANTE(1) r rcorr group = ARMCD; 57 | RUN; 58 | " 59 | ) 60 | result <- r2stream::bee_sas(data = list("dat" = data), sascode = sascode) 61 | result$test$sas_log 62 | writeLines(result$test$sas_out, con = "sas_group_adh_ml.txt") 63 | 64 | ## REML ---- 65 | sascode <- list( 66 | # "show" = " 67 | # PROC CONTENTS DATA = ana.dat; 68 | # RUN; 69 | # " 70 | "test" = " 71 | PROC MIXED DATA = ana.dat cl method=reml; 72 | CLASS AVISIT(ref = 'VIS4') USUBJID ARMCD; 73 | MODEL FEV1 = / ddfm=satterthwaite solution chisq; 74 | REPEATED AVISIT / subject=USUBJID type=ANTE(1) r rcorr group = ARMCD; 75 | RUN; 76 | " 77 | ) 78 | result <- r2stream::bee_sas(data = list("dat" = data), sascode = sascode) 79 | result$test$sas_log 80 | writeLines(result$test$sas_out, con = "sas_group_adh_reml.txt") 81 | -------------------------------------------------------------------------------- /design/SAS/sas_cs.R: -------------------------------------------------------------------------------- 1 | # Homogeneous compound symmetry covariance structure ---- 2 | formula <- FEV1 ~ cs(AVISIT | USUBJID) 3 | data <- fev_data 4 | 5 | ## ML ---- 6 | sascode <- list( 7 | # "show" = " 8 | # PROC CONTENTS DATA = ana.dat; 9 | # RUN; 10 | # " 11 | "test" = " 12 | PROC MIXED DATA = ana.dat cl method=ml; 13 | CLASS AVISIT(ref = 'VIS4') USUBJID; 14 | MODEL FEV1 = / ddfm=satterthwaite solution chisq; 15 | REPEATED AVISIT / subject=USUBJID type=CS r=1, 2, 3, 4, 5, 6, 7, 8, 9, 10 rcorr; 16 | RUN; 17 | " 18 | ) 19 | result <- r2stream::bee_sas(data = list("dat" = data), sascode = sascode) 20 | result$test$sas_log 21 | writeLines(result$test$sas_out, con = "sas_cs_ml.txt") 22 | 23 | ## REML ---- 24 | sascode <- list( 25 | # "show" = " 26 | # PROC CONTENTS DATA = ana.dat; 27 | # RUN; 28 | # " 29 | "test" = " 30 | PROC MIXED DATA = ana.dat cl method=reml; 31 | CLASS AVISIT(ref = 'VIS4') USUBJID; 32 | MODEL FEV1 = / ddfm=satterthwaite solution chisq; 33 | REPEATED AVISIT / subject=USUBJID type=CS r=1, 2, 3, 4, 5, 6, 7, 8, 9, 10 rcorr; 34 | RUN; 35 | " 36 | ) 37 | result <- r2stream::bee_sas(data = list("dat" = data), sascode = sascode) 38 | result$test$sas_log 39 | writeLines(result$test$sas_out, con = "sas_cs_reml.txt") 40 | 41 | # Homogeneous compound symmetry covariance structure ---- 42 | formula <- FEV1 ~ cs(AVISIT | ARMCD / USUBJID) 43 | data <- fev_data 44 | 45 | ## ML ---- 46 | sascode <- list( 47 | # "show" = " 48 | # PROC CONTENTS DATA = ana.dat; 49 | # RUN; 50 | # " 51 | "test" = " 52 | PROC MIXED DATA = ana.dat cl method=ml; 53 | CLASS AVISIT(ref = 'VIS4') USUBJID ARMCD; 54 | MODEL FEV1 = / ddfm=satterthwaite solution chisq; 55 | REPEATED AVISIT / subject=USUBJID type=CS r=1, 2, 3, 4, 5, 6, 7, 8, 9, 10 rcorr group=ARMCD; 56 | RUN; 57 | " 58 | ) 59 | result <- r2stream::bee_sas(data = list("dat" = data), sascode = sascode) 60 | result$test$sas_log 61 | writeLines(result$test$sas_out, con = "sas_group_cs_ml.txt") 62 | 63 | ## REML ---- 64 | sascode <- list( 65 | # "show" = " 66 | # PROC CONTENTS DATA = ana.dat; 67 | # RUN; 68 | # " 69 | "test" = " 70 | PROC MIXED DATA = ana.dat cl method=reml; 71 | CLASS AVISIT(ref = 'VIS4') USUBJID ARMCD; 72 | MODEL FEV1 = / ddfm=satterthwaite solution chisq; 73 | REPEATED AVISIT / subject=USUBJID type=CS r=1, 2, 3, 4, 5, 6, 7, 8, 9, 10 rcorr group=ARMCD; 74 | RUN; 75 | " 76 | ) 77 | result <- r2stream::bee_sas(data = list("dat" = data), sascode = sascode) 78 | result$test$sas_log 79 | writeLines(result$test$sas_out, con = "sas_group_cs_reml.txt") 80 | -------------------------------------------------------------------------------- /design/SAS/sas_sp_exp.R: -------------------------------------------------------------------------------- 1 | # Spatial exponential covariance structure ---- 2 | formula <- FEV1 ~ sp_exp(VISITN | USUBJID) 3 | formula2 <- FEV1 ~ sp_exp(VISITN, VISITN2 | USUBJID) 4 | data <- fev_data 5 | 6 | ## ML ---- 7 | sascode <- list( 8 | # "show" = " 9 | # PROC CONTENTS DATA = ana.dat; 10 | # RUN; 11 | # " 12 | "test" = " 13 | PROC MIXED DATA = ana.dat cl method=ml; 14 | CLASS USUBJID; 15 | MODEL FEV1 = / ddfm=satterthwaite solution chisq; 16 | REPEATED / subject=USUBJID type=sp(exp)(visitn) rcorr; 17 | RUN; 18 | " 19 | ) 20 | result <- r2stream::bee_sas(data = list("dat" = data), sascode = sascode) 21 | result$test$sas_log 22 | writeLines(result$test$sas_out, con = "sas_sp_exp_ml.txt") 23 | 24 | 25 | sascode <- list( 26 | # "show" = " 27 | # PROC CONTENTS DATA = ana.dat; 28 | # RUN; 29 | # " 30 | "test" = " 31 | PROC MIXED DATA = ana.dat cl method=ml; 32 | CLASS USUBJID; 33 | MODEL FEV1 = / ddfm=satterthwaite solution chisq; 34 | REPEATED / subject=USUBJID type=sp(exp)(visitn visitn2) rcorr; 35 | RUN; 36 | " 37 | ) 38 | result <- r2stream::bee_sas(data = list("dat" = data), sascode = sascode) 39 | result$test$sas_log 40 | writeLines(result$test$sas_out, con = "sas_sp_exp2_ml.txt") 41 | 42 | ## REML ---- 43 | sascode <- list( 44 | # "show" = " 45 | # PROC CONTENTS DATA = ana.dat; 46 | # RUN; 47 | # " 48 | "test" = " 49 | PROC MIXED DATA = ana.dat cl method=reml; 50 | CLASS USUBJID; 51 | MODEL FEV1 = / ddfm=satterthwaite solution chisq; 52 | REPEATED / subject=USUBJID type=sp(exp)(visitn) rcorr; 53 | RUN; 54 | " 55 | ) 56 | result <- r2stream::bee_sas(data = list("dat" = data), sascode = sascode) 57 | result$test$sas_log 58 | writeLines(result$test$sas_out, con = "sas_sp_exp_reml.txt") 59 | 60 | sascode <- list( 61 | # "show" = " 62 | # PROC CONTENTS DATA = ana.dat; 63 | # RUN; 64 | # " 65 | "test" = " 66 | PROC MIXED DATA = ana.dat cl method=reml; 67 | CLASS USUBJID; 68 | MODEL FEV1 = / ddfm=satterthwaite solution chisq; 69 | REPEATED / subject=USUBJID type=sp(exp)(visitn visitn2) rcorr; 70 | RUN; 71 | " 72 | ) 73 | result <- r2stream::bee_sas(data = list("dat" = data), sascode = sascode) 74 | result$test$sas_log 75 | writeLines(result$test$sas_out, con = "sas_sp_exp2_reml.txt") 76 | -------------------------------------------------------------------------------- /design/SAS/sas_toep.sas: -------------------------------------------------------------------------------- 1 | * Homogeneous Toeplitz covariance structure ----; 2 | 3 | ** ML ----; 4 | ODS RTF FILE="sas_toep_ml.rtf"; 5 | PROC MIXED DATA = fev_data cl method=ml; 6 | CLASS AVISIT(ref = 'VIS4') USUBJID; 7 | MODEL FEV1 = / ddfm=satterthwaite solution chisq; 8 | REPEATED AVISIT / subject=USUBJID type=TOEP r=1, 2, 3, 4, 5, 6, 7, 8, 9, 10 rcorr; 9 | RUN; 10 | ODS RTF CLOSE; 11 | 12 | *** REML ----; 13 | ODS RTF FILE="sas_toep_reml.rtf"; 14 | PROC MIXED DATA = fev_data cl method=reml; 15 | CLASS AVISIT(ref = 'VIS4') USUBJID; 16 | MODEL FEV1 = / ddfm=satterthwaite solution chisq; 17 | REPEATED AVISIT / subject=USUBJID type=TOEP r=1, 2, 3, 4, 5, 6, 7, 8, 9, 10 rcorr; 18 | RUN; 19 | ODS RTF CLOSE; 20 | -------------------------------------------------------------------------------- /design/SAS/sas_weighted.R: -------------------------------------------------------------------------------- 1 | # Weighted MMRM - 2 | formula <- FEV1 ~ RACE + SEX + ARMCD * AVISIT + us(AVISIT | USUBJID) 3 | fit <- mmrm(formula, fev_data, weights = fev_data$WEIGHT) 4 | 5 | ## REML ---- 6 | sascode <- list( 7 | # "show" = " 8 | # PROC CONTENTS DATA = ana.dat; 9 | # RUN; 10 | # " 11 | "test" = " 12 | PROC MIXED DATA = ana.dat cl method=reml; 13 | CLASS RACE(ref = 'Asian') AVISIT(ref = 'VIS4') SEX(ref = 'Male') ARMCD(ref = 'PBO') USUBJID; 14 | MODEL FEV1 = RACE SEX ARMCD AVISIT ARMCD*AVISIT / ddfm=satterthwaite solution chisq; 15 | REPEATED AVISIT / subject=USUBJID type=un r rcorr; 16 | WEIGHT WEIGHT; 17 | LSMEANS AVISIT*ARMCD / pdiff=all cl alpha=0.05 slice=AVISIT; 18 | RUN; 19 | " 20 | ) 21 | result <- r2stream::bee_sas(data = list("dat" = fev_data), sascode = sascode) 22 | result$test$sas_log 23 | writeLines(result$test$sas_out, con = "sas_weighted.txt") 24 | -------------------------------------------------------------------------------- /design/SAS/sas_weighted_mmrm.sas: -------------------------------------------------------------------------------- 1 | * Weighted MMRM ----; 2 | 3 | ** ML ----; 4 | 5 | ODS RTF FILE="&datpath\sas_weighted_mmrm_ml.rtf"; 6 | 7 | proc mixed data = fev_data cl method = ml; 8 | class AVISIT(ref = 'VIS4') USUBJID; 9 | model FEV1 = / ddfm=satterthwaite solution chisq; 10 | repeated AVISIT / subject=USUBJID type=ante(1) r=1,2,3,4,5, 6, 7, 8, 9, 10 rcorr; 11 | weight WEIGHT; 12 | run; 13 | 14 | ODS RTF CLOSE; 15 | 16 | 17 | *** REML ----; 18 | 19 | ODS RTF FILE="&datpath\sas_weighted_mmrm_reml.rtf"; 20 | 21 | proc mixed data = fev_data cl method = reml; 22 | class AVISIT(ref = 'VIS4') USUBJID; 23 | model FEV1 = / ddfm=satterthwaite solution chisq; 24 | repeated AVISIT / subject=USUBJID type=ante(1) r=1,2,3,4,5, 6, 7, 8, 9, 10 rcorr; 25 | weight WEIGHT; 26 | run; 27 | 28 | ODS RTF CLOSE; 29 | -------------------------------------------------------------------------------- /design/TMB/check_autodiff.R: -------------------------------------------------------------------------------- 1 | ## Check correctness of 'autdiff' namespace 2 | library(TMB) 3 | 4 | ## Compile and load the model 5 | compile("check_autodiff.cpp") 6 | dyn.load(dynlib("check_autodiff")) 7 | 8 | ## Data and parameters 9 | data <- list() 10 | parameters <- list(theta = 1:2) 11 | 12 | ## Make a function object 13 | data$select <- 1 14 | obj <- MakeADFun(data, parameters, DLL = "check_autodiff", ADreport = TRUE, silent = TRUE) 15 | 16 | obj$report(obj$par) # gives g and h 17 | obj$gr(obj$par) 18 | obj$he(obj$par) 19 | test <- sdreport(obj) 20 | str(test) # gives f 21 | 22 | ## Check autodiff::gradient and autodiff::hessian 23 | stopifnot(all(obj$report(obj$par)$g == obj$gr(obj$par))) 24 | stopifnot(identical(obj$report(obj$par)$h, obj$he(obj$par))) 25 | 26 | ## Make a function object 27 | data$select <- 2 28 | obj <- MakeADFun(data, parameters, DLL = "check_autodiff", ADreport = TRUE, silent = TRUE) 29 | stopifnot(all(obj$gr(obj$par) == diag(exp(obj$par)))) 30 | 31 | ## Make new function object 32 | data$select <- 3 33 | obj <- MakeADFun(data, parameters, DLL = "check_autodiff", ADreport = TRUE, silent = TRUE) 34 | stopifnot(all(obj$report(obj$par)$j == obj$gr(obj$par))) 35 | -------------------------------------------------------------------------------- /design/TMB/check_autodiff.cpp: -------------------------------------------------------------------------------- 1 | // Check correctness of 'autdiff' namespace 2 | #include 3 | 4 | // Function with one output 5 | struct func1 { 6 | template 7 | T operator() (vector x) { // Evaluate function 8 | return x.prod(); 9 | } 10 | }; 11 | 12 | // Function with three output 13 | struct func3 { 14 | template 15 | vector operator()(vector x) { // Evaluate function 16 | vector y(3); 17 | y(0) = x(0); 18 | y(1) = x.sum(); 19 | y(2) = x.prod(); 20 | return y; 21 | } 22 | }; 23 | 24 | // Function with local variables 25 | // grad_x(func2) = [ exp(a), exp(b) ] 26 | // jac_ab = diag( [ exp(a), exp(b) ] ) 27 | template 28 | struct func2 { 29 | Type a; 30 | Type b; 31 | template 32 | T operator()(vector x) { // Evaluate function 33 | T c = exp(a) * x[0] + exp(b) * x[1]; 34 | return c; 35 | } 36 | }; 37 | 38 | template 39 | Type objective_function::operator() () { 40 | PARAMETER_VECTOR(theta); 41 | DATA_INTEGER(select); 42 | 43 | if (select == 1) { 44 | func1 f; 45 | // Calculate gradient and hessian 46 | vector g = autodiff::gradient(f, theta); 47 | matrix h = autodiff::hessian (f, theta); 48 | REPORT(g); 49 | REPORT(h); 50 | ADREPORT(f(theta)); 51 | } 52 | 53 | if (select == 2) { 54 | func2 f = { theta[0], theta[1] }; 55 | // Calculate gradient and hessian 56 | vector g = autodiff::gradient(f, theta); 57 | ADREPORT(g); 58 | } 59 | 60 | if (select == 3) { 61 | func3 f; 62 | // Calculate jacobian 63 | matrix j = autodiff::jacobian(f, theta); 64 | REPORT(j); 65 | ADREPORT(f(theta)); 66 | } 67 | 68 | // Exit 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /design/anova/anova.sas: -------------------------------------------------------------------------------- 1 | %xpt2loc(libref = work, filespec = '/home/lil128/Project/mmrm/data-raw/fev.xpt'); 2 | ods output Tests1 = Tests1 Tests2 = Tests2 Tests3 = Tests3; 3 | 4 | PROC MIXED DATA = fev cl method=reml; 5 | CLASS RACE(ref = '3') AVISIT(ref = '4') SEX(ref = '2') ARMCD(ref = '2') USUBJID; 6 | MODEL FEV1 = ARMCD AVISIT ARMCD*AVISIT / ddfm=satterthwaite htype=1,2,3; 7 | REPEATED AVISIT / subject=USUBJID type=ar(1); 8 | RUN; 9 | 10 | libname mm '/home/lil128/Project/mmrm/data-raw'; 11 | data mm.test1; 12 | set tests1; 13 | data mm.test2; 14 | set tests2; 15 | data mm.test3; 16 | set tests3; 17 | run; 18 | -------------------------------------------------------------------------------- /design/anova/test2_1.csv: -------------------------------------------------------------------------------- 1 | "","Effect","NumDF","DenDF","ChiSq","FValue","ProbChiSq","ProbF" 2 | "1","ARMCD",1,199.582314485653,0.03099660681111,0.03099660681111,0.86024795837881,0.86042646803505 3 | "2","FEV1_BL",1,196.41571750149,11.5301174147263,11.5301174147263,0.00068477688975,0.00082860861048 4 | "3","FEV1_BL*ARMCD",1,198.163532037944,0.7644368094469,0.7644368094469,0.38194359117097,0.38300197080559 5 | -------------------------------------------------------------------------------- /design/anova/test2_2.csv: -------------------------------------------------------------------------------- 1 | "","Effect","NumDF","DenDF","ChiSq","FValue","ProbChiSq","ProbF" 2 | "1","ARMCD",1,196.700026021882,0.03093826913613,0.03093826913613,0.86037817970071,0.86055912789767 3 | "2","SEX",1,186.404412481085,0.10489707559679,0.10489707559679,0.74603026404544,0.74639336822641 4 | "3","SEX*ARMCD",1,186.11901853766,0.46643535342468,0.46643535342468,0.49463165974308,0.49548089306181 5 | "4","FEV1_BL*ARMCD",2,194.942672335072,12.2296433517045,6.11482167585228,0.00220986980743,0.0026566780461 6 | -------------------------------------------------------------------------------- /design/anova/test3_1.csv: -------------------------------------------------------------------------------- 1 | "","Effect","NumDF","DenDF","ChiSq","FValue","ProbChiSq","ProbF" 2 | "1","ARMCD",1,199.582314485653,0.03099660681111,0.03099660681111,0.86024795837881,0.86042646803505 3 | "2","FEV1_BL",1,198.163532037936,11.0435094615508,11.0435094615508,0.00088998227841,0.00105994994938 4 | "3","FEV1_BL*ARMCD",1,198.163532037944,0.7644368094469,0.7644368094469,0.38194359117097,0.38300197080559 5 | -------------------------------------------------------------------------------- /design/anova/test3_2.csv: -------------------------------------------------------------------------------- 1 | "","Effect","NumDF","DenDF","ChiSq","FValue","ProbChiSq","ProbF" 2 | "1","ARMCD",1,197.423866403271,0.04875135180324,0.04875135180324,0.82525043506483,0.82547861285648 3 | "2","SEX",1,186.119018537661,0.09277653315012,0.09277653315012,0.76067660529697,0.76101691812013 4 | "3","SEX*ARMCD",1,186.11901853766,0.46643535342468,0.46643535342468,0.49463165974308,0.49548089306181 5 | "4","FEV1_BL*ARMCD",2,194.942672335072,12.2296433517045,6.11482167585228,0.00220986980743,0.0026566780461 6 | -------------------------------------------------------------------------------- /design/ddfm_covtype/ddfm_covtype.R: -------------------------------------------------------------------------------- 1 | library(sasr) 2 | library(mmrm) 3 | df2sd(fev_data, "fev") 4 | 5 | sas_code <- function(ddfm, covtype) { 6 | sprintf("ods output diffs = diff; 7 | PROC MIXED DATA = fev cl method=reml; 8 | CLASS RACE(ref = 'Asian') AVISIT(ref = 'VIS4') SEX(ref = 'Male') ARMCD(ref = 'PBO') USUBJID; 9 | MODEL FEV1 = ARMCD / ddfm=%s solution chisq; 10 | REPEATED AVISIT / subject=USUBJID type=%s r rcorr; 11 | LSMEANS ARMCD / pdiff=all cl alpha=0.05 slice=AVISIT; 12 | RUN;", ddfm, covtype) 13 | } 14 | 15 | 16 | sas_wrapper <- function(ddfm, covtype, result_name) { 17 | sas_result <- run_sas(sas_code(ddfm, covtype)) 18 | result <- sd2df("diff") 19 | cat(sas_result$LST, file = sprintf("design/ddfm_covtype/%s.txt", result_name)) 20 | write.csv(result, file = sprintf("design/ddfm_covtype/%s.csv", result_name)) 21 | } 22 | 23 | sas_wrapper("kr", "ar(1)", "kr_ar1") 24 | sas_wrapper("kr(linear)", "ar(1)", "kr1_ar1") 25 | sas_wrapper("kr", "arh(1)", "kr_arh1") 26 | sas_wrapper("kr(linear)", "arh(1)", "kr1_arh1") 27 | sas_wrapper("kr", "cs", "kr_cs") 28 | sas_wrapper("kr(linear)", "cs", "kr1_cs") 29 | sas_wrapper("kr", "csh", "kr_csh") 30 | sas_wrapper("kr(linear)", "csh", "kr1_csh") 31 | sas_wrapper("kr", "ante(1)", "kr_adh") 32 | sas_wrapper("kr(linear)", "ante(1)", "kr1_adh") 33 | sas_wrapper("kr", "toep", "kr_toep") 34 | sas_wrapper("kr(linear)", "toep", "kr1_toep") 35 | sas_wrapper("kr", "toeph", "kr_toeph") 36 | sas_wrapper("kr(linear)", "toeph", "kr1_toeph") 37 | sas_wrapper("kr", "un", "kr_us") 38 | sas_wrapper("kr(linear)", "un", "kr1_us") 39 | sas_wrapper("kr", "sp(exp)(VISITN VISITN2)", "kr1_spexp") 40 | sas_wrapper("kr(linear)", "sp(exp)(VISITN VISITN2)", "kr_spexp") 41 | -------------------------------------------------------------------------------- /design/ddfm_covtype/kr1_adh.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.72344028834729,0.66158550758897,162.393385281755,5.62805600430501,7.8243188286883e-08,0.05,2.41702075846239,5.02985981823218 3 | -------------------------------------------------------------------------------- /design/ddfm_covtype/kr1_ar1.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",4.22574315817874,0.96058142305176,188.46934887972,4.39915144804024,1.815453738e-05,0.05,2.3308705916013,6.12061572475617 3 | -------------------------------------------------------------------------------- /design/ddfm_covtype/kr1_arh1.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.72674356244499,0.75924807546934,188.225339095373,4.90846626136162,1.9827820499298e-06,0.05,2.22901482545413,5.22447229943586 3 | -------------------------------------------------------------------------------- /design/ddfm_covtype/kr1_cs.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",4.19663617897035,0.7964696053595,177.038485931223,5.26904749500904,3.9513758117516e-07,0.05,2.62483985242729,5.7684325055134 3 | -------------------------------------------------------------------------------- /design/ddfm_covtype/kr1_csh.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.77090812499029,0.67403858183242,190.737701349941,5.59449893022268,7.5979370864976e-08,0.05,2.44138098548593,5.10043526449464 3 | -------------------------------------------------------------------------------- /design/ddfm_covtype/kr1_spexp.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",4.21488979997259,0.90527620094771,195.584197921463,4.65591583602897,5.9438569570101e-06,0.05,2.4295337081138,6.00024589183139 3 | -------------------------------------------------------------------------------- /design/ddfm_covtype/kr1_toep.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",4.47051860580552,0.87839805519623,160.027408337368,5.08939948052002,9.9712975278958e-07,0.05,2.73577118036349,6.20526603124755 3 | -------------------------------------------------------------------------------- /design/ddfm_covtype/kr1_toeph.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.92287746213894,0.72537324518435,180.062730071701,5.40808127151413,2.0060237730601e-07,0.05,2.4915519913325,5.35420293294538 3 | -------------------------------------------------------------------------------- /design/ddfm_covtype/kr1_us.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.81972492174648,0.66124382270307,160.733266403768,5.77657558467911,3.8418051504164e-08,0.05,2.51387886026607,5.12557098322688 3 | -------------------------------------------------------------------------------- /design/ddfm_covtype/kr_adh.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.72344028834729,0.66172017349971,162.393385281755,5.62691064510651,7.8678872626732e-08,0.05,2.41675483641031,5.03012574028427 3 | -------------------------------------------------------------------------------- /design/ddfm_covtype/kr_ar1.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",4.22574315817874,0.95865439662225,188.46934887972,4.40799434401785,1.749576207e-05,0.05,2.33467190342009,6.11681441293738 3 | -------------------------------------------------------------------------------- /design/ddfm_covtype/kr_arh1.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.72674356244499,0.7590316099633,188.225339095373,4.90986608927285,1.9702804119225e-06,0.05,2.22944183557037,5.22404528931962 3 | -------------------------------------------------------------------------------- /design/ddfm_covtype/kr_cs.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",4.19663617897035,0.7964696053595,177.038485931223,5.26904749500904,3.9513758117516e-07,0.05,2.62483985242729,5.7684325055134 3 | -------------------------------------------------------------------------------- /design/ddfm_covtype/kr_csh.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.77090812499029,0.67414806011886,190.737701349941,5.59359041146748,7.6321785400906e-08,0.05,2.44116504183384,5.10065120814674 3 | -------------------------------------------------------------------------------- /design/ddfm_covtype/kr_numderiv.R: -------------------------------------------------------------------------------- 1 | v <- matrix(c(0, 0.5, 1, 0.5, 0, 0.5, 1, 0.5, 0), ncol = 3) 2 | 3 | f <- function(theta) { 4 | sd <- exp(theta[1]) 5 | rho <- plogis(theta[2]) 6 | v <- sd * rho^v 7 | as.vector(v) 8 | } 9 | 10 | f2 <- function(theta) { 11 | as.vector(numDeriv::jacobian(f, theta)) 12 | } 13 | 14 | aa <- numDeriv::jacobian(f, c(1, 1)) 15 | 16 | bb <- numDeriv::jacobian(f2, c(1, 1)) 17 | toString(rbind(matrix(aa[, 1], ncol = 3), matrix(aa[, 2], ncol = 3))) 18 | 19 | 20 | toString(t(rbind(matrix(bb[1:9, 1], ncol = 3), matrix(bb[10:18, 1], ncol = 3), matrix(bb[1:9, 2], ncol = 3), matrix(bb[10:18, 2], ncol = 3)))) 21 | -------------------------------------------------------------------------------- /design/ddfm_covtype/kr_spexp.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",4.21488979997259,0.90552903839818,195.584197921463,4.65461583366607,5.9777049233939e-06,0.05,2.42903507036989,6.00074452957529 3 | -------------------------------------------------------------------------------- /design/ddfm_covtype/kr_toep.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",4.47051860580552,0.87839805519623,160.027408337368,5.08939948052002,9.9712975278958e-07,0.05,2.73577118036349,6.20526603124755 3 | -------------------------------------------------------------------------------- /design/ddfm_covtype/kr_toeph.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.92287746213894,0.72543828853831,180.062730071701,5.40759637879484,2.0106987035365e-07,0.05,2.49142364608424,5.35433127819364 3 | -------------------------------------------------------------------------------- /design/ddfm_covtype/kr_us.csv: -------------------------------------------------------------------------------- 1 | "","Effect","ARMCD","_ARMCD","Estimate","StdErr","DF","tValue","Probt","Alpha","Lower","Upper" 2 | "1","ARMCD","TRT","PBO",3.81972492174648,0.66124382270307,160.733266403768,5.77657558467911,3.8418051504164e-08,0.05,2.51387886026607,5.12557098322688 3 | -------------------------------------------------------------------------------- /inst/WORDLIST: -------------------------------------------------------------------------------- 1 | ARMCD 2 | AstraZeneca 3 | BCVA 4 | Benchmarking 5 | Boehringer 6 | Bolker 7 | Bove 8 | COPD 9 | Cnaan 10 | Crossproduct 11 | DF 12 | DPD 13 | DeclareMathOperator 14 | Dohme 15 | FEV 16 | GmbH 17 | Gower 18 | Hoffmann 19 | Indexible 20 | Ingelheim 21 | Kenward 22 | LDL 23 | Lukas 24 | MMRMs 25 | MacOS 26 | Mallinckrodt 27 | Mancuso 28 | Nikolas 29 | ORCID 30 | Optimizers 31 | Peng 32 | Raphson 33 | SAS's 34 | SICI 35 | Sabanes 36 | Satterthwaite 37 | Schnell 38 | Slasor 39 | TMB 40 | Tidymodels 41 | Toeplitz 42 | WLS 43 | adh 44 | ansi 45 | ar 46 | ast 47 | biostatistics 48 | blockdiag 49 | boldsymbol 50 | cdots 51 | cli 52 | cov 53 | crossproduct 54 | csh 55 | customizations 56 | ddots 57 | de 58 | det 59 | doi 60 | dotsb 61 | dotsc 62 | eigen 63 | emmeans 64 | factorizations 65 | frac 66 | funder 67 | hj 68 | ih 69 | ihj 70 | ij 71 | ijk 72 | ik 73 | im 74 | indexible 75 | infty 76 | intra 77 | jh 78 | ji 79 | jj 80 | ldots 81 | leq 82 | lintr 83 | mathbb 84 | mathcal 85 | mathop 86 | mathrm 87 | na 88 | nabla 89 | ne 90 | newcommand 91 | nlminb 92 | nonidentifiability 93 | onLoad 94 | optimizers 95 | parametrized 96 | pearson 97 | pkgdown 98 | plc 99 | pmatrix 100 | pre 101 | reproducibility 102 | rightarrow 103 | simeq 104 | sp 105 | subfolders 106 | tabset 107 | th 108 | tidymodels 109 | toep 110 | toeph 111 | unadjusted 112 | unreproducible 113 | unscaled 114 | untracked 115 | vairance 116 | varepsilon 117 | varphi 118 | vcov 119 | vdots 120 | widehat 121 | -------------------------------------------------------------------------------- /man/Anova.mmrm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/interop-car.R 3 | \name{Anova.mmrm} 4 | \alias{Anova.mmrm} 5 | \title{Conduct type II/III hypothesis testing on the MMRM fit results.} 6 | \usage{ 7 | Anova.mmrm( 8 | mod, 9 | type = c("II", "III", "2", "3"), 10 | tol = sqrt(.Machine$double.eps), 11 | ... 12 | ) 13 | } 14 | \arguments{ 15 | \item{mod}{(\code{mmrm})\cr the fitted MMRM.} 16 | 17 | \item{type}{(\code{string}) type of test, "II", "III", '2', or '3'.} 18 | 19 | \item{tol}{(\code{numeric}) threshold blow which values are treated as 0.} 20 | 21 | \item{...}{not used.} 22 | } 23 | \description{ 24 | Conduct type II/III hypothesis testing on the MMRM fit results. 25 | } 26 | \details{ 27 | \code{Anova} will return \code{anova} object with one row per variable and columns 28 | \verb{Num Df}(numerator degrees of freedom), \verb{Denom Df}(denominator degrees of freedom), 29 | \verb{F Statistic} and \verb{Pr(>=F)}. 30 | } 31 | \keyword{internal} 32 | -------------------------------------------------------------------------------- /man/COV_TYPES.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cov_struct.R 3 | \docType{data} 4 | \name{COV_TYPES} 5 | \alias{COV_TYPES} 6 | \title{Covariance Type Database} 7 | \format{ 8 | A data frame with 5 variables and one record per covariance type: 9 | 10 | \describe{ 11 | \item{name}{ 12 | The long-form name of the covariance structure type 13 | } 14 | \item{abbr}{ 15 | The abbreviated name of the covariance structure type 16 | } 17 | \item{habbr}{ 18 | The abbreviated name of the heterogeneous version of a covariance 19 | structure type (The abbreviated name (\code{abbr}) with a trailing \code{"h"} if 20 | the structure has a heterogeneous implementation or \code{NA} otherwise). 21 | } 22 | \item{heterogeneous}{ 23 | A logical value indicating whether the covariance structure has a 24 | heterogeneous counterpart. 25 | } 26 | \item{spatial}{ 27 | A logical value indicating whether the covariance structure is spatial. 28 | } 29 | } 30 | } 31 | \usage{ 32 | COV_TYPES 33 | } 34 | \description{ 35 | An internal constant for covariance type information. 36 | } 37 | \keyword{internal} 38 | -------------------------------------------------------------------------------- /man/as.cov_struct.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cov_struct.R 3 | \name{as.cov_struct} 4 | \alias{as.cov_struct} 5 | \alias{as.cov_struct.formula} 6 | \title{Coerce into a Covariance Structure Definition} 7 | \usage{ 8 | as.cov_struct(x, ...) 9 | 10 | \method{as.cov_struct}{formula}(x, warn_partial = TRUE, ...) 11 | } 12 | \arguments{ 13 | \item{x}{an object from which to derive a covariance structure. See object 14 | specific sections for details.} 15 | 16 | \item{...}{additional arguments unused.} 17 | 18 | \item{warn_partial}{(\code{flag})\cr whether to emit a warning when parts of the 19 | formula are disregarded.} 20 | } 21 | \value{ 22 | A \code{\link[=cov_struct]{cov_struct()}} object. 23 | } 24 | \description{ 25 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} 26 | } 27 | \details{ 28 | A covariance structure can be parsed from a model definition formula or call. 29 | Generally, covariance structures defined using non-standard evaluation take 30 | the following form: 31 | 32 | \if{html}{\out{
}}\preformatted{type( (visit, )* visit | (group /)? subject ) 33 | }\if{html}{\out{
}} 34 | 35 | For example, formulas may include terms such as 36 | 37 | \if{html}{\out{
}}\preformatted{us(time | subject) 38 | cp(time | group / subject) 39 | sp_exp(coord1, coord2 | group / subject) 40 | }\if{html}{\out{
}} 41 | 42 | Note that only \code{sp_exp} (spatial) covariance structures may provide multiple 43 | coordinates, which identify the Euclidean distance between the time points. 44 | } 45 | \section{Methods (by class)}{ 46 | \itemize{ 47 | \item \code{as.cov_struct(formula)}: When provided a formula, any specialized functions are assumed to be 48 | covariance structure definitions and must follow the form: 49 | 50 | \if{html}{\out{
}}\preformatted{y ~ xs + type( (visit, )* visit | (group /)? subject ) 51 | }\if{html}{\out{
}} 52 | 53 | Any component on the right hand side of a formula is considered when 54 | searching for a covariance definition. 55 | 56 | }} 57 | \examples{ 58 | # provide a covariance structure as a right-sided formula 59 | as.cov_struct(~ csh(visit | group / subject)) 60 | 61 | # when part of a full formula, suppress warnings using `warn_partial = FALSE` 62 | as.cov_struct(y ~ x + csh(visit | group / subject), warn_partial = FALSE) 63 | 64 | } 65 | \seealso{ 66 | Other covariance types: 67 | \code{\link{cov_struct}()}, 68 | \code{\link{covariance_types}} 69 | } 70 | \concept{covariance types} 71 | -------------------------------------------------------------------------------- /man/bcva_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{bcva_data} 5 | \alias{bcva_data} 6 | \title{Example Data on BCVA} 7 | \format{ 8 | A \code{tibble} with 10,000 rows and 7 variables: 9 | \itemize{ 10 | \item \code{USUBJID}: subject ID. 11 | \item \code{VISITN}: visit number (numeric). 12 | \item \code{AVISIT}: visit number (factor). 13 | \item \code{ARMCD}: treatment, \code{TRT} or \code{CTL}. 14 | \item \code{RACE}: 3-category race. 15 | \item \code{BCVA_BL}: BCVA at baseline. 16 | \item \code{BCVA_CHG}: Change in BCVA at study visits. 17 | } 18 | } 19 | \source{ 20 | This is an artificial dataset. 21 | } 22 | \usage{ 23 | bcva_data 24 | } 25 | \description{ 26 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} 27 | } 28 | \note{ 29 | Measurements of BCVA (best corrected visual acuity) is a measure of how 30 | how many letters a person can read off of an eye chart using corrective 31 | lenses or contacts. This a common endpoint in ophthalmology trials. 32 | } 33 | \keyword{datasets} 34 | -------------------------------------------------------------------------------- /man/cached_mmrm_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{cached_mmrm_results} 5 | \alias{cached_mmrm_results} 6 | \title{Cache Data for \code{mmrm} Model Comparison} 7 | \format{ 8 | A \code{list} with following elements: 9 | \itemize{ 10 | \item \code{conv_time_fev}: Convergence time on FEV data. 11 | \item \code{conv_time_bcva}: Convergence time on BCVA data. 12 | \item \code{rel_diff_ests_tbl_fev}: Relative difference in estimates on FEV data. 13 | \item \code{rel_diff_ests_tbl_bcva}: Relative difference in estimates on BCVA data. 14 | \item \code{conv_rate}: Convergence rate on data with different missing levels. 15 | \item \code{df_missingness}: Summary of missingness on simulated data. 16 | } 17 | } 18 | \source{ 19 | This is created based on simulations on FEV data and BCVA data. 20 | } 21 | \usage{ 22 | cached_mmrm_results 23 | } 24 | \description{ 25 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} 26 | } 27 | \note{ 28 | The cached data for comparison is used for the vignettes generation. 29 | Please make sure that this data is refreshed before each package release 30 | by running the script \code{data-raw/mmrm_review.R}. 31 | Please make sure to install the \code{mmrm} package instead of using 32 | \code{devtools::load_all()} before running the script to achieve accurate timings. 33 | } 34 | \keyword{internal} 35 | -------------------------------------------------------------------------------- /man/car_add_mmrm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/interop-car.R 3 | \name{car_add_mmrm} 4 | \alias{car_add_mmrm} 5 | \title{Register \code{mmrm} For Use With \code{car::Anova}} 6 | \usage{ 7 | car_add_mmrm(quietly = FALSE) 8 | } 9 | \arguments{ 10 | \item{quietly}{logical: should progress and error messages be suppressed?} 11 | } 12 | \value{ 13 | A logical value indicating whether registration was successful. 14 | } 15 | \description{ 16 | Register \code{mmrm} For Use With \code{car::Anova} 17 | } 18 | \keyword{internal} 19 | -------------------------------------------------------------------------------- /man/check_package_version.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/zzz.R 3 | \name{check_package_version} 4 | \alias{check_package_version} 5 | \title{Check Suggested Dependency Against Version Requirements} 6 | \usage{ 7 | check_package_version(pkg, ver = c(NA_character_, NA_character_)) 8 | } 9 | \arguments{ 10 | \item{pkg}{(\code{string})\cr package name.} 11 | 12 | \item{ver}{(\code{character})\cr of length 2 whose elements can be provided to 13 | \code{\link[=numeric_version]{numeric_version()}}, representing a minimum and maximum (inclusive) version 14 | requirement for interoperability. When \code{NA}, no version requirement is 15 | imposed. Defaults to no version requirement.} 16 | } 17 | \value{ 18 | A logical (invisibly) indicating whether the loaded package meets 19 | the version requirements. A warning is emitted otherwise. 20 | } 21 | \description{ 22 | Check Suggested Dependency Against Version Requirements 23 | } 24 | \keyword{internal} 25 | -------------------------------------------------------------------------------- /man/cov_struct.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cov_struct.R 3 | \name{cov_struct} 4 | \alias{cov_struct} 5 | \title{Define a Covariance Structure} 6 | \usage{ 7 | cov_struct( 8 | type = cov_types(), 9 | visits, 10 | subject, 11 | group = character(), 12 | heterogeneous = FALSE 13 | ) 14 | } 15 | \arguments{ 16 | \item{type}{(\code{string})\cr the name of the covariance structure type to use. 17 | For available options, see \code{cov_types()}. If a type abbreviation is used 18 | that implies heterogeneity (e.g. \code{cph}) and no value is provided to 19 | \code{heterogeneous}, then the heterogeneity is derived from the type name.} 20 | 21 | \item{visits}{(\code{character})\cr a vector of variable names to use for the 22 | longitudinal terms of the covariance structure. Multiple terms are only 23 | permitted for the \code{"spatial"} covariance type.} 24 | 25 | \item{subject}{(\code{string})\cr the name of the variable that encodes a subject 26 | identifier.} 27 | 28 | \item{group}{(\code{string})\cr optionally, the name of the variable that encodes 29 | a grouping variable for subjects.} 30 | 31 | \item{heterogeneous}{(\code{flag})\cr} 32 | } 33 | \value{ 34 | A \code{cov_struct} object. 35 | } 36 | \description{ 37 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} 38 | } 39 | \examples{ 40 | cov_struct("csh", "AVISITN", "USUBJID") 41 | cov_struct("spatial", c("VISITA", "VISITB"), group = "GRP", subject = "SBJ") 42 | 43 | } 44 | \seealso{ 45 | Other covariance types: 46 | \code{\link{as.cov_struct}()}, 47 | \code{\link{covariance_types}} 48 | } 49 | \concept{covariance types} 50 | -------------------------------------------------------------------------------- /man/cov_type_abbr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cov_struct.R 3 | \name{cov_type_abbr} 4 | \alias{cov_type_abbr} 5 | \title{Retrieve Associated Abbreviated Covariance Structure Type Name} 6 | \usage{ 7 | cov_type_abbr(type) 8 | } 9 | \arguments{ 10 | \item{type}{(\code{string})\cr either a full name or abbreviate covariance 11 | structure type name to collapse into an abbreviated type.} 12 | } 13 | \value{ 14 | The corresponding abbreviated covariance type name. 15 | } 16 | \description{ 17 | Retrieve Associated Abbreviated Covariance Structure Type Name 18 | } 19 | \keyword{internal} 20 | -------------------------------------------------------------------------------- /man/cov_type_name.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cov_struct.R 3 | \name{cov_type_name} 4 | \alias{cov_type_name} 5 | \title{Retrieve Associated Full Covariance Structure Type Name} 6 | \usage{ 7 | cov_type_name(type) 8 | } 9 | \arguments{ 10 | \item{type}{(\code{string})\cr either a full name or abbreviate covariance 11 | structure type name to convert to a long-form type.} 12 | } 13 | \value{ 14 | The corresponding abbreviated covariance type name. 15 | } 16 | \description{ 17 | Retrieve Associated Full Covariance Structure Type Name 18 | } 19 | \keyword{internal} 20 | -------------------------------------------------------------------------------- /man/df_1d.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/testing.R 3 | \name{df_1d} 4 | \alias{df_1d} 5 | \title{Calculation of Degrees of Freedom for One-Dimensional Contrast} 6 | \usage{ 7 | df_1d(object, contrast) 8 | } 9 | \arguments{ 10 | \item{object}{(\code{mmrm})\cr the MMRM fit.} 11 | 12 | \item{contrast}{(\code{numeric})\cr contrast vector. Note that this should not include 13 | elements for singular coefficient estimates, i.e. only refer to the 14 | actually estimated coefficients.} 15 | } 16 | \value{ 17 | List with \code{est}, \code{se}, \code{df}, \code{t_stat} and \code{p_val}. 18 | } 19 | \description{ 20 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} 21 | Calculates the estimate, adjusted standard error, degrees of freedom, 22 | t statistic and p-value for one-dimensional contrast. 23 | } 24 | \examples{ 25 | object <- mmrm( 26 | formula = FEV1 ~ RACE + SEX + ARMCD * AVISIT + us(AVISIT | USUBJID), 27 | data = fev_data 28 | ) 29 | contrast <- numeric(length(object$beta_est)) 30 | contrast[3] <- 1 31 | df_1d(object, contrast) 32 | } 33 | -------------------------------------------------------------------------------- /man/df_md.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/testing.R 3 | \name{df_md} 4 | \alias{df_md} 5 | \title{Calculation of Degrees of Freedom for Multi-Dimensional Contrast} 6 | \usage{ 7 | df_md(object, contrast) 8 | } 9 | \arguments{ 10 | \item{object}{(\code{mmrm})\cr the MMRM fit.} 11 | 12 | \item{contrast}{(\code{matrix})\cr numeric contrast matrix, if given a \code{numeric} 13 | then this is coerced to a row vector. Note that this should not include 14 | elements for singular coefficient estimates, i.e. only refer to the 15 | actually estimated coefficients.} 16 | } 17 | \value{ 18 | List with \code{num_df}, \code{denom_df}, \code{f_stat} and \code{p_val} (2-sided p-value). 19 | } 20 | \description{ 21 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} 22 | Calculates the estimate, standard error, degrees of freedom, 23 | t statistic and p-value for one-dimensional contrast, depending on the method 24 | used in \code{\link[=mmrm]{mmrm()}}. 25 | } 26 | \examples{ 27 | object <- mmrm( 28 | formula = FEV1 ~ RACE + SEX + ARMCD * AVISIT + us(AVISIT | USUBJID), 29 | data = fev_data 30 | ) 31 | contrast <- matrix(data = 0, nrow = 2, ncol = length(object$beta_est)) 32 | contrast[1, 2] <- contrast[2, 3] <- 1 33 | df_md(object, contrast) 34 | } 35 | -------------------------------------------------------------------------------- /man/drop_elements.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{drop_elements} 4 | \alias{drop_elements} 5 | \title{Drop Items from an Indexible} 6 | \usage{ 7 | drop_elements(x, n) 8 | } 9 | \arguments{ 10 | \item{x}{Any object that can be consumed by \code{\link[=seq_along]{seq_along()}} and indexed by a 11 | logical vector of the same length.} 12 | 13 | \item{n}{(\code{integer})\cr the number of terms to drop.} 14 | } 15 | \value{ 16 | A subset of \code{x}. 17 | } 18 | \description{ 19 | Drop elements from an indexible object (\code{vector}, \code{list}, etc.). 20 | } 21 | \keyword{internal} 22 | -------------------------------------------------------------------------------- /man/emit_tidymodels_register_msg.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/zzz.R 3 | \name{emit_tidymodels_register_msg} 4 | \alias{emit_tidymodels_register_msg} 5 | \title{Format a Message to Emit When Tidymodels is Loaded} 6 | \usage{ 7 | emit_tidymodels_register_msg() 8 | } 9 | \value{ 10 | A character message to emit. Either a ansi-formatted cli output if 11 | package 'cli' is available or a plain-text message otherwise. 12 | } 13 | \description{ 14 | Format a Message to Emit When Tidymodels is Loaded 15 | } 16 | \keyword{internal} 17 | -------------------------------------------------------------------------------- /man/emmeans_support.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/interop-emmeans.R 3 | \name{emmeans_support} 4 | \alias{emmeans_support} 5 | \title{Support for \code{emmeans}} 6 | \description{ 7 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} 8 | 9 | This package includes methods that allow \code{mmrm} objects to be used 10 | with the \code{emmeans} package. \code{emmeans} computes estimated marginal means 11 | (also called least-square means) for the coefficients of the MMRM. 12 | We can also e.g. obtain differences between groups by applying 13 | \code{\link[emmeans:contrast]{pairs()}} on the object returned 14 | by \code{\link[emmeans:emmeans]{emmeans::emmeans()}}. 15 | } 16 | \examples{ 17 | fit <- mmrm( 18 | formula = FEV1 ~ RACE + SEX + ARMCD * AVISIT + us(AVISIT | USUBJID), 19 | data = fev_data 20 | ) 21 | if (require(emmeans)) { 22 | emmeans(fit, ~ ARMCD | AVISIT) 23 | pairs(emmeans(fit, ~ ARMCD | AVISIT), reverse = TRUE) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /man/emp_start.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{emp_start} 4 | \alias{emp_start} 5 | \title{Empirical Starting Value} 6 | \usage{ 7 | emp_start(data, model_formula, visit_var, subject_var, subject_groups, ...) 8 | } 9 | \arguments{ 10 | \item{data}{(\code{data.frame})\cr data used for model fitting.} 11 | 12 | \item{model_formula}{(\code{formula})\cr the formula in mmrm model without covariance structure part.} 13 | 14 | \item{visit_var}{(\code{string})\cr visit variable.} 15 | 16 | \item{subject_var}{(\code{string})\cr subject id variable.} 17 | 18 | \item{subject_groups}{(\code{factor})\cr subject group assignment.} 19 | 20 | \item{...}{not used.} 21 | } 22 | \value{ 23 | A numeric vector of starting values. 24 | } 25 | \description{ 26 | Obtain empirical start value for unstructured covariance 27 | } 28 | \details{ 29 | This \code{emp_start} only works for unstructured covariance structure. 30 | It uses linear regression to first obtain the coefficients and use the residuals 31 | to obtain the empirical variance-covariance, and it is then used to obtain the 32 | starting values. 33 | } 34 | \note{ 35 | \code{data} is used instead of \code{full_frame} because \code{full_frame} is already 36 | transformed if model contains transformations, e.g. \code{log(FEV1) ~ exp(FEV1_BL)} will 37 | drop \code{FEV1} and \code{FEV1_BL} but add \code{log(FEV1)} and \code{exp(FEV1_BL)} in \code{full_frame}. 38 | } 39 | -------------------------------------------------------------------------------- /man/fev_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{fev_data} 5 | \alias{fev_data} 6 | \title{Example Data on FEV1} 7 | \format{ 8 | A \code{tibble} with 800 rows and 7 variables: 9 | \itemize{ 10 | \item \code{USUBJID}: subject ID. 11 | \item \code{AVISIT}: visit number. 12 | \item \code{ARMCD}: treatment, \code{TRT} or \code{PBO}. 13 | \item \code{RACE}: 3-category race. 14 | \item \code{SEX}: sex. 15 | \item \code{FEV1_BL}: FEV1 at baseline (\%). 16 | \item \code{FEV1}: FEV1 at study visits. 17 | \item \code{WEIGHT}: weighting variable. 18 | \item \code{VISITN}: integer order of the visit. 19 | \item \code{VISITN2}: coordinates of the visit for distance calculation. 20 | } 21 | } 22 | \source{ 23 | This is an artificial dataset. 24 | } 25 | \usage{ 26 | fev_data 27 | } 28 | \description{ 29 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} 30 | } 31 | \note{ 32 | Measurements of FEV1 (forced expired volume in one second) is a measure 33 | of how quickly the lungs can be emptied. Low levels of FEV1 may indicate 34 | chronic obstructive pulmonary disease (COPD). 35 | } 36 | \keyword{datasets} 37 | -------------------------------------------------------------------------------- /man/figures/lifecycle-archived.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclearchivedarchived 2 | -------------------------------------------------------------------------------- /man/figures/lifecycle-defunct.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecycledefunctdefunct 2 | -------------------------------------------------------------------------------- /man/figures/lifecycle-deprecated.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecycledeprecateddeprecated 2 | -------------------------------------------------------------------------------- /man/figures/lifecycle-experimental.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecycleexperimentalexperimental 2 | -------------------------------------------------------------------------------- /man/figures/lifecycle-maturing.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclematuringmaturing 2 | -------------------------------------------------------------------------------- /man/figures/lifecycle-questioning.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclequestioningquestioning 2 | -------------------------------------------------------------------------------- /man/figures/lifecycle-stable.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclestablestable 2 | -------------------------------------------------------------------------------- /man/figures/lifecycle-superseded.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclesupersededsuperseded 2 | -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openpharma/mmrm/ca604819431a6b43a3a227a122173a1e9b1a8fda/man/figures/logo.png -------------------------------------------------------------------------------- /man/fill_names.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{fill_names} 4 | \alias{fill_names} 5 | \title{Complete \code{character} Vector Names From Values} 6 | \usage{ 7 | fill_names(x) 8 | } 9 | \arguments{ 10 | \item{x}{(\code{character} or \code{list})\cr value whose names should be completed 11 | from element values.} 12 | } 13 | \value{ 14 | A named vector or list. 15 | } 16 | \description{ 17 | Complete \code{character} Vector Names From Values 18 | } 19 | \keyword{internal} 20 | -------------------------------------------------------------------------------- /man/flat_expr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils-nse.R 3 | \name{flat_expr} 4 | \alias{flat_expr} 5 | \alias{flatten_call} 6 | \alias{flatten_expr} 7 | \title{Flatten Expressions for Non-standard Evaluation} 8 | \usage{ 9 | flatten_call(call) 10 | 11 | flatten_expr(expr) 12 | } 13 | \arguments{ 14 | \item{call, expr}{(\code{language})\cr a language object to flatten.} 15 | } 16 | \value{ 17 | A list of atomic values, symbols, infix operator names and 18 | subexpressions. 19 | } 20 | \description{ 21 | Used primarily to support the parsing of covariance structure definitions 22 | from formulas, these functions flatten the syntax tree into a hierarchy-less 23 | grammar, allowing for parsing that doesn't abide by R's native operator 24 | precedence. 25 | } 26 | \details{ 27 | Where \code{1 + 2 | 3} in R's syntax tree is \code{(|, (+, 1, 2), 3)}, 28 | flattening it into its visual order produces \code{(1, +, 2, |, 3)}, which 29 | makes for more fluent interpretation of non-standard grammar rules used in 30 | formulas. 31 | } 32 | \section{Functions}{ 33 | \itemize{ 34 | \item \code{flatten_call()}: Flatten a call into a list of names and argument expressions. 35 | 36 | The call name and all arguments are flattened into the same list, meaning a 37 | call of the form \code{sp_exp(a, b, c | d / e)} produces a list of the form 38 | \code{(sp_exp, a, b, c, |, d, /, e)}. 39 | 40 | \if{html}{\out{
}}\preformatted{flatten_call(quote(sp_exp(a, b, c | d / e))) 41 | }\if{html}{\out{
}} 42 | 43 | \item \code{flatten_expr()}: Flatten nested expressions 44 | 45 | \if{html}{\out{
}}\preformatted{flatten_expr(quote(1 + 2 + 3 | 4)) 46 | }\if{html}{\out{
}} 47 | 48 | }} 49 | \keyword{internal} 50 | -------------------------------------------------------------------------------- /man/format.cov_struct.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cov_struct.R 3 | \name{format.cov_struct} 4 | \alias{format.cov_struct} 5 | \title{Format Covariance Structure Object} 6 | \usage{ 7 | \method{format}{cov_struct}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{(\code{cov_struct})\cr a covariance structure object.} 11 | 12 | \item{...}{Additional arguments unused.} 13 | } 14 | \value{ 15 | A formatted string for \code{x}. 16 | } 17 | \description{ 18 | Format Covariance Structure Object 19 | } 20 | -------------------------------------------------------------------------------- /man/format_symbols.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils-nse.R 3 | \name{format_symbols} 4 | \alias{format_symbols} 5 | \title{Format Symbol Objects} 6 | \usage{ 7 | format_symbols(x) 8 | } 9 | \arguments{ 10 | \item{x}{(\code{character}) A vector of variable names.} 11 | } 12 | \value{ 13 | A formatted string of comma-separated variables. 14 | } 15 | \description{ 16 | For printing, variable names are converted to symbols and deparsed to use R's 17 | built-in formatting of variables that may contain spaces or quote characters. 18 | } 19 | \keyword{internal} 20 | -------------------------------------------------------------------------------- /man/formula_rhs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils-nse.R 3 | \name{formula_rhs} 4 | \alias{formula_rhs} 5 | \title{Extract Right-Hand-Side (rhs) from Formula} 6 | \usage{ 7 | formula_rhs(f) 8 | } 9 | \arguments{ 10 | \item{f}{(\code{formula})\cr a formula.} 11 | } 12 | \value{ 13 | A formula without a response, derived from the right-hand-side of the 14 | formula, \code{f}. 15 | 16 | \if{html}{\out{
}}\preformatted{formula_rhs(a ~ b + c) 17 | formula_rhs(~ b + c) 18 | }\if{html}{\out{
}} 19 | } 20 | \description{ 21 | Extract Right-Hand-Side (rhs) from Formula 22 | } 23 | \keyword{internal} 24 | -------------------------------------------------------------------------------- /man/h_add_covariance_terms.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils-formula.R 3 | \name{h_add_covariance_terms} 4 | \alias{h_add_covariance_terms} 5 | \title{Add Individual Covariance Variables As Terms to Formula} 6 | \usage{ 7 | h_add_covariance_terms(f, covariance) 8 | } 9 | \arguments{ 10 | \item{f}{(\code{formula})\cr a formula to which covariance structure terms should 11 | be added.} 12 | 13 | \item{covariance}{(\code{cov_struct})\cr a covariance structure object from which 14 | additional variables should be sourced.} 15 | } 16 | \value{ 17 | A new formula with included covariance terms. 18 | } 19 | \description{ 20 | Add Individual Covariance Variables As Terms to Formula 21 | } 22 | \details{ 23 | \code{\link[stats:update]{stats::update()}} is used to append the covariance structure and the environment 24 | attribute will not be changed. This ensures the returned formula and the input formula 25 | have the same environment. 26 | } 27 | \keyword{internal} 28 | -------------------------------------------------------------------------------- /man/h_add_terms.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils-formula.R 3 | \name{h_add_terms} 4 | \alias{h_add_terms} 5 | \title{Add Formula Terms with Character} 6 | \usage{ 7 | h_add_terms(f, adds, drop_response = FALSE) 8 | } 9 | \arguments{ 10 | \item{f}{(\code{formula})\cr a formula to be updated.} 11 | 12 | \item{adds}{(\code{character})\cr representation of elements to be added.} 13 | 14 | \item{drop_response}{(\code{flag})\cr whether response should be dropped.} 15 | } 16 | \value{ 17 | A new formula with elements in \code{drops} removed. 18 | } 19 | \description{ 20 | Add formula terms from the original formula with character representation. 21 | } 22 | \details{ 23 | Elements in \code{adds} will be added from the formula, while the environment 24 | of the formula is unchanged. If \code{adds} is \code{NULL} or \code{character(0)}, the formula is 25 | unchanged. 26 | } 27 | \keyword{internal} 28 | -------------------------------------------------------------------------------- /man/h_coef_table.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mmrm-methods.R 3 | \name{h_coef_table} 4 | \alias{h_coef_table} 5 | \title{Coefficients Table for MMRM Fit} 6 | \usage{ 7 | h_coef_table(object) 8 | } 9 | \arguments{ 10 | \item{object}{(\code{mmrm})\cr model fit.} 11 | } 12 | \value{ 13 | Matrix with one row per coefficient and columns 14 | \code{Estimate}, \verb{Std. Error}, \code{df}, \verb{t value} and \verb{Pr(>|t|)}. 15 | } 16 | \description{ 17 | This is used by \code{\link[=summary.mmrm]{summary.mmrm()}} to obtain the coefficients table. 18 | } 19 | \keyword{internal} 20 | -------------------------------------------------------------------------------- /man/h_confirm_large_levels.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{h_confirm_large_levels} 4 | \alias{h_confirm_large_levels} 5 | \title{Ask for Confirmation on Large Visit Levels} 6 | \usage{ 7 | h_confirm_large_levels(x) 8 | } 9 | \arguments{ 10 | \item{x}{(\code{numeric})\cr number of visit levels.} 11 | } 12 | \value{ 13 | Logical value \code{TRUE}. 14 | } 15 | \description{ 16 | Ask the user for confirmation if there are too many visit levels 17 | for non-spatial covariance structure in interactive sessions. 18 | } 19 | \keyword{internal} 20 | -------------------------------------------------------------------------------- /man/h_construct_model_frame_inputs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tmb-methods.R 3 | \name{h_construct_model_frame_inputs} 4 | \alias{h_construct_model_frame_inputs} 5 | \title{Construction of Model Frame Formula and Data Inputs} 6 | \usage{ 7 | h_construct_model_frame_inputs( 8 | formula, 9 | data, 10 | include, 11 | include_choice = c("subject_var", "visit_var", "group_var", "response_var"), 12 | full 13 | ) 14 | } 15 | \arguments{ 16 | \item{formula}{(\code{mmrm})\cr mmrm fit object.} 17 | 18 | \item{data}{optional data frame that will be 19 | passed to \code{model.frame()} or \code{model.matrix()}} 20 | 21 | \item{include}{(\code{character})\cr names of variable to include} 22 | 23 | \item{full}{(\code{flag})\cr indicator whether to return full model frame (deprecated).} 24 | } 25 | \value{ 26 | named list with four elements: 27 | \itemize{ 28 | \item \code{"formula"}: the formula including the columns requested in the \verb{include=} argument. 29 | \item \code{"data"}: a data frame including all columns needed in the formula. 30 | full formula are identical 31 | } 32 | } 33 | \description{ 34 | Input formulas are converted from mmrm-style to a style compatible 35 | with default \code{\link[stats:model.frame]{stats::model.frame()}} and \code{\link[stats:model.matrix]{stats::model.matrix()}} methods. 36 | 37 | The full formula is returned so we can construct, for example, the 38 | \code{model.frame()} including all columns as well as the requested subset. 39 | The full set is used to identify rows to include in the reduced model frame. 40 | } 41 | \keyword{internal} 42 | -------------------------------------------------------------------------------- /man/h_default_value.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{h_default_value} 4 | \alias{h_default_value} 5 | \title{Default Value on NULL 6 | Return default value when first argument is NULL.} 7 | \usage{ 8 | h_default_value(x, y) 9 | } 10 | \arguments{ 11 | \item{x}{Object.} 12 | 13 | \item{y}{Object.} 14 | } 15 | \description{ 16 | Default Value on NULL 17 | Return default value when first argument is NULL. 18 | } 19 | \details{ 20 | If \code{x} is NULL, returns \code{y}. Otherwise return \code{x}. 21 | } 22 | \keyword{internal} 23 | -------------------------------------------------------------------------------- /man/h_df_1d_bw.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/between-within.R 3 | \name{h_df_1d_bw} 4 | \alias{h_df_1d_bw} 5 | \title{Calculation of Between-Within Degrees of Freedom for One-Dimensional Contrast} 6 | \usage{ 7 | h_df_1d_bw(object, contrast) 8 | } 9 | \arguments{ 10 | \item{object}{(\code{mmrm})\cr the MMRM fit.} 11 | 12 | \item{contrast}{(\code{numeric})\cr contrast vector. Note that this should not include 13 | elements for singular coefficient estimates, i.e. only refer to the 14 | actually estimated coefficients.} 15 | } 16 | \value{ 17 | List with \code{est}, \code{se}, \code{df}, \code{t_stat} and \code{p_val}. 18 | } 19 | \description{ 20 | Used in \code{\link[=df_1d]{df_1d()}} if method is "Between-Within". 21 | } 22 | \keyword{internal} 23 | -------------------------------------------------------------------------------- /man/h_df_1d_kr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/kenwardroger.R 3 | \name{h_df_1d_kr} 4 | \alias{h_df_1d_kr} 5 | \title{Calculation of Kenward-Roger Degrees of Freedom for One-Dimensional Contrast} 6 | \usage{ 7 | h_df_1d_kr(object, contrast) 8 | } 9 | \arguments{ 10 | \item{object}{(\code{mmrm})\cr the MMRM fit.} 11 | 12 | \item{contrast}{(\code{numeric})\cr contrast vector. Note that this should not include 13 | elements for singular coefficient estimates, i.e. only refer to the 14 | actually estimated coefficients.} 15 | } 16 | \value{ 17 | List with \code{est}, \code{se}, \code{df}, \code{t_stat} and \code{p_val}. 18 | } 19 | \description{ 20 | Used in \code{\link[=df_1d]{df_1d()}} if method is 21 | "Kenward-Roger" or "Kenward-Roger-Linear". 22 | } 23 | \keyword{internal} 24 | -------------------------------------------------------------------------------- /man/h_df_1d_res.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/residual.R 3 | \name{h_df_1d_res} 4 | \alias{h_df_1d_res} 5 | \title{Calculation of Residual Degrees of Freedom for One-Dimensional Contrast} 6 | \usage{ 7 | h_df_1d_res(object, contrast) 8 | } 9 | \arguments{ 10 | \item{object}{(\code{mmrm})\cr the MMRM fit.} 11 | 12 | \item{contrast}{(\code{numeric})\cr contrast vector. Note that this should not include 13 | elements for singular coefficient estimates, i.e. only refer to the 14 | actually estimated coefficients.} 15 | } 16 | \value{ 17 | List with \code{est}, \code{se}, \code{df}, \code{t_stat} and \code{p_val}. 18 | } 19 | \description{ 20 | Used in \code{\link[=df_1d]{df_1d()}} if method is 21 | "Residual". 22 | } 23 | \keyword{internal} 24 | -------------------------------------------------------------------------------- /man/h_df_1d_sat.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/satterthwaite.R 3 | \name{h_df_1d_sat} 4 | \alias{h_df_1d_sat} 5 | \title{Calculation of Satterthwaite Degrees of Freedom for One-Dimensional Contrast} 6 | \usage{ 7 | h_df_1d_sat(object, contrast) 8 | } 9 | \arguments{ 10 | \item{object}{(\code{mmrm})\cr the MMRM fit.} 11 | 12 | \item{contrast}{(\code{numeric})\cr contrast vector. Note that this should not include 13 | elements for singular coefficient estimates, i.e. only refer to the 14 | actually estimated coefficients.} 15 | } 16 | \value{ 17 | List with \code{est}, \code{se}, \code{df}, \code{t_stat} and \code{p_val}. 18 | } 19 | \description{ 20 | Used in \code{\link[=df_1d]{df_1d()}} if method is 21 | "Satterthwaite". 22 | } 23 | \keyword{internal} 24 | -------------------------------------------------------------------------------- /man/h_df_1d_sat_empirical.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/satterthwaite.R 3 | \name{h_df_1d_sat_empirical} 4 | \alias{h_df_1d_sat_empirical} 5 | \title{Helper for Calculation of Satterthwaite with Empirical Covariance Matrix} 6 | \usage{ 7 | h_df_1d_sat_empirical(object, contrast_matrix) 8 | } 9 | \arguments{ 10 | \item{object}{(\code{mmrm})\cr the MMRM fit.} 11 | 12 | \item{contrast_matrix}{(\code{matrix})\cr contrast matrix with number of subjects times 13 | number of coefficients as the number of columns.} 14 | } 15 | \value{ 16 | Adjusted degrees of freedom value. 17 | } 18 | \description{ 19 | Used in \code{\link[=h_df_1d_sat]{h_df_1d_sat()}} and \code{\link[=h_df_md_sat]{h_df_md_sat()}} if empirical covariance 20 | matrix is used. 21 | } 22 | \keyword{internal} 23 | -------------------------------------------------------------------------------- /man/h_df_bw_calc.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/between-within.R 3 | \name{h_df_bw_calc} 4 | \alias{h_df_bw_calc} 5 | \title{Calculation of Between-Within Degrees of Freedom} 6 | \usage{ 7 | h_df_bw_calc(object) 8 | } 9 | \arguments{ 10 | \item{object}{(\code{mmrm})\cr the fitted MMRM.} 11 | } 12 | \value{ 13 | List with: 14 | \itemize{ 15 | \item \code{coefs_between_within} calculated via \code{\link[=h_within_or_between]{h_within_or_between()}} 16 | \item \code{ddf_between} 17 | \item \code{ddf_within} 18 | } 19 | } 20 | \description{ 21 | Used in \code{\link[=h_df_1d_bw]{h_df_1d_bw()}} and \code{\link[=h_df_md_bw]{h_df_md_bw()}}. 22 | } 23 | \keyword{internal} 24 | -------------------------------------------------------------------------------- /man/h_df_md_bw.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/between-within.R 3 | \name{h_df_md_bw} 4 | \alias{h_df_md_bw} 5 | \title{Calculation of Between-Within Degrees of Freedom for Multi-Dimensional Contrast} 6 | \usage{ 7 | h_df_md_bw(object, contrast) 8 | } 9 | \arguments{ 10 | \item{object}{(\code{mmrm})\cr the MMRM fit.} 11 | 12 | \item{contrast}{(\code{matrix})\cr numeric contrast matrix, if given a \code{numeric} 13 | then this is coerced to a row vector. Note that this should not include 14 | elements for singular coefficient estimates, i.e. only refer to the 15 | actually estimated coefficients.} 16 | } 17 | \value{ 18 | List with \code{num_df}, \code{denom_df}, \code{f_stat} and \code{p_val} (2-sided p-value). 19 | } 20 | \description{ 21 | Used in \code{\link[=df_md]{df_md()}} if method is "Between-Within". 22 | } 23 | \keyword{internal} 24 | -------------------------------------------------------------------------------- /man/h_df_md_from_1d.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/satterthwaite.R 3 | \name{h_df_md_from_1d} 4 | \alias{h_df_md_from_1d} 5 | \title{Creating F-Statistic Results from One-Dimensional Contrast} 6 | \usage{ 7 | h_df_md_from_1d(object, contrast) 8 | } 9 | \arguments{ 10 | \item{object}{(\code{mmrm})\cr model fit.} 11 | 12 | \item{contrast}{(\code{numeric})\cr one-dimensional contrast.} 13 | } 14 | \value{ 15 | The one-dimensional degrees of freedom are calculated and then 16 | based on that the p-value is calculated. 17 | } 18 | \description{ 19 | Creates multi-dimensional result from one-dimensional contrast from \code{\link[=df_1d]{df_1d()}}. 20 | } 21 | \keyword{internal} 22 | -------------------------------------------------------------------------------- /man/h_df_md_kr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/kenwardroger.R 3 | \name{h_df_md_kr} 4 | \alias{h_df_md_kr} 5 | \title{Calculation of Kenward-Roger Degrees of Freedom for Multi-Dimensional Contrast} 6 | \usage{ 7 | h_df_md_kr(object, contrast) 8 | } 9 | \arguments{ 10 | \item{object}{(\code{mmrm})\cr the MMRM fit.} 11 | 12 | \item{contrast}{(\code{matrix})\cr numeric contrast matrix, if given a \code{numeric} 13 | then this is coerced to a row vector. Note that this should not include 14 | elements for singular coefficient estimates, i.e. only refer to the 15 | actually estimated coefficients.} 16 | } 17 | \value{ 18 | List with \code{num_df}, \code{denom_df}, \code{f_stat} and \code{p_val} (2-sided p-value). 19 | } 20 | \description{ 21 | Used in \code{\link[=df_md]{df_md()}} if method is "Kenward-Roger" or "Kenward-Roger-Linear". 22 | } 23 | \keyword{internal} 24 | -------------------------------------------------------------------------------- /man/h_df_md_res.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/residual.R 3 | \name{h_df_md_res} 4 | \alias{h_df_md_res} 5 | \title{Calculation of Residual Degrees of Freedom for Multi-Dimensional Contrast} 6 | \usage{ 7 | h_df_md_res(object, contrast) 8 | } 9 | \arguments{ 10 | \item{object}{(\code{mmrm})\cr the MMRM fit.} 11 | 12 | \item{contrast}{(\code{matrix})\cr numeric contrast matrix, if given a \code{numeric} 13 | then this is coerced to a row vector. Note that this should not include 14 | elements for singular coefficient estimates, i.e. only refer to the 15 | actually estimated coefficients.} 16 | } 17 | \value{ 18 | List with \code{num_df}, \code{denom_df}, \code{f_stat} and \code{p_val} (2-sided p-value). 19 | } 20 | \description{ 21 | Used in \code{\link[=df_md]{df_md()}} if method is "Residual". 22 | } 23 | \keyword{internal} 24 | -------------------------------------------------------------------------------- /man/h_df_md_sat.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/satterthwaite.R 3 | \name{h_df_md_sat} 4 | \alias{h_df_md_sat} 5 | \title{Calculation of Satterthwaite Degrees of Freedom for Multi-Dimensional Contrast} 6 | \usage{ 7 | h_df_md_sat(object, contrast) 8 | } 9 | \arguments{ 10 | \item{object}{(\code{mmrm})\cr the MMRM fit.} 11 | 12 | \item{contrast}{(\code{matrix})\cr numeric contrast matrix, if given a \code{numeric} 13 | then this is coerced to a row vector. Note that this should not include 14 | elements for singular coefficient estimates, i.e. only refer to the 15 | actually estimated coefficients.} 16 | } 17 | \value{ 18 | List with \code{num_df}, \code{denom_df}, \code{f_stat} and \code{p_val} (2-sided p-value). 19 | } 20 | \description{ 21 | Used in \code{\link[=df_md]{df_md()}} if method is "Satterthwaite". 22 | } 23 | \keyword{internal} 24 | -------------------------------------------------------------------------------- /man/h_df_min_bw.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/between-within.R 3 | \name{h_df_min_bw} 4 | \alias{h_df_min_bw} 5 | \title{Assign Minimum Degrees of Freedom Given Involved Coefficients} 6 | \usage{ 7 | h_df_min_bw(bw_calc, is_coef_involved) 8 | } 9 | \arguments{ 10 | \item{bw_calc}{(\code{list})\cr from \code{\link[=h_df_bw_calc]{h_df_bw_calc()}}.} 11 | 12 | \item{is_coef_involved}{(\code{logical})\cr whether each coefficient is involved 13 | in the contrast.} 14 | } 15 | \value{ 16 | The minimum of the degrees of freedom assigned to each involved 17 | coefficient according to its between-within categorization. 18 | } 19 | \description{ 20 | Used in \code{\link[=h_df_1d_bw]{h_df_1d_bw()}} and \code{\link[=h_df_md_bw]{h_df_md_bw()}}. 21 | } 22 | \keyword{internal} 23 | -------------------------------------------------------------------------------- /man/h_df_to_tibble.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tidiers.R 3 | \name{h_df_to_tibble} 4 | \alias{h_df_to_tibble} 5 | \title{Coerce a Data Frame to a \code{tibble}} 6 | \usage{ 7 | h_df_to_tibble(data) 8 | } 9 | \arguments{ 10 | \item{data}{(\code{data.frame})\cr what to coerce.} 11 | } 12 | \value{ 13 | The \code{data} as a \code{tibble}, potentially with a \code{.rownames} column. 14 | } 15 | \description{ 16 | This is used in \code{\link[=h_newdata_add_pred]{h_newdata_add_pred()}}. 17 | } 18 | \details{ 19 | This is only a thin wrapper around \code{\link[tibble:as_tibble]{tibble::as_tibble()}}, except 20 | giving a useful error message and it checks for \code{rownames} and adds them 21 | as a new column \code{.rownames} if they are not just a numeric sequence as 22 | per the \code{\link[tibble:rownames]{tibble::has_rownames()}} decision. 23 | } 24 | \keyword{internal} 25 | -------------------------------------------------------------------------------- /man/h_drop_covariance_terms.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils-formula.R 3 | \name{h_drop_covariance_terms} 4 | \alias{h_drop_covariance_terms} 5 | \title{Drop Formula Terms used for Covariance Structure Definition} 6 | \usage{ 7 | h_drop_covariance_terms(f) 8 | } 9 | \arguments{ 10 | \item{f}{(\code{formula})\cr a formula from which covariance terms should be 11 | dropped.} 12 | } 13 | \value{ 14 | The formula without accepted covariance terms. 15 | } 16 | \description{ 17 | Drop Formula Terms used for Covariance Structure Definition 18 | } 19 | \details{ 20 | \code{terms} is used and it will preserve the environment attribute. 21 | This ensures the returned formula and the input formula have the same environment. 22 | } 23 | \keyword{internal} 24 | -------------------------------------------------------------------------------- /man/h_drop_levels.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{h_drop_levels} 4 | \alias{h_drop_levels} 5 | \title{Drop Levels from Dataset} 6 | \usage{ 7 | h_drop_levels(data, subject_var, visit_var, except) 8 | } 9 | \arguments{ 10 | \item{data}{(\code{data.frame}) data to drop levels.} 11 | 12 | \item{subject_var}{(\code{character}) subject variable.} 13 | 14 | \item{visit_var}{(\code{character}) visit variable.} 15 | 16 | \item{except}{(\code{character}) variables to exclude from dropping.} 17 | } 18 | \description{ 19 | Drop Levels from Dataset 20 | } 21 | \keyword{internal} 22 | -------------------------------------------------------------------------------- /man/h_extra_levels.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{h_extra_levels} 4 | \alias{h_extra_levels} 5 | \title{Check if a Factor Should Drop Levels} 6 | \usage{ 7 | h_extra_levels(x) 8 | } 9 | \arguments{ 10 | \item{x}{(\code{vector}) vector to check.} 11 | } 12 | \description{ 13 | Check if a Factor Should Drop Levels 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/h_extract_covariance_terms.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils-formula.R 3 | \name{h_extract_covariance_terms} 4 | \alias{h_extract_covariance_terms} 5 | \title{Extract Formula Terms used for Covariance Structure Definition} 6 | \usage{ 7 | h_extract_covariance_terms(f) 8 | } 9 | \arguments{ 10 | \item{f}{(\code{formula})\cr a formula from which covariance terms should be 11 | extracted.} 12 | } 13 | \value{ 14 | A list of covariance structure expressions found in \code{f}. 15 | } 16 | \description{ 17 | Extract Formula Terms used for Covariance Structure Definition 18 | } 19 | \keyword{internal} 20 | -------------------------------------------------------------------------------- /man/h_first_contain_categorical.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/interop-car.R 3 | \name{h_first_contain_categorical} 4 | \alias{h_first_contain_categorical} 5 | \title{Check if the Effect is the First Categorical Effect} 6 | \usage{ 7 | h_first_contain_categorical(effect, factors, categorical) 8 | } 9 | \arguments{ 10 | \item{effect}{(\code{string}) name of the effect.} 11 | 12 | \item{factors}{(\code{matrix}) the factor matrix.} 13 | 14 | \item{categorical}{(\code{character}) names of the categorical values.} 15 | } 16 | \description{ 17 | Check if the Effect is the First Categorical Effect 18 | } 19 | \keyword{internal} 20 | -------------------------------------------------------------------------------- /man/h_get_contrast.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/interop-car.R 3 | \name{h_get_contrast} 4 | \alias{h_get_contrast} 5 | \title{Obtain Contrast for Specified Effect} 6 | \usage{ 7 | h_get_contrast( 8 | object, 9 | effect, 10 | type = c("II", "III", "2", "3"), 11 | tol = sqrt(.Machine$double.eps) 12 | ) 13 | } 14 | \arguments{ 15 | \item{object}{(\code{mmrm})\cr the fitted MMRM.} 16 | 17 | \item{effect}{(\code{string}) the name of the effect.} 18 | 19 | \item{type}{(\code{string}) type of test, "II", "III", '2', or '3'.} 20 | 21 | \item{tol}{(\code{numeric}) threshold blow which values are treated as 0.} 22 | } 23 | \value{ 24 | A \code{matrix} of the contrast. 25 | } 26 | \description{ 27 | This is support function to obtain contrast matrix for type II/III testing. 28 | } 29 | \keyword{internal} 30 | -------------------------------------------------------------------------------- /man/h_get_cov_default.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{h_get_cov_default} 4 | \alias{h_get_cov_default} 5 | \title{Obtain Default Covariance Method} 6 | \usage{ 7 | h_get_cov_default( 8 | method = c("Satterthwaite", "Kenward-Roger", "Residual", "Between-Within") 9 | ) 10 | } 11 | \arguments{ 12 | \item{method}{(\code{string})\cr degrees of freedom method.} 13 | } 14 | \value{ 15 | String of the default covariance method. 16 | } 17 | \description{ 18 | Obtain the default covariance method depending on 19 | the degrees of freedom method used. 20 | } 21 | \details{ 22 | The default covariance method is different for different degrees of freedom method. 23 | For "Satterthwaite" or "Between-Within", "Asymptotic" is returned. 24 | For "Kenward-Roger" only, "Kenward-Roger" is returned. 25 | For "Residual" only, "Empirical" is returned. 26 | } 27 | \keyword{internal} 28 | -------------------------------------------------------------------------------- /man/h_get_empirical.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/empirical.R 3 | \name{h_get_empirical} 4 | \alias{h_get_empirical} 5 | \title{Obtain Empirical/Jackknife/Bias-Reduced Covariance} 6 | \usage{ 7 | h_get_empirical(tmb_data, theta, beta, beta_vcov, type) 8 | } 9 | \arguments{ 10 | \item{tmb_data}{(\code{mmrm_tmb_data})\cr produced by \code{\link[=h_mmrm_tmb_data]{h_mmrm_tmb_data()}}.} 11 | 12 | \item{theta}{(\code{numeric})\cr theta estimate.} 13 | 14 | \item{beta}{(\code{numeric})\cr beta estimate.} 15 | 16 | \item{beta_vcov}{(\code{matrix})\cr covariance of beta estimate.} 17 | 18 | \item{type}{(\code{string})\cr type of empirical method, including "Empirical", "Empirical-Jackknife" 19 | and "Empirical-Bias-Reduced".} 20 | } 21 | \value{ 22 | Named list with elements: 23 | \itemize{ 24 | \item \code{cov}: \code{matrix} empirical covariance. 25 | \item \code{g_mat}: \code{matrix} to calculate Satterthwaite degrees of freedom. 26 | } 27 | } 28 | \description{ 29 | Obtain the empirical or Jackknife covariance for \eqn{\beta}. 30 | Used in \code{mmrm} fitting if method is "Empirical", "Empirical-Jackknife" or 31 | "Empirical-Bias-Reduced". 32 | } 33 | \note{ 34 | This function used to return \code{df_mat}, which was equivalent to \code{crossproduct(g_mat)}. However, 35 | executing the cross product in C++ was a costly matrix multiplication, in particular when the number of coefficients 36 | and/or the number of subjects was large. Therefore this is now avoided and \code{g_mat} is returned instead. 37 | } 38 | \keyword{internal} 39 | -------------------------------------------------------------------------------- /man/h_get_index.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/interop-car.R 3 | \name{h_get_index} 4 | \alias{h_get_index} 5 | \title{Test if the First Vector is Subset of the Second Vector} 6 | \usage{ 7 | h_get_index(x, y) 8 | } 9 | \arguments{ 10 | \item{x}{(\code{vector}) the first list.} 11 | 12 | \item{y}{(\code{vector}) the second list.} 13 | } 14 | \description{ 15 | Test if the First Vector is Subset of the Second Vector 16 | } 17 | \keyword{internal} 18 | -------------------------------------------------------------------------------- /man/h_get_kr_comp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/kenwardroger.R 3 | \name{h_get_kr_comp} 4 | \alias{h_get_kr_comp} 5 | \title{Obtain Kenward-Roger Adjustment Components} 6 | \usage{ 7 | h_get_kr_comp(tmb_data, theta) 8 | } 9 | \arguments{ 10 | \item{tmb_data}{(\code{mmrm_tmb_data})\cr produced by \code{\link[=h_mmrm_tmb_data]{h_mmrm_tmb_data()}}.} 11 | 12 | \item{theta}{(\code{numeric})\cr theta estimate.} 13 | } 14 | \value{ 15 | Named list with elements: 16 | \itemize{ 17 | \item \code{P}: \code{matrix} of \eqn{P} component. 18 | \item \code{Q}: \code{matrix} of \eqn{Q} component. 19 | \item \code{R}: \code{matrix} of \eqn{R} component. 20 | } 21 | } 22 | \description{ 23 | Obtains the components needed downstream for the computation of Kenward-Roger degrees of freedom. 24 | Used in \code{\link[=mmrm]{mmrm()}} fitting if method is "Kenward-Roger". 25 | } 26 | \details{ 27 | the function returns a named list, \eqn{P}, \eqn{Q} and \eqn{R}, which corresponds to the 28 | paper in 1997. The matrices are stacked in columns so that \eqn{P}, \eqn{Q} and \eqn{R} has the same 29 | column number(number of beta parameters). The number of rows, is dependent on 30 | the total number of theta and number of groups, if the fit is a grouped mmrm. 31 | For \eqn{P} matrix, it is stacked sequentially. For \eqn{Q} and \eqn{R} matrix, it is stacked so 32 | that the \eqn{Q_{ij}} and \eqn{R_{ij}} is stacked from \eqn{j} then to \eqn{i}, i.e. \eqn{R_{i1}}, \eqn{R_{i2}}, etc. 33 | \eqn{Q} and \eqn{R} only contains intra-group results and inter-group results should be all zero matrices 34 | so they are not stacked in the result. 35 | } 36 | \keyword{internal} 37 | -------------------------------------------------------------------------------- /man/h_get_na_action.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{h_get_na_action} 4 | \alias{h_get_na_action} 5 | \title{Obtain \code{na.action} as Function} 6 | \usage{ 7 | h_get_na_action(na_action) 8 | } 9 | \description{ 10 | Obtain \code{na.action} as Function 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/h_get_optimizers.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{h_get_optimizers} 4 | \alias{h_get_optimizers} 5 | \title{Obtain Optimizer according to Optimizer String Value} 6 | \usage{ 7 | h_get_optimizers( 8 | optimizer = c("L-BFGS-B", "BFGS", "CG", "nlminb"), 9 | optimizer_fun = h_optimizer_fun(optimizer), 10 | optimizer_args = list(), 11 | optimizer_control = list() 12 | ) 13 | } 14 | \arguments{ 15 | \item{optimizer}{(\code{character})\cr names of built-in optimizers to try, subset 16 | of "L-BFGS-B", "BFGS", "CG" and "nlminb".} 17 | 18 | \item{optimizer_fun}{(\code{function} or \code{list} of \code{function})\cr alternatively to \code{optimizer}, 19 | an optimizer function or a list of optimizer functions can be passed directly here.} 20 | 21 | \item{optimizer_args}{(\code{list})\cr additional arguments for \code{optimizer_fun}.} 22 | 23 | \item{optimizer_control}{(\code{list})\cr passed to argument \code{control} in \code{optimizer_fun}.} 24 | } 25 | \value{ 26 | Named \code{list} of optimizers created by \code{\link[=h_partial_fun_args]{h_partial_fun_args()}}. 27 | } 28 | \description{ 29 | This function creates optimizer functions with arguments. 30 | } 31 | \details{ 32 | If you want to use only the built-in optimizers: 33 | \itemize{ 34 | \item \code{optimizer} is a shortcut to create a list of built-in optimizer functions 35 | passed to \code{optimizer_fun}. 36 | \item Allowed are "L-BFGS-B", "BFGS", "CG" (using \code{\link[stats:optim]{stats::optim()}} with corresponding method) 37 | and "nlminb" (using \code{\link[stats:nlminb]{stats::nlminb()}}). 38 | \item Other arguments should go into \code{optimizer_args}. 39 | } 40 | 41 | If you want to use your own optimizer function: 42 | \itemize{ 43 | \item Make sure that there are three arguments: parameter (start value), objective function 44 | and gradient function are sequentially in the function arguments. 45 | \item If there are other named arguments in front of these, make sure they are correctly 46 | specified through \code{optimizer_args}. 47 | \item If the hessian can be used, please make sure its argument name is \code{hessian} and 48 | please add attribute \code{use_hessian = TRUE} to the function, 49 | using \verb{attr(fun, "use_hessian) <- TRUE}. 50 | } 51 | } 52 | \keyword{internal} 53 | -------------------------------------------------------------------------------- /man/h_get_prediction.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tmb-methods.R 3 | \name{h_get_prediction} 4 | \alias{h_get_prediction} 5 | \title{Get Prediction} 6 | \usage{ 7 | h_get_prediction(tmb_data, theta, beta, beta_vcov) 8 | } 9 | \arguments{ 10 | \item{tmb_data}{(\code{mmrm_tmb_data})\cr object.} 11 | 12 | \item{theta}{(\code{numeric})\cr theta value.} 13 | 14 | \item{beta}{(\code{numeric})\cr beta value.} 15 | 16 | \item{beta_vcov}{(\code{matrix})\cr beta_vcov matrix.} 17 | } 18 | \value{ 19 | List with: 20 | \itemize{ 21 | \item \code{prediction}: Matrix with columns \code{fit}, \code{conf_var}, and \code{var}. 22 | \item \code{covariance}: List with subject specific covariance matrices. 23 | \item \code{index}: List of zero-based subject indices. 24 | } 25 | } 26 | \description{ 27 | Get predictions with given \code{data}, \code{theta}, \code{beta}, \code{beta_vcov}. 28 | } 29 | \details{ 30 | See \code{predict} function in \code{predict.cpp} which is called internally. 31 | } 32 | \keyword{internal} 33 | -------------------------------------------------------------------------------- /man/h_get_prediction_variance.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tmb-methods.R 3 | \name{h_get_prediction_variance} 4 | \alias{h_get_prediction_variance} 5 | \title{Get Prediction Variance} 6 | \usage{ 7 | h_get_prediction_variance(object, nsim, tmb_data) 8 | } 9 | \arguments{ 10 | \item{object}{(\code{mmrm_tmb})\cr the fitted MMRM.} 11 | 12 | \item{nsim}{(\code{count})\cr number of samples.} 13 | 14 | \item{tmb_data}{(\code{mmrm_tmb_data})\cr object.} 15 | } 16 | \description{ 17 | Get prediction variance with given fit, \code{tmb_data} with the Monte Carlo sampling method. 18 | } 19 | \keyword{internal} 20 | -------------------------------------------------------------------------------- /man/h_get_sim_per_subj.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tmb-methods.R 3 | \name{h_get_sim_per_subj} 4 | \alias{h_get_sim_per_subj} 5 | \title{Get simulated values by patient.} 6 | \usage{ 7 | h_get_sim_per_subj(predict_res, nsub, nsim) 8 | } 9 | \arguments{ 10 | \item{predict_res}{(\code{list})\cr from \code{\link[=h_get_prediction]{h_get_prediction()}}.} 11 | 12 | \item{nsub}{(\code{count})\cr number of subjects.} 13 | 14 | \item{nsim}{(\code{count})\cr number of values to simulate.} 15 | } 16 | \description{ 17 | Get simulated values by patient. 18 | } 19 | \keyword{internal} 20 | -------------------------------------------------------------------------------- /man/h_get_theta_from_cov.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{h_get_theta_from_cov} 4 | \alias{h_get_theta_from_cov} 5 | \title{Obtain Theta from Covariance Matrix} 6 | \usage{ 7 | h_get_theta_from_cov(covariance) 8 | } 9 | \arguments{ 10 | \item{covariance}{(\code{matrix}) of covariance matrix values.} 11 | } 12 | \value{ 13 | Numeric vector of the theta values. 14 | } 15 | \description{ 16 | Obtain unstructured theta from covariance matrix. 17 | } 18 | \details{ 19 | If the covariance matrix has \code{NA} in some of the elements, they will be replaced by 20 | 0 (non-diagonal) and 1 (diagonal). This ensures that the matrix is positive definite. 21 | } 22 | \keyword{internal} 23 | -------------------------------------------------------------------------------- /man/h_gradient.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/satterthwaite.R 3 | \name{h_gradient} 4 | \alias{h_gradient} 5 | \title{Computation of a Gradient Given Jacobian and Contrast Vector} 6 | \usage{ 7 | h_gradient(jac_list, contrast) 8 | } 9 | \arguments{ 10 | \item{jac_list}{(\code{list})\cr Jacobian list produced e.g. by \code{\link[=h_jac_list]{h_jac_list()}}.} 11 | 12 | \item{contrast}{(\code{numeric})\cr contrast vector, which needs to have the 13 | same number of elements as there are rows and columns in each element of 14 | \code{jac_list}.} 15 | } 16 | \value{ 17 | Numeric vector which contains the quadratic forms of each element of 18 | \code{jac_list} with the \code{contrast} vector. 19 | } 20 | \description{ 21 | Computes the gradient of a linear combination of \code{beta} given the Jacobian matrix and 22 | variance parameters. 23 | } 24 | \keyword{internal} 25 | -------------------------------------------------------------------------------- /man/h_jac_list.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/satterthwaite.R 3 | \name{h_jac_list} 4 | \alias{h_jac_list} 5 | \title{Obtain List of Jacobian Matrix Entries for Covariance Matrix} 6 | \usage{ 7 | h_jac_list(tmb_data, theta_est, beta_vcov) 8 | } 9 | \arguments{ 10 | \item{tmb_data}{(\code{mmrm_tmb_data})\cr produced by \code{\link[=h_mmrm_tmb_data]{h_mmrm_tmb_data()}}.} 11 | 12 | \item{theta_est}{(\code{numeric})\cr variance parameters point estimate.} 13 | 14 | \item{beta_vcov}{(\code{matrix})\cr vairance covariance matrix of coefficients.} 15 | } 16 | \value{ 17 | List with one element per variance parameter containing a matrix 18 | of the same dimensions as the covariance matrix. The values are the derivatives 19 | with regards to this variance parameter. 20 | } 21 | \description{ 22 | Obtain the Jacobian matrices given the covariance function and variance parameters. 23 | } 24 | \keyword{internal} 25 | -------------------------------------------------------------------------------- /man/h_kr_df.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/kenwardroger.R 3 | \name{h_kr_df} 4 | \alias{h_kr_df} 5 | \title{Obtain the Adjusted Kenward-Roger degrees of freedom} 6 | \usage{ 7 | h_kr_df(v0, l, w, p) 8 | } 9 | \arguments{ 10 | \item{v0}{(\code{matrix})\cr unadjusted covariance matrix.} 11 | 12 | \item{l}{(\code{matrix})\cr linear combination matrix.} 13 | 14 | \item{w}{(\code{matrix})\cr hessian matrix.} 15 | 16 | \item{p}{(\code{matrix})\cr P matrix from \code{\link[=h_get_kr_comp]{h_get_kr_comp()}}.} 17 | } 18 | \value{ 19 | Named list with elements: 20 | \itemize{ 21 | \item \code{m}: \code{numeric} degrees of freedom. 22 | \item \code{lambda}: \code{numeric} F statistic scale parameter. 23 | } 24 | } 25 | \description{ 26 | Obtains the adjusted Kenward-Roger degrees of freedom and F statistic scale parameter. 27 | Used in \code{\link[=h_df_md_kr]{h_df_md_kr()}} or \link{h_df_1d_kr}. 28 | } 29 | \keyword{internal} 30 | -------------------------------------------------------------------------------- /man/h_md_denom_df.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/satterthwaite.R 3 | \name{h_md_denom_df} 4 | \alias{h_md_denom_df} 5 | \title{Calculating Denominator Degrees of Freedom for the Multi-Dimensional Case} 6 | \usage{ 7 | h_md_denom_df(t_stat_df) 8 | } 9 | \arguments{ 10 | \item{t_stat_df}{(\code{numeric})\cr \code{n} t-statistic derived degrees of freedom.} 11 | } 12 | \value{ 13 | Usually the calculation is returning \code{2 * E / (E - n)} where 14 | \code{E} is the sum of \code{t / (t - 2)} over all \code{t_stat_df} values \code{t}. 15 | } 16 | \description{ 17 | Calculates the degrees of freedom for multi-dimensional contrast. 18 | } 19 | \note{ 20 | If the input values are two similar to each other then just the average 21 | of them is returned. If any of the inputs is not larger than 2 then 2 is 22 | returned. 23 | } 24 | \keyword{internal} 25 | -------------------------------------------------------------------------------- /man/h_mmrm_tmb_assert_start.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tmb.R 3 | \name{h_mmrm_tmb_assert_start} 4 | \alias{h_mmrm_tmb_assert_start} 5 | \title{Asserting Sane Start Values for \code{TMB} Fit} 6 | \usage{ 7 | h_mmrm_tmb_assert_start(tmb_object) 8 | } 9 | \arguments{ 10 | \item{tmb_object}{(\code{list})\cr created with \code{\link[TMB:MakeADFun]{TMB::MakeADFun()}}.} 11 | } 12 | \value{ 13 | Nothing, only used for assertions. 14 | } 15 | \description{ 16 | Asserting Sane Start Values for \code{TMB} Fit 17 | } 18 | \keyword{internal} 19 | -------------------------------------------------------------------------------- /man/h_mmrm_tmb_check_conv.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tmb.R 3 | \name{h_mmrm_tmb_check_conv} 4 | \alias{h_mmrm_tmb_check_conv} 5 | \title{Checking the \code{TMB} Optimization Result} 6 | \usage{ 7 | h_mmrm_tmb_check_conv(tmb_opt, mmrm_tmb) 8 | } 9 | \arguments{ 10 | \item{tmb_opt}{(\code{list})\cr optimization result.} 11 | 12 | \item{mmrm_tmb}{(\code{mmrm_tmb})\cr result from \code{\link[=h_mmrm_tmb_fit]{h_mmrm_tmb_fit()}}.} 13 | } 14 | \value{ 15 | Nothing, only used to generate warnings in case that the model 16 | did not converge. 17 | } 18 | \description{ 19 | Checking the \code{TMB} Optimization Result 20 | } 21 | \keyword{internal} 22 | -------------------------------------------------------------------------------- /man/h_mmrm_tmb_extract_cov.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tmb.R 3 | \name{h_mmrm_tmb_extract_cov} 4 | \alias{h_mmrm_tmb_extract_cov} 5 | \title{Extract covariance matrix from \code{TMB} report and input data} 6 | \usage{ 7 | h_mmrm_tmb_extract_cov(tmb_report, tmb_data, visit_var, is_spatial) 8 | } 9 | \arguments{ 10 | \item{tmb_report}{(\code{list})\cr report created with \code{\link[TMB:MakeADFun]{TMB::MakeADFun()}} report function.} 11 | 12 | \item{tmb_data}{(\code{mmrm_tmb_data})\cr produced by \code{\link[=h_mmrm_tmb_data]{h_mmrm_tmb_data()}}.} 13 | 14 | \item{visit_var}{(\code{character})\cr character vector of the visit variable} 15 | 16 | \item{is_spatial}{(\code{flag})\cr indicator whether the covariance structure is spatial.} 17 | } 18 | \value{ 19 | Return a simple covariance matrix if there is no grouping, or a named 20 | list of estimated grouped covariance matrices, 21 | with its name equal to the group levels. 22 | } 23 | \description{ 24 | This helper does some simple post-processing to extract covariance matrix or named 25 | list of covariance matrices if the fitting is using grouped covariance matrices. 26 | } 27 | \keyword{internal} 28 | -------------------------------------------------------------------------------- /man/h_mmrm_tmb_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tmb.R 3 | \name{h_mmrm_tmb_fit} 4 | \alias{h_mmrm_tmb_fit} 5 | \title{Build \code{TMB} Fit Result List} 6 | \usage{ 7 | h_mmrm_tmb_fit(tmb_object, tmb_opt, formula_parts, tmb_data) 8 | } 9 | \arguments{ 10 | \item{tmb_object}{(\code{list})\cr created with \code{\link[TMB:MakeADFun]{TMB::MakeADFun()}}.} 11 | 12 | \item{tmb_opt}{(\code{list})\cr optimization result.} 13 | 14 | \item{formula_parts}{(\code{mmrm_tmb_formula_parts})\cr produced by 15 | \code{\link[=h_mmrm_tmb_formula_parts]{h_mmrm_tmb_formula_parts()}}.} 16 | 17 | \item{tmb_data}{(\code{mmrm_tmb_data})\cr produced by \code{\link[=h_mmrm_tmb_data]{h_mmrm_tmb_data()}}.} 18 | } 19 | \value{ 20 | List of class \code{mmrm_tmb} with: 21 | \itemize{ 22 | \item \code{cov}: estimated covariance matrix, or named list of estimated group specific covariance matrices. 23 | \item \code{beta_est}: vector of coefficient estimates. 24 | \item \code{beta_vcov}: Variance-covariance matrix for coefficient estimates. 25 | \item \code{beta_vcov_inv_L}: Lower triangular matrix \code{L} of the inverse variance-covariance matrix decomposition. 26 | \item \code{beta_vcov_inv_D}: vector of diagonal matrix \code{D} of the inverse variance-covariance matrix decomposition. 27 | \item \code{theta_est}: vector of variance parameter estimates. 28 | \item \code{theta_vcov}: variance-covariance matrix for variance parameter estimates. 29 | \item \code{neg_log_lik}: obtained negative log-likelihood. 30 | \item \code{formula_parts}: input. 31 | \item \code{data}: input. 32 | \item \code{weights}: input. 33 | \item \code{reml}: input as a flag. 34 | \item \code{opt_details}: list with optimization details including convergence code. 35 | \item \code{tmb_object}: original \code{TMB} object created with \code{\link[TMB:MakeADFun]{TMB::MakeADFun()}}. 36 | \item \code{tmb_data}: input. 37 | } 38 | } 39 | \description{ 40 | This helper does some simple post-processing of the \code{TMB} object and 41 | optimization results, including setting names, inverting matrices etc. 42 | } 43 | \details{ 44 | Instead of inverting or decomposing \code{beta_vcov}, it can be more efficient to use its robust 45 | Cholesky decomposition \code{LDL^T}, therefore we return the corresponding two components \code{L} and \code{D} 46 | as well since they have been available on the \verb{C++} side already. 47 | } 48 | \keyword{internal} 49 | -------------------------------------------------------------------------------- /man/h_mmrm_tmb_formula_parts.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tmb.R 3 | \name{h_mmrm_tmb_formula_parts} 4 | \alias{h_mmrm_tmb_formula_parts} 5 | \title{Processing the Formula for \code{TMB} Fit} 6 | \usage{ 7 | h_mmrm_tmb_formula_parts( 8 | formula, 9 | covariance = as.cov_struct(formula, warn_partial = FALSE) 10 | ) 11 | } 12 | \arguments{ 13 | \item{formula}{(\code{formula})\cr Original formula.} 14 | 15 | \item{covariance}{(\code{cov_struct})\cr A covariance structure from which 16 | additional formula parts should be added.} 17 | } 18 | \value{ 19 | List of class \code{mmrm_tmb_formula_parts} with elements: 20 | \itemize{ 21 | \item \code{formula}: the original input. 22 | \item \code{model_formula}: \code{formula} with the covariance term is removed. 23 | \item \code{model_formula}: \code{formula} with the covariance term removed. 24 | \item \code{full_formula}: same as \code{model_formula} but includes the covariance 25 | structure's subject, visit and (optionally) group variables. 26 | \item \code{cov_type}: \code{string} with covariance term type (e.g. \code{"us"}). 27 | \item \code{is_spatial}: \code{flag} indicator of whether the covariance structure is 28 | spatial 29 | \item \code{visit_var}: \code{character} with the visit variable name. 30 | \item \code{subject_var}: \code{string} with the subject variable name. 31 | \item \code{group_var}: \code{string} with the group variable name. If no group specified, 32 | this element is \code{NULL}. 33 | \item \code{model_var}: \code{character} with the variables names of the formula, except \code{subject_var}. 34 | } 35 | } 36 | \description{ 37 | Processing the Formula for \code{TMB} Fit 38 | } 39 | \keyword{internal} 40 | -------------------------------------------------------------------------------- /man/h_mmrm_tmb_parameters.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tmb.R 3 | \name{h_mmrm_tmb_parameters} 4 | \alias{h_mmrm_tmb_parameters} 5 | \title{Start Parameters for \code{TMB} Fit} 6 | \usage{ 7 | h_mmrm_tmb_parameters(formula_parts, tmb_data, start, n_groups = 1L) 8 | } 9 | \arguments{ 10 | \item{formula_parts}{(\code{mmrm_tmb_formula_parts})\cr produced by 11 | \code{\link[=h_mmrm_tmb_formula_parts]{h_mmrm_tmb_formula_parts()}}.} 12 | 13 | \item{tmb_data}{(\code{mmrm_tmb_data})\cr produced by \code{\link[=h_mmrm_tmb_data]{h_mmrm_tmb_data()}}.} 14 | 15 | \item{start}{(\code{numeric} or \code{NULL})\cr optional start values for variance 16 | parameters.} 17 | 18 | \item{n_groups}{(\code{int})\cr number of groups.} 19 | } 20 | \value{ 21 | List with element \code{theta} containing the start values for the variance 22 | parameters. 23 | } 24 | \description{ 25 | Start Parameters for \code{TMB} Fit 26 | } 27 | \keyword{internal} 28 | -------------------------------------------------------------------------------- /man/h_newdata_add_pred.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tidiers.R 3 | \name{h_newdata_add_pred} 4 | \alias{h_newdata_add_pred} 5 | \title{Add Prediction Results to New Data} 6 | \usage{ 7 | h_newdata_add_pred(x, newdata, se_fit, interval, ...) 8 | } 9 | \arguments{ 10 | \item{x}{(\code{mmrm})\cr fit.} 11 | 12 | \item{newdata}{(\code{data.frame})\cr data to predict.} 13 | 14 | \item{se_fit}{(\code{flag})\cr whether to return standard error of prediction, 15 | can only be used when \code{interval} is not "none".} 16 | 17 | \item{interval}{(\code{string})\cr type of interval.} 18 | 19 | \item{...}{passed to \code{\link[=predict.mmrm_tmb]{predict.mmrm_tmb()}}.} 20 | } 21 | \value{ 22 | The \code{newdata} as a \code{tibble} with additional columns \code{.fitted}, 23 | \code{.lower}, \code{.upper} (if interval is not \code{none}) and \code{.se.fit} (if \code{se_fit} 24 | requested). 25 | } 26 | \description{ 27 | This is used in \code{\link[=augment.mmrm]{augment.mmrm()}}. 28 | } 29 | \keyword{internal} 30 | -------------------------------------------------------------------------------- /man/h_obtain_lvls.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/interop-car.R 3 | \name{h_obtain_lvls} 4 | \alias{h_obtain_lvls} 5 | \title{Obtain Levels Prior and Posterior} 6 | \usage{ 7 | h_obtain_lvls(var, additional_vars, xlev, factors) 8 | } 9 | \arguments{ 10 | \item{var}{(\code{string}) name of the effect.} 11 | 12 | \item{additional_vars}{(\code{character}) names of additional variables.} 13 | 14 | \item{xlev}{(\code{list}) named list of character levels.} 15 | 16 | \item{factors}{(\code{matrix}) the factor matrix.} 17 | } 18 | \description{ 19 | Obtain Levels Prior and Posterior 20 | } 21 | \keyword{internal} 22 | -------------------------------------------------------------------------------- /man/h_optimizer_fun.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{h_optimizer_fun} 4 | \alias{h_optimizer_fun} 5 | \title{Obtain Optimizer Function with Character} 6 | \usage{ 7 | h_optimizer_fun(optimizer = c("L-BFGS-B", "BFGS", "CG", "nlminb")) 8 | } 9 | \arguments{ 10 | \item{optimizer}{(\code{character})\cr vector of optimizers.} 11 | } 12 | \value{ 13 | A (\code{list})\cr of optimizer functions generated from \code{\link[=h_partial_fun_args]{h_partial_fun_args()}}. 14 | } 15 | \description{ 16 | Obtain the optimizer function through the character provided. 17 | } 18 | \keyword{internal} 19 | -------------------------------------------------------------------------------- /man/h_partial_fun_args.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{h_partial_fun_args} 4 | \alias{h_partial_fun_args} 5 | \title{Create Partial Functions} 6 | \usage{ 7 | h_partial_fun_args(fun, ..., additional_attr = list()) 8 | } 9 | \arguments{ 10 | \item{fun}{(\code{function})\cr to be wrapped.} 11 | 12 | \item{...}{Additional arguments for \code{fun}.} 13 | 14 | \item{additional_attr}{(\code{list})\cr of additional attributes to apply to the result.} 15 | } 16 | \value{ 17 | Object with S3 class \code{"partial"}, a \code{function} with \code{args} attribute (and possibly more 18 | attributes from \code{additional_attr}). 19 | } 20 | \description{ 21 | Creates partial functions with arguments. 22 | } 23 | \details{ 24 | This function add \code{args} attribute to the original function, 25 | and add an extra class \code{partial} to the function. 26 | \code{args} is the argument for the function, and elements in \code{...} will override the existing 27 | arguments in attribute \code{args}. \code{additional_attr} will override the existing attributes. 28 | } 29 | \keyword{internal} 30 | -------------------------------------------------------------------------------- /man/h_print_aic_list.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mmrm-methods.R 3 | \name{h_print_aic_list} 4 | \alias{h_print_aic_list} 5 | \title{Printing AIC and other Model Fit Criteria} 6 | \usage{ 7 | h_print_aic_list(aic_list, digits = 1) 8 | } 9 | \arguments{ 10 | \item{aic_list}{(\code{list})\cr list as part of from \code{\link[=summary.mmrm]{summary.mmrm()}}.} 11 | 12 | \item{digits}{(\code{number})\cr number of decimal places used with \code{\link[=round]{round()}}.} 13 | } 14 | \description{ 15 | This is used in \code{\link[=print.summary.mmrm]{print.summary.mmrm()}}. 16 | } 17 | \keyword{internal} 18 | -------------------------------------------------------------------------------- /man/h_print_call.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mmrm-methods.R 3 | \name{h_print_call} 4 | \alias{h_print_call} 5 | \title{Printing MMRM Function Call} 6 | \usage{ 7 | h_print_call(call, n_obs, n_subjects, n_timepoints) 8 | } 9 | \arguments{ 10 | \item{call}{(\code{call})\cr original \code{\link[=mmrm]{mmrm()}} function call.} 11 | 12 | \item{n_obs}{(\code{int})\cr number of observations.} 13 | 14 | \item{n_subjects}{(\code{int})\cr number of subjects.} 15 | 16 | \item{n_timepoints}{(\code{int})\cr number of timepoints.} 17 | } 18 | \description{ 19 | This is used in \code{\link[=print.summary.mmrm]{print.summary.mmrm()}}. 20 | } 21 | \keyword{internal} 22 | -------------------------------------------------------------------------------- /man/h_print_cov.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mmrm-methods.R 3 | \name{h_print_cov} 4 | \alias{h_print_cov} 5 | \title{Printing MMRM Covariance Type} 6 | \usage{ 7 | h_print_cov(cov_type, n_theta, n_groups) 8 | } 9 | \arguments{ 10 | \item{cov_type}{(\code{string})\cr covariance structure abbreviation.} 11 | 12 | \item{n_theta}{(\code{count})\cr number of variance parameters.} 13 | 14 | \item{n_groups}{(\code{count})\cr number of groups.} 15 | } 16 | \description{ 17 | This is used in \code{\link[=print.summary.mmrm]{print.summary.mmrm()}}. 18 | } 19 | \keyword{internal} 20 | -------------------------------------------------------------------------------- /man/h_quad_form.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/satterthwaite.R 3 | \name{h_quad_form} 4 | \alias{h_quad_form} 5 | \alias{h_quad_form_vec} 6 | \alias{h_quad_form_mat} 7 | \title{Quadratic Form Calculations} 8 | \usage{ 9 | h_quad_form_vec(vec, center) 10 | 11 | h_quad_form_mat(mat, center) 12 | } 13 | \arguments{ 14 | \item{vec}{(\code{numeric})\cr interpreted as a row vector.} 15 | 16 | \item{center}{(\code{matrix})\cr square numeric matrix with the same dimensions as 17 | \code{x} as the center of the quadratic form.} 18 | 19 | \item{mat}{(\code{matrix})\cr numeric matrix to be multiplied left and right of 20 | \code{center}, therefore needs to have as many columns as there are rows and columns 21 | in \code{center}.} 22 | } 23 | \description{ 24 | These helpers are mainly for easier readability and slightly better efficiency 25 | of the quadratic forms used in the Satterthwaite calculations. 26 | } 27 | \section{Functions}{ 28 | \itemize{ 29 | \item \code{h_quad_form_vec()}: calculates the number \code{vec \%*\% center \%*\% t(vec)} 30 | as a numeric (not a matrix). 31 | 32 | \item \code{h_quad_form_mat()}: calculates the quadratic form \code{mat \%*\% center \%*\% t(mat)} 33 | as a matrix, the result is square and has dimensions identical to the number 34 | of rows in \code{mat}. 35 | 36 | }} 37 | \keyword{internal} 38 | -------------------------------------------------------------------------------- /man/h_reconcile_cov_struct.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cov_struct.R 3 | \name{h_reconcile_cov_struct} 4 | \alias{h_reconcile_cov_struct} 5 | \title{Reconcile Possible Covariance Structure Inputs} 6 | \usage{ 7 | h_reconcile_cov_struct(formula = NULL, covariance = NULL) 8 | } 9 | \arguments{ 10 | \item{formula}{(\code{formula})\cr the model formula, see details.} 11 | 12 | \item{covariance}{(\code{cov_struct})\cr a covariance structure type definition 13 | as produced with \code{\link[=cov_struct]{cov_struct()}}, or value that can be coerced to a 14 | covariance structure using \code{\link[=as.cov_struct]{as.cov_struct()}}. If no value is provided, 15 | a structure is derived from the provided formula.} 16 | } 17 | \value{ 18 | The value \code{covariance} if it's provided or a covariance structure 19 | derived from the provided \code{formula} otherwise. An error is raised of both 20 | are provided. 21 | } 22 | \description{ 23 | Reconcile Possible Covariance Structure Inputs 24 | } 25 | \keyword{internal} 26 | -------------------------------------------------------------------------------- /man/h_record_all_output.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{h_record_all_output} 4 | \alias{h_record_all_output} 5 | \title{Capture all Output} 6 | \usage{ 7 | h_record_all_output(expr, remove = list(), divergence = list()) 8 | } 9 | \arguments{ 10 | \item{expr}{(\code{expression})\cr to be executed.} 11 | 12 | \item{remove}{(\code{list})\cr optional list with elements \code{warnings}, \code{errors}, 13 | \code{messages} which can be character vectors, which will be removed from the 14 | results if specified.} 15 | 16 | \item{divergence}{(\code{list})\cr optional list similar as \code{remove}, but these 17 | character vectors will be moved to the \code{divergence} result and signal 18 | that the fit did not converge.} 19 | } 20 | \value{ 21 | A list containing 22 | \itemize{ 23 | \item \code{result}: The object returned by \code{expr} or \code{list()} if an error was thrown. 24 | \item \code{warnings}: \code{NULL} or a character vector if warnings were thrown. 25 | \item \code{errors}: \code{NULL} or a string if an error was thrown. 26 | \item \code{messages}: \code{NULL} or a character vector if messages were produced. 27 | \item \code{divergence}: \code{NULL} or a character vector if divergence messages were caught. 28 | } 29 | } 30 | \description{ 31 | This function silences all warnings, errors & messages and instead returns a list 32 | containing the results (if it didn't error), as well as the warnings, errors 33 | and messages and divergence signals as character vectors. 34 | } 35 | \keyword{internal} 36 | -------------------------------------------------------------------------------- /man/h_register_s3.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{h_register_s3} 4 | \alias{h_register_s3} 5 | \title{Register S3 Method 6 | Register S3 method to a generic.} 7 | \usage{ 8 | h_register_s3(pkg, generic, class, envir = parent.frame()) 9 | } 10 | \arguments{ 11 | \item{pkg}{(\code{string}) name of the package name.} 12 | 13 | \item{generic}{(\code{string}) name of the generic.} 14 | 15 | \item{class}{(\code{string}) class name the function want to dispatch.} 16 | 17 | \item{envir}{(\code{environment}) the location the method is defined.} 18 | } 19 | \description{ 20 | Register S3 Method 21 | Register S3 method to a generic. 22 | } 23 | \details{ 24 | This function is adapted from \code{emmeans:::register_s3_method()}. 25 | } 26 | \keyword{internal} 27 | -------------------------------------------------------------------------------- /man/h_residuals_normalized.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tmb-methods.R 3 | \name{h_residuals_normalized} 4 | \alias{h_residuals_normalized} 5 | \title{Calculate normalized residuals} 6 | \usage{ 7 | h_residuals_normalized(object) 8 | } 9 | \arguments{ 10 | \item{object}{(\code{mmrm_tmb})\cr the fitted MMRM.} 11 | } 12 | \value{ 13 | Vector of residuals 14 | } 15 | \description{ 16 | This is used by \code{\link[=residuals.mmrm_tmb]{residuals.mmrm_tmb()}} to calculate normalized / scaled residuals. 17 | } 18 | \keyword{internal} 19 | -------------------------------------------------------------------------------- /man/h_residuals_pearson.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tmb-methods.R 3 | \name{h_residuals_pearson} 4 | \alias{h_residuals_pearson} 5 | \title{Calculate Pearson Residuals} 6 | \usage{ 7 | h_residuals_pearson(object) 8 | } 9 | \arguments{ 10 | \item{object}{(\code{mmrm_tmb})\cr the fitted MMRM.} 11 | } 12 | \value{ 13 | Vector of residuals. 14 | } 15 | \description{ 16 | This is used by \code{\link[=residuals.mmrm_tmb]{residuals.mmrm_tmb()}} to calculate Pearson residuals. 17 | } 18 | \keyword{internal} 19 | -------------------------------------------------------------------------------- /man/h_residuals_response.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tmb-methods.R 3 | \name{h_residuals_response} 4 | \alias{h_residuals_response} 5 | \title{Calculate response residuals.} 6 | \usage{ 7 | h_residuals_response(object) 8 | } 9 | \arguments{ 10 | \item{object}{(\code{mmrm_tmb})\cr the fitted MMRM.} 11 | } 12 | \value{ 13 | Vector of residuals 14 | } 15 | \description{ 16 | This is used by \code{\link[=residuals.mmrm_tmb]{residuals.mmrm_tmb()}} to calculate response residuals. 17 | } 18 | \keyword{internal} 19 | -------------------------------------------------------------------------------- /man/h_split_control.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{h_split_control} 4 | \alias{h_split_control} 5 | \title{Split Control List} 6 | \usage{ 7 | h_split_control(control, ...) 8 | } 9 | \arguments{ 10 | \item{control}{(\code{mmrm_control})\cr object.} 11 | 12 | \item{...}{additional parameters to update the \code{control} object.} 13 | } 14 | \value{ 15 | A \code{list} of \code{mmrm_control} entries. 16 | } 17 | \description{ 18 | Split the \code{\link[=mmrm_control]{mmrm_control()}} object according to its optimizers and use additional arguments 19 | to replace the elements in the original object. 20 | } 21 | \keyword{internal} 22 | -------------------------------------------------------------------------------- /man/h_summarize_all_fits.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fit.R 3 | \name{h_summarize_all_fits} 4 | \alias{h_summarize_all_fits} 5 | \title{Summarizing List of Fits} 6 | \usage{ 7 | h_summarize_all_fits(all_fits) 8 | } 9 | \arguments{ 10 | \item{all_fits}{(\code{list} of \code{mmrm_fit} or \code{try-error})\cr list of fits.} 11 | } 12 | \value{ 13 | List with \code{warnings}, \code{messages}, \code{log_liks} and \code{converged} results. 14 | } 15 | \description{ 16 | Summarizing List of Fits 17 | } 18 | \keyword{internal} 19 | -------------------------------------------------------------------------------- /man/h_tbl_confint_terms.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tidiers.R 3 | \name{h_tbl_confint_terms} 4 | \alias{h_tbl_confint_terms} 5 | \title{Extract \code{tibble} with Confidence Intervals and Term Names} 6 | \usage{ 7 | h_tbl_confint_terms(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{(\code{mmrm})\cr fit object.} 11 | 12 | \item{...}{passed to \code{\link[stats:confint]{stats::confint()}}, hence not used at the moment.} 13 | } 14 | \value{ 15 | A \code{tibble} with \code{term}, \code{conf.low}, \code{conf.high} columns. 16 | } 17 | \description{ 18 | This is used in \code{\link[=tidy.mmrm]{tidy.mmrm()}}. 19 | } 20 | \keyword{internal} 21 | -------------------------------------------------------------------------------- /man/h_test_1d.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/testing.R 3 | \name{h_test_1d} 4 | \alias{h_test_1d} 5 | \title{Creating T-Statistic Test Results For One-Dimensional Contrast} 6 | \usage{ 7 | h_test_1d(object, contrast, df) 8 | } 9 | \arguments{ 10 | \item{object}{(\code{mmrm})\cr the MMRM fit.} 11 | 12 | \item{contrast}{(\code{numeric})\cr contrast vector. Note that this should not include 13 | elements for singular coefficient estimates, i.e. only refer to the 14 | actually estimated coefficients.} 15 | 16 | \item{df}{(\code{number})\cr degrees of freedom for the one-dimensional contrast.} 17 | } 18 | \value{ 19 | List with \code{est}, \code{se}, \code{df}, \code{t_stat} and \code{p_val} (2-sided p-value). 20 | } 21 | \description{ 22 | Creates a list of results for one-dimensional contrasts using 23 | a t-test statistic and the given degrees of freedom. 24 | } 25 | \keyword{internal} 26 | -------------------------------------------------------------------------------- /man/h_test_md.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/testing.R 3 | \name{h_test_md} 4 | \alias{h_test_md} 5 | \title{Creating F-Statistic Test Results For Multi-Dimensional Contrast} 6 | \usage{ 7 | h_test_md(object, contrast, df, f_stat_factor = 1) 8 | } 9 | \arguments{ 10 | \item{object}{(\code{mmrm})\cr the MMRM fit.} 11 | 12 | \item{contrast}{(\code{matrix})\cr numeric contrast matrix.} 13 | 14 | \item{df}{(\code{number})\cr denominator degrees of freedom for the multi-dimensional contrast.} 15 | 16 | \item{f_stat_factor}{(\code{number})\cr optional scaling factor on top of the standard F-statistic.} 17 | } 18 | \value{ 19 | List with \code{num_df}, \code{denom_df}, \code{f_stat} and \code{p_val} (2-sided p-value). 20 | } 21 | \description{ 22 | Creates a list of results for multi-dimensional contrasts using 23 | an F-test statistic and the given degrees of freedom. 24 | } 25 | \keyword{internal} 26 | -------------------------------------------------------------------------------- /man/h_tmb_version_sufficient.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{h_tmb_version_sufficient} 4 | \alias{h_tmb_version_sufficient} 5 | \title{Predicate if the TMB Version Used to Compile the Package is Sufficient} 6 | \usage{ 7 | h_tmb_version_sufficient() 8 | } 9 | \value{ 10 | Flag whether the TMB version is sufficient. 11 | } 12 | \description{ 13 | Predicate if the TMB Version Used to Compile the Package is Sufficient 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/h_tmb_warn_non_deterministic.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{h_tmb_warn_non_deterministic} 4 | \alias{h_tmb_warn_non_deterministic} 5 | \title{Warn if TMB is Configured to Use Non-Deterministic Hash for Tape Optimizer} 6 | \usage{ 7 | h_tmb_warn_non_deterministic() 8 | } 9 | \value{ 10 | No return value, called for side effects. 11 | } 12 | \description{ 13 | This function checks the TMB configuration for the \code{tmbad_deterministic_hash} setting 14 | If it is set to \code{FALSE}, a warning is issued indicating that this may lead to 15 | unreproducible results. 16 | } 17 | \keyword{internal} 18 | -------------------------------------------------------------------------------- /man/h_tr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{h_tr} 4 | \alias{h_tr} 5 | \title{Trace of a Matrix} 6 | \usage{ 7 | h_tr(x) 8 | } 9 | \arguments{ 10 | \item{x}{(\code{matrix})\cr square matrix input.} 11 | } 12 | \value{ 13 | The trace of the square matrix. 14 | } 15 | \description{ 16 | Obtain the trace of a matrix if the matrix is diagonal, otherwise raise an error. 17 | } 18 | \keyword{internal} 19 | -------------------------------------------------------------------------------- /man/h_valid_formula.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{h_valid_formula} 4 | \alias{h_valid_formula} 5 | \title{Validate mmrm Formula} 6 | \usage{ 7 | h_valid_formula(formula) 8 | } 9 | \arguments{ 10 | \item{formula}{(\code{formula})\cr to check.} 11 | } 12 | \description{ 13 | Validate mmrm Formula 14 | } 15 | \details{ 16 | In mmrm models, \code{.} is not allowed as it introduces ambiguity of covariates 17 | to be used, so it is not allowed to be in formula. 18 | } 19 | \keyword{internal} 20 | -------------------------------------------------------------------------------- /man/h_var_adj.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/kenwardroger.R 3 | \name{h_var_adj} 4 | \alias{h_var_adj} 5 | \title{Obtain the Adjusted Covariance Matrix} 6 | \usage{ 7 | h_var_adj(v, w, p, q, r, linear = FALSE) 8 | } 9 | \arguments{ 10 | \item{v}{(\code{matrix})\cr unadjusted covariance matrix.} 11 | 12 | \item{w}{(\code{matrix})\cr hessian matrix.} 13 | 14 | \item{p}{(\code{matrix})\cr P matrix from \code{\link[=h_get_kr_comp]{h_get_kr_comp()}}.} 15 | 16 | \item{q}{(\code{matrix})\cr Q matrix from \code{\link[=h_get_kr_comp]{h_get_kr_comp()}}.} 17 | 18 | \item{r}{(\code{matrix})\cr R matrix from \code{\link[=h_get_kr_comp]{h_get_kr_comp()}}.} 19 | 20 | \item{linear}{(\code{flag})\cr whether to use linear Kenward-Roger approximation.} 21 | } 22 | \value{ 23 | The matrix of adjusted covariance matrix. 24 | } 25 | \description{ 26 | Obtains the Kenward-Roger adjusted covariance matrix for the 27 | coefficient estimates. 28 | Used in \code{\link[=mmrm]{mmrm()}} fitting if method is "Kenward-Roger" or "Kenward-Roger-Linear". 29 | } 30 | \keyword{internal} 31 | -------------------------------------------------------------------------------- /man/h_warn_na_action.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{h_warn_na_action} 4 | \alias{h_warn_na_action} 5 | \title{Warn on na.action} 6 | \usage{ 7 | h_warn_na_action() 8 | } 9 | \description{ 10 | Warn on na.action 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/h_within_or_between.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/between-within.R 3 | \name{h_within_or_between} 4 | \alias{h_within_or_between} 5 | \title{Determine Within or Between for each Design Matrix Column} 6 | \usage{ 7 | h_within_or_between(x_matrix, subject_ids) 8 | } 9 | \arguments{ 10 | \item{x_matrix}{(\code{matrix})\cr the design matrix with column names.} 11 | 12 | \item{subject_ids}{(\code{factor})\cr the subject IDs.} 13 | } 14 | \value{ 15 | Character vector with "intercept", "within" or "between" for each 16 | design matrix column identified via the names of the vector. 17 | } 18 | \description{ 19 | Used in \code{\link[=h_df_bw_calc]{h_df_bw_calc()}} to determine whether a variable 20 | differs only between subjects or also within subjects. 21 | } 22 | \keyword{internal} 23 | -------------------------------------------------------------------------------- /man/is_infix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils-nse.R 3 | \name{is_infix} 4 | \alias{is_infix} 5 | \title{Test Whether a Symbol is an Infix Operator} 6 | \usage{ 7 | is_infix(name) 8 | } 9 | \arguments{ 10 | \item{name}{(\code{symbol} or \code{name} or \code{string})\cr a possible reference to an 11 | infix operator to check.} 12 | } 13 | \value{ 14 | A logical indicating whether the name is the name of an infix 15 | operator. 16 | 17 | \if{html}{\out{
}}\preformatted{is_infix(as.name("|")) 18 | is_infix("|") 19 | is_infix("c") 20 | }\if{html}{\out{
}} 21 | } 22 | \description{ 23 | Test Whether a Symbol is an Infix Operator 24 | } 25 | \keyword{internal} 26 | -------------------------------------------------------------------------------- /man/mmrm-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mmrm-package.R 3 | \docType{package} 4 | \name{mmrm-package} 5 | \alias{mmrm-package} 6 | \title{\code{mmrm} Package} 7 | \description{ 8 | \code{mmrm} implements mixed models with repeated measures (MMRM) in R. 9 | } 10 | \seealso{ 11 | Useful links: 12 | \itemize{ 13 | \item \url{https://openpharma.github.io/mmrm/} 14 | \item Report bugs at \url{https://github.com/openpharma/mmrm/issues} 15 | } 16 | 17 | } 18 | \author{ 19 | \strong{Maintainer}: Daniel Sabanes Bove \email{daniel.sabanes_bove@rconis.com} (\href{https://orcid.org/0000-0002-0176-9239}{ORCID}) 20 | 21 | Authors: 22 | \itemize{ 23 | \item Liming Li \email{liming.li1@astrazeneca.com} (\href{https://orcid.org/0009-0008-6870-0878}{ORCID}) 24 | \item Julia Dedic \email{julia.dedic@roche.com} 25 | \item Doug Kelkhoff \email{doug.kelkhoff@roche.com} 26 | \item Kevin Kunzmann \email{kevin.kunzmann@boehringer-ingelheim.com} 27 | \item Brian Matthew Lang \email{brian.lang@msd.com} 28 | \item Christian Stock \email{christian.stock@boehringer-ingelheim.com} 29 | \item Ya Wang \email{ya.wang10@gilead.com} 30 | \item Dan James \email{dan.james@astrazeneca.com} 31 | \item Jonathan Sidi \email{yoni@pinpointstrategies.io} 32 | \item Daniel Leibovitz \email{daniel.leibovitz@roche.com} 33 | \item Daniel D. Sjoberg \email{sjobergd@gene.com} (\href{https://orcid.org/0000-0003-0862-2018}{ORCID}) 34 | \item Nikolas Ivan Krieger \email{nikolas.krieger@experis.com} (\href{https://orcid.org/0000-0002-4581-3545}{ORCID}) 35 | } 36 | 37 | Other contributors: 38 | \itemize{ 39 | \item Craig Gower-Page \email{craig.gower-page@roche.com} [contributor] 40 | \item Lukas A. Widmer (\href{https://orcid.org/0000-0003-1471-3493}{ORCID}) [contributor] 41 | \item Boehringer Ingelheim Ltd. [copyright holder, funder] 42 | \item Gilead Sciences, Inc. [copyright holder, funder] 43 | \item F. Hoffmann-La Roche AG [copyright holder, funder] 44 | \item Merck Sharp & Dohme, Inc. [copyright holder, funder] 45 | \item AstraZeneca plc [copyright holder, funder] 46 | \item inferential.biostatistics GmbH [copyright holder, funder] 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /man/parsnip_add_mmrm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/interop-parsnip.R 3 | \name{parsnip_add_mmrm} 4 | \alias{parsnip_add_mmrm} 5 | \title{Register \code{mmrm} For Use With \code{tidymodels}} 6 | \usage{ 7 | parsnip_add_mmrm(quietly = FALSE) 8 | } 9 | \arguments{ 10 | \item{quietly}{logical: should progress and error messages be suppressed?} 11 | } 12 | \value{ 13 | A logical value indicating whether registration was successful. 14 | } 15 | \description{ 16 | Register \code{mmrm} For Use With \code{tidymodels} 17 | } 18 | \details{ 19 | We can use \code{parsnip::show_model_info("linear_reg")} to check the 20 | registration with \code{parsnip} and thus the wider \code{tidymodels} ecosystem. 21 | } 22 | \keyword{internal} 23 | -------------------------------------------------------------------------------- /man/position_symbol.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils-nse.R 3 | \name{position_symbol} 4 | \alias{position_symbol} 5 | \title{Search For the Position of a Symbol} 6 | \usage{ 7 | position_symbol(x, sym, ...) 8 | } 9 | \arguments{ 10 | \item{x}{(\code{list} of \code{language})\cr a list of language objects in which to 11 | search for a specific symbol.} 12 | 13 | \item{sym}{(\code{name} or \code{symbol} or \code{character})\cr a symbol to search for in 14 | \code{x}.} 15 | 16 | \item{...}{Additional arguments passed to \code{Position()}.} 17 | } 18 | \value{ 19 | The position of the symbol if found, or the \code{nomatch} value 20 | otherwise. 21 | } 22 | \description{ 23 | A thin wrapper around \code{\link[base:funprog]{base::Position()}} to search through a list of language 24 | objects, as produced by \code{\link[=flatten_call]{flatten_call()}} or \code{\link[=flatten_expr]{flatten_expr()}}, for the 25 | presence of a specific symbol. 26 | } 27 | \keyword{internal} 28 | -------------------------------------------------------------------------------- /man/print.cov_struct.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cov_struct.R 3 | \name{print.cov_struct} 4 | \alias{print.cov_struct} 5 | \title{Print a Covariance Structure Object} 6 | \usage{ 7 | \method{print}{cov_struct}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{(\code{cov_struct})\cr a covariance structure object.} 11 | 12 | \item{...}{Additional arguments unused.} 13 | } 14 | \value{ 15 | \code{x} invisibly. 16 | } 17 | \description{ 18 | Print a Covariance Structure Object 19 | } 20 | -------------------------------------------------------------------------------- /man/reexports.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mmrm-package.R 3 | \docType{import} 4 | \name{reexports} 5 | \alias{reexports} 6 | \alias{tidy} 7 | \alias{glance} 8 | \alias{augment} 9 | \title{Objects exported from other packages} 10 | \keyword{internal} 11 | \description{ 12 | These objects are imported from other packages. Follow the links 13 | below to see their documentation. 14 | 15 | \describe{ 16 | \item{generics}{\code{\link[generics]{augment}}, \code{\link[generics]{glance}}, \code{\link[generics]{tidy}}} 17 | }} 18 | 19 | -------------------------------------------------------------------------------- /man/refit_multiple_optimizers.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fit.R 3 | \name{refit_multiple_optimizers} 4 | \alias{refit_multiple_optimizers} 5 | \title{Refitting MMRM with Multiple Optimizers} 6 | \usage{ 7 | refit_multiple_optimizers(fit, ..., control = mmrm_control(...)) 8 | } 9 | \arguments{ 10 | \item{fit}{(\code{mmrm_fit})\cr original model fit from \code{\link[=fit_single_optimizer]{fit_single_optimizer()}}.} 11 | 12 | \item{...}{Additional arguments passed to \code{\link[=mmrm_control]{mmrm_control()}}.} 13 | 14 | \item{control}{(\code{mmrm_control})\cr object.} 15 | } 16 | \value{ 17 | The best (in terms of log likelihood) fit which converged. 18 | } 19 | \description{ 20 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} 21 | } 22 | \note{ 23 | For Windows, no parallel computations are currently implemented. 24 | } 25 | \examples{ 26 | fit <- fit_single_optimizer( 27 | formula = FEV1 ~ RACE + SEX + ARMCD * AVISIT + us(AVISIT | USUBJID), 28 | data = fev_data, 29 | weights = rep(1, nrow(fev_data)), 30 | optimizer = "nlminb" 31 | ) 32 | best_fit <- refit_multiple_optimizers(fit) 33 | } 34 | -------------------------------------------------------------------------------- /man/register_on_load.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/zzz.R 3 | \name{register_on_load} 4 | \alias{register_on_load} 5 | \title{Helper Function for Registering Functionality With Suggests Packages} 6 | \usage{ 7 | register_on_load( 8 | pkg, 9 | ver = c(NA_character_, NA_character_), 10 | callback, 11 | message = NULL 12 | ) 13 | } 14 | \arguments{ 15 | \item{pkg}{(\code{string})\cr package name.} 16 | 17 | \item{ver}{(\code{character})\cr of length 2 whose elements can be provided to 18 | \code{\link[=numeric_version]{numeric_version()}}, representing a minimum and maximum (inclusive) version 19 | requirement for interoperability. When \code{NA}, no version requirement is 20 | imposed. Defaults to no version requirement.} 21 | 22 | \item{callback}{(\code{function(...) ANY})\cr a callback to execute upon package 23 | load. Note that no arguments are passed to this function. Any necessary 24 | data must be provided upon construction.} 25 | 26 | \item{message}{(\code{NULL} or \code{string})\cr an optional message to print after 27 | the callback is executed upon successful registration.} 28 | } 29 | \value{ 30 | A logical (invisibly) indicating whether registration was successful. 31 | If not, a onLoad hook was set for the next time the package is loaded. 32 | } 33 | \description{ 34 | Helper Function for Registering Functionality With Suggests Packages 35 | } 36 | \keyword{internal} 37 | -------------------------------------------------------------------------------- /man/std_start.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{std_start} 4 | \alias{std_start} 5 | \title{Standard Starting Value} 6 | \usage{ 7 | std_start(cov_type, n_visits, n_groups, ...) 8 | } 9 | \arguments{ 10 | \item{cov_type}{(\code{string})\cr name of the covariance structure.} 11 | 12 | \item{n_visits}{(\code{int})\cr number of visits.} 13 | 14 | \item{n_groups}{(\code{int})\cr number of groups.} 15 | 16 | \item{...}{not used.} 17 | } 18 | \value{ 19 | A numeric vector of starting values. 20 | } 21 | \description{ 22 | Obtain standard start values. 23 | } 24 | \details{ 25 | \code{std_start} will try to provide variance parameter from identity matrix. 26 | However, for \code{ar1} and \code{ar1h} the corresponding values are not ideal because the 27 | \eqn{\rho} is usually a positive number thus using 0 as starting value can lead to 28 | incorrect optimization result, and we use 0.5 as the initial value of \eqn{\rho}. 29 | } 30 | -------------------------------------------------------------------------------- /man/tmb_cov_type.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cov_struct.R 3 | \name{tmb_cov_type} 4 | \alias{tmb_cov_type} 5 | \title{Produce A Covariance Identifier Passing to TMB} 6 | \usage{ 7 | tmb_cov_type(cov) 8 | } 9 | \arguments{ 10 | \item{cov}{(\code{cov_struct})\cr a covariance structure object.} 11 | } 12 | \value{ 13 | A string used for method dispatch when passed to TMB. 14 | } 15 | \description{ 16 | Produce A Covariance Identifier Passing to TMB 17 | } 18 | \keyword{internal} 19 | -------------------------------------------------------------------------------- /man/validate_cov_struct.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cov_struct.R 3 | \name{validate_cov_struct} 4 | \alias{validate_cov_struct} 5 | \title{Validate Covariance Structure Data} 6 | \usage{ 7 | validate_cov_struct(x) 8 | } 9 | \arguments{ 10 | \item{x}{(\code{cov_struct})\cr a covariance structure object.} 11 | } 12 | \value{ 13 | \code{x} if successful, or an error is thrown otherwise. 14 | } 15 | \description{ 16 | Run checks against relational integrity of covariance definition 17 | } 18 | \keyword{internal} 19 | -------------------------------------------------------------------------------- /mmrm.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageCheckArgs: --no-vignettes 22 | PackageRoxygenize: rd,collate,namespace 23 | -------------------------------------------------------------------------------- /simulations/csh-benchmarks/.gitignore: -------------------------------------------------------------------------------- 1 | slurm.out 2 | -------------------------------------------------------------------------------- /simulations/csh-benchmarks/results/hom_rct-het_rct/Varying num_part-num_part/.gitignore: -------------------------------------------------------------------------------- 1 | fit_results.rds 2 | experiment_cached_params.rds 3 | -------------------------------------------------------------------------------- /simulations/csh-benchmarks/results/hom_rct-het_rct/Varying num_part-num_part/eval_results.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openpharma/mmrm/ca604819431a6b43a3a227a122173a1e9b1a8fda/simulations/csh-benchmarks/results/hom_rct-het_rct/Varying num_part-num_part/eval_results.rds -------------------------------------------------------------------------------- /simulations/csh-benchmarks/results/hom_rct-het_rct/Varying num_part-num_part/experiment.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openpharma/mmrm/ca604819431a6b43a3a227a122173a1e9b1a8fda/simulations/csh-benchmarks/results/hom_rct-het_rct/Varying num_part-num_part/experiment.rds -------------------------------------------------------------------------------- /simulations/csh-benchmarks/results/hom_rct-het_rct/Varying num_part-num_part/viz_results.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openpharma/mmrm/ca604819431a6b43a3a227a122173a1e9b1a8fda/simulations/csh-benchmarks/results/hom_rct-het_rct/Varying num_part-num_part/viz_results.rds -------------------------------------------------------------------------------- /simulations/csh-benchmarks/slurm/meal.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Job name: 3 | #SBATCH --job-name=csh-sim 4 | # 5 | # Quality of Service: 6 | #SBATCH --qos=medium 7 | # 8 | # Processors (1 node = 28 cores): 9 | #SBATCH --nodes=1 10 | #SBATCH --ntasks=1 11 | #SBATCH --cpus-per-task=1 12 | #SBATCH --mem-per-cpu=40G 13 | # 14 | # Mail type: 15 | #SBATCH --mail-type=all 16 | # 17 | # Mail user: 18 | #SBATCH --mail-user=boileap2@gene.com 19 | # 20 | # Job output: 21 | #SBATCH --output=slurm.out 22 | #SBATCH --error=slurm.out 23 | # 24 | ## Command(s) to run: 25 | ## Initialize work environment 26 | cd ~/mmrm/simulations/csh-benchmarks || exit 27 | module load R/prd 28 | # 29 | ## Run the script 30 | R CMD BATCH --no-save --no-restore \ 31 | R/meal.R \ 32 | logs/meal.Rout 33 | -------------------------------------------------------------------------------- /simulations/missing-data-benchmarks/README.md: -------------------------------------------------------------------------------- 1 | # Mmrm Simulation 2 | 3 | ## Usage 4 | 5 | ### R simulation 6 | 7 | R simulations can be done on any platform where R and snakemake is available. Current snakefile is also compatible with HPC where batch system like lsf is installed. 8 | 9 | Make sure the lsf plugin for snakemake is installed. 10 | 11 | ```{sh} 12 | pip install snakemake-executor-plugin-lsf 13 | ``` 14 | 15 | Then you can use snakemake to submit jobs. 16 | 17 | ```{sh} 18 | snakemake --executor lsf all_r_analysis 19 | ``` 20 | 21 | The data generation step is using a specific seed so reproducibility is ensured. 22 | 23 | ### SAS simulation 24 | 25 | The simulation in SAS can be completed on systems where SAS and R are both available. 26 | If you don't have machines that both are available, the execution should take two steps. 27 | 28 | 1. Generate the data using `snakemake all_simulated_data` (this must run on R machine) 29 | 1. Generate the estimate using `snakemake all_sas_analysis` (this must run on SAS machine) 30 | -------------------------------------------------------------------------------- /simulations/missing-data-benchmarks/aggregate_all_results.R: -------------------------------------------------------------------------------- 1 | library(googledrive) 2 | library(dplyr) 3 | drive_auth() 4 | 5 | args <- R.utils::commandArgs(trailingOnly = TRUE, asValues = TRUE, excludeReserved = TRUE) 6 | 7 | outname <- args$output 8 | input_folder <- args$input 9 | 10 | inputs <- list.files(input_folder, full.names = TRUE, pattern = ".*rds") 11 | results <- lapply(inputs, readRDS) 12 | 13 | all_results <- do.call(bind_rows, results) 14 | saveRDS(all_results, outname) 15 | -------------------------------------------------------------------------------- /simulations/missing-data-benchmarks/config.yaml: -------------------------------------------------------------------------------- 1 | miss: ['no', 'low', 'high', 'extreme'] 2 | trt: ['no', 'small', 'mod'] 3 | cov: ['us', 'toeph', 'csh'] 4 | n: ['200', '400', '600'] 5 | seed: ['13412112'] 6 | reml: ['reml', 'ml'] 7 | covar_rsp: ['us', 'toeph', 'csh'] 8 | rep: 1000 9 | -------------------------------------------------------------------------------- /simulations/missing-data-benchmarks/process_sas.R: -------------------------------------------------------------------------------- 1 | args <- R.utils::commandArgs(asValues = TRUE, excludeReserved = TRUE) 2 | 3 | input_data <- SASxport::read.xport(args$input_file, names.tolower = TRUE) 4 | output_data <- args$output_file 5 | 6 | library(dplyr) 7 | 8 | method_covar <- args$cov 9 | covar_rsp <- args$covar_rsp 10 | reml <- args$reml 11 | 12 | fit_time <- input_data$fittime %>% 13 | mutate(fit_time = dur, src = substr(src, 4, 8)) %>% 14 | mutate(fit_time = if_else(fit_time < 0, fit_time + 24 * 60 * 60, fit_time)) 15 | convergence <- input_data$conv %>% 16 | mutate(converged = status == 0, src = substr(src, 4, 8)) %>% 17 | select(src, converged) 18 | emmeans <- input_data$diffs %>% 19 | filter(trt == 1, x.trt == 0, visit == x.visit) %>% 20 | mutate(src = substr(src, 4, 8)) %>% 21 | group_by(src) %>% 22 | summarize( 23 | emmeans_output = list(data.frame(visit, estimate, stderr, df, tvalue, pvalue = probt, lower, upper)) 24 | ) 25 | 26 | cov_from_parm <- function(x, type) { 27 | type <- type[1] 28 | if (type == "csh") { 29 | nl <- length(x) - 1 30 | d <- matrix(tail(x, 1), nl, nl) 31 | diag(d) <- 1 32 | v <- sqrt(head(x, nl)) 33 | outer(v, v) * d 34 | } else if (type == "toeph") { 35 | nl <- (length(x) + 1) / 2 36 | d <- toeplitz(c(1, tail(x, nl - 1))) 37 | v <- sqrt(head(x, nl)) 38 | outer(v, v) * d 39 | } else if (type == "us") { 40 | nl <- floor(sqrt(2 * length(x))) 41 | v <- sqrt(head(x, nl)) 42 | d <- matrix(0, nl, nl) 43 | d[upper.tri(d, diag = FALSE)] <- tail(x, nl * (nl - 1) / 2) 44 | d <- d + t(d) 45 | diag(d) <- 1 46 | outer(v, v) * d 47 | } 48 | } 49 | 50 | cov_csh <- input_data$cvparm %>% 51 | mutate(src = substr(src, 4, 8)) %>% 52 | group_by(src) %>% 53 | summarize(covmat_estimates = list(cov_from_parm(estimate, method_covar))) 54 | 55 | df <- fit_time %>% 56 | full_join(convergence, by = "src") %>% 57 | full_join(emmeans, by = "src") %>% 58 | full_join(cov_csh, by = "src") %>% 59 | mutate(missingness = miss, treatment_effect = trt.eff) %>% 60 | mutate(method_covar = method_covar, method = "sas", rep = as.numeric(src)) %>% 61 | mutate(reml = reml, covar_rsp = covar_rsp) %>% 62 | select(fit_time, converged, rep, method_covar, method, missingness, n, treatment_effect, seed, emmeans_output, covmat_estimates, covar_rsp, reml) 63 | 64 | saveRDS(df, output_data) 65 | -------------------------------------------------------------------------------- /simulations/missing-data-benchmarks/run_analysis.R: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env Rscript 2 | 3 | args <- R.utils::commandArgs(asValues = TRUE, excludeReserved = TRUE) 4 | 5 | missingness <- args$missingness 6 | treatment_effect <- args$treatment_effect 7 | reps <- args$reps 8 | seed <- as.numeric(args$seed) 9 | n <- as.numeric(args$n) 10 | n_reps <- as.numeric(args$reps) 11 | covar_rsp <- args$covar_rsp 12 | covar_type <- args$covar_type 13 | method <- args$method # "mmrm", "glmmtmb", "nlme", "sas" 14 | reml <- args$reml # reml or ml 15 | input_data <- args$input_data 16 | output_file <- args$output_file 17 | 18 | source("programs/analyze_data.R") 19 | 20 | data <- arrow::read_parquet(input_data) 21 | 22 | ret <- analyze_data(data, method, covar_rsp, covar_type, identical(reml, "reml")) 23 | 24 | ret$missingness <- missingness 25 | ret$n <- n 26 | ret$treatment_effect <- treatment_effect 27 | ret$seed <- seed 28 | ret$reml <- reml 29 | ret$covar_rsp <- covar_rsp 30 | 31 | saveRDS(ret, output_file) 32 | -------------------------------------------------------------------------------- /simulations/missing-data-benchmarks/run_analysis.sas: -------------------------------------------------------------------------------- 1 | %let inputdata=%sysget(inputdata); 2 | %let outputdata=%sysget(outputdata); 3 | %let n=%sysget(n); 4 | %let rep=%sysget(rep); 5 | %let covar=%sysget(cov); 6 | %let covarrsp=%sysget(covarrsp); 7 | %let seed=%sysget(seed); 8 | %let miss=%sysget(miss); 9 | %let trt=%sysget(trt); 10 | %let reml=%sysget(reml); 11 | 12 | libname xptin xport "&inputdata"; 13 | libname xptout xport "&outputdata"; 14 | 15 | proc copy inlib = xptin outlib = work; 16 | run; 17 | 18 | %macro set_var(); 19 | src = scan(source,2,'.'); 20 | seed = &seed; 21 | n = &n; 22 | miss = "&miss"; 23 | trt_eff = "&trt"; 24 | %mend; 25 | 26 | %macro mix_fit(i); 27 | %let _timer_start = %sysfunc(time()); 28 | ODS OUTPUT DIFFS = df_&i. CovParms = cv_&i. ConvergenceStatus = cs_&i.; 29 | PROC MIXED DATA = filter_data_&i METHOD = &reml.; 30 | CLASS trt(ref = '0') visit strata id; 31 | %if "&covarrsp" eq "csh" %then %do; 32 | MODEL chgcsh = bcva_bl strata trt*visit / DDFM = SAT; 33 | %end; 34 | %else %if "&covarrsp" eq "unr" %then %do; 35 | MODEL chgus = bcva_bl strata trt*visit / DDFM = SAT; 36 | %end; 37 | %else %do; 38 | MODEL chgtoeph = bcva_bl strata trt*visit / DDFM = SAT; 39 | %end; 40 | %if "&covar" eq "us" %then %do; 41 | REPEATED visit / subject=id type=unr; 42 | %end; 43 | %else %if "&covar" eq "csh" %then %do; 44 | REPEATED visit / subject=id type=csh; 45 | %end; 46 | %else %do; 47 | REPEATED visit / subject=id type=toeph; 48 | %end; 49 | LSMEANS trt*visit / pdiff cl alpha = 0.05 OBSMARGINS; 50 | RUN; 51 | data ft_&i; 52 | dur = time() - &_timer_start; 53 | %mend; 54 | 55 | %macro run_proc_mixed(rep); 56 | %do i = 0 %to (&rep - 1); 57 | data filter_data_&i; 58 | set simdata; 59 | if id gt &i * &n and id le (&i + 1) * &n; 60 | run; 61 | %mix_fit(&i.); 62 | %end; 63 | data fittime; 64 | set ft: indsname = source; 65 | %set_var(); 66 | data diffs; 67 | length margins $40.; 68 | set df: indsname = source; 69 | %set_var(); 70 | data conv; 71 | set cs: indsname = source; 72 | %set_var(); 73 | data cvparm; 74 | length covparm $40.; 75 | set cv_: indsname = source; 76 | %set_var(); 77 | proc datasets lib=work; 78 | delete df_: cs_: cv_: ft_:; 79 | quit; 80 | proc copy in=work out=xptout; 81 | select diffs conv fittime cvparm; 82 | run; 83 | %mend; 84 | 85 | %run_proc_mixed(&rep); 86 | -------------------------------------------------------------------------------- /simulations/missing-data-benchmarks/simulate_data.R: -------------------------------------------------------------------------------- 1 | args <- R.utils::commandArgs(asValues = TRUE, excludeReserved = TRUE) 2 | 3 | seed <- as.numeric(args$seed) 4 | missingness <- args$missingness # "no", "low", "high", "extreme" 5 | treatment_effect <- args$treatment_effect # "no", "small", "mod" 6 | xpt_out <- args$xpt 7 | parquet_out <- args$parquet 8 | n <- as.numeric(args$n) 9 | nrep <- as.numeric(args$rep) 10 | 11 | # source the R scripts 12 | source("programs/generate_data.R") 13 | 14 | # generate the simulation data 15 | set.seed(seed + n) 16 | 17 | data <- generate_data( 18 | n_sample_size = n, 19 | n_rep = nrep, 20 | n_visits = 10, 21 | missing_level = missingness, 22 | trt_visit_coef = switch(treatment_effect, 23 | no = 0, 24 | small = 0.25, 25 | mod = 0.5 26 | ), 27 | ) 28 | 29 | arrow::write_parquet(data, parquet_out) 30 | 31 | haven::write_xpt( 32 | data, 33 | xpt_out, 34 | name = "simdata", 35 | version = 5 36 | ) 37 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.so 3 | *.dll 4 | -------------------------------------------------------------------------------- /src/Makevars: -------------------------------------------------------------------------------- 1 | PKG_CXXFLAGS = -D TMBAD_FRAMEWORK -D EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS 2 | -------------------------------------------------------------------------------- /src/test-chol_cache.cpp: -------------------------------------------------------------------------------- 1 | #include "testthat-helpers.h" 2 | #include "chol_cache.h" 3 | 4 | context("cholesky cache") { 5 | test_that("cached cholesky stores result correctly") { 6 | vector theta {{log(1.0), log(2.0), 3.0}}; 7 | auto chol = lower_chol_nonspatial(theta, 2, "us"); 8 | matrix chol1_expected(2, 2); 9 | chol1_expected << 10 | 1.0, 0.0, 11 | 6.0, 2.0; 12 | std::vector vis{0, 1}; 13 | matrix dist; 14 | expect_equal_matrix(chol.get_chol(vis, dist), chol1_expected); 15 | expect_equal_matrix(chol.chols[vis], chol1_expected); 16 | 17 | matrix simga1_expected(2, 2); 18 | simga1_expected << 19 | 1.0, 6.0, 20 | 6.0, 40.0; 21 | expect_equal_matrix(chol.get_sigma(vis, dist), simga1_expected); 22 | expect_equal_matrix(chol.sigmas[vis], simga1_expected); 23 | 24 | matrix simga1_inv = chol.get_sigma_inverse(vis, dist); 25 | matrix simga1_inv_expected(2, 2); 26 | simga1_inv_expected << 27 | 10.0, -1.5, 28 | -1.5, 0.25; 29 | expect_equal_matrix(simga1_inv, simga1_inv_expected); 30 | expect_equal_matrix(chol.sigmas_inv[vis], simga1_inv_expected); 31 | 32 | matrix chol2_expect(1, 1); 33 | chol2_expect << 1.0; 34 | std::vector vis2{0}; 35 | expect_equal_matrix(chol.get_chol(vis2, dist), chol2_expect); 36 | expect_equal_matrix(chol.chols[vis2], chol2_expect); 37 | 38 | matrix sigma2_expect(1, 1); 39 | sigma2_expect << 1.0; 40 | expect_equal_matrix(chol.get_sigma(vis2, dist), sigma2_expect); 41 | expect_equal_matrix(chol.sigmas[vis2], sigma2_expect); 42 | 43 | matrix sigma2_inv_expect(1, 1); 44 | sigma2_inv_expect << 1.0; 45 | expect_equal_matrix(chol.get_sigma_inverse(vis2, dist), sigma2_inv_expect); 46 | expect_equal_matrix(chol.sigmas_inv[vis2], sigma2_inv_expect); 47 | } 48 | } 49 | 50 | context("cholesky group object") { 51 | test_that("cholesky group return result correctly") { 52 | vector theta {{log(1.0), log(2.0), 3.0, log(2.0), log(4.0), 5}}; 53 | auto chol_group = chol_cache_groups(theta, 2, false, "us", 2); 54 | matrix chol1_expected(2, 2); 55 | chol1_expected << 56 | 1.0, 0.0, 57 | 6.0, 2.0; 58 | std::vector vis{0, 1}; 59 | matrix dist; 60 | expect_equal_matrix(chol_group.cache[0]->get_chol(vis, dist), chol1_expected); 61 | matrix chol2_expected(2, 2); 62 | chol2_expected << 63 | 2.0, 0.0, 64 | 20.0, 4.0; 65 | expect_equal_matrix(chol_group.cache[1]->get_chol(vis, dist), chol2_expected); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/test-runner.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Please do not edit this file -- it ensures that your package will export a 3 | * 'run_testthat_tests()' C routine that can be used to run the Catch unit tests 4 | * available in your package. 5 | */ 6 | #define TESTTHAT_TEST_RUNNER 7 | #include 8 | -------------------------------------------------------------------------------- /src/testthat-helpers.h: -------------------------------------------------------------------------------- 1 | #ifndef TESTTHAT_WRAP_H 2 | #define TESTTHAT_WRAP_H 3 | #include 4 | #include 5 | #include "utils.h" 6 | 7 | // Expect equal: Here use a default epsilon which gives around 1e-4 on 8 | // my computer here. 9 | #define expect_equal(TARGET, CURRENT) \ 10 | { \ 11 | double const eps = \ 12 | std::pow(std::numeric_limits::epsilon(), 0.25); \ 13 | \ 14 | if(std::abs((TARGET)) > eps) \ 15 | expect_true(std::abs((TARGET) - (CURRENT)) / \ 16 | std::abs((TARGET)) < eps); \ 17 | else \ 18 | expect_true(std::abs((TARGET) - (CURRENT)) < eps); \ 19 | } 20 | 21 | #define expect_equal_eps(TARGET, CURRENT, EPS) \ 22 | { \ 23 | if(std::abs((TARGET)) > (EPS)) \ 24 | expect_true(std::abs((TARGET) - (CURRENT)) / \ 25 | std::abs((TARGET)) < (EPS)); \ 26 | else \ 27 | expect_true(std::abs((TARGET) - (CURRENT)) < (EPS)); \ 28 | } 29 | 30 | template 31 | void expect_equal_matrix(const T& target, const T& current) 32 | { 33 | int nrow = target.rows(); 34 | int ncol = target.cols(); 35 | 36 | expect_true(nrow == current.rows()); 37 | expect_true(ncol == current.cols()); 38 | 39 | for (int i = 0; i < nrow; i++) { 40 | for (int j = 0; j < ncol; j++) { 41 | expect_equal(target(i, j), current(i, j)); 42 | } 43 | } 44 | } 45 | 46 | template 47 | void expect_equal_vector(const T& target, const T& current) 48 | { 49 | int n = target.size(); 50 | expect_true(n == current.size()); 51 | 52 | for (int i = 0; i < n; i++) { 53 | expect_equal(target(i), current(i)); 54 | } 55 | } 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/tmb.cpp: -------------------------------------------------------------------------------- 1 | #ifdef WITH_LIBTMB 2 | #undef WITH_LIBTMB 3 | #endif 4 | 5 | 6 | #include 7 | -------------------------------------------------------------------------------- /src/tmb_includes.h: -------------------------------------------------------------------------------- 1 | #ifndef TMB_INCLUDES_H 2 | #define TMB_INCLUDES_H 3 | #ifdef INCLUDE_RCPP 4 | /* Rcpp defines `R_NO_REMAP` which causes errors when using TMB. Thus, we 5 | * define a few macros. */ 6 | #ifndef findVar 7 | #define findVar Rf_findVar 8 | #endif 9 | #ifndef install 10 | #define install Rf_install 11 | #endif 12 | #ifndef error 13 | #define error Rf_error 14 | #endif 15 | /* TMB redefines a few macro. Thus, we undefine them first */ 16 | #ifdef R_D_val 17 | #undef R_D_val 18 | #endif 19 | #ifdef R_D_qIv 20 | #undef R_D_qIv 21 | #endif 22 | #ifdef R_D_exp 23 | #undef R_D_exp 24 | #endif 25 | #ifdef R_D_log 26 | #undef R_D_log 27 | #endif 28 | #ifdef R_D_Clog 29 | #undef R_D_Clog 30 | #endif 31 | #ifdef R_D_LExp 32 | #undef R_D_LExp 33 | #endif 34 | #ifdef R_DT_qIv 35 | #undef R_DT_qIv 36 | #endif 37 | #ifdef R_DT_CIv 38 | #undef R_DT_CIv 39 | #endif 40 | #ifdef R_Q_P01_check 41 | #undef R_Q_P01_check 42 | #endif 43 | #ifdef R_Q_P01_boundaries 44 | #undef R_Q_P01_boundaries 45 | #endif 46 | #ifdef R_D_negInonint 47 | #undef R_D_negInonint 48 | #endif 49 | #ifdef R_D_nonint_check 50 | #undef R_D_nonint_check 51 | #endif 52 | #endif // ifdef INCLUDE_RCPP 53 | 54 | /* TMB */ 55 | #define WITH_LIBTMB 56 | 57 | #include 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | pkg_name <- "mmrm" 2 | library(pkg_name, character.only = TRUE) 3 | testthat::test_check(pkg_name) 4 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/between-within.md: -------------------------------------------------------------------------------- 1 | # h_df_bw_calc works as expected for the vignette example 2 | 3 | Code 4 | result$coefs_between_within 5 | Output 6 | (Intercept) RACEBlack or African American 7 | "intercept" "between" 8 | RACEWhite SEXFemale 9 | "between" "between" 10 | ARMCDTRT AVISITVIS2 11 | "between" "within" 12 | AVISITVIS3 AVISITVIS4 13 | "within" "within" 14 | ARMCDTRT:AVISITVIS2 ARMCDTRT:AVISITVIS3 15 | "within" "within" 16 | ARMCDTRT:AVISITVIS4 17 | "within" 18 | 19 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/empirical.md: -------------------------------------------------------------------------------- 1 | # h_get_empirical obtain empirical covariance 2 | 3 | structure(c(0.276669200825678, -0.276669200825678, -0.276669200825678, 4 | 0.681966674143019), dim = c(2L, 2L)) 5 | 6 | # h_get_empirical obtain jackknife covariance 7 | 8 | structure(c(0.282126502688394, -0.282126502688394, -0.282126502688394, 9 | 0.696645916580453), dim = c(2L, 2L)) 10 | 11 | --- 12 | 13 | structure(c(0.27938383855849, -0.27938383855849, -0.27938383855849, 14 | 0.689265455017577), dim = c(2L, 2L)) 15 | 16 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/fit.md: -------------------------------------------------------------------------------- 1 | # mmrm will use the provided contrast 2 | 3 | c("(Intercept)" = 34.8020627013113, ARMCD.L = 3.16770190939602, 4 | AVISITVIS2 = 4.9509698654855, AVISITVIS3 = 9.7992494156101, AVISITVIS4 = 15.4927989788533, 5 | "ARMCD.L:AVISITVIS2" = -0.162690886814969, "ARMCD.L:AVISITVIS3" = -0.799945287499386, 6 | "ARMCD.L:AVISITVIS4" = 0.221049368976004) 7 | 8 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/testing.md: -------------------------------------------------------------------------------- 1 | # h_test_1d works as expected 2 | 3 | list(est = 5.64356534807864, se = 0.66560934580673, df = 3.5, 4 | t_stat = 8.47879523271798, p_val = 0.00187339012243507) 5 | 6 | # h_test_md works as expected 7 | 8 | list(num_df = 2L, denom_df = 5, f_stat = 798.827755352408, p_val = 5.43656466194095e-07) 9 | 10 | -------------------------------------------------------------------------------- /tests/testthat/helper-skipping.R: -------------------------------------------------------------------------------- 1 | # Custom skipping function, specializing testthat::skip. 2 | skip_if_r_devel_linux_clang <- function() { 3 | do_skip <- is_r_devel_linux_clang() 4 | if (do_skip) { 5 | skip("On R-devel Linux system with non-standard clang") 6 | } else { 7 | invisible() 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/testthat/test-cpp-utils.R: -------------------------------------------------------------------------------- 1 | # get_corr_mat_chol ---- 2 | 3 | test_that("prepare numbers for get_corr_mat_chol tests", { 4 | cor_mat <- matrix(data = 0.5, nrow = 3, ncol = 3) 5 | diag(cor_mat) <- 1 6 | result <- t(chol(cor_mat)) 7 | expected <- square_matrix(c( 8 | 1, 0, 0, 9 | 0.5, 0.866025403784439, 0, 10 | 0.5, 0.288675134594813, 0.816496580927726 11 | )) 12 | expect_equal(result, expected) 13 | }) 14 | 15 | test_that("prepare numbers for pseudoInverseSqrt", { 16 | input <- matrix(c( 17 | 5.483417, 2.861011, 3.478399, 18 | 2.861011, 3.169936, -1.075550, 19 | 3.478399, -1.075550, 10.525825 20 | ), 3, 3) 21 | ed <- eigen(solve(input)) 22 | result <- ed$vectors %*% diag(sqrt(ed$values)) %*% t(ed$vectors) 23 | expected <- matrix(c( 24 | 0.8235633, -0.5514385, -0.2586037, 25 | -0.5514385, 1.0568775, 0.2548210, 26 | -0.2586037, 0.2548210, 0.4095994 27 | ), 3, 3) 28 | expect_equal(result, expected, tolerance = 1e-4) 29 | }) 30 | 31 | test_that("prepare numbers for pseudoInverseSqrt rank deficient", { 32 | skip_if_not_installed("MASS") 33 | input <- matrix(c( 34 | 5.483417, 2.861011, 0, 35 | 2.861011, 3.169936, 0, 36 | 0, 0, 0 37 | ), 3, 3) 38 | ed <- eigen(MASS::ginv(input)) 39 | result <- ed$vectors %*% diag(sqrt(ed$values)) %*% t(ed$vectors) 40 | expected <- matrix(c( 41 | 0.5331152, -0.2459070, 0.0, 42 | -0.2459070, 0.7319613, 0.0, 43 | 0.0000000, 0.0000000, 0.0 44 | ), 3, 3) 45 | expect_equal(result, expected, tolerance = 1e-4) 46 | }) 47 | -------------------------------------------------------------------------------- /tests/testthat/test-cpp.R: -------------------------------------------------------------------------------- 1 | run_cpp_tests("mmrm") 2 | -------------------------------------------------------------------------------- /tests/testthat/test-interop.R: -------------------------------------------------------------------------------- 1 | test_that("check_package_version warns when version is not compatible", { 2 | skip_if_not_installed("mockery") 3 | mockery::stub(check_package_version, "utils::packageVersion", numeric_version("1.2.3")) 4 | 5 | # When no version requirements are specified, checking package always succeeds 6 | expect_true(check_package_version("fakePackage")) 7 | 8 | # Warns when a minimum version isn't met 9 | expect_warning(check_package_version("fakePackage", c("10", NA)), "fakePackage") 10 | 11 | # Warns when a maximum version isn't met 12 | expect_warning(check_package_version("fakePackage", c(NA, "1")), "fakePackage") 13 | }) 14 | 15 | test_that("register_on_load sets an onLoad hook when package is not yet loaded", { 16 | expect_silent(register_on_load("fakePackage", callback = function() NULL)) 17 | expect_true(!is.null(getHook(packageEvent("fakePackage", "onLoad")))) 18 | }) 19 | 20 | test_that("check_package_version rejects numeric version input", { 21 | expect_error( 22 | check_package_version("fakePackage", c(1, 2)), 23 | "Must be of type 'character'" 24 | ) 25 | }) 26 | -------------------------------------------------------------------------------- /tests/testthat/test-residual.R: -------------------------------------------------------------------------------- 1 | # h_df_1d_res ---- 2 | 3 | test_that("h_df_1d_res works as expected", { 4 | fit <- get_mmrm() 5 | contrast <- numeric(length = length(coef(fit))) 6 | contrast[2] <- 1 7 | result <- expect_silent(h_df_1d_res(fit, contrast)) 8 | expect_list(result) 9 | expect_equal(result$est, 1.5305, tolerance = 1e-3) 10 | expect_equal(result$se, 0.6245, tolerance = 1e-3) 11 | expect_identical(result$df, 526L) 12 | expect_equal(result$t_stat, 2.4509, tolerance = 1e-3) 13 | expect_equal(result$p_val, 0.01458, tolerance = 1e-3) 14 | }) 15 | 16 | # h_df_md_res ---- 17 | 18 | test_that("h_df_md_res works as expected", { 19 | fit <- get_mmrm() 20 | contrast <- matrix(data = 0, ncol = length(coef(fit)), nrow = 2) 21 | contrast[1, 2] <- 1 22 | contrast[2, 3] <- 1 23 | result <- expect_silent(h_df_md_res(fit, contrast)) 24 | expect_list(result) 25 | expect_identical(result$num_df, 2L) 26 | expect_identical(result$denom_df, 526L) 27 | expect_equal(result$f_stat, 36.9114, tolerance = 1e-3) 28 | expect_true(result$p_val < 1e-10) 29 | }) 30 | -------------------------------------------------------------------------------- /tests/testthat/test-skipping.R: -------------------------------------------------------------------------------- 1 | # is_r_devel ---- 2 | 3 | test_that("is_r_devel works as expected", { 4 | expect_flag(is_r_devel()) 5 | }) 6 | 7 | # is_linux ---- 8 | 9 | test_that("is_linux works as expected", { 10 | expect_flag(is_linux()) 11 | }) 12 | 13 | # get_compiler ---- 14 | 15 | test_that("get_compiler works as expected", { 16 | expect_string(get_compiler()) 17 | }) 18 | 19 | # is_using_clang ---- 20 | 21 | test_that("is_using_clang works as expected", { 22 | expect_flag(is_using_clang()) 23 | }) 24 | 25 | test_that("is_using_clang gives the same information as R_compiled_by in recent R versions", { 26 | skip_if(getRversion() < "4.3") 27 | result <- is_using_clang() 28 | expected <- grepl("clang", R_compiled_by()["C"]) # Only available from R 4.3 onward. 29 | expect_identical(result, expected) 30 | }) 31 | 32 | # is_r_devel_linux_clang ---- 33 | 34 | test_that("is_r_devel_linux_clang works as expected", { 35 | expect_flag(is_r_devel_linux_clang()) 36 | }) 37 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | -------------------------------------------------------------------------------- /vignettes/introduction.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Package Introduction" 3 | package: mmrm 4 | output: 5 | rmarkdown::html_vignette: 6 | toc: true 7 | vignette: | 8 | %\VignetteIndexEntry{Package Introduction} 9 | %\VignetteEncoding{UTF-8} 10 | %\VignetteEngine{knitr::rmarkdown} 11 | editor_options: 12 | chunk_output_type: console 13 | --- 14 | 15 | ```{r, include = FALSE} 16 | knitr::opts_chunk$set( 17 | collapse = TRUE, 18 | comment = "#>" 19 | ) 20 | library(mmrm) 21 | ``` 22 | 23 | # Common usage 24 | 25 | A minimal call of `mmrm()`, consisting of only formula and data arguments will produce an object of class `mmrm`, `mmrm_fit`, and `mmrm_tmb`. 26 | 27 | Here we fit a mmrm model with `us` (unstructured) covariance structure specified, as well as the defaults of `reml = TRUE` and `control = mmrm_control()`. 28 | 29 | ```{r, child='subsections/_intro-getting_started.Rmd'} 30 | ``` 31 | 32 | # Common customizations 33 | 34 | ```{r, child='subsections/_intro-customizations.Rmd'} 35 | ``` 36 | 37 | # Extraction of model features 38 | 39 | ```{r, child='subsections/_intro-model_features.Rmd'} 40 | ``` 41 | 42 | # Lower level functions 43 | 44 | ```{r, child='subsections/_intro-lower_level.Rmd'} 45 | ``` 46 | 47 | # Hypothesis testing 48 | 49 | ```{r, child='subsections/_intro-hypothesis_testing.Rmd'} 50 | ``` 51 | 52 | # Tidymodels 53 | 54 | ```{r, child='subsections/_intro-tidymodels.Rmd'} 55 | ``` 56 | 57 | 58 | # Acknowledgments 59 | 60 | ```{r, child='subsections/_intro-acknowledgments.Rmd'} 61 | ``` 62 | 63 | 64 | # References 65 | -------------------------------------------------------------------------------- /vignettes/subsections/_intro-acknowledgments.Rmd: -------------------------------------------------------------------------------- 1 | The `mmrm` package is based on previous work internal in Roche, namely 2 | the `tern` and `tern.mmrm` packages which were based on `lme4`. 3 | The work done in the `rbmi` package has been important since it used 4 | `glmmTMB` for fitting MMRMs. 5 | 6 | We would like to thank Ben Bolker from the `glmmTMB` team for multiple 7 | discussions when we tried to get the Satterthwaite degrees of freedom 8 | implemented with `glmmTMB` (see https://github.com/glmmTMB/glmmTMB/blob/satterthwaite_df/glmmTMB/vignettes/satterthwaite_unstructured_example2.Rmd). Also Ben helped us significantly with 9 | an example showing how to use `TMB` for a random effect vector (https://github.com/bbolker/tmb-case-studies/tree/master/vectorMixed). 10 | -------------------------------------------------------------------------------- /vignettes/subsections/_intro-getting_started.Rmd: -------------------------------------------------------------------------------- 1 | ```{r getting-started} 2 | library(mmrm) 3 | fit <- mmrm( 4 | formula = FEV1 ~ RACE + SEX + ARMCD * AVISIT + us(AVISIT | USUBJID), 5 | data = fev_data 6 | ) 7 | ``` 8 | 9 | The code specifies an MMRM with the given covariates and an unstructured covariance 10 | matrix for the timepoints (also called visits in the clinical trial context, here 11 | given by `AVISIT`) within the subjects (here `USUBJID`). While by default this uses 12 | restricted maximum likelihood (REML), it is also possible to use ML, see `?mmrm`. 13 | 14 | Printing the object will show you output which should be familiar to anyone who 15 | has used any popular modeling functions such as `stats::lm()`, `stats::glm()`, 16 | `glmmTMB::glmmTMB()`, and `lme4::nlmer()`. From this print out we see the function call, 17 | the data used, the covariance structure with number of variance parameters, as well 18 | as the likelihood method, and model deviance achieved. Additionally the user is 19 | provided a printout of the estimated coefficients and the model convergence information: 20 | 21 | ```{r print} 22 | fit 23 | ``` 24 | 25 | The `summary()` method then provides the coefficients table with Satterthwaite 26 | degrees of freedom as well as the covariance matrix estimate: 27 | 28 | ```{r summary} 29 | summary(fit) 30 | ``` 31 | -------------------------------------------------------------------------------- /vignettes/subsections/_intro-lower_level.Rmd: -------------------------------------------------------------------------------- 1 | ```{r, include = FALSE} 2 | library(mmrm) 3 | ``` 4 | 5 | ## Low-level mmrm 6 | 7 | The lower level function which is called by [`mmrm()`](https://openpharma.github.io/mmrm/main/reference/mmrm.html) is [`fit_mmrm()`](https://openpharma.github.io/mmrm/main/reference/fit_mmrm.html). This 8 | function is exported and can be used directly. It is similar to [`mmrm()`](https://openpharma.github.io/mmrm/main/reference/mmrm.html) but lacks 9 | some post-processing and support for Satterthwaite and Kenward-Roger calculations. 10 | It may be useful for other packages that want to fit the model without 11 | the adjustment calculations. 12 | 13 | ```{r low-level-hmmrmtmb} 14 | fit_mmrm( 15 | formula = FEV1 ~ RACE + ARMCD * AVISIT + us(AVISIT | USUBJID), 16 | data = fev_data, 17 | weights = rep(1, nrow(fev_data)), 18 | reml = TRUE, 19 | control = mmrm_control() 20 | ) 21 | ``` 22 | --------------------------------------------------------------------------------