# linearmodel: Compute the Posterior Distribution for a Linear Model In lestat: A Package for Learning Statistics

## Description

Given a vector of data and a design matrix, describing how these data are thought to relate to some predictors in a linear model, the posterior for the parameters of this linear model is found, using a flat prior.

## Usage

 `1` ```linearmodel(data, design) ```

## Arguments

 `data` A vector with data values. `design` A design matrix. The number of rows must be equal to the length of the data vector. The number of columns corresponds to the number of explanatory variables.

## Details

If y_i is the i'th data value and β_j is the j'th unknown parameter, and if x_{ij} is the value in the i'th row and j'th column of the design matrix, then one assumes that y_i is normally distributed with exptectation

x_{i1}β_1 + x_{i2}β_2 + … + x_{ik}β_k

and logged standard deviation λ. The computed probability distribution is then the posterior for the joint distribution of

(β_1,β_2,…,β_k,λ)

.

## Value

If k is the number of columns in the design matrix and if k>1, then the output is a multivariate Normal-ExpGamma distribution representing the posterior for the corresponding k values and the logged scale parameter in the linear model. If k=1, the output is a Normal-ExpGamma distribution representing the posterior.

## Author(s)

`fittedvalues`, `leastsquares`, `linearpredict`
 ```1 2 3 4 5 6``` ```data1 <- simulate(normal(3.3, log(2)), 9) data2 <- simulate(normal(4.5, log(2)), 8) data3 <- simulate(normal(2.9, log(2)), 7) design <- designManyGroups(c(9,8,7)) posterior <- linearmodel(c(data1, data2, data3), design) plot(posterior) ```