# SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.stats.regression.linear.glm

## Class IWLS

• All Implemented Interfaces:
GLMFitting

public class IWLS
extends Object
implements GLMFitting
This implementation estimates parameters β in a GLM model using the Iteratively Re-weighted Least Squares algorithm. The idea is that, at each iteration, we regress the adjusted, weighted, dependent variables on the same design matrix.

The R equivalent function is glm.fit.

• "P. J. MacCullagh and J. A. Nelder, "An algorithm for fitting generalized linear models," Generalized Linear Models. 2nd ed. pp.40. Section 2.5."
• Wikipedia: Maximum likelihood
• ### Constructor Summary

Constructors
Constructor and Description
IWLS(double threshold, int maxIterations)
Construct an instance to run the Iteratively Re-weighted Least Squares algorithm.
• ### Method Summary

Methods
Modifier and Type Method and Description
ImmutableVector betaHat()
Gets the estimates of β, β^, as in E(Y) = μ = g-1(Xβ)
void fit(GLMProblem probelm, Vector beta0Initial)
Fits a Generalized Linear Model.
double logLikelihood()
ImmutableVector mu()
Gets μ as in E(Y) = μ = g-1(Xβ)
ImmutableVector weights()
Gets the weights assigned to the observations.
• ### Methods inherited from class java.lang.Object

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

• #### IWLS

public IWLS(double threshold,
int maxIterations)
Construct an instance to run the Iteratively Re-weighted Least Squares algorithm.
Parameters:
threshold - the convergence threshold
maxIterations - maximum number of iterations
• ### Method Detail

• #### fit

public void fit(GLMProblem probelm,
Vector beta0Initial)
Description copied from interface: GLMFitting
Fits a Generalized Linear Model.

This method must be called before the three get methods.

Specified by:
fit in interface GLMFitting
Parameters:
probelm - the generalized linear regression problem to be solved
beta0Initial - initial guess for β^
• #### mu

public ImmutableVector mu()
Description copied from interface: GLMFitting
Gets μ as in
E(Y) = μ = g-1(Xβ)
Specified by:
mu in interface GLMFitting
Returns:
μ
• #### betaHat

public ImmutableVector betaHat()
Description copied from interface: GLMFitting
Gets the estimates of β, β^, as in
E(Y) = μ = g-1(Xβ)
Specified by:
betaHat in interface GLMFitting
Returns:
β^
• #### weights

public ImmutableVector weights()
Description copied from interface: GLMFitting
Gets the weights assigned to the observations.
Specified by:
weights in interface GLMFitting
Returns:
the weights
• #### logLikelihood

public double logLikelihood()
Specified by:
logLikelihood in interface GLMFitting