Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkliming committed Apr 24, 2024
1 parent 53273d7 commit 37e5903
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 45 deletions.
4 changes: 2 additions & 2 deletions R/tmb-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ predict.mmrm_tmb <- function(object,
newdata <- h_factor_ref_data(
newdata,
object$tmb_data$full_frame,
h_mmrm_vars(object$formula_parts)
object$formula_parts$model_var
)
tmb_data <- h_mmrm_tmb_data(
object$formula_parts, newdata,
Expand Down Expand Up @@ -618,7 +618,7 @@ simulate.mmrm_tmb <- function(object,
newdata <- h_factor_ref_data(
newdata,
object$tmb_data$full_frame,
h_mmrm_vars(object$formula_parts)
object$formula_parts$model_var
)
tmb_data <- h_mmrm_tmb_data(
object$formula_parts, newdata,
Expand Down
12 changes: 6 additions & 6 deletions R/tmb.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#' - `subject_var`: `string` with the subject variable name.
#' - `group_var`: `string` with the group variable name. If no group specified,
#' this element is `NULL`.
#' - `model_var`: `character` with the variables names of the formula, except `subject_var`.
#'
#' @keywords internal
h_mmrm_tmb_formula_parts <- function(
Expand All @@ -37,7 +38,8 @@ h_mmrm_tmb_formula_parts <- function(
is_spatial = covariance$type == "sp_exp",
visit_var = covariance$visits,
subject_var = covariance$subject,
group_var = if (length(covariance$group) < 1) NULL else covariance$group
group_var = if (length(covariance$group) < 1) NULL else covariance$group,
model_var = setdiff(all.vars(formula[[3]]), covariance$subject)
),
class = "mmrm_tmb_formula_parts"
)
Expand Down Expand Up @@ -135,10 +137,7 @@ h_mmrm_tmb_data <- function(formula_parts,
# Weights is always the last column.
weights_name <- colnames(data)[ncol(data)]
# If `y` is allowed to be NA, then first replace y with 1:n, then replace it with original y.
if (allow_na_response) {
y_original <- eval(formula_parts$full_formula[[2]], envir = data)
vn <- deparse(formula_parts$full_formula[[2]])
} else {
if (!allow_na_response) {
h_warn_na_action()
}
full_frame <- eval(
Expand All @@ -153,7 +152,8 @@ h_mmrm_tmb_data <- function(formula_parts,
full_frame <- droplevels(full_frame, except = formula_parts$visit_var)
}
if (allow_na_response) {
keep_ind <- complete.cases(full_frame[, colnames(full_frame) != vn])
# response is always the first column
keep_ind <- complete.cases(full_frame[, -1L, drop = FALSE])
} else {
keep_ind <- complete.cases(full_frame)
}
Expand Down
10 changes: 0 additions & 10 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,6 @@ h_factor_ref_data <- function(x, ref, vars) {
x
}

#' Obtain Right Hand Side Variables of `mmrm_tmb_formula_parts` Object
#'
#' @param object (`mmrm_tmb_formula_parts`)\cr object.
#'
#' @keywords internal
h_mmrm_vars <- function(object) {
assert_class(object, "mmrm_tmb_formula_parts")
setdiff(all.vars(object$formula[[3]]), object$subject_var)
}

#' Warn on na.action
#' @keywords internal
h_warn_na_action <- function() {
Expand Down
1 change: 1 addition & 0 deletions man/h_mmrm_tmb_formula_parts.Rd

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

15 changes: 0 additions & 15 deletions man/h_mmrm_vars.Rd

This file was deleted.

12 changes: 8 additions & 4 deletions tests/testthat/test-tmb.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ test_that("h_mmrm_tmb_formula_parts works as expected", {
is_spatial = FALSE,
visit_var = "AVISIT",
subject_var = "USUBJID",
group_var = NULL
group_var = NULL,
model_var = c("RACE", "SEX", "ARMCD", "AVISIT")
),
class = "mmrm_tmb_formula_parts"
)
Expand All @@ -53,7 +54,8 @@ test_that("h_mmrm_tmb_formula_parts works as expected", {
is_spatial = FALSE,
visit_var = "AVISIT",
subject_var = "USUBJID",
group_var = "ARMCD"
group_var = "ARMCD",
model_var = c("RACE", "SEX", "ARMCD", "AVISIT")
),
class = "mmrm_tmb_formula_parts"
)
Expand Down Expand Up @@ -115,7 +117,8 @@ test_that("h_mmrm_tmb_formula_parts works without covariates", {
is_spatial = FALSE,
visit_var = "AVISIT",
subject_var = "USUBJID",
group_var = NULL
group_var = NULL,
model_var = c("AVISIT")
),
class = "mmrm_tmb_formula_parts"
)
Expand All @@ -135,7 +138,8 @@ test_that("h_mmrm_tmb_formula_parts works as expected for antedependence", {
is_spatial = FALSE,
visit_var = "AVISIT",
subject_var = "USUBJID",
group_var = NULL
group_var = NULL,
model_var = c("RACE", "SEX", "ARMCD", "AVISIT")
),
class = "mmrm_tmb_formula_parts"
)
Expand Down
8 changes: 0 additions & 8 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,3 @@ test_that("emp_start works", {
h_get_theta_from_cov(emp_mat)
)
})

# h_mmrm_vars ----

test_that("h_mmrm_vars works", {
fit <- get_mmrm()
expect_silent(v <- h_mmrm_vars(fit$formula_parts))
expect_identical(v, c("RACE", "SEX", "ARMCD", "AVISIT"))
})

0 comments on commit 37e5903

Please sign in to comment.