| f_gaussian | R Documentation |
This function can be used in the family argument of create_sampler
or generate_data to specify a Gaussian sampling distribution.
f_gaussian(
link = "identity",
var.prior = pr_invchisq(df = 0, scale = 1),
var.vec = ~1,
prec.mat = NULL,
var.model = NULL,
logJacobian = NULL,
control = gaussian_control()
)
link |
the name of a link function. Currently the only allowed link function
for a Gaussian distribution is |
var.prior |
prior for the variance parameter of a Gaussian sampling distribution.
This can be specified by a call to one of the prior specification functions
|
var.vec |
a formula to specify unequal variances, i.e. heteroscedasticity. The default corresponds to equal variances. |
prec.mat |
a possibly non-diagonal positive-definite symmetric matrix
interpreted as the precision matrix, i.e. inverse of the covariance matrix.
If this argument is specified |
var.model |
a formula specifying the terms of a variance model in the case of a Gaussian likelihood.
Several types of terms are supported: a regression term for the log-variance
specified with |
logJacobian |
if the data are transformed the logarithm of the Jacobian can be supplied so that it
is incorporated in all log-likelihood computations. This can be useful for comparing information criteria
for different transformations. It should be supplied as a vector of the same size as the response variable.
For example, when a log-transformation is used on response vector |
control |
a list with computational options. These options can
be specified using function |
A family object.
## Not run:
n <- 4000
m <- 25
dat <- data.frame(
x = rnorm(n),
g = factor(sample(1:m, n, replace=TRUE), levels=1:m)
)
v <- rnorm(m, sd=0.6)
dat$y <- rnorm(n, mean = with(dat, 1 - 0.5*x + v[g]), sd=0.4)
sampler <- create_sampler(
y ~ x + (1|g), data=dat
)
sim <- MCMCsim(sampler, store.all=TRUE)
compute_DIC(sim)
summary(sim)
# more explicit specification, allowing non-default names, priors etc.
sampler <- create_sampler(
y ~ reg(~ x, name="beta") + gen(~1, factor = ~ g, name="v"),
data=dat,
family = f_gaussian(var.prior = pr_fixed(value = 0.4^2))
)
sim <- MCMCsim(sampler, store.all=TRUE)
compute_DIC(sim)
summary(sim)
bayesplot::mcmc_recover_intervals(as.array(sim$beta), c(1, -0.5))
bayesplot::mcmc_recover_hist(as.array(sim$v_sigma), 0.6)
bayesplot::mcmc_recover_scatter(as.array(sim$v), v)
# heteroscedastic data
dat$y <- rnorm(n,
mean = with(dat, 1 - 0.5*x + v[g]),
sd = with(dat, exp(0.5*(0.2 + 0.5*x)))
)
sampler <- create_sampler(
y ~ reg(~ x, name="beta") + gen(~1, factor = ~ g, name="v"),
data=dat,
family = f_gaussian(
var.prior = pr_fixed(value = 1),
var.model = ~ 1 + x
)
)
sim <- MCMCsim(sampler, store.all=TRUE)
compute_DIC(sim)
compute_WAIC(sim)
summary(sim)
bayesplot::mcmc_recover_intervals(as.array(sim$beta), c(1, -0.5))
bayesplot::mcmc_recover_intervals(as.array(sim$vreg1), c(0.2, 0.5))
bayesplot::mcmc_recover_hist(as.array(sim$v_sigma), 0.6)
bayesplot::mcmc_recover_scatter(as.array(sim$v), v)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.