# SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.stats.regression.linear.residualanalysis

## Class LMResiduals

• java.lang.Object
• com.numericalmethod.suanshu.stats.regression.linear.residualanalysis.LMResiduals
• Direct Known Subclasses:
GLMResiduals, LogisticResiduals, OLSResiduals

public class LMResiduals
extends Object
This is the residual analysis of the results of a linear regression model. Once a regression model has been constructed, it may be important to confirm the goodness of fit of the model and the statistical significance of the estimated parameters. Commonly used checks of goodness of fit include the R-squared, analysis of the pattern of residuals and hypothesis testing. Statistical significance can be checked by an F-test of the overall fit, followed by t-tests of individual parameters.
• ### Constructor Summary

Constructors
Constructor and Description
LMResiduals(LMProblem problem, Vector fitted)
Performs residual analysis for a linear regression problem.
• ### Method Summary

All Methods
Modifier and Type Method and Description
double AR2()
Gets the diagnostic measure: adjusted R-squared
int df()
Gets the degree of freedom.
ImmutableVector fitted()
Gets the fitted values, y^.
double Fstat()
Gets the diagnostic measure: F statistics
LMProblem getProblem()
Gets the linear regression problem.
ImmutableMatrix hHat()
Gets the projection matrix, H-hat.
ImmutableVector leverage()
Gets the leverage.
double R2()
Gets the diagnostic measure: R-squared.
ImmutableVector residuals()
Gets the residuals, ε, the differences between sample and fitted values.
double RSS()
Gets the diagnostic measure: sum of squared residuals, $$\sum \epsilon^2$$.
ImmutableVector standardized()
standard residual = residual / v1 / sqrt(RSS / (n-m))
double stderr()
Gets the standard error of the residuals.
ImmutableVector studentized()
studentized residual = standardized * sqrt((n-m-1) / (n-m-standardized^2))
double TSS()
Gets the diagnostic measure: total sum of squares, $$\sum (y-y_mean)^2$$.
ImmutableVector weightedFittedValues()
Gets the weighted, fitted values.
ImmutableVector weightedResiduals()
Gets the weighted residuals.
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Constructor Detail

• #### LMResiduals

public LMResiduals(LMProblem problem,
Vector fitted)
Performs residual analysis for a linear regression problem.
Parameters:
problem - the linear regression problem to be solved
fitted - the fitted values, y^
• ### Method Detail

• #### getProblem

public LMProblem getProblem()
Gets the linear regression problem.
Returns:
the linear regression problem
• #### fitted

public ImmutableVector fitted()
Gets the fitted values, y^.
Returns:
the fitted values, y^
• #### residuals

public ImmutableVector residuals()
Gets the residuals, ε, the differences between sample and fitted values.
Returns:
the residuals, ε
• #### weightedFittedValues

public ImmutableVector weightedFittedValues()
Gets the weighted, fitted values.
Returns:
the weighted, fitted values
• #### weightedResiduals

public ImmutableVector weightedResiduals()
Gets the weighted residuals.
Returns:
the weighted residuals

public double RSS()
Gets the diagnostic measure: sum of squared residuals, $$\sum \epsilon^2$$.
Returns:
sum of squared residuals, $$\sum \epsilon^2$$
• #### TSS

public double TSS()
Gets the diagnostic measure: total sum of squares, $$\sum (y-y_mean)^2$$.
Returns:
total sum of squares, $$\sum (y-y_mean)^2$$
• #### R2

public double R2()
Gets the diagnostic measure: R-squared.
Returns:
R-squared
• #### AR2

public double AR2()
Gets the diagnostic measure: adjusted R-squared
Returns:
• #### stderr

public double stderr()
Gets the standard error of the residuals.
Returns:
the standard error of the residuals
• #### Fstat

public double Fstat()
Gets the diagnostic measure: F statistics

mean of regression / mean squared error =
sum((y_i_hat-y_mean)^2) / mean squared error =

y_i_hat are the fitted values of the regression.
Returns:
F statistics
"Kutner, Nachtsheim and Neter, "p.69, equation (2.60)," Applied linear regression models. 4th edition."
• #### hHat

public ImmutableMatrix hHat()
Gets the projection matrix, H-hat.
Returns:
the projection matrix
"Sanford Weisberg, "p.168, Section 8.1, Chapter 8," Applied Linear Regression, 3rd edition, 2005. Wiley-Interscience."
• #### leverage

public ImmutableVector leverage()
Gets the leverage. The bigger the leverage for an observation, the bigger influence on the prediction.
Returns:
the leverage
• #### standardized

public ImmutableVector standardized()
standard residual = residual / v1 / sqrt(RSS / (n-m))
Returns:
standardized residuals
• #### studentized

public ImmutableVector studentized()
studentized residual = standardized * sqrt((n-m-1) / (n-m-standardized^2))
Returns:
studentized residuals
public int df()