linear_least_squares Subroutine

public subroutine linear_least_squares(order, intercept, x, y, coeffs, ymod, resid, stats, alpha, err)

Computes a linear least-squares regression to fit a set of data.

See Also

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: order

The order of the equation to fit. This value must be at least one (linear equation), but can be higher as desired, as long as there is sufficient data.

logical, intent(in) :: intercept

Set to true if the intercept is being computed as part of the regression; else, false.

real(kind=real64), intent(in) :: x(:)

An N-element array containing the independent variable measurement points.

real(kind=real64), intent(in) :: y(:)

An N-element array containing the dependent variable measurement points.

real(kind=real64), intent(out) :: coeffs(:)

An ORDER+1 element array where the coefficients will be written.

real(kind=real64), intent(out) :: ymod(:)

An N-element array where the modeled data will be written.

real(kind=real64), intent(out) :: resid(:)

An N-element array where the residual error data will be written (modeled - actual).

type(regression_statistics), intent(out), optional :: stats(:)

An M-element array of regression_statistics items where M = ORDER + 1 when intercept is set to true; however, if intercept is set to false, M = ORDER.

real(kind=real64), intent(in), optional :: alpha

The significance level at which to evaluate the confidence intervals. The default value is 0.05 such that a 95% confidence interval is calculated.

class(errors), intent(inout), optional, target :: err

A mechanism for communicating errors and warnings to the caller. Possible warning and error codes are as follows. - FS_NO_ERROR: No errors encountered. - FS_ARRAY_SIZE_ERROR: Occurs if any of the arrays are not approriately sized. - FS_INVALID_INPUT_ERROR: Occurs if order is less than 1. - FS_MEMORY_ERROR: Occurs if there is a memory allocation error.


Contents