background preloader

Research

Facebook Twitter

Quick-R: Home Page. Www.comp.nus.edu.sg/~yuhf/dsybil-oakland09.pdf. Artificial Intelligence.

Publication search

XML/XQuery. Report typing. Using Python (and R) to calculate Linear Regressions. You might also be interested in my page on doing Rank Correlations with Python and/or R. This page demonstrates three different ways to calculate a linear regression from python: Pure Python - Gary Strangman's linregress function In Python, Gary Strangman's library (available in the SciPy library) can be used to do a simple linear regression as follows:- >>> from scipy import stats >>> x = [5.05, 6.75, 3.21, 2.66] >>> y = [1.65, 26.5, -5.93, 7.96] >>> gradient, intercept, r_value, p_value, std_err = stats.linregress(x,y) >>> print "Gradient and intercept", gradient, intercept Gradient and intercept (5.3935773611970186, -16.281127993087829) >>> print "R-squared", r_value**2 R-squared 0.524806275136 >>> print "p-value", p_value p-value 0.27556485788150242 Typing help(stats.linregress) will tell you about the return values (gradient, y-axis intercept, r, two-tailed probability, and the standard error of the estimate).