[Numpy-discussion] 2d binning and linear regression

Tom Durrant thdurrant@gmail....
Tue Jun 22 09:09:01 CDT 2010


>
>
> the basic idea is in "polyfit  on multiple data points" on
> numpy-disscusion mailing list April 2009
>
> In this case, calculations have to be done by groups
>
> subtract mean (this needs to be replaced by group demeaning)
> modeldm = model - model.mean()
> obsdm = obs - obs.mean()
>
> xx = np.histogram2d(
> xx, xedges, yedges = np.histogram2d(lat, lon, weights=modeldm*modeldm,
>      bins=(latedges,lonedges))
> xy, xedges, yedges = np.histogram2d(lat, lon, weights=obsdm*obsdm,
>      bins=(latedges,lonedges))
>
>
> slopes = xy/xx  # slopes by group
>
> expand slopes to length of original array
> predicted = model - obs * slopes_expanded
> ...
>
> the main point is to get the group functions, for demeaning, ... for
> the 2d labels (and get the labels out of histogramdd)
>
> I'm out of time (off to the airport soon), but I can look into it next
> weekend.
>
> Josef
>
> Thanks Josef, I will chase up the April list...

If I understand what you have done above, this returns the slope of best fit
lines forced through the origin, is that right?

Have a great trip!

Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100623/d560ba7d/attachment.html 


More information about the NumPy-Discussion mailing list