Skip to content

Commit

Permalink
mmrm updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ddsjoberg committed Nov 28, 2023
1 parent b1749da commit d6072ac
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 49 deletions.
4 changes: 0 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ S3method(model_get_model_matrix,clm)
S3method(model_get_model_matrix,default)
S3method(model_get_model_matrix,fixest)
S3method(model_get_model_matrix,glmmTMB)
S3method(model_get_model_matrix,mmrm)
S3method(model_get_model_matrix,model_fit)
S3method(model_get_model_matrix,multinom)
S3method(model_get_model_matrix,plm)
Expand Down Expand Up @@ -71,10 +70,8 @@ S3method(model_get_terms,betareg)
S3method(model_get_terms,brmsfit)
S3method(model_get_terms,default)
S3method(model_get_terms,glmmTMB)
S3method(model_get_terms,mmrm)
S3method(model_get_terms,model_fit)
S3method(model_get_weights,default)
S3method(model_get_weights,mmrm)
S3method(model_get_weights,model_fit)
S3method(model_get_weights,svyglm)
S3method(model_get_xlevels,brmsfit)
Expand All @@ -83,7 +80,6 @@ S3method(model_get_xlevels,felm)
S3method(model_get_xlevels,glmerMod)
S3method(model_get_xlevels,glmmTMB)
S3method(model_get_xlevels,lmerMod)
S3method(model_get_xlevels,mmrm)
S3method(model_get_xlevels,model_fit)
S3method(model_get_xlevels,plm)
S3method(model_identify_variables,aov)
Expand Down
9 changes: 0 additions & 9 deletions R/model_get_model_matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,6 @@ model_get_model_matrix.LORgee <- function(model, ...) {
)
}

#' @export
#' @rdname model_get_model_matrix
model_get_model_matrix.mmrm <- function(model, ...) {
stats::model.matrix.default(
model %>% model_get_terms(),
data = stats::model.frame(model)
)
}

#' @export
#' @rdname model_get_model_matrix
model_get_model_matrix.betareg <- function(model, ...) {
Expand Down
6 changes: 0 additions & 6 deletions R/model_get_terms.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ model_get_terms.model_fit <- function(model) {
model_get_terms(model$fit)
}

#' @export
#' @rdname model_get_terms
model_get_terms.mmrm <- function(model) {
model$formula_parts$model_formula %>% stats::terms()
}

#' @export
#' @rdname model_get_terms
model_get_terms.betareg <- function(model) {
Expand Down
8 changes: 0 additions & 8 deletions R/model_get_weights.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,3 @@ model_get_weights.svyglm <- function(model) {
model_get_weights.model_fit <- function(model) {
model_get_weights(model$fit)
}

#' @export
#' @rdname model_get_weights
model_get_weights.mmrm <- function(model) {
w <- stats::weights(model)
mf <- model %>% model_get_model_frame()
w[as.integer(row.names(mf))]
}
10 changes: 0 additions & 10 deletions R/model_get_xlevels.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,3 @@ model_get_xlevels.plm <- model_get_xlevels.lmerMod
model_get_xlevels.model_fit <- function(model) {
model_get_xlevels(model$fit)
}

#' @export
#' @rdname model_get_xlevels
model_get_xlevels.mmrm <- function(model) {
xlevels <- stats::.getXlevels(
model %>% model_get_terms(),
model %>% model_get_model_frame()
)
xlevels %>% .add_xlevels_for_logical_variables(model)
}
3 changes: 0 additions & 3 deletions man/model_get_model_matrix.Rd

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

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

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

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

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

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

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

32 changes: 32 additions & 0 deletions tests/testthat/test-tidy_plus_plus.R
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,38 @@ test_that("tidy_plus_plus() works with betareg::betareg() models", {
expect_equal(nrow(res), 24)
})

test_that("tidy_plus_plus() works with mmrm::mmrm() models", {
skip_on_cran()
skip_if_not_installed("mmrm")

m1 <- mmrm::mmrm(FEV1 ~ SEX + ARMCD + AVISIT + us(AVISIT | USUBJID), data = mmrm::fev_data)
m2 <- mmrm::mmrm(FEV1 ~ SEX + ARMCD * AVISIT + us(AVISIT | USUBJID), data = mmrm::fev_data)

expect_error(
res <- m1 %>% tidy_plus_plus(intercept = TRUE),
NA
)
expect_equal(nrow(res), 9)

expect_error(
res <- m1 %>% tidy_plus_plus(add_header_rows = TRUE),
NA
)
expect_equal(nrow(res), 11)

expect_error(
res <- m2 %>% tidy_plus_plus(intercept = TRUE),
NA
)
expect_equal(nrow(res), 12)

expect_error(
res <- m2 %>% tidy_plus_plus(add_header_rows = TRUE),
NA
)
expect_equal(nrow(res), 15)
})

test_that("tidy_post_fun argument of `tidy_plus_plus()`", {
mod <- lm(Petal.Length ~ Petal.Width + Species, iris)

Expand Down

0 comments on commit d6072ac

Please sign in to comment.