Extreme Optimization > User's Guide > Statistics Library > Regression Analysis > Multiple Linear Regression

Extreme Optimization User's Guide

User's Guide

Up: Regression Analysis Next: Polynomial Regression Previous: Simple Linear Regression Contents

Multiple Linear Regression

Multiple linear regression is a technique to analyze a linear relationship between one or more independent variables and a dependent variable. The values of the independent variables are considered to be exact, while the values of the dependent variables are subject to error. The Extreme Optimization Numerical Libraries for .NET supports linear regression through the LinearRegressionModel class.

Constructing Multiple Linear Regression Models

The LinearRegressionModel class has four constructors.

The first constructor takes two parameters. The first is a NumericalVariable that represents the dependent variable. The second is an array of NumericalVariable objects that represent the independent variables.

C# CopyCode imageCopy Code
NumericalVariable dependent = new NumericalVariable("y", yData);
NumericalVariable independent1 = new NumericalVariable("x1", x1Data);
NumericalVariable independent2 = new NumericalVariable("x2", x2Data);
LinearRegressionModel model1 =    new LinearRegressionModel(dependent, independent);
Visual Basic CopyCode imageCopy Code
Dim dependent As NumericalVariable = New NumericalVariable("y", yData)
Dim independent1 As NumericalVariable = New NumericalVariable("x1", xData)
Dim independent2 As NumericalVariable = New NumericalVariable("x2", xData)
Dim model1 As LinearRegressionModel = _
    New LinearRegressionModel(dependent, independent)

The second constructor takes 3 parameters. The first parameter is a VariableCollection object that contains the variables to be used in the regression. The second parameter is a string containing the name of the dependent variable. The third parameter is an array of strings containing the names of the independent variables. All the names must exist in the collection specified by the first parameter. All variables must be of type NumericalVariable.

C# CopyCode imageCopy Code
VariableCollection variables = new VariableCollection();
variables.Add(dependent);
variables.Add(independent1);
variables.Add(independent2);
LinearRegressionModel model2 =    new LinearRegressionModel(variables, "y", new string() {"x1", "x2"});
Visual Basic CopyCode imageCopy Code
Dim variables As VariableCollection = New VariableCollection()
variables.Add(dependent)
variables.Add(independent1)
variables.Add(independent2)
Dim model2 As LinearRegressionModel = _
    New LinearRegressionModel(variables, "y", New String() {"x1", "x2"})

The third constructor also takes 3 parameters. The first parameter is a DataTable object that contains the data for the regression analysis. The second parameter is a string containing the name of the column that contains the data for the dependent variable. The third parameter is a string containing the name of the column that contains the data for the independent variable. Both columns must be numerical or convertible to numerical values.

C# CopyCode imageCopy Code
// Fill data table with data from some datasource.
LinearRegressionModel model3 =    new LinearRegressionModel(table, "y", new string() {"x1", "x2"});
Visual Basic CopyCode imageCopy Code
Dim table As DataTable = New DataTable()
' Fill data table with data from some datasource.
Dim model3 As LinearRegressionModel = _
    New LinearRegressionModel(table, "y", New String() {"x1", "x2"})

Computing the Regression

The Compute method performs the actual analysis. Most properties and methods throw an exception when they are accessed before the Compute method is called. You can verify that the model has been calculated by inspecting the Computed property.

C# CopyCode imageCopy Code
model1.Compute();
Visual Basic CopyCode imageCopy Code
model1.Compute()

The PredictedValues property returns a Vector that contains the values of the dependent variable as predicted by the model. The Residuals property returns a vector containing the difference between the actual and the predicted values of the dependent variable. Both vectors contain one element for each observation.

Regression Parameters

The LinearRegressionModel class' Parameters property returns a ParameterCollection object that contains the parameters of the regression model. The members of this collection are of type Parameter. Regression parameters are created by the model. You cannot create them directly.

Parameters can be accessed by numerical index or by name. The name of a parameter is usually the name of the variable associated with it.

A multiple linear regression model has as many parameters as there are independent variables, plus one for the intercept (constant term) when it is included. The intercept, if present, is the first parameter in the collection, with index 0. The name of the intercept parameter can be retrieved or set through the InterceptParameterName property.

The Parameter class has four useful properties. The Value property returns the numerical value of the parameter, while the StandardError property returns the standard deviation of the parameter's distribution.

