This is an old version, view current version.

## 15.2 Normal-Id Generalized Linear Model (Linear Regression)

Stan also supplies a single function for a generalized linear lodel with normal likelihood and identity link function, i.e. a function for a linear regression. This provides 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(real 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 the same intercept alpha, scale sigma and dependent variable value y are used for all observations. The number of columns of x needs to match the size of the coefficient vector beta. If x and y are data (not parameters) this function can be executed on a GPU.

real normal_id_glm_lpdf(real 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 the same scale sigma and dependent variable valuey are used for all observations and an intercept alpha is used that is allowed to vary by observation. The number of rows of the independent variable matrix x needs to match the size of the intercept vector alpha and the number of columns of x needs to match the size of the coefficient vector beta. If x and y are data (not parameters) this function can be executed on a GPU.

real normal_id_glm_lpdf(vector y | row_vector x, real alpha, vector beta, real sigma)
The log normal probability density of y given location alpha + x * beta and scale sigma, where the same intercept alpha, scale sigma and independent variable values x are used for all observations. The number of columns of x needs to match the size of the coefficient vector beta.

real normal_id_glm_lpdf(vector y | row_vector x, vector alpha, vector beta, real sigma)
The log normal probability density of y given location alpha + x * beta and scale sigma, where the same scale sigma and independent variable values x are used for all observations and an intercept alpha is used that is allowed to vary by observation. The size of the dependent variable vector y needs to match the size of the intercept vector alpha and the number of columns of x needs to match the size of the coefficient vector beta.

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 the same intercept alpha and scale sigma is used for all observations. The number of rows of the independent variable matrix x needs to match the size of the dependent variable vector y and the number of columns of x needs to match the size of the coefficient vector beta. If x and y are data (not parameters) this function can be executed on a GPU.

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 the same scale sigma is used for all observations and an intercept alpha is used that is allowed to vary by observation. The number of rows of the independent variable matrix x needs to match the size of the dependent variable vector y and the size of the intercept vector alpha. The number of columns of x needs to match the size of the coefficient vector beta. If x and y are data (not parameters) this function can be executed on a GPU.