You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
a = c(12.9, 13.5, 12.8, 15.6, 17.2, 19.2, 12.6, 15.3, 14.4, 11.3)
b = c(12.7, 13.6, 12.0, 15.2, 16.8, 20.0, 12.0, 15.9, 16.0, 11.1)
t.test(a,b, paired=TRUE)
Paired t-test
data: a and b
t = -0.2133, df = 9, p-value = 0.8358
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-0.5802549 0.4802549
sample estimates:
mean of the differences
-0.05
I googled for "statsmodels t-test paired" and only found a ttost_paired. Is there simply no paired t-test or am I just not good enough in statistics to find the right test? In the latter case, for the sake of people like me: it would be nice if then the documentation could be adjusted :-)
data: a and b
t = -0.2133, df = 9, p-value = 0.8358
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-0.5802549 0.4802549
sample estimates:
mean of the differences
-0.05
It's one of those things where it's not clear where it should go as a special case.
In statsmodels stats I often didn't know whether we need a specific function for the user to find and quickly use, or if we rely just at some general function (or class) where the user needs to "know" how to use it.
I thought I had a standalone function for one sample t-test, but don't see it.
Documentation for different use cases is for sure insufficient.
Pointing out what's unclear or/and a PR to improve this is always helpful.
The availability of summary for tests is still unclear and inconsistent because we still haven't decided what the "obvious" return is, i.e. similar to Results instances or R's class "htest".
The main ambiguity comes from the two usecases, one as library function that might be used in a heavy loop, and one as interactive function with nice summaries.
I don't think a simple test like a t-test should calculate confidence intervals and other results by default because it might be quite a bit of overhead in relative terms if we just want to bootstrap the t-statistic or p-values, for example.
If the calculations itself are already time consuming, then the overhead will be small in relative terms, e.g. the model Results.t_tests return a relatively nice ContrastResults instance.
The availability of summary for tests is still unclear and inconsistent because we still haven't decided what the "obvious" return is, i.e. similar to Results instances or R's class "htest".
Yes, that's also something I noticed. It would be nice to have something which automatically can be passed to Summary and summary_col...
Re performance: if that's the main problem then IMO the split the API: one for backends which is Fine-grained and fast and one for interactive work which has functions ala R, returns an object of a subclass of StatResult and which prints via a Summary and can be used in summary_col.
Or if a split API is too much work: make the repr compute the things? So if you get the StatResult object you can poke it for what you need (using on demand properties) and repr will call all properties and get the nice things for interactive work.
one possibility to get this in a relatively easy way would be to add a new function ttest_all or ttest_complete or ttest_summary or some similar name, that handles the different types of ttest plus the confidence interval, and returns something like the ContrastResults instance, which includes summary and summary_frame, and a __str__ and __repr__ IIRC.
This can also add proper names if the data is a pandas Series with name or a DataFrame.
Something like ttest_summary could also be added to DescrStatsW, which I thought about before, and which would have already access to the methods.
Since Kerby added contingency tables (including summary method) we have a trend to go to classes for a "topic",
e.g. one-sample, two-sample and k-sample classes for t or z-tests.
contingency table class for multivariate binomial, multinomial or poisson.
If this is going to be a "how the API should be discussion": I would vote that statsmodels gets an API access point (e.g. anything directly available from statsmodels or statsmodels.interactive) only for interactive work. The available functions should have some common design principles:
should be a function
take a formula + data as well as arrays-like; data should be the first argument, so that it can be used in a pandas pipe.
returns either a Result or, if it is computational intensive, a Model:
a Result prints a nice explaining text and can be used in summary_col
a Model which has a .fit() method which returns the Result.
If you only want one special method which returns raw data, you need to import from a sub module (e.g. statsmodels.stats or statsmodels.regressions) directly.
Activity
dengemann commentedon Dec 7, 2015
you've got such a thing in sicpy.stats I think, anyway a 1samp-ttest would
be the same after subtracting your 2 signals or conditions.
On Mon, Dec 7, 2015 at 3:50 PM, Jan Schulz [email protected] wrote:
josef-pkt commentedon Dec 7, 2015
Yes, as @dengemann pointed out it's just a one sample t-test on the difference
edit
stats is scipy.stats, added ttest_rel also
josef-pkt commentedon Dec 7, 2015
It's one of those things where it's not clear where it should go as a special case.
In statsmodels stats I often didn't know whether we need a specific function for the user to find and quickly use, or if we rely just at some general function (or class) where the user needs to "know" how to use it.
I thought I had a standalone function for one sample t-test, but don't see it.
Documentation for different use cases is for sure insufficient.
Pointing out what's unclear or/and a PR to improve this is always helpful.
josef-pkt commentedon Dec 7, 2015
labeled as FAQ
jankatins commentedon Dec 7, 2015
first of all: thanks for the fast help!
I can't be the first person to google "paired t-test statsmodels" and felt lost. Especially when I see the results of "paired t-test R".
It would also be nice if statsmodels would wrap the scipy functions to return a nice printable object which is similar to the regression output (or Rs output) and not only the plain numbers. A function like https://stat.ethz.ch/R-manual/R-devel/library/stats/html/t.test.html would be nice...
jankatins commentedon Dec 7, 2015
BTW: this website in statsmodel would be great: http://www.statmethods.net/stats/descriptives.html
josef-pkt commentedon Dec 7, 2015
the only page that we have similar is a notebook for regression diagnostics
http://www.statmethods.net/stats/rdiagnostics.html
http://statsmodels.sourceforge.net/devel/examples/notebooks/generated/regression_diagnostics.html
The availability of summary for tests is still unclear and inconsistent because we still haven't decided what the "obvious" return is, i.e. similar to Results instances or R's
class "htest".The main ambiguity comes from the two usecases, one as library function that might be used in a heavy loop, and one as interactive function with nice summaries.
I don't think a simple test like a t-test should calculate confidence intervals and other results by default because it might be quite a bit of overhead in relative terms if we just want to bootstrap the t-statistic or p-values, for example.
If the calculations itself are already time consuming, then the overhead will be small in relative terms, e.g. the model Results.t_tests return a relatively nice ContrastResults instance.
jankatins commentedon Dec 7, 2015
Yes, that's also something I noticed. It would be nice to have something which automatically can be passed to
Summaryandsummary_col...Re performance: if that's the main problem then IMO the split the API: one for backends which is Fine-grained and fast and one for interactive work which has functions ala R, returns an object of a subclass of
StatResultand which prints via aSummaryand can be used insummary_col.Or if a split API is too much work: make the repr compute the things? So if you get the
StatResultobject you can poke it for what you need (using on demand properties) and repr will call all properties and get the nice things for interactive work.josef-pkt commentedon Dec 7, 2015
one possibility to get this in a relatively easy way would be to add a new function
ttest_allor ttest_complete or ttest_summary or some similar name, that handles the different types of ttest plus the confidence interval, and returns something like the ContrastResults instance, which includes summary and summary_frame, and a__str__and__repr__IIRC.This can also add proper names if the data is a pandas Series with name or a DataFrame.
Something like ttest_summary could also be added to DescrStatsW, which I thought about before, and which would have already access to the methods.
Since Kerby added contingency tables (including summary method) we have a trend to go to classes for a "topic",
e.g. one-sample, two-sample and k-sample classes for t or z-tests.
contingency table class for multivariate binomial, multinomial or poisson.
josef-pkt commentedon Dec 7, 2015
a bit related http://stackoverflow.com/questions/24904822/scipy-stats-ttest-ind-without-array-python/34125188 and corresponding discussion in issue #1843 and scipy PR.
For most of the basic cases scipy.stats has the "less complicated" interface, and we have some freedom in statsmodels to go beyond that, and users can still use the scipy version for most of the functionality.
jankatins commentedon Dec 8, 2015
If this is going to be a "how the API should be discussion": I would vote that statsmodels gets an API access point (e.g. anything directly available from
statsmodelsorstatsmodels.interactive) only for interactive work. The available functions should have some common design principles:Resultor, if it is computational intensive, aModel:Resultprints a nice explaining text and can be used insummary_colModelwhich has a.fit()method which returns theResult.statsmodels.statsorstatsmodels.regressions) directly.