Skip to content

Commit

Permalink
A few more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chjackson committed Apr 3, 2024
1 parent 1a9eaab commit 18d3422
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
14 changes: 0 additions & 14 deletions R/msmbayes_internal.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,6 @@ form_qmodel <- function(Q,Qfix=NULL){
)
}

tidy_Q <- function(Q, full=FALSE){
nst <- nrow(Q)
fromnames <- rownames(Q)
tonames <- colnames(Q)
if (is.null(fromnames)) fromnames <- as.character(1:nst)
if (is.null(tonames)) tonames <- as.character(1:nst)
dat <- data.frame(fromstate = fromnames[row(Q)],
tostate = tonames[col(Q)],
rate = as.vector(Q))
dat <- dat[dat$fromstate != dat$tostate,,drop=FALSE]
if (!full) dat <- dat[dat$rate >0,,drop=FALSE]
dat
}

#' @return List of information about the misclassification structure
#'
#' @noRd
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test_msmbayes.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,16 @@ test_that("Covariates msmbayes model agrees with msm",{
(bayes_ests_age |> pull(`97.5%`) > msm_age)))
expect_true(all((bayes_ests_sex |> pull(`2.5%`) < msm_sex) &
(bayes_ests_sex |> pull(`97.5%`) > msm_sex)))
expect_s3_class(summary(draws)$value,"rvar")
})


test_that("Phase-type model runs, print and summary",{
draws <- msmbayes(infsim2, state="state", time="months", subject="subject",
Q=Q, nphase=c(1,2), fit_method="optimize")
expect_s3_class(draws,"msmbayes")
print(draws)
expect_s3_class(summary(draws)$value,"rvar")
expect_true(nrow(mean_sojourn(draws, by_phase=FALSE)) == 2)
expect_true(nrow(mean_sojourn(draws, by_phase=TRUE)) == 3)
})
8 changes: 8 additions & 0 deletions tests/testthat/test_msmhist.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test_that("msmhist runs",{
p <- msmhist(infsim, "state","months", "subject", nbins=10)
expect_s3_class(p, "ggplot")
p <- msmhist(infsim, "state","months", "subject", absorbing=2, nbins=10)
expect_s3_class(p, "ggplot")
bdat <- msmhist_bardata(infsim, "state","months", "subject", nbins=10)
expect_s3_class(bdat, "data.frame")
})

0 comments on commit 18d3422

Please sign in to comment.