The Statistic property returns the value of the t-statistic corresponding to the hypothesis that the parameter equals zero. The PValue property returns the corresponding p-value. A high p-value indicates that the variable associated with the parameter does not make a significant contribution to explaining the data. The p-value always corresponds to a two-tailed test. The following example prints the properties of the slope parameter of our earlier example:

C# CopyCode imageCopy Code
Parameter x1Parameter = model1.Parameters["x1"];
Console.WriteLine("Name:        {0}", x1Parameter.Name);
Console.WriteLine("Value:       {0}", x1Parameter.Value);
Console.WriteLine("St.Err.:     {0}", x1Parameter.StandardError);
Console.WriteLine("t-statistic: {0}", x1Parameter.TStatistic);
Console.WriteLine("p-value:     {0}", x1Parameter.PValue);
Visual Basic CopyCode imageCopy Code
Dim x1Parameter As = model1.Parameters("x1")
Console.WriteLine("Name:        {0}", x1Parameter.Name)
Console.WriteLine("Value:       {0}", x1Parameter.Value)
Console.WriteLine("St.Err.:     {0}", x1Parameter.StandardError)
Console.WriteLine("t-statistic: {0}", x1Parameter.TStatistic)
Console.WriteLine("p-value:     {0}", x1Parameter.PValue)

The Parameter class has one method: GetConfidenceInterval. This method takes one parameter: a confidence level between 0 and 1. A value of 0.95 corresponds to a confidence level of 95%. The method returns the confidence interval for the parameter at the specified confidence level as an Interval structure.

Verifying the Quality of the Regression

The ResidualSumOfSquares property gives the sum of the squares of the residuals. The regression line was found by minimizing this value. The StandardError property gives the standard deviation of the data.

The RSquared property returns the coefficient of determination. It is the ratio of the variation in the data that is explained by the model compared to the total variation in the data. Its value is always between 0 and 1, where 0 means the model explains nothing and 1 means the model explains the data perfectly.

When the model contains many independent variables, the additional variables may be modeling the errors in the data rather than the data itself. This causes the full model to be less reliable for making predictions. The AdjustedRSquared property returns an adjusted R2 value that attempts to compensate for this phenomenon.

An entirely different assessment is available through an analysis of variance. Here, the variation in the data is decomposed into a component explained by the model, and the variation in the residuals. The FStatistic property returns the F-statistic for the ratio of these two variances. The PValue property returns the corresponding p-value. A low p-value means that it is unlikely that the variation in the model is the same as the variation in the residuals. This means that the model is significant.

The results of the analysis of variance are also summarized in the regression model's ANOVA table, returned by the AnovaTable property.

Up: Regression Analysis Next: Polynomial Regression Previous: Simple Linear Regression Contents

Overview
Introduction
Features
Documentation
QuickStart Samples
Sample Applications
Downloads
Get it now!
Download trial version
How to Buy
Information
Resources
Contact Us
Search

"The Extreme Optimization Statistics Library for .NET is a major boon for those doing statistical work in .NET. I strongly recommend this product."
- Marc Brooks

"I have made it my mission to institutionalize the value of good API design.  I strongly believe that this is key to making developers more productive and happy on our platform. It is clear that you value good API design in your work, and take to heart developer productivity and synergy with the .NET framework."
- Brad Abrams,
Lead Program Manager, Microsoft.

This is a partial list of companies who are using our libraries:
ABB Robotics
Allstate
Applied Materials
Arcam
Astra Schedule
Babson College
Canadian Council on Learning
Canyon Associates
Caxton Associates
CECity
Constellation Energy
CreditSights
DeepOcean
Duke University
Dynamotive
Elecsoft
Engelhard Corporation
Epcor
Equipoise Software
Galileo International
GAM UK
Gammex
GlaxoSmithKline
Global Matrix
The Hartford
Infinera Corporation
Intel
JDS Uniphase
LaBranche & Co.
Learning & Skills Council
Jacobs Consultancy
Litman Gregory
Lucas Systems
Malvern Instruments
Medrio
Merck & Co.
Mintera.
Monitor Software
MorningStar
NanoString Technologies
Paletta Invent
Parametric Portfolio Associates
Prosanos
RATA Associates
RiskShield
Ramboll
Standard & Poor's
Strategic Analysis Corporation
Univ. of Alicante
Univ. of South Carolina
vielife
Xerox
US Army