Skip to content

Commit

Permalink
fix parallel error with bayes_cen
Browse files Browse the repository at this point in the history
moving geweke test within the parallel loop
  • Loading branch information
Kuan-Liu committed Nov 5, 2024
1 parent 650643c commit ccb3f2d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
20 changes: 11 additions & 9 deletions R/bayesweight_cen.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
#' C3 ~ L11 + L21 + A1 +
#' L12 + L22 + A2),
#' data = simdat_cen,
#' n.iter = 2500,
#' n.burnin = 1500,
#' n.thin = 5,
#' n.iter = 1500,
#' n.burnin = 500,
#' n.thin = 1,
#' parallel = FALSE,
#' n.chains = 1,
#' seed = 890123)
Expand Down Expand Up @@ -318,6 +318,7 @@ bayesweight_cen <- function(trtmodel.list = list(A1 ~ L11 + L21,
# Combine MCMC output from multiple chains
out.mcmc <- as.mcmc(jagsfit)
return(do.call(rbind, lapply(out.mcmc, as.matrix)))

}

parallel::stopCluster(cl)
Expand All @@ -337,14 +338,15 @@ bayesweight_cen <- function(trtmodel.list = list(A1 ~ L11 + L21,

out.mcmc <- as.mcmc(jagsfit)
posterior <- as.matrix(out.mcmc[[1]])
}

diagnostics <- geweke.diag(out.mcmc)
diagnostics <- geweke.diag(out.mcmc)

# Check diagnostics for convergence issues
significant_indices <- which(abs(diagnostics[[1]]$z) > 1.96)
if (length(significant_indices) > 0) {
warning("Some parameters have not converged with Geweke index > 1.96. More iterations may be needed.")
}

# Check diagnostics for convergence issues
significant_indices <- which(abs(diagnostics[[1]]$z) > 1.96)
if (length(significant_indices) > 0) {
warning("Some parameters have not converged with Geweke index > 1.96. More iterations may be needed.")
}

expit <- function(x){exp(x) / (1+exp(x))}
Expand Down
1 change: 1 addition & 0 deletions R/globals.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
if (getRversion() >= "2.15.1") {
utils::globalVariables(c("chain_idx"))
utils::globalVariables(c("x", "y", "Treatment", "Mean", "LowerCI", "UpperCI"))
}
6 changes: 3 additions & 3 deletions man/bayesweight_cen.Rd

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

Binary file removed tests/testthat/Rplots.pdf
Binary file not shown.
10 changes: 5 additions & 5 deletions tests/testthat/test-bayesweight_cen.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ test_that("bayesweight_cen works with no errors", {
C2 ~ L11 + L21 + A1,
C3 ~ L11 + L21 + A1 + L12 + L22 + A2),
data = simdat_cen,
n.iter = 2500,
n.burnin = 1500,
n.thin = 5,
parallel = FALSE,
n.chains = 1,
n.iter = 1500,
n.burnin = 500,
n.thin = 1,
parallel = TRUE,
n.chains = 2,
seed = 890123)

# Check that the weights_cen object has the expected dimensions (length or rows matching the data size)
Expand Down
2 changes: 1 addition & 1 deletion vignettes/bayesmsm-censoring.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: "Longitudinal causal analysis with informative right-censoring"
author: "Xiao Yan, Kuan Liu"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{`bayesmsm` for longitudinal data without right-censoring}
%\VignetteIndexEntry{`bayesmsm` for longitudinal data with informative right-censoring}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
Expand Down

0 comments on commit ccb3f2d

Please sign in to comment.