15.2 Normal-Id Generalised Linear Model (Linear Regression)
Stan also supplies a single primitive for a Generalised Linear Model with normal likelihood and identity link function, i.e. a primitive for a linear regression. This should provide a more efficient implementation of linear regression than a manually written regression in terms of a normal likelihood and matrix multiplication.
15.2.1 Probability Distribution Function
If \(x\in \mathbb{R}^{n\cdot m}, \alpha \in \mathbb{R}^n, \beta\in \mathbb{R}^m, \sigma\in \mathbb{R}^+\), then for \(y \in \mathbb{R}^n\), \[ \text{NormalIdGLM}(y|x, \alpha, \beta, \sigma) = \prod_{1\leq i \leq n}\text{Normal}(y_i|\alpha_i + x_i\cdot \beta, \sigma). \]
15.2.2 Sampling Statement
y ~
normal_id_glm
(x, alpha, beta, sigma)
Increment target log probability density with normal_id_glm_lpdf( y | x, alpha, beta, sigma)
dropping constant additive terms.
15.2.3 Stan Functions
real
normal_id_glm_lpdf
(vector y | matrix x, real alpha, vector beta, real sigma)
The log normal probability density of y given location alpha+x*beta
and scale sigma
, where a constant intercept alpha
and sigma
is
used for all observations. The number of rows of the independent
variable matrix x
needs to match the length of the dependent
variable vector y
and the number of columns of x
needs to match
the length of the weight vector beta
.
real
normal_id_glm_lpdf
(vector y | matrix x, vector alpha, vector beta, real sigma)
The log normal probability density of y given location alpha+x*beta
and scale sigma
, where a constant sigma
is used for all
observations and an intercept alpha
is used that is allowed to vary
with the different observations. The number of rows of the independent
variable matrix x
needs to match the length of the dependent
variable vector y
and the number of columns of x
needs to match
the length of the weight vector beta
.