Skip to content

Commit

Permalink
fix time in pem interval
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsecrest committed Oct 23, 2024
1 parent 0c14336 commit a1d8894
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions R/cast_mat_to_long_pem.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ cast_mat_to_long_pem <- function(analysis_obj) {
end = analysis_obj@outcome@time_var)
names(long_df)[which(names(long_df) == "psb2__period")] <- "__period__"
long_df[, analysis_obj@outcome@cens_var] <- 1 - long_df[, "psb2__status"]
long_df[, "time"] <- long_df[, "time"] - long_df[, "psb2__tstart"]
long_df <- long_df[, c(cn, "__period__")]
long_mat <- as.matrix(long_df)

Expand Down
16 changes: 11 additions & 5 deletions tests/testthat/test-mcmc_sample-analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,18 @@ test_that("mcmc_sample for Analysis works for full borrowing, piecewise exponent

full_pem_bayes <- mcmc_sample(full_pem_bayes_ao,
iter_warmup = 2000,
iter_sampling = 10000,
chains = 4
iter_sampling = 5000,
chains = 2
)
expect_r6(full_pem_bayes, "CmdStanMCMC")
expect_equal(full_pem_bayes$summary("beta_trt")[[2]], pem_eha$coefficients[['trt']], tolerance = 0.1)
expect_equal(full_pem_bayes$summary("beta[1]")[[2]], pem_eha$coefficients[['cov1']], tolerance = 0.1)
expect_equal(full_pem_bayes$summary("beta[2]")[[2]], pem_eha$coefficients[['cov2']], tolerance = 0.1)
expect_equal(full_pem_bayes$summary("beta_trt")[[2]], pem_eha$coefficients[['trt']], tolerance = 0.05)
expect_equal(full_pem_bayes$summary("beta[1]")[[2]], pem_eha$coefficients[['cov1']], tolerance = 0.05)
expect_equal(full_pem_bayes$summary("beta[2]")[[2]], pem_eha$coefficients[['cov2']], tolerance = 0.05)

# Check that the cut points are the same
expect_equal(full_pem_bayes$summary("alpha[1]")[[2]], log(pem_eha$hazards[1]), tolerance = 0.05)
expect_equal(full_pem_bayes$summary("alpha[2]")[[2]], log(pem_eha$hazards[2]), tolerance = 0.05)
expect_equal(full_pem_bayes$summary("alpha[3]")[[2]], log(pem_eha$hazards[3]), tolerance = 0.05)
expect_equal(full_pem_bayes$summary("alpha[4]")[[2]], log(pem_eha$hazards[4]), tolerance = 0.05)

})

0 comments on commit a1d8894

Please sign in to comment.