extract.sienaBayes: Extraction of posterior samples or posterior means from...

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

View source: R/bayesTest.r

Description

The first function extracts posterior samples from a list of sienaBayesFit object to be used, e.g., for assessing convergence.
The second function extracts posterior means and standard deviations per group from a sienaBayesFit object.

Usage

1
2
3
4
extract.sienaBayes(zlist, nfirst=zlist[[1]]$nwarm+1, extracted,
                   sdLog=TRUE)
extract.posteriorMeans(z, nfirst=z$nwarm+1, pmonly=1, excludeRates=FALSE,
                   verbose=TRUE)

Arguments

zlist

A list of sienaBayesFit objects, further called 'chains', resulting from calls to sienaBayes with a common data set and model specification.

z

A sienaBayesFit object.

nfirst

Integer: the first element for the first MCMC chain used for calculating properties of the chain.

extracted

The parameters for which posterior samples are to be extracted:
"all": all parameters;
"rates": all groupwise rate parameters;
"varying": all varying non-rate parameters: global means and standard deviations;
"non-varying": all estimated non-varying (and therefore, non-rate) parameters;
"objective": all non-rate parameters.

sdLog

Logical: should the logarithms be taken of the posterior standard deviations (applies only to varying parameters).

pmonly

if pmonly=0 the posterior means and standard deviations are extracted, if pmonly=1 only the posterior means, if pmonly=2 only the posterior standard deviations.

excludeRates

Logical: whether to exclude the rate parameters.

verbose

Logical: gives some console output to show ongoing activity (may be reassuring for large number of groups).

Details

extract.sienaBayes produces a 3-dimensional array, iterations by chains by parameters, suitable for use, e.g., in function monitor() of package rstan. The 'iterations' are draws from the posterior distribution (provided that convergence was achieved), after the thinning in sienaBayes implied by its parameters nrunMHBatches, nSampVarying, nSampConst and nSampRate.
The number of iterations should be the same for all chains.
It is not checked that the specifications of the chains are identical. For the parameter names, the shortNames in the first chain are used.

extract.posteriorMeans produces the posterior means of the groupwise varying parameters. The resulting matrix has the groups in the rows. The effects are in the columns: for each effect comes first the posterior mean, then the posterior standard deviation.

Value

For extract.sienaBayes a 3-dimensional array, iterations by chains by parameters, the third dimension having the names of the parameters.
For extract.posteriorMeans a matrix with the groups in the rows and all effects in the columns, with for each effect two columns: first the posterior mean (effect name preceded by "p.m.") and then the posterior standard deviation (effect name preceded by "psd.").
If some names are duplicated (e.g., because of the presence of evaluation and creation effects), these can be changed by the user after creation of the array.

Author(s)

Tom Snijders

References

See the manual and http://www.stats.ox.ac.uk/~snijders/siena/

See Also

sienaBayes, plotPostMeansMDS

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  Group1 <- sienaDependent(array(c(N3401, HN3401), dim=c(45, 45, 2)))
  Group3 <- sienaDependent(array(c(N3403, HN3403), dim=c(37, 37, 2)))
  Group4 <- sienaDependent(array(c(N3404, HN3404), dim=c(33, 33, 2)))
  Group6 <- sienaDependent(array(c(N3406, HN3406), dim=c(36, 36, 2)))
  dataset.1 <- sienaDataCreate(Friends = Group1)
  dataset.3 <- sienaDataCreate(Friends = Group3)
  dataset.4 <- sienaDataCreate(Friends = Group4)
  dataset.6 <- sienaDataCreate(Friends = Group6)
  FourGroups <- sienaGroupCreate(
        list(dataset.1, dataset.3, dataset.4, dataset.6))
  FourEffects <- getEffects(FourGroups)
  FourEffects <- includeEffects(FourEffects, transTrip)
  FourEffects <- setEffect(FourEffects, density, random=TRUE)
  FourEffects <- setEffect(FourEffects, recip, random=TRUE)
  print(FourEffects, includeRandoms=TRUE)
  # Note this also shows the "randomEffects" column.
  FourAlgo <- sienaAlgorithmCreate(projname = "FourGroups", maxlike=TRUE)
## Not run: 
  bayes.models <- replicate(4, sienaBayes(FourAlgo, data = FourGroups,
        effects = FourEffects, nwarm=10, nmain=25, nrunMHBatches=10),
        simplify=FALSE)
  bayes.extracted <- extract.sienaBayes(bayes.models, extracted="all")
  dim(bayes.extracted)
  dimnames(bayes.extracted)
  extract.posteriorMeans(bayes.models[[1]])

## End(Not run)

RSienaTest documentation built on July 14, 2021, 3 a.m.