blob: eb6cb85c58b779dd5aec6e3f71b160773046da93 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html" charset="UTF-8">
<title>OLSMultipleLinearRegression (Apache Commons Math 3.3 API)</title>
<link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style">
</head>
<body>
<script type="text/javascript"><!--
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="OLSMultipleLinearRegression (Apache Commons Math 3.3 API)";
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar_top">
<!-- -->
</a><a href="#skip-navbar_top" title="Skip navigation links"></a><a name="navbar_top_firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/OLSMultipleLinearRegression.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../../help-doc.html">Help</a></li>
</ul>
<div class="aboutLanguage"><em><script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script></em></div>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../../org/apache/commons/math3/stat/regression/MultipleLinearRegression.html" title="interface in org.apache.commons.math3.stat.regression"><span class="strong">Prev Class</span></a></li>
<li><a href="../../../../../../org/apache/commons/math3/stat/regression/RegressionResults.html" title="class in org.apache.commons.math3.stat.regression"><span class="strong">Next Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../../index.html?org/apache/commons/math3/stat/regression/OLSMultipleLinearRegression.html" target="_top">Frames</a></li>
<li><a href="OLSMultipleLinearRegression.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../../../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor_summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method_summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor_detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method_detail">Method</a></li>
</ul>
</div>
<a name="skip-navbar_top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">org.apache.commons.math3.stat.regression</div>
<h2 title="Class OLSMultipleLinearRegression" class="title">Class OLSMultipleLinearRegression</h2>
</div>
<div class="contentContainer">
<ul class="inheritance">
<li><a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">java.lang.Object</a></li>
<li>
<ul class="inheritance">
<li><a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html" title="class in org.apache.commons.math3.stat.regression">org.apache.commons.math3.stat.regression.AbstractMultipleLinearRegression</a></li>
<li>
<ul class="inheritance">
<li>org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression</li>
</ul>
</li>
</ul>
</li>
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
<dl>
<dt>All Implemented Interfaces:</dt>
<dd><a href="../../../../../../org/apache/commons/math3/stat/regression/MultipleLinearRegression.html" title="interface in org.apache.commons.math3.stat.regression">MultipleLinearRegression</a></dd>
</dl>
<hr>
<br>
<pre>public class <span class="strong">OLSMultipleLinearRegression</span>
extends <a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html" title="class in org.apache.commons.math3.stat.regression">AbstractMultipleLinearRegression</a></pre>
<div class="block"><p>Implements ordinary least squares (OLS) to estimate the parameters of a
multiple linear regression model.</p>
<p>The regression coefficients, <code>b</code>, satisfy the normal equations:
<pre><code> X<sup>T</sup> X b = X<sup>T</sup> y </code></pre></p>
<p>To solve the normal equations, this implementation uses QR decomposition
of the <code>X</code> matrix. (See <a href="../../../../../../org/apache/commons/math3/linear/QRDecomposition.html" title="class in org.apache.commons.math3.linear"><code>QRDecomposition</code></a> for details on the
decomposition algorithm.) The <code>X</code> matrix, also known as the <i>design matrix,</i>
has rows corresponding to sample observations and columns corresponding to independent
variables. When the model is estimated using an intercept term (i.e. when
<a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#isNoIntercept()"><code>isNoIntercept</code></a> is false as it is by default), the <code>X</code>
matrix includes an initial column identically equal to 1. We solve the normal equations
as follows:
<pre><code> X<sup>T</sup>X b = X<sup>T</sup> y
(QR)<sup>T</sup> (QR) b = (QR)<sup>T</sup>y
R<sup>T</sup> (Q<sup>T</sup>Q) R b = R<sup>T</sup> Q<sup>T</sup> y
R<sup>T</sup> R b = R<sup>T</sup> Q<sup>T</sup> y
(R<sup>T</sup>)<sup>-1</sup> R<sup>T</sup> R b = (R<sup>T</sup>)<sup>-1</sup> R<sup>T</sup> Q<sup>T</sup> y
R b = Q<sup>T</sup> y </code></pre></p>
<p>Given <code>Q</code> and <code>R</code>, the last equation is solved by back-substitution.</p></div>
<dl><dt><span class="strong">Since:</span></dt>
<dd>2.0</dd>
<dt><span class="strong">Version:</span></dt>
<dd>$Id: OLSMultipleLinearRegression.java 1591624 2014-05-01 11:54:06Z tn $</dd></dl>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor_summary">
<!-- -->
</a>
<h3>Constructor Summary</h3>
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation">
<caption><span>Constructors</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colOne" scope="col">Constructor and Description</th>
</tr>
<tr class="altColor">
<td class="colOne"><code><strong><a href="../../../../../../org/apache/commons/math3/stat/regression/OLSMultipleLinearRegression.html#OLSMultipleLinearRegression()">OLSMultipleLinearRegression</a></strong>()</code>
<div class="block">Create an empty OLSMultipleLinearRegression instance.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colOne"><code><strong><a href="../../../../../../org/apache/commons/math3/stat/regression/OLSMultipleLinearRegression.html#OLSMultipleLinearRegression(double)">OLSMultipleLinearRegression</a></strong>(double&nbsp;threshold)</code>
<div class="block">Create an empty OLSMultipleLinearRegression instance, using the given
singularity threshold for the QR decomposition.</div>
</td>
</tr>
</table>
</li>
</ul>
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method_summary">
<!-- -->
</a>
<h3>Method Summary</h3>
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
<caption><span>Methods</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>double</code></td>
<td class="colLast"><code><strong><a href="../../../../../../org/apache/commons/math3/stat/regression/OLSMultipleLinearRegression.html#calculateAdjustedRSquared()">calculateAdjustedRSquared</a></strong>()</code>
<div class="block">Returns the adjusted R-squared statistic, defined by the formula</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>protected <a href="../../../../../../org/apache/commons/math3/linear/RealVector.html" title="class in org.apache.commons.math3.linear">RealVector</a></code></td>
<td class="colLast"><code><strong><a href="../../../../../../org/apache/commons/math3/stat/regression/OLSMultipleLinearRegression.html#calculateBeta()">calculateBeta</a></strong>()</code>
<div class="block">Calculates the regression coefficients using OLS.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>protected <a href="../../../../../../org/apache/commons/math3/linear/RealMatrix.html" title="interface in org.apache.commons.math3.linear">RealMatrix</a></code></td>
<td class="colLast"><code><strong><a href="../../../../../../org/apache/commons/math3/stat/regression/OLSMultipleLinearRegression.html#calculateBetaVariance()">calculateBetaVariance</a></strong>()</code>
<div class="block">Calculates the variance-covariance matrix of the regression parameters.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code><a href="../../../../../../org/apache/commons/math3/linear/RealMatrix.html" title="interface in org.apache.commons.math3.linear">RealMatrix</a></code></td>
<td class="colLast"><code><strong><a href="../../../../../../org/apache/commons/math3/stat/regression/OLSMultipleLinearRegression.html#calculateHat()">calculateHat</a></strong>()</code>
<div class="block">Compute the "hat" matrix.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>double</code></td>
<td class="colLast"><code><strong><a href="../../../../../../org/apache/commons/math3/stat/regression/OLSMultipleLinearRegression.html#calculateResidualSumOfSquares()">calculateResidualSumOfSquares</a></strong>()</code>
<div class="block">Returns the sum of squared residuals.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>double</code></td>
<td class="colLast"><code><strong><a href="../../../../../../org/apache/commons/math3/stat/regression/OLSMultipleLinearRegression.html#calculateRSquared()">calculateRSquared</a></strong>()</code>
<div class="block">Returns the R-Squared statistic, defined by the formula</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>double</code></td>
<td class="colLast"><code><strong><a href="../../../../../../org/apache/commons/math3/stat/regression/OLSMultipleLinearRegression.html#calculateTotalSumOfSquares()">calculateTotalSumOfSquares</a></strong>()</code>
<div class="block">Returns the sum of squared deviations of Y from its mean.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><strong><a href="../../../../../../org/apache/commons/math3/stat/regression/OLSMultipleLinearRegression.html#newSampleData(double[], double[][])">newSampleData</a></strong>(double[]&nbsp;y,
double[][]&nbsp;x)</code>
<div class="block">Loads model x and y sample data, overriding any previous sample.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><strong><a href="../../../../../../org/apache/commons/math3/stat/regression/OLSMultipleLinearRegression.html#newSampleData(double[], int, int)">newSampleData</a></strong>(double[]&nbsp;data,
int&nbsp;nobs,
int&nbsp;nvars)</code>
<div class="block">Loads model x and y sample data from a flat input array, overriding any previous sample.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>protected void</code></td>
<td class="colLast"><code><strong><a href="../../../../../../org/apache/commons/math3/stat/regression/OLSMultipleLinearRegression.html#newXSampleData(double[][])">newXSampleData</a></strong>(double[][]&nbsp;x)</code>
<div class="block">Loads new x sample data, overriding any previous data.</div>
</td>
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods_inherited_from_class_org.apache.commons.math3.stat.regression.AbstractMultipleLinearRegression">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;org.apache.commons.math3.stat.regression.<a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html" title="class in org.apache.commons.math3.stat.regression">AbstractMultipleLinearRegression</a></h3>
<code><a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#calculateErrorVariance()">calculateErrorVariance</a>, <a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#calculateResiduals()">calculateResiduals</a>, <a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#calculateYVariance()">calculateYVariance</a>, <a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#estimateErrorVariance()">estimateErrorVariance</a>, <a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#estimateRegressandVariance()">estimateRegressandVariance</a>, <a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#estimateRegressionParameters()">estimateRegressionParameters</a>, <a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#estimateRegressionParametersStandardErrors()">estimateRegressionParametersStandardErrors</a>, <a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#estimateRegressionParametersVariance()">estimateRegressionParametersVariance</a>, <a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#estimateRegressionStandardError()">estimateRegressionStandardError</a>, <a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#estimateResiduals()">estimateResiduals</a>, <a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#getX()">getX</a>, <a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#getY()">getY</a>, <a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#isNoIntercept()">isNoIntercept</a>, <a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#newYSampleData(double[])">newYSampleData</a>, <a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#setNoIntercept(boolean)">setNoIntercept</a>, <a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#validateCovarianceData(double[][], double[][])">validateCovarianceData</a>, <a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#validateSampleData(double[][], double[])">validateSampleData</a></code></li>
</ul>
<ul class="blockList">
<li class="blockList"><a name="methods_inherited_from_class_java.lang.Object">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;java.lang.<a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</a></h3>
<code><a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#clone()" title="class or interface in java.lang">clone</a>, <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#equals(java.lang.Object)" title="class or interface in java.lang">equals</a>, <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#finalize()" title="class or interface in java.lang">finalize</a>, <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#getClass()" title="class or interface in java.lang">getClass</a>, <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#hashCode()" title="class or interface in java.lang">hashCode</a>, <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#notify()" title="class or interface in java.lang">notify</a>, <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#notifyAll()" title="class or interface in java.lang">notifyAll</a>, <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#toString()" title="class or interface in java.lang">toString</a>, <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait()" title="class or interface in java.lang">wait</a>, <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait(long)" title="class or interface in java.lang">wait</a>, <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait(long, int)" title="class or interface in java.lang">wait</a></code></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor_detail">
<!-- -->
</a>
<h3>Constructor Detail</h3>
<a name="OLSMultipleLinearRegression()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>OLSMultipleLinearRegression</h4>
<pre>public&nbsp;OLSMultipleLinearRegression()</pre>
<div class="block">Create an empty OLSMultipleLinearRegression instance.</div>
</li>
</ul>
<a name="OLSMultipleLinearRegression(double)">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>OLSMultipleLinearRegression</h4>
<pre>public&nbsp;OLSMultipleLinearRegression(double&nbsp;threshold)</pre>
<div class="block">Create an empty OLSMultipleLinearRegression instance, using the given
singularity threshold for the QR decomposition.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>threshold</code> - the singularity threshold</dd><dt><span class="strong">Since:</span></dt>
<dd>3.3</dd></dl>
</li>
</ul>
</li>
</ul>
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method_detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a name="newSampleData(double[], double[][])">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>newSampleData</h4>
<pre>public&nbsp;void&nbsp;newSampleData(double[]&nbsp;y,
double[][]&nbsp;x)
throws <a href="../../../../../../org/apache/commons/math3/exception/MathIllegalArgumentException.html" title="class in org.apache.commons.math3.exception">MathIllegalArgumentException</a></pre>
<div class="block">Loads model x and y sample data, overriding any previous sample.
Computes and caches QR decomposition of the X matrix.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>y</code> - the [n,1] array representing the y sample</dd><dd><code>x</code> - the [n,k] array representing the x sample</dd>
<dt><span class="strong">Throws:</span></dt>
<dd><code><a href="../../../../../../org/apache/commons/math3/exception/MathIllegalArgumentException.html" title="class in org.apache.commons.math3.exception">MathIllegalArgumentException</a></code> - if the x and y array data are not
compatible for the regression</dd></dl>
</li>
</ul>
<a name="newSampleData(double[], int, int)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>newSampleData</h4>
<pre>public&nbsp;void&nbsp;newSampleData(double[]&nbsp;data,
int&nbsp;nobs,
int&nbsp;nvars)</pre>
<div class="block"><p>Loads model x and y sample data from a flat input array, overriding any previous sample.
</p>
<p>Assumes that rows are concatenated with y values first in each row. For example, an input
<code>data</code> array containing the sequence of values (1, 2, 3, 4, 5, 6, 7, 8, 9) with
<code>nobs = 3</code> and <code>nvars = 2</code> creates a regression dataset with two
independent variables, as below:
<pre>
y x[0] x[1]
--------------
1 2 3
4 5 6
7 8 9
</pre>
</p>
<p>Note that there is no need to add an initial unitary column (column of 1's) when
specifying a model including an intercept term. If <a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#isNoIntercept()"><code>AbstractMultipleLinearRegression.isNoIntercept()</code></a> is <code>true</code>,
the X matrix will be created without an initial column of "1"s; otherwise this column will
be added.
</p>
<p>Throws IllegalArgumentException if any of the following preconditions fail:
<ul><li><code>data</code> cannot be null</li>
<li><code>data.length = nobs * (nvars + 1)</li>
<li><code>nobs > nvars</code></li></ul>
</p>
<p>This implementation computes and caches the QR decomposition of the X matrix.</p></div>
<dl>
<dt><strong>Overrides:</strong></dt>
<dd><code><a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#newSampleData(double[], int, int)">newSampleData</a></code>&nbsp;in class&nbsp;<code><a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html" title="class in org.apache.commons.math3.stat.regression">AbstractMultipleLinearRegression</a></code></dd>
<dt><span class="strong">Parameters:</span></dt><dd><code>data</code> - input data array</dd><dd><code>nobs</code> - number of observations (rows)</dd><dd><code>nvars</code> - number of independent variables (columns, not counting y)</dd></dl>
</li>
</ul>
<a name="calculateHat()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>calculateHat</h4>
<pre>public&nbsp;<a href="../../../../../../org/apache/commons/math3/linear/RealMatrix.html" title="interface in org.apache.commons.math3.linear">RealMatrix</a>&nbsp;calculateHat()</pre>
<div class="block"><p>Compute the "hat" matrix.
</p>
<p>The hat matrix is defined in terms of the design matrix X
by X(X<sup>T</sup>X)<sup>-1</sup>X<sup>T</sup>
</p>
<p>The implementation here uses the QR decomposition to compute the
hat matrix as Q I<sub>p</sub>Q<sup>T</sup> where I<sub>p</sub> is the
p-dimensional identity matrix augmented by 0's. This computational
formula is from "The Hat Matrix in Regression and ANOVA",
David C. Hoaglin and Roy E. Welsch,
<i>The American Statistician</i>, Vol. 32, No. 1 (Feb., 1978), pp. 17-22.
</p>
<p>Data for the model must have been successfully loaded using one of
the <code>newSampleData</code> methods before invoking this method; otherwise
a <code>NullPointerException</code> will be thrown.</p></div>
<dl><dt><span class="strong">Returns:</span></dt><dd>the hat matrix</dd>
<dt><span class="strong">Throws:</span></dt>
<dd><code><a href="http://docs.oracle.com/javase/6/docs/api/java/lang/NullPointerException.html?is-external=true" title="class or interface in java.lang">NullPointerException</a></code> - unless method <code>newSampleData</code> has been
called beforehand.</dd></dl>
</li>
</ul>
<a name="calculateTotalSumOfSquares()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>calculateTotalSumOfSquares</h4>
<pre>public&nbsp;double&nbsp;calculateTotalSumOfSquares()
throws <a href="../../../../../../org/apache/commons/math3/exception/MathIllegalArgumentException.html" title="class in org.apache.commons.math3.exception">MathIllegalArgumentException</a></pre>
<div class="block"><p>Returns the sum of squared deviations of Y from its mean.</p>
<p>If the model has no intercept term, <code>0</code> is used for the
mean of Y - i.e., what is returned is the sum of the squared Y values.</p>
<p>The value returned by this method is the SSTO value used in
the <a href="../../../../../../org/apache/commons/math3/stat/regression/OLSMultipleLinearRegression.html#calculateRSquared()"><code>R-squared</code></a> computation.</p></div>
<dl><dt><span class="strong">Returns:</span></dt><dd>SSTO - the total sum of squares</dd>
<dt><span class="strong">Throws:</span></dt>
<dd><code><a href="../../../../../../org/apache/commons/math3/exception/MathIllegalArgumentException.html" title="class in org.apache.commons.math3.exception">MathIllegalArgumentException</a></code> - if the sample has not been set or does
not contain at least 3 observations</dd><dt><span class="strong">Since:</span></dt>
<dd>2.2</dd>
<dt><span class="strong">See Also:</span></dt><dd><a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#isNoIntercept()"><code>AbstractMultipleLinearRegression.isNoIntercept()</code></a></dd></dl>
</li>
</ul>
<a name="calculateResidualSumOfSquares()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>calculateResidualSumOfSquares</h4>
<pre>public&nbsp;double&nbsp;calculateResidualSumOfSquares()</pre>
<div class="block">Returns the sum of squared residuals.</div>
<dl><dt><span class="strong">Returns:</span></dt><dd>residual sum of squares</dd><dt><span class="strong">Since:</span></dt>
<dd>2.2</dd></dl>
</li>
</ul>
<a name="calculateRSquared()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>calculateRSquared</h4>
<pre>public&nbsp;double&nbsp;calculateRSquared()
throws <a href="../../../../../../org/apache/commons/math3/exception/MathIllegalArgumentException.html" title="class in org.apache.commons.math3.exception">MathIllegalArgumentException</a></pre>
<div class="block">Returns the R-Squared statistic, defined by the formula <pre>
R<sup>2</sup> = 1 - SSR / SSTO
</pre>
where SSR is the <a href="../../../../../../org/apache/commons/math3/stat/regression/OLSMultipleLinearRegression.html#calculateResidualSumOfSquares()"><code>sum of squared residuals</code></a>
and SSTO is the <a href="../../../../../../org/apache/commons/math3/stat/regression/OLSMultipleLinearRegression.html#calculateTotalSumOfSquares()"><code>total sum of squares</code></a></div>
<dl><dt><span class="strong">Returns:</span></dt><dd>R-square statistic</dd>
<dt><span class="strong">Throws:</span></dt>
<dd><code><a href="../../../../../../org/apache/commons/math3/exception/MathIllegalArgumentException.html" title="class in org.apache.commons.math3.exception">MathIllegalArgumentException</a></code> - if the sample has not been set or does
not contain at least 3 observations</dd><dt><span class="strong">Since:</span></dt>
<dd>2.2</dd></dl>
</li>
</ul>
<a name="calculateAdjustedRSquared()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>calculateAdjustedRSquared</h4>
<pre>public&nbsp;double&nbsp;calculateAdjustedRSquared()
throws <a href="../../../../../../org/apache/commons/math3/exception/MathIllegalArgumentException.html" title="class in org.apache.commons.math3.exception">MathIllegalArgumentException</a></pre>
<div class="block"><p>Returns the adjusted R-squared statistic, defined by the formula <pre>
R<sup>2</sup><sub>adj</sub> = 1 - [SSR (n - 1)] / [SSTO (n - p)]
</pre>
where SSR is the <a href="../../../../../../org/apache/commons/math3/stat/regression/OLSMultipleLinearRegression.html#calculateResidualSumOfSquares()"><code>sum of squared residuals</code></a>,
SSTO is the <a href="../../../../../../org/apache/commons/math3/stat/regression/OLSMultipleLinearRegression.html#calculateTotalSumOfSquares()"><code>total sum of squares</code></a>, n is the number
of observations and p is the number of parameters estimated (including the intercept).</p>
<p>If the regression is estimated without an intercept term, what is returned is <pre>
<code> 1 - (1 - <a href="../../../../../../org/apache/commons/math3/stat/regression/OLSMultipleLinearRegression.html#calculateRSquared()"><code>calculateRSquared()</code></a>) * (n / (n - p)) </code>
</pre></p></div>
<dl><dt><span class="strong">Returns:</span></dt><dd>adjusted R-Squared statistic</dd>
<dt><span class="strong">Throws:</span></dt>
<dd><code><a href="../../../../../../org/apache/commons/math3/exception/MathIllegalArgumentException.html" title="class in org.apache.commons.math3.exception">MathIllegalArgumentException</a></code> - if the sample has not been set or does
not contain at least 3 observations</dd><dt><span class="strong">Since:</span></dt>
<dd>2.2</dd>
<dt><span class="strong">See Also:</span></dt><dd><a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#isNoIntercept()"><code>AbstractMultipleLinearRegression.isNoIntercept()</code></a></dd></dl>
</li>
</ul>
<a name="newXSampleData(double[][])">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>newXSampleData</h4>
<pre>protected&nbsp;void&nbsp;newXSampleData(double[][]&nbsp;x)</pre>
<div class="block"><p>Loads new x sample data, overriding any previous data.
</p>
The input <code>x</code> array should have one row for each sample
observation, with columns corresponding to independent variables.
For example, if <pre>
<code> x = new double[][] {{1, 2}, {3, 4}, {5, 6}} </code></pre>
then <code>setXSampleData(x) </code> results in a model with two independent
variables and 3 observations:
<pre>
x[0] x[1]
----------
1 2
3 4
5 6
</pre>
</p>
<p>Note that there is no need to add an initial unitary column (column of 1's) when
specifying a model including an intercept term.
</p>
<p>This implementation computes and caches the QR decomposition of the X matrix
once it is successfully loaded.</p></div>
<dl>
<dt><strong>Overrides:</strong></dt>
<dd><code><a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#newXSampleData(double[][])">newXSampleData</a></code>&nbsp;in class&nbsp;<code><a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html" title="class in org.apache.commons.math3.stat.regression">AbstractMultipleLinearRegression</a></code></dd>
<dt><span class="strong">Parameters:</span></dt><dd><code>x</code> - the rectangular array representing the x sample</dd></dl>
</li>
</ul>
<a name="calculateBeta()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>calculateBeta</h4>
<pre>protected&nbsp;<a href="../../../../../../org/apache/commons/math3/linear/RealVector.html" title="class in org.apache.commons.math3.linear">RealVector</a>&nbsp;calculateBeta()</pre>
<div class="block">Calculates the regression coefficients using OLS.
<p>Data for the model must have been successfully loaded using one of
the <code>newSampleData</code> methods before invoking this method; otherwise
a <code>NullPointerException</code> will be thrown.</p></div>
<dl>
<dt><strong>Specified by:</strong></dt>
<dd><code><a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#calculateBeta()">calculateBeta</a></code>&nbsp;in class&nbsp;<code><a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html" title="class in org.apache.commons.math3.stat.regression">AbstractMultipleLinearRegression</a></code></dd>
<dt><span class="strong">Returns:</span></dt><dd>beta</dd></dl>
</li>
</ul>
<a name="calculateBetaVariance()">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>calculateBetaVariance</h4>
<pre>protected&nbsp;<a href="../../../../../../org/apache/commons/math3/linear/RealMatrix.html" title="interface in org.apache.commons.math3.linear">RealMatrix</a>&nbsp;calculateBetaVariance()</pre>
<div class="block"><p>Calculates the variance-covariance matrix of the regression parameters.
</p>
<p>Var(b) = (X<sup>T</sup>X)<sup>-1</sup>
</p>
<p>Uses QR decomposition to reduce (X<sup>T</sup>X)<sup>-1</sup>
to (R<sup>T</sup>R)<sup>-1</sup>, with only the top p rows of
R included, where p = the length of the beta vector.</p>
<p>Data for the model must have been successfully loaded using one of
the <code>newSampleData</code> methods before invoking this method; otherwise
a <code>NullPointerException</code> will be thrown.</p></div>
<dl>
<dt><strong>Specified by:</strong></dt>
<dd><code><a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html#calculateBetaVariance()">calculateBetaVariance</a></code>&nbsp;in class&nbsp;<code><a href="../../../../../../org/apache/commons/math3/stat/regression/AbstractMultipleLinearRegression.html" title="class in org.apache.commons.math3.stat.regression">AbstractMultipleLinearRegression</a></code></dd>
<dt><span class="strong">Returns:</span></dt><dd>The beta variance-covariance matrix</dd></dl>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar_bottom">
<!-- -->
</a><a href="#skip-navbar_bottom" title="Skip navigation links"></a><a name="navbar_bottom_firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/OLSMultipleLinearRegression.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../../help-doc.html">Help</a></li>
</ul>
<div class="aboutLanguage"><em><script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script></em></div>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../../org/apache/commons/math3/stat/regression/MultipleLinearRegression.html" title="interface in org.apache.commons.math3.stat.regression"><span class="strong">Prev Class</span></a></li>
<li><a href="../../../../../../org/apache/commons/math3/stat/regression/RegressionResults.html" title="class in org.apache.commons.math3.stat.regression"><span class="strong">Next Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../../index.html?org/apache/commons/math3/stat/regression/OLSMultipleLinearRegression.html" target="_top">Frames</a></li>
<li><a href="OLSMultipleLinearRegression.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../../../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor_summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method_summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor_detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method_detail">Method</a></li>
</ul>
</div>
<a name="skip-navbar_bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<p class="legalCopy"><small>Copyright &#169; 2003&#x2013;2014 <a href="http://www.apache.org/">The Apache Software Foundation</a>. All rights reserved.</small></p>
</body>
</html>