Class LMResiduals
- java.lang.Object
-
- dev.nm.stat.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 Description LMResiduals(LMProblem problem, Vector fitted)
Performs residual analysis for a linear regression problem.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
AR2()
Gets the diagnostic measure: adjusted R-squaredint
df()
Gets the degree of freedom.ImmutableVector
fitted()
Gets the fitted values, y^.double
Fstat()
Gets the diagnostic measure: F statisticsLMProblem
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.
-
-
-
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
-
RSS
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:
- adjusted R-squared
-
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
y_i_hat are the fitted values of the regression.mean of regression / mean squared error = sum((y_i_hat-y_mean)^2) / mean squared error = [(TSS-RSS)/n] / [RSS/(m-n)]
- Returns:
- F statistics
-
hHat
public ImmutableMatrix hHat()
Gets the projection matrix, H-hat.- Returns:
- the projection matrix
-
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
- See Also:
- "Chatterjee, Hadi and Price, "p.90 (4.15), Section 4.3," Regression Analysis by Example, 3rd edition, 2000. Wiley Series in Probability and Statistics."
- @see Wikipedia: Studentized residual
-
df
public int df()
Gets the degree of freedom. TODO: User should be able to modify this method for a different regression.- Returns:
- the degree of freedom
-
-