| read_hobbs_mean | R Documentation |
For declaration-level save=mean, reads the one-record standard hobbs
binary written beside the ordinary chain. The saved field is the number of
retained draws used in each posterior mean. The older global
hobbs(save = "mean") CSV format remains readable for compatibility.
read_hobbs_mean(file, param_names = NULL)
file |
An |
param_names |
Optional parameter names. Usually supplied automatically. |
A one-row data frame with saved, logp, and posterior mean columns.
library(hobbs)
set.seed(1)
n <- 200L
p <- 4L
X <- cbind(1, matrix(rnorm(n * (p - 1L)), nrow = n))
beta_true <- c(0.5, 1, -0.75, 0.25)
sigma_true <- 0.75
y <- as.numeric(X %*% beta_true + rnorm(n, sd = sigma_true))
dat <- list(n = n, p = p, X = X, y = y)
model <- '
param beta(p) save=mean;
param logsigma(1);
func llk() {
double sigma = exp(logsigma(1));
for (i = 1:n) {
y(i) ~ dnorm(mu(i), sigma);
}
}
block beta(j) {
beta(j) ~ dnorm(0, 10);
llk();
} cache mu(n) {
for (i = 1:n) {
for (k = 1:p) {
mu(i) += beta(k) * X(i, k);
}
}
} update mu(n) {
for (i = 1:n) {
mu(i) += (proposal(beta(j)) - current(beta(j))) * X(i, j);
}
}
block logsigma(1) {
logsigma(1) ~ dnorm(0, 2);
llk();
}
'
out <- tempfile("regression", fileext = ".bin")
fit <- hobbs(
model = model,
data = dat,
samples = 2000,
burnin = 1000,
seed = 123,
out = out
)
draws <- read_hobbs(fit)
draws_mean <- read_hobbs_mean(fit)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.