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

Optional Burn in for the models - mtc.run #79

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ gemtc.Rcheck
*.swp
gemtc_*.tar.gz
*.so
*.o
*.o
2 changes: 1 addition & 1 deletion gemtc/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: gemtc
Version: 1.0-2
Version: 1.0-2.9000
Date: 2023-06-21
Title: Network Meta-Analysis Using Bayesian Methods
Author: Gert van Valkenhoef, Joel Kuiper
Expand Down
7 changes: 7 additions & 0 deletions gemtc/NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
gemtc 1.0-2.9000
===========

Released 2024-XX-XX

* Add addtional n.burnin argument to the mtc.run and mtc.sample. The update is connected with the fact that the nadapt is not equal to nburnin.

gemtc 1.0-2
===========

Expand Down
10 changes: 7 additions & 3 deletions gemtc/R/mtc.run.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ mtc.model.run <- function(network, type, ...) {

# If is.na(sampler), a sampler will be chosen based on availability, in this order:
# JAGS, BUGS. When the sampler is BUGS, BRugs or R2WinBUGS will be used.
mtc.run <- function(model, sampler=NA, n.adapt=5000, n.iter=20000, thin=1) {
mtc.run <- function(model, sampler=NA, n.adapt=5000, n.iter=20000, thin=1, n.burnin=0) {

if (!is.na(sampler)) {
if (sampler %in% c("JAGS", "rjags")) {
warning("Setting the sampler is deprecated.")
Expand All @@ -28,7 +29,7 @@ mtc.run <- function(model, sampler=NA, n.adapt=5000, n.iter=20000, thin=1) {
}
}

result <- mtc.sample(model, n.adapt=n.adapt, n.iter=n.iter, thin=thin)
result <- mtc.sample(model, n.adapt=n.adapt, n.iter=n.iter, thin=thin, n.burnin=n.burnin)

result <- c(result, list(model = model))
class(result) <- "mtc.result"
Expand All @@ -44,7 +45,7 @@ mtc.build.syntaxModel <- function(model) {
)
}

mtc.sample <- function(model, n.adapt=n.adapt, n.iter=n.iter, thin=thin) {
mtc.sample <- function(model, n.adapt, n.iter, thin, n.burnin) {
# generate JAGS model
syntax <- mtc.build.syntaxModel(model)

Expand All @@ -64,6 +65,9 @@ mtc.sample <- function(model, n.adapt=n.adapt, n.iter=n.iter, thin=thin) {
inits=syntax[['inits']],
n.chains=model[['n.chain']],
n.adapt=n.adapt)

if (n.burnin > 0) update(jags, n.iter=n.burnin)

samples <- rjags::coda.samples(jags, variable.names=vars,
n.iter=n.iter, thin=thin)
unlink(file.model)
Expand Down
3 changes: 2 additions & 1 deletion gemtc/man/mtc.run.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The function \code{mtc.run} is used to generate samples from a object of type \c
The resulting \code{mtc.result} object can be coerced to an \code{mcmc.list} for further analysis of the dataset using the \code{coda} package.
}
\usage{
mtc.run(model, sampler = NA, n.adapt = 5000, n.iter = 20000, thin = 1)
mtc.run(model, sampler = NA, n.adapt = 5000, n.iter = 20000, thin = 1, n.burnin = 0)

\method{summary}{mtc.result}(object, ...)
\method{plot}{mtc.result}(x, ...)
Expand All @@ -28,6 +28,7 @@ mtc.run(model, sampler = NA, n.adapt = 5000, n.iter = 20000, thin = 1)
\item{n.adapt}{Amount of adaptation (or tuning) iterations.}
\item{n.iter}{Amount of simulation iterations.}
\item{thin}{Thinning factor.}
\item{n.burnin}{Amount of burn-in iterations. Has to be positive number.}

\item{object}{Object of S3 class \code{mtc.result}.}
\item{x}{Object of S3 class \code{mtc.result}.}
Expand Down