[SciPy-User] calculating numerous linear regressions quickly

Jonathan Helmus jjhelmus at gmail.com
Mon Jan 13 15:09:43 EST 2014


Since the points are equally spaced and you want the coefficients of a 
low order polynomial you should be able to use a analytical solution to 
the linear least squares problem.  The Savitzky-Golay filter can be used 
to calculate the derivatives which are related to the polynomials 
coefficients. S-G isn't in Scipy but there is a cookbook page in the 
wiki: http://wiki.scipy.org/Cookbook/SavitzkyGolay

     - Jonathan Helmus

On 01/13/2014 02:02 PM, David Shean wrote:
> Hi Bryan,
> The discussion/links here might be useful:
> http://stackoverflow.com/questions/20343500/efficient-1d-linear-regression-for-each-element-of-3d-numpy-array
> -David
>
> On Jan 13, 2014, at 11:49 AM, Bryan Woods <bwoods at aer.com> wrote:
>
>> Given some geospatial grid with a time dimension V[t, lat, lon], I want to compute the trend at each spatial point in the domain. Essentially I am trying to compute many linear regressions in the form:
>> y = mx+b
>> where y is the predicted value of V, x is the time coordinate array. The coordinates t, lat, lon at all equispaced 1-D arrays, so the predictor (x, or t) will be the same for each regression. I want to gather the regression coefficients (m,b), correlation, and p-value for the temporal trend at each spatial point. This can be directly accomplished by repeatedly calling stats.linregress inside of a loop for every [lat, lon] point in the domain, but it is not efficient.
>>
>> The challenge is that I need to compute a lot of them quickly and a python loop is proving very slow. I feel like there should be some version of stats.linregress that accepts and returns multidimensional without being forced into using a python loop. Suggestions?
>>
>> Thanks,
>> Bryan
>> <bwoods.vcf>_______________________________________________
>> SciPy-User mailing list
>> SciPy-User at scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user




More information about the SciPy-User mailing list