pandas: ENH: Standard Error of the Mean (sem) aggregation method
A very common operation when trying to work with data is to find out the error range for the data. In scientific research, including error ranges is required.
There are two main ways to do this: standard deviation and standard error of the mean. Pandas has an optimized std aggregation method for both dataframe and groupby. However, it does not have an optimized standard error method, meaning users who want to compute error ranges have to rely on the unoptimized scipy method.
Since computing error ranges is such a common operation, I think it would be very useful if there was an optimized sem
method like there is for std
.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 15 (14 by maintainers)
I have also been at three different institutions, and they also all used SEM. And I have seen it on hundreds of papers, presentations, and posters.
every science institution i’ve ever worked in (just 3 really so not a whole lot of weight there) has used
sem
at some point (even if just to get a rough idea of error ranges). i see your point about different definitions, maybe other folks want to chime in@jreback i don’t think this is code bloat relative to the alternative:
You can’t really use
scipy.stats.sem
because it doesn’t handlenan
s:Okay, so let’s try it with
scipy.stats.mstats.sem
:That’s hardly what I would expect here, and masked arrays are almost as fun as recarrays. I’m +1 on reopening this.
Here’s what it would take to get the desired result from
scipy
:http://docs.scipy.org/doc/scipy-0.13.0/reference/generated/scipy.stats.sem.html
@toddrjen What do you mean with an optimized method?
std
is optimized, so you don’t have to rely on an ‘unoptimized’ scipy.stats method, you can just do:df.std()/len(df)
And by the way, scipy.stats.sem is not that ‘unoptimized’. In fact, it is even faster, as this does not do eg the extra nan-checking as pandas does:
But of course, the question still remains, do we provide a shortcut to this functionality in the form of a
sem
method, or do we just expect out users to divide the std themselves.