Description Usage Arguments Details Value Author(s) Examples
View source: R/functions_bayes.R
Draws a sample from the posterior distribution of parameters from a Bayesian Linear regression model.
1 2 3 4 5 6 7 8 9 10 11 | samplePosterior(
X,
y,
n,
a0 = 1,
b0 = 5e-05,
v0inv = 1/1000,
mu0 = 0,
returnParams = TRUE,
intercept = FALSE
)
|
X |
Design matrix of size |
y |
Outcome variable |
n |
Size of posterior sample to be computed. A value of 0 is accepted. |
a0, b0 |
Hyperparameters (shape, rate) for inverse gamma distribution of the error variance. |
v0inv |
Prior precision for the error term. Either a single value
to be repeated in a diagonal precision matrix, or a |
mu0 |
Prior mean. Either a single value that will be repeated,
or a vector of length |
returnParams |
Logical indicating whether the parameters of the posterior distribution are returned. |
intercept |
Logical indicating whether an intercept is included in the model.
If |
This function draws a sample from the posterior distributions of the coefficient parameter (β) and error variance parameter (σ^2) from a Bayesian linear regression model. The variance parameter is assumed to follow an inverse-gamma distribution. Conditional on the error variance parameter and a specified precision matrix, the coefficient parameters (β) are multivariate normal.
A list containing the following elements:
sigma2 |
A vector containing the posterior sample of σ^2 values. |
beta |
Matrix containing the posterior sample of β values. |
postMu |
Vector containing the posterior mean (if |
postV |
Matrix giving the posterior mean (if |
an,bn |
Posterior hyperparameters for the inverse gamma
distribution of the error variance (if |
Joshua Keller
1 2 3 4 5 | x <- rnorm(40, mean=2, sd=2)
y <- x + rnorm(40, sd=1)
samplePosterior(X=x, y=y, n=10)
samplePosterior(X=cbind(1, x), y=y, n=10, intercept=TRUE)
samplePosterior(X=cbind(1, x), y=y, n=0, mu=c(3, 3), intercept=TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.