fsml_ols Interface

public interface fsml_ols

The multiple linear Ordinary Least Squares (OLS) regression models the relationship or linear dependence between a dependent (predictand) variable and and one or more independent (predictor) variables. The procedure estimates the linear regression coefficients by minimising the sum of squared residuals.

The estimated regression model is of the form:

where is the predictand variable, are the predictor variables (x) with nd observations, is the y-intercept (b0), (b) are the regression coefficients, and (nv) is the number of predictors (excluding the intercept).

The subroutine constructs a full matrix internally by prepending a column of ones to account for the intercept. The regression coefficients are estimated as:

where is the extended design matrix including the intercept term.

The coefficient of determination (r2) which represents the proportion of the total variance of (y) explained by the predictors. The predicted values (y_hat), standard errors (se) of the coefficients, and the covariance matrix of the predictors (cov_b) can optionally be returned by the procedure, too.

Note: This subroutine uses eigh from the stdlib_linalg module. Note: The intercept and predictor coefficients are computed separately and returned explicitly.

Calls

interface~~fsml_ols~~CallsGraph interface~fsml_ols fsml_ols proc~s_lin_ols s_lin_ols interface~fsml_ols->proc~s_lin_ols eigh eigh proc~s_lin_ols->eigh proc~f_sts_mean_core f_sts_mean_core proc~s_lin_ols->proc~f_sts_mean_core proc~s_err_print s_err_print proc~s_lin_ols->proc~s_err_print proc~f_utl_r2c f_utl_r2c proc~s_err_print->proc~f_utl_r2c

Module Procedures

public subroutine s_lin_ols(x, y, nd, nv, b0, b, r2, y_hat, se, cov_b)

Multiple Linear Ordinary Least Squares (OLS) Regression with intercept. NOTE: OLS could be wrapper for ridge (with lambda = 0 or presence checks if mande an optional argument). However, it would increase computation slightly and make code less readable. OLS is often used in teaching and therefore, an easily readable standalone is kept.

Read more…

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: x(nd,nv)

predictor data matrix (no intercept column)

real(kind=wp), intent(in) :: y(nd)

response vector

integer(kind=i4), intent(in) :: nd

number of datapoints

integer(kind=i4), intent(in) :: nv

number of predictors (excluding intercept)

real(kind=wp), intent(out) :: b0

intercept coefficient

real(kind=wp), intent(out) :: b(nv)

predictor coefficients

real(kind=wp), intent(out) :: r2

coefficient of determination R²

real(kind=wp), intent(out), optional :: y_hat(nd)

predicted y values

real(kind=wp), intent(out), optional :: se(nv)

standard errors of predictor coefficients

real(kind=wp), intent(out), optional :: cov_b(nv,nv)

covariance matrix of predictor coefficients