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

Ignore class when comparing with msm qmatrix #127

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Changes from all commits
Commits
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
17 changes: 11 additions & 6 deletions tests/testthat/test-tpmatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ fit <- msm(state_id ~ time, subject = patient_id,

test_that("qmatrix.msm() works with factor covariates and 'newdata' is one row" , {
newdata <- data.frame(strategy_name = "New 1", age = 50)
msmq <- msm::qmatrix.msm(fit, newdata[1, , drop = FALSE], ci = "none")
expect_equal(
msm::qmatrix.msm(fit, newdata[1, , drop = FALSE], ci = "none"),
unclass(msmq),
qmatrix(fit, newdata, uncertainty = "none")[, , 1],
check.attributes = FALSE
)
Expand All @@ -239,8 +240,9 @@ test_that("qmatrix.msm() works with factor covariates and 'newdata' is one row"
test_that("qmatrix.msm() works with factor covariates and 'newdata' is multiple rows" , {
newdata <- data.frame(strategy_name = c("New 1", "New 2"),
age = c(50, 55))
msmq <- msm::qmatrix.msm(fit, newdata[2, , drop = FALSE], ci = "none")
expect_equal(
msm::qmatrix.msm(fit, newdata[2, , drop = FALSE], ci = "none"),
unclass(msmq),
qmatrix(fit, newdata, uncertainty = "none")[, , 2],
check.attributes = FALSE
)
Expand All @@ -250,8 +252,9 @@ test_that("qmatrix.msm() works with covariates that vary by transition" , {
fit <- update(fit, covariates = list("1-2" = ~ strategy_name + age))
newdata <- data.frame(strategy_name = c("New 1", "New 2"),
age = c(50, 55))
msmq <- msm::qmatrix.msm(fit, newdata[2, , drop = FALSE], ci = "none")
expect_equal(
msm::qmatrix.msm(fit, newdata[2, , drop = FALSE], ci = "none"),
unclass(msmq),
qmatrix(fit, newdata, uncertainty = "none")[, , 2],
check.attributes = FALSE
)
Expand All @@ -277,8 +280,9 @@ test_that("qmatrix.msm() works with a hidden Markov model" , {
hconstraint = list(acute = c(1, 1)),
death = 3,
method = "BFGS")
msmq <- msm::qmatrix.msm(fith, covariates = list(acute = 0), ci = "none")
expect_equal(
msm::qmatrix.msm(fith, covariates = list(acute = 0), ci = "none"),
unclass(msmq),
qmatrix(fith, data.frame(acute = 0), uncertainty = "none")[,,1],
check.attributes = FALSE
)
Expand All @@ -299,8 +303,9 @@ test_that("qmatrix.msm() requires 'newdata' if covariates are included in the mo

test_that("qmatrix.msm() does not require 'newdata' if no covariates are included in the model." , {
fit <- update(fit, covariates =~ 1)
msmq <- msm::qmatrix.msm(fit, ci = "none")
expect_equal(
msm::qmatrix.msm(fit, ci = "none"),
unclass(msmq),
qmatrix(fit, uncertainty = "none")[,,1],
check.attributes = FALSE
)
Expand Down Expand Up @@ -408,4 +413,4 @@ test_that("apply_rr() can only have one complementary column for each row in mat
complement = list(c(1, 1), c(1,2))),
"There can only be one complementary column in each row."
)
})
})
Loading