Java Statistical Classes

jsc.curvefitting
Class LineFitThruOrigin

java.lang.Object
  |
  +--jsc.curvefitting.LineFitThruOrigin
All Implemented Interfaces:
StraightLineFit

public class LineFitThruOrigin
extends Object
implements StraightLineFit

Least squares fitted straight line through the origin. This class calculates and stores the least squares straight line constrained to pass through the origin, y = Bx, fitted to an array of data pairs (x,y).

Version:
1.0
Author:
A. J. Bertie.

Constructor Summary
LineFitThruOrigin(PairedData data)
          Creates the least squares estimate from paired data (x,y).
 
Method Summary
 double getA()
          Returns estimate of intercept term, A.
 double getB()
          Returns least squares estimate of B.
 ConfidenceInterval getCIB(double coeff)
          Returns confidence interval of estimate of slope, B.
 double[][] getIntervals(double coeff, int k, double xMin, double xMax)
          Calculates confidence intervals for the mean, Bx, and prediction intervals for the response, Y.
 double getMeanX()
          Returns mean of x.
 double getMeanY()
          Returns mean of y.
 int getN()
          Returns number of observations in sample.
 double getSumOfSquares()
          Return the sum of squared deviations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LineFitThruOrigin

public LineFitThruOrigin(PairedData data)
Creates the least squares estimate from paired data (x,y).

Parameters:
data - the data pairs (x,y).
Throws:
IllegalArgumentException - if x data are constant.
Method Detail

getA

public double getA()
Description copied from interface: StraightLineFit
Returns estimate of intercept term, A.

Specified by:
getA in interface StraightLineFit
Returns:
the estimate of A.

getB

public double getB()
Returns least squares estimate of B.

Specified by:
getB in interface StraightLineFit
Returns:
the least squares estimate of B.

getCIB

public ConfidenceInterval getCIB(double coeff)
Returns confidence interval of estimate of slope, B.

Parameters:
coeff - the confidence coefficient, which must be between 0 and 1.
Returns:
confidence interval of estimate of slope, B.
Throws:
IllegalArgumentException - if coeff < 0 or > 1.
IllegalArgumentException - if < 2 observations.

getIntervals

public double[][] getIntervals(double coeff,
                               int k,
                               double xMin,
                               double xMax)
Calculates confidence intervals for the mean, Bx, and prediction intervals for the response, Y. The CIs are calculated at k equally spaced x-values between xMin and xMax inclusive. The method returns a matrix with five columns as follows.

Column 0 contains the k x-values.

Column 1 contains the corresponding lower limits of the CIs for the mean,

Column 2 contains the corresponding upper limits of the CIs for the mean.

Column 3 contains the corresponding lower limits of the prediction intervals.

Column 4 contains the corresponding upper limits of the prediction intervals.

This method is useful for obtaining the co-ordinates for drawing the CI and prediction interval curves on a scatterplot.

Parameters:
coeff - the confidence coefficient, which must be between 0 and 1.
k - the number of x-values at which the CIs are calculated.
xMin - the first x-values at which the CIs are calculated.
xMax - the last x-values at which the CIs are calculated.
Returns:
matrix of co-ordinates for plotting the confidence intervals.
Throws:
IllegalArgumentException - if coeff < 0 or > 1.
IllegalArgumentException - if xMin is not < xMax.
IllegalArgumentException - if < 2 observations.

getMeanX

public double getMeanX()
Returns mean of x.

Returns:
mean of x.

getMeanY

public double getMeanY()
Returns mean of y.

Returns:
mean of y.

getN

public int getN()
Returns number of observations in sample.

Returns:
number of observations.

getSumOfSquares

public double getSumOfSquares()
Return the sum of squared deviations.

Returns:
the sum of squared deviations.

Java Statistical Classes

Copyright © Andrew James Bertie, 2005, all rights reserved. Updated 12th Aug 2005