<< oct_interp | FOSSEE_Signal_Processing_Toolbox | parser >>

FOSSEE_Signal_Processing_Toolbox >> FOSSEE_Signal_Processing_Toolbox > ols

# ols

Ordinary least squares estimation.

### Description

OLS applies to the multivariate model y = x*b + e with mean (e) = 0 and cov (vec (e)) = kron (s, I). where y is a t by p matrix, x is a t by k matrix, b is a k by p matrix, and e is a t by p matrix. Each row of y and x is an observation and each column a variable. The return values beta, sigma, and r are defined as follows.

### Syntax

    [beta, sigma, r] = ols (y, x)

### Parameters

beta :

  The OLS estimator for b. beta is calculated directly via inv (x'*x) * x' * y if the matrix x'*x is of full rank. Otherwise, beta = pinv (x) * y where pinv (x) denotes the pseudoinverse of x.

sigma :

  The OLS estimator for the matrix s, sigma = (y-x*beta)'* (y-x*beta) / (t-rank(x))

r :

  The matrix of OLS residuals, r = y - x*beta.

### Examples

    // Simulated data
    t = 100;                       // Number of observations
    x = [ones(t, 1), rand(t, 1)];  // Design matrix: intercept + one regressor
    b_true = [2; 3]               // True coefficients: intercept = 2, slope = 3
    // Generate response variable with noise
    y = x * b_true + rand(t, 1,'normal');  // y = 2 + 3*x + noise
    // Perform OLS estimation
    [beta, sigma, r] = ols(y, x)

Report an issue
<< oct_interp | FOSSEE_Signal_Processing_Toolbox | parser >>