Many physical situations involving two variables can be described by a linear model. When linear data are plotted, we need to determine the best-fit line for that data set, which is referred to as .
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 correlatons and plot confidence levels and predictions. This is a simple example:
>>> from jhplot import HPlot,P1D,F1D >>> from jhplot.regression import * >>> >>> 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 P1Ds with predictions and confidence level data.
In addition, linear regression analysis can be done either by using the Jakarta Commons-Mathhttp://jakarta.apache.org/commons/math/ or Thomas Flanagan's Java Libraryhttp://www.ee.ucl.ac.uk/ mflanaga/java/Regression.html. Both libraries are included to the jHepWork. You can find jHepWork Jython examples in the directory "macros/examples/regression".
Look at an example in ``histo_fit.py''. This script fills a histogram, creates factories and does a fit with a Gaussian function.