sbhm: Fit a simple hierarchical normal model with MCMC

Description Usage Arguments Details Value Methods (by generic) Author(s) Examples

View source: R/sbhm.R

Description

Fit a simple hierarchical normal model with MCMC

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
sbhm(y, s, m = 0, tauScale = NULL, engine = c("stan", "jags"),
  nchains = NULL, iter = 41000, burn = 1000, thin = 4,
  probs = c(0.025, 0.25, 0.5, 0.75, 0.975))

## S3 method for class 'sbhm'
print(x, digits = 3, ...)

## S3 method for class 'sbhm'
plot(x, xlab = "Estimates", ylab = "", main = "",
  mle.col = "blue", sbhm.col = "orange", margins = c(5.1, 7.1, 4.1, 2.1),
  offset = 0.2, lwd.step = 2, cex = 1.5, ...)

Arguments

y

The observed group means.

s

The observed group standard errors.

m

The top level mean. Defaults to m=0.

tauScale

The scale parameter for the half-Cauchy distribution for the top level scale. Defaults to twice the range of y.

engine

Which MCMC engine to use. Defaults to engine="stan" and if stan is not avaiable will try JAGS. Note that if the engine is JAGS, a since Markov chain will be run, irrespective of the nchains argument.

nchains

The number of chains to run. If not specified and stan is available, the function tries to figure out how many cores are available, then uses all but one of them to run a chain. If JAGS is to be used, it defaults to running 3 chains in sequence, not parallel.

iter

The number of steps in each Markov chain. Defaults to iter=41000.

burn

The number of burn-in steps to be discarded from each chain. Defaults to burn=1000.

thin

The amount of thinning of each chain to do. Defaults to thin=4.

probs

The quantiles of the posterior distribution to print. Defaults to probs=c(.025, .25, .5, .75, .975).

x

In plot.sbhm, an object of class "sbhm".

digits

In print.sbhm, the number of digits to round to.

...

Additional arguments to plot. Not used.

xlab

In plot.sbhm, the x-axis label.

ylab

In plot.sbhm, the y-axis label.

main

In plot.sbhm, the main title.

mle.col

In plot.sbhm, the colour of the mles.

sbhm.col

In plot.sbhm, the colour of the shrunken estimates.

margins

Vector of length 4 giving the margin sizes for plot. Defaults to margins=c(5.1, 7.1, 4.1, 2.1).

offset

In plot.sbhm, how much to nudge the mle estiamtes upwards and the sbhm estimates downwards. Defaults to offset=.2.

lwd.step

The difference in line widths for the confidence intervals. Defaults to lwd.step=2.

cex,

In plot.sbhm, character expansion. Defaults to cex=1.5.

Details

The function requires that you have either rstan or rjags installed. Because many users of rstan would have no need for rjags, rjags is not featured as a dependency. Because rstan is not on CRAN and takes a little effort to install, the user might want to use rjags instead, so rstan is not featured as a dpeendency.

Value

An object of class "sbhm" containing the fitted model, probs, engine, the data and function call.

Methods (by generic)

Author(s)

Harry Southworth

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## Not run: 
mod <- sbhm(schools$effect, schools$se)
plot(mod)
# The MERIT-HF study
y <- merit$logHR
names(y) <- merit$country # used as labels in the plot
mod <- sbhm(y=y, s=merit$se, nchains=2)
plot(mod)

## End(Not run)

harrysouthworth/sbhm documentation built on May 17, 2019, 3:03 p.m.