[Numpy-discussion] 2d binning and linear regression
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,
> xy, xedges, yedges = np.histogram2d(lat, lon, weights=obsdm*obsdm,
> 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
> 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!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion