BayES BayES

4.1 Basic linear model

Mathematical representation

yi = xiβ + 𝜀 i,𝜀i N 0, 1 τ (4.1)

Priors




Parameter Probability density function Default hyperparameters



β p β = |P|12 2πK2 exp 1 2 β mP β m m = 0 K, P = 0.001 IK
τ p τ = bτaτ Γaτ τaτ1eτbτ aτ = 0.001, bτ = 0.001



Syntax

[<model name> = ] lm( y ~ x1 x2  xK [, <options> ] );

where:

The optional arguments for the simple linear model are:1

Gibbs parameters


"chains"

number of chains to run in parallel (positive integer); the default value is 1

"burnin"

number of burn-in draws per chain (positive integer); the default value is 10000

"draws"

number of retained draws per chain (positive integer); the default value is 20000

"thin"

value of the thinning parameter (positive integer); the default value is 1

"seed"

value of the seed for the random-number generator (positive integer); the default value is 42

Hyperparameters


"m"

mean vector of the prior for β (K ×1 vector); the default value is 0K

"P"

precision matrix of the prior for β (K ×K symmetric and positive-definite matrix); the default value is 0.001 IK

"a_tau"

shape parameter of the prior for τ (positive number); the default value is 0.001

"b_tau"

rate parameter of the prior for τ (positive number); the default value is 0.001

Dataset and log-marginal likelihood


"dataset"

the id value of the dataset that will be used for estimation; the default value is the first dataset in memory (in alphabetical order)

"logML_CJ"

boolean indicating whether the Chib (1995)/Chib & Jeliazkov (2001) approximation to the log-marginal likelihood should be calculated (true|false); the default value is false

Reported Parameters




β

variable_name

vector of parameters associated with the independent variables




τ

tau

precision parameter of the error term, 𝜀i




σ𝜀

sigma_e

standard deviation of the error term: σ𝜀 = 1τ12




Stored values and post-estimation analysis
If a left-hand-side id value is provided when a simple linear model is created, then the following results are saved in the model item and are accessible via the ‘.’ operator:

Samples

a matrix containing the draws from the posterior of β and τ

x1,,xK

vectors containing the draws from the posterior of the parameters associated with variables x1,,xK (the names of these vectors are the names of the variables that were included in the right-hand side of the model)

tau

vector containing the draws from the posterior of τ

logML

the Lewis & Raftery (1997) approximation of the log-marginal likelihood

logML_CJ

the Chib (1995)/Chib & Jeliazkov (2001) approximation to the log-marginal likelihood; this is available only if the model was estimated with the "logML_CJ"=true option

nchains

the number of chains that were used to estimate the model

nburnin

the number of burn-in draws per chain that were used when estimating the model

ndraws

the total number of retained draws from the posterior ( =chains draws)

nthin

value of the thinning parameter that was used when estimating the model

nseed

value of the seed for the random-number generator that was used when estimating the model

Additionally, the following functions are available for post-estimation analysis (see section B.14):

Examples

Example 1

myData = import("$BayESHOME/Datasets/dataset1.csv"); 
myData.constant = ones(rows(myData), 1); 
 
lm( y ~ constant x1 x2 x3);

Example 2

myData = import("$BayESHOME/Datasets/dataset1.csv"); 
myData.constant = ones(rows(myData), 1); 
 
myModel = lm(y ~ constant x1 x2 x3, 
    "m"=ones(4,1), "P" = 0.1*eye(4,4), 
    "a_tau"=0.01, "b_tau"=0.01, 
    "burnin"=10000, "draws"=40000, "thin"=4, "chains"=2, 
    "logML_CJ" = true, "dataset"=myData); 
 
diagnostics("model"=myModel); 
 
plot(myModel.tau, 
    "title"="draws from the posterior of tau", 
    "grid"="on");

1Optional arguments are always given in option-value pairs (eg. "chains"=3).

Share this content:
Facebook Twitter LinkedIn Email
© 2016–20 Grigorios Emvalomatis