Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] adding support for the {mmrm} package #1000

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
34ba6a5
initial attempt to implement interface
kkmann Jan 10, 2024
98b8038
register method correctly and conforming with API of get_predict()
Jan 24, 2024
1c7bb76
added news item
Jan 24, 2024
3cc027f
Merge branch 'main' into mmrm-extension
kkmann Jan 24, 2024
93b6cce
using model.frame to avoid insights pkg
Jan 24, 2024
52116fe
switch back to model$data for now
lang-benjamin Jan 24, 2024
ade1672
Merge branch 'main' into mmrm-extension
vincentarelbundock Apr 6, 2024
68c8486
update predictions
clarkliming Apr 22, 2024
5a4ecc4
use arg conditional for predict
clarkliming Apr 22, 2024
73eca1d
Merge branch 'main' into mmrm-extension
vincentarelbundock Apr 26, 2024
780747d
sanity + docs
vincentarelbundock Apr 26, 2024
ed55867
Merge branch 'main' into mmrm-extension
vincentarelbundock Aug 11, 2024
41f4cc9
bump + test
vincentarelbundock Aug 11, 2024
f7109ad
tinytable print
vincentarelbundock Aug 11, 2024
17b5d10
mgcv allows discrete argument
vincentarelbundock Aug 21, 2024
3f5467f
comparisons manual computation
vincentarelbundock Aug 22, 2024
6670a54
Support class `model_fit` directly #1194
vincentarelbundock Aug 22, 2024
970cc4e
bump
vincentarelbundock Aug 22, 2024
a4e87a7
bump
vincentarelbundock Aug 24, 2024
95ef3e9
issue #1204 (#1205)
vincentarelbundock Aug 30, 2024
dd13491
issue #1202 default value of `type` `plot_comparison()` (#1206)
vincentarelbundock Aug 31, 2024
60ed303
Support `glmtoolbox::glmgee()` (#1207)
vincentarelbundock Aug 31, 2024
be5ba13
news
vincentarelbundock Aug 31, 2024
c5290e8
Support `glmtoolbox::glmgee()` (#1207)
vincentarelbundock Aug 31, 2024
c6730c4
Merge branch 'main' into mmrm-extension
vincentarelbundock Aug 31, 2024
9dd18c0
Merge branch 'main' into mmrm-extension
vincentarelbundock Aug 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Suggests:
miceadds,
mlogit,
mlr3verse,
mmrm (>= 0.3.12),
modelbased,
modelsummary,
nlme,
Expand Down Expand Up @@ -246,6 +247,7 @@ Collate:
'methods_mlm.R'
'methods_mlogit.R'
'methods_mlr3.R'
'methods_mmrm.R'
'methods_nlme.R'
'methods_ordinal.R'
'methods_plm.R'
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ S3method(get_coef,lmerModLmerTest)
S3method(get_coef,mblogit)
S3method(get_coef,merMod)
S3method(get_coef,mlm)
S3method(get_coef,mmrm)
S3method(get_coef,multinom)
S3method(get_coef,nls)
S3method(get_coef,polr)
Expand Down Expand Up @@ -76,6 +77,7 @@ S3method(get_predict,mblogit)
S3method(get_predict,merMod)
S3method(get_predict,mhurdle)
S3method(get_predict,mlogit)
S3method(get_predict,mmrm)
S3method(get_predict,model_fit)
S3method(get_predict,multinom)
S3method(get_predict,ols)
Expand Down Expand Up @@ -104,6 +106,7 @@ S3method(get_vcov,glimML)
S3method(get_vcov,glmmTMB)
S3method(get_vcov,gsm)
S3method(get_vcov,mhurdle)
S3method(get_vcov,mmrm)
S3method(get_vcov,model_fit)
S3method(get_vcov,orm)
S3method(get_vcov,pstpm2)
Expand Down Expand Up @@ -160,6 +163,7 @@ S3method(set_coef,lmerMod)
S3method(set_coef,lmerModLmerTest)
S3method(set_coef,merMod)
S3method(set_coef,mlm)
S3method(set_coef,mmrm)
S3method(set_coef,model_fit)
S3method(set_coef,multinom)
S3method(set_coef,nls)
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ Breaking changes:

New models supported:

* `stpm2`, `pstpm2`, `gsm`, and `aft` models from `rstpm2`. Thanks to @aghaynes and @mclements.
* `rstpm2` package: support for `stpm2`, `pstpm2`, `gsm`, and `aft` models. Thanks to @mclements for contribution #1188 and @aghayes for useful comments.
* `glm_weightit`, `coxph_weightit`, `multinom_weightit`, and `ordinal_weightit` models from `Weightit`. Thanks to @ngreifer.
* `glmmgee` from the `glmtoolbox` package. Thanks to @adrianolszewski for the request and @lhvanegasp for help with implementation.
* `mmrm` package for mixed effects modelling. Thanks to @kkmann for contribution #1000, as well as @clarkliming and @lang-benjamin for useful comments.

New features:

Expand Down
48 changes: 48 additions & 0 deletions R/methods_mmrm.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#' @include set_coef.R
#' @rdname set_coef
#' @keywords internal
#' @export
set_coef.mmrm <- function(model, coefs, ...) {
model$beta_est <- coefs
return(model)
}


#' @include get_coef.R
#' @rdname get_coef
#' @keywords internal
#' @export
get_coef.mmrm <- function(model, ...) {
return(coef(model, ...))
}


#' @include get_vcov.R
#' @rdname get_vcov
#' @keywords internal
#' @export
get_vcov.mmrm <- function(model, ...) {
return(vcov(model, ...))
}


#' @rdname get_predict
#' @keywords internal
#' @export
get_predict.mmrm <- function(model, newdata = model$data, type = "response", ...) {
type <- match.arg(type)
res <- data.frame(
rowid = seq_len(nrow(newdata)),
estimate = predict(model, newdata = newdata, type = type, conditional = FALSE)
)
return(res)
}


#' @include sanity_model.R
#' @rdname sanitize_model_specific
#' @keywords internal
sanitize_model_specific.mmrm <- function(model, ...) {
insight::check_if_installed("mmrm", minimum_version = "0.3.11.9000")
return(model)
}
1 change: 1 addition & 0 deletions R/sanity_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ sanity_model_supported_class <- function(model) {
"mhurdle",
"mira",
"mlogit",
"mmrm",
"model_fit",
c("multinom", "nnet"),
"multinom_weightit",
Expand Down
17 changes: 17 additions & 0 deletions inst/tinytest/test-pkg-mmrm.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
source("helpers.R")
using("marginaleffects")

requiet("mmrm")

fit <- mmrm(
formula = FEV1 ~ RACE + SEX + ARMCD * AVISIT + us(AVISIT | USUBJID),
data = fev_data
)

pre <- avg_predictions(fit, newdata = fev_data)
expect_inherits(pre, "predictions")

cmp <- avg_comparisons(fit,
variables = "SEX",
newdata = fev_data)
expect_inherits(cmp, "comparisons")
3 changes: 3 additions & 0 deletions man/get_coef.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/get_predict.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions man/get_vcov.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/sanitize_model_specific.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/set_coef.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading