runjags (version 0.9.0-4)

read.winbugs: Extract Any Models, Data, Monitored Variables or Initial Values As Character Vectors from a Winbugs Type Textfile

Description

Read a user specified WinBUGS type textfile or character variable and extract any models, data, monitored variables or initial values as character vectors. Used by run.jagsfile to interpret the input file.

Usage

read.winbugs(path)

Arguments

path
either a relative or absolute path to a textfile (including the file extension) containing a model in the JAGS language and possibly data and/or initial values, or a character string of the same. No default. The model must be started with the string 'mo

Value

  • A named list of 'model' containing the model description, 'data' containing the data given in the data block(s) (if any), 'inits' containing the initial values given in the initial value block(s) (if any), and 'monitor' containing the monitored variables specified in the monitor blocks and by using '#monitor#' within the model block. The list may also contain elements 'autodata' containing data variables specified using '#data#' in the model block, and 'autoinits' containing initial value variables specified using '#inits#' in the model block, where appropriate.

See Also

run.jagsfile

Examples

Run this code
# ALL SYNTAX GIVEN BELOW IS EQUIVALENT


# Use a modified WinBUGS text file with manual inits and manual data and a seperate monitor block (requires least modification from a WinBUGS file).  For compatibility with WinBUGS, the use of list() to enclose data and initial values is allowed and ignored, however all seperate variables in the data and inits blocks must be seperated with a line break (commas or semicolons before linebreaks are ignored).  'data{' and 'inits{' must also be added to WinBUGS textfiles so that the function can seperate data from initial values.  See also the differences in JAGS versus WinBUGS syntax in the JAGS help file.

# Contents of a textfile 'mymodel.bug':

model{

	for(i in 1:N){
		Count[i] ~ dpois(mean)
	}
	mean ~ dgamma(0.01, 100)
}

data{
list(Count <- c(1,2,3,4,5,6,7,8,9,10),
N <- 10)

}
inits{
list(
	mean <- 1)
}

inits{
list(
	mean <- 100)
}

monitor{
	mean
}

# end text file

read.winbugs('pathtofile/mymodel.bug')


# Use internal character variable, define monitors in the model, use autodata and manual initial values:

string <- "
model{

	for(i in 1:N){
		Count[i] ~ dpois(mean) #data# Count, N
	}
	mean ~ dgamma(0.01, 100)
	#monitor# mean
}

inits{
	mean <- 1
}

inits{
	mean <- 100
}
"

read.winbugs(string)


# Use autoinits and a mixture of manual and autodata:
string <- "
model{

	for(i in 1:N){ 
		Count[i] ~ dpois(mean) #data# Count
	}
	mean ~ dgamma(0.01, 100) 
	#monitor# mean
	#inits# mean
}

data{

	N <- 10

}
"

read.winbugs(string)

Run the code above in your browser using DataLab