normgibbs: A simple Gibbs sampler for Bayesian inference for the mean...

Description Usage Arguments Value See Also Examples

Description

This function runs a simple Gibbs sampler for the Bayesian posterior distribution of the mean and precision given a normal random sample.

Usage

1
normgibbs(N, n, a, b, cc, d, xbar, ssquared)

Arguments

N

The number of iterations of the Gibbs sampler.

n

The sample size of the normal random sample.

a

The shape parameter of the gamma prior on the sample precision.

b

The scale parameter of the gamma prior on the sample precision.

cc

The mean of the normal prior on the sample mean.

d

The precision of the normal prior on the sample mean.

xbar

The sample mean of the data. eg. mean(x) for a vector x.

ssquared

The sample variance of the data. eg. var(x) for a vector x.

Value

An R matrix object containing the samples of the Gibbs sampler.

See Also

rcfmc, metrop, mcmcSummary

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
postmat=normgibbs(N=1100,n=15,a=3,b=11,cc=10,d=1/100,xbar=25,ssquared=20)
postmat=postmat[101:1100,]
op=par(mfrow=c(3,3))
plot(postmat)
plot(postmat,type="l")
plot.new()
plot(ts(postmat[,1]))
plot(ts(postmat[,2]))
plot(ts(sqrt(1/postmat[,2])))
hist(postmat[,1],30)
hist(postmat[,2],30)
hist(sqrt(1/postmat[,2]),30)
par(op)

Example output

Loading required package: abind
Loading required package: parallel

smfsb documentation built on May 2, 2019, 5:13 a.m.