Subsections

3.32 Linear regression.

3.32.1 Linear regression

Many physical situations involving two variables can be described by a linear model. When linear data are plotted, one needs to determine the best-fit line for that data set, which is referred to as linear regression.

The package jhplot.regression can be used for the linear-regression tasks. It can evaluate the slope and intercept parameters, the standard errors, coefficient of correlations and plot confidence levels and predictions. This is a simple example:

>>> from jhplot  import HPlot,P1D,F1D
>>> from jhplot.regression  import LRegression 
>>>
>>> c1 = HPlot("Canvas",600,400)
>>> c1.visible(1)
>>> c1.setAutoRange()
>>> p1= P1D("data") # fill data in X and Y
>>> p1.add(20,6)
>>> p1.add(1,3)
>>> p1.add(19,30)
>>> p1.add(29,16)
>>>
>>> r = LRegression(p1)
>>> print "Intercept=",r.getIntercept(), "+/-",r.getInterceptError()
>>> print "Slope=",r.getSlope(),"+/-",r.getSlopeError()
# draw original data
>>> c1.draw(p1);
# draw F1D function with the result
>>> c1.draw(  r.getResult()  ) # getResult() return F1D function
# draw P1D[2] with predictions
>>> c1.draw(   r.getPrediction() ) # getPrediction() returns P1D[]
# draw P1D[2} with confidence
>>> c1.draw(   r.getConfidence() ) # getConfidence() returns P1D[]
It should be noted that, in this example, the methods getPrediction() and getConfidence() return arrays of P1D with predictions and confidence level data.

In addition, linear regression analysis can be done either by using the Jakarta mathematical library [16] or T.Flanagan's Java Library [17]. Both libraries are included to the jHepWork. One can find jHepWork Jython examples in the directory regression.