schools: 8 schools

Description Usage Format Source Examples

Description

8 schools analysis from section 5.5 of "Bayesian Data Analysis" by Andrew Gelman, John B. Carlin, Hal S. Stern, and Donald B. Rubin.

Usage

1

Format

A data frame with 8 observations on the following 3 variables.

school

a factor with levels A B C D E F G H

estimate

a numeric vector

sd

a numeric vector

Source

Gelman, A., Carlin, J.B., Stern, H.S., Rubin, D.B. (2003): Bayesian Data Analysis, 2nd edition, CRC Press.

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
28
29
30
31
32
33
34
35
36
37
38
data(schools)
J <- nrow(schools)
y <- schools$estimate
y <- rnorm(length(y))
sigma.y <- schools$sd
schools.data <- list ("J", "y", "sigma.y") 
## schools.data <- list(J=J, y=y, sigma.y=sigma.y)
inits <- function() {list (theta=rnorm(J,0,100),
                           mu.theta=rnorm(1,0,100),
                           sigma.theta=runif(1,0,100))}
parameters <- c("theta", "mu.theta", "sigma.theta")
schools.bug <- system.file("bugs/model/schools.bug", package="rbugs")
file.show(schools.bug)

## Not run: 
## no tested examples for mac-os.

schools.sim <- rbugs(data=schools.data, inits, parameters,
                     schools.bug, n.chains=3, n.iter=1000,
                     bugs="/usr/bin/OpenBUGS",
                     bugsWorkingDir="~/tmp/")
                    
## generate files only
schools.sim <- rbugs(data=schools.data, inits, parameters,
                     schools.bug, n.chains=3, n.iter=1000,
                     bugsWorkingDir="~/tmp/",
                     OpenBugs=TRUE, genFilesOnly=TRUE)

## MCMC analysis
library("coda")
schools.mcmc <- rbugs2coda(schools.sim)
summary(schools.mcmc)
effectiveSize(schools.mcmc)
gelman.diag(schools.mcmc)



## End(Not run)

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

Related to schools in rbugs...