ETHZ_Logo RAMSES_Logo_Right   RAMSES   RAMSES_Logo_Left Systems Ecology  
Start    search button      Modules:   A-Z   Function   Layer        QuickRefs:   DM   AuxLib   AuxLibE   SciLib   EasyMW   MW   ISIS   RMSLib

DEFINITION MODULE MultLinReg;

  (*******************************************************************

    Module  MultLinReg     (Version 1.0)

      Copyright (c) 2002-2006 by Dimitrios Gyalistras and ETH Zurich.

    Purpose   Performs multiple linear regression.

    Remarks   --


    Programming

      o Design
        Dimitrios Gyalistras      08/02/2002

      o Implementation
        Dimitrios Gyalistras      08/02/2002


    ETH Zurich
    Systems Ecology
    CHN E 35.1
    Universitaetstrasse 16
    8092 Zurich
    SWITZERLAND

    URLs:
        <mailto:RAMSES@env.ethz.ch>
        <http://www.sysecol.ethz.ch>
        <http://www.sysecol.ethz.ch/SimSoftware/RAMSES>


    Last revision of definition:  25/05/2002  AF

  *******************************************************************)


  IMPORT Errors;
  FROM LgMatrices IMPORT LMatrix, LVector;

  CONST  (* result codes returned *)
    allOk   = Errors.allOk;
    notDone = Errors.onlyAnInsert;


  PROCEDURE FitMultLinReg( (* inputs *)
                           xDat           : LMatrix;
                           yDat           : LMatrix;
                           nXVarsToUse    : INTEGER;
                           nDataRowsToUse : INTEGER;
                           (* outputs *)
                           muX            : LMatrix;
                           sigX           : LMatrix;
                           VAR muY        : LONGREAL;
                           VAR sigY       : LONGREAL;
                           VAR alpha      : LONGREAL;
                           beta           : LMatrix;
                           eps            : LMatrix;
                           VAR smin       : LONGREAL;
                           VAR se         : LONGREAL;
                           VAR r2         : LONGREAL;
                           VAR fVal       : LONGREAL;
                           VAR df         : INTEGER;
                           VAR pVal       : LONGREAL;
                           VAR resCode    : INTEGER;
                           VAR errTxt     : ARRAY OF CHAR );

  (*
    The procedure estimates the parameters alpha and beta(i) (i=1..nX) of
    the regression equation

      y = alpha + Sum(i=1,nX) beta(i)*x(i) + eps

    with

      eps ~ N( 0, se).

    Meaning of input and output parameters:

    xDat           = Predictors (independent data, nX x nXRows)
    yDat           = Predictand (dependent data, 1 x nYRows)
    nXVarsToUse    = Number of predictors to actually use for regression,
                     must be <= nX.
    nDataRowsToUse = Number of data rows to actually use for regression,
                     must be <= Min( nXRows, nYRows ).
    muX            = means of x-variables
    sigX           = standard deviations of x-variables
    muY            = mean of y-variable
    sigY           = standard deviation of y-variable
    alpha          = regression intercept
    beta           = regression coefficients (nXVarsToUse x 1)
    eps            = regression residuals (nDataPtsToUse x 1)
    smin           = minimum sum of squares from regression
    se             = standard deviation of the residuals, also known as
                     the "standard error of regression" (note, se^2 is
                     an unbiased estimator of the error variance).
    r2             = coefficient of determination
    fVal           = F-value from testing of the hypothesis
                     Ho: alpha = beta1 = beta2 = ... = 0, i.e. the
                     entire regression model is not significant.
    df             = degrees of freedom for fitting of the full model
    pVal           = p-value for the full model, i.e. probability that
                     Ho is rejected although it is correct.
  *)

END MultLinReg.

  Contact RAMSES@env.ethz.ch Last updated: 25-Jul-2011 [Top of page]