blm: Bayesian Linear Regression

Description Usage Arguments Details Value Examples

Description

Computes a bayesian linear regression fit.

Usage

1
blm(formula, prior = NULL, beta, ...)

Arguments

formula

an object of class "formula": a symbolic description of the model to be fitted.

prior

the prior distribution, either a mvnd or a blm object.

beta

the precision of the data used for the model.

...

Additional arguments and values.

Details

Models for blm are provided as for lm. If prior distribution prior of the weights is not provided the prior means are set to 0 and the variances to 1.

Value

A object of class blm. An object of class "lm" is a list containing at least the following components:

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
  w0 <- 0.3 ; w1 <- 1.1 ; b <- 1.3 
  x <- rnorm(50)
  y <- rnorm(50, w1 * x + w0, 1/b) 
  mod <- blm(y~x, data=data.frame(x=x, y=y))
  mod
  plot(mod)
  
  #use with known precision
  mod_det <- blm(y~x, beta=b, data=data.frame(x=x, y=y))
  mod_det
  
  #use of a prior, typically from an existing model 
  x2 <- rnorm(50) 
  y2 <- rnorm(50, w1 * x2 + w0, 1/b) 
  mod2 <- blm(y~x, prior=mod, data=data.frame(x=x2, y=y2)) 
  mod2
  
  #use with 2 explanatory variables 
  w2 <- 3.3 
  z <- rnorm(50) 
  y <- rnorm(50, w2 * z + w1 * x + w0, 1/b) 
  mod <- blm(y~x+z, data=data.frame(x=x, y=y, z=z)) 
  mod
 

manschmi/blmr documentation built on May 21, 2019, 11:25 a.m.