Apache commons math SimpleRegression has a very handy predict method for predicting a y value for a given x value. What it doesn't have, however, is an out of the box means for getting the standard error of that prediction, which would be very useful for an application I'm working on. I am not a good statistician so I would like to know the following:
Whether it is possible to calculate a prediction stderr given a SimpleRegression instance, an x value, and the public interface of SimpleRegression, and if so how?
Having looked at the source for getInterceptStdErr:
public double getInterceptStdErr() { if( !hasIntercept ){ return Double.NaN; } return FastMath.sqrt( getMeanSquareError() * ((1d / n) + (xbar * xbar) / sumXX)); }
to get the prediction stderr is it as simple as subtracting the x value for the prediction from the xbar values in the calculation? Like so:
public double getPredictionStdErr(double x) { if( !hasIntercept ){ return Double.NaN; } return FastMath.sqrt( getMeanSquareError() * ((1d / n) + ((xbar - x) * (xbar - x)) / sumXX)); }