f_student_t: Specify a Student-t sampling distribution

View source: R/f_student_t.R

f_student_tR Documentation

Specify a Student-t sampling distribution

Description

This function can be used in the family argument of create_sampler or generate_data to specify a Student-t sampling distribution.

Usage

f_student_t(
  link = "identity",
  df.prior = pr_gamma(2, 0.1),
  control = student_t_control(),
  ...
)

Arguments

link

the name of a link function. Currently the only allowed link function for a Student-t distribution is "identity".

df.prior

prior specification for the (scalar) number of degrees of freedom of the Studen-t sampling distribution. Currently allowed priors are gamma priors specified using pr_gamma, or a degenerate prior fixing the degrees of freedom parameter at a fixed value.

control

sampling options for the degrees of freedom parameter (if not fixed).

...

further arguments passed to f_gaussian. Note that var.prior, var.vec and var.model now refer to the Student-t scale parameters.

Value

A family object.

Examples

## 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 <- with(dat, 1 - 0.5*x + v[g]) + 0.4 * rt(n, df=2.5)

sampler <- create_sampler(
  y ~ x + (1|g), data=dat, family="student_t"
)
sim <- MCMCsim(sampler, store.all=TRUE)
compute_DIC(sim)
waic(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_student_t(df.prior=pr_gamma(2, 0.2))
)
sim <- MCMCsim(sampler, store.all=TRUE)
loo(sim)
summary(sim)
bayesplot::mcmc_recover_hist(as.array(sim$student_t_df), 2.5)
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)

## End(Not run)


mcmcsae documentation built on July 21, 2026, 1:06 a.m.