genInitsFile: Generating Initial Value Files for BUGS

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/rbugs.R

Description

Generating the files of initial values for MCMC which can be used in the script for running BUGS in batch-mode.

Usage

1
genInitsFile(n.chains, inits, initsFileStem)

Arguments

n.chains

The number of chains to run.

inits

A list of list of initial values or a function which returns a list of initial values. See details.

initsFileStem

A character string naming the files to print to. See details.

Details

if inits is a list, it should have length n.chains, and each element of the list should be a list which contains one set of initial values. If inits is a function, it will be run n.chains times to generate a list of list of initial values.

The initsFileStem is the stem of the file names. The resulted file names end with .txt. For example, if n.chains is 3 and initsFileStem is "init", then the file names will be init1.txt, init2.txt, and init3.txt.

Value

None.

Author(s)

Jun Yan jyan@stat.uiowa.edu and Marcos Prates marcosop@est.ufmg.br

See Also

genDataFile, genBugsScript

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## when inits is a list:
inits <- list(list(alpha=1, beta=2), list(alpha=4, beta=4))
genInitsFile(2, inits, "foo.init")
file.show("foo.init1.txt")
file.show("foo.init2.txt")
## when inits is a function:
inits <- function() list(alpha=rnorm(2, sd=100),
                         beta=rgamma(1, 0.1, 0.001))
genInitsFile(2, inits, "foo.init")
file.show("foo.init1.txt")
file.show("foo.init2.txt")
unlink("foo.init1.txt")
unlink("foo.init2.txt")

Example output

list(
alpha
=
1.00000E+00, beta
=
2.00000E+00
)

list(
alpha
=
4.00000E+00, beta
=
4.00000E+00
)

list(
alpha
=c(
-6.08204E+01, 1.75619E+01
), beta
=
8.85401E+01
)

list(
alpha
=c(
-1.22095E+02, 1.41052E+01
), beta
=
1.99390E+01
)

rbugs documentation built on Jan. 15, 2019, 5:04 p.m.

Related to genInitsFile in rbugs...