Skip to content

paired t-test? #2725

Open
Open

Description

@jankatins

This is either a "implement such a test" or a "document it better":

I'm currently looking for the statsmodel equivalent of (from http://statistic-on-air.blogspot.de/2009/07/paired-students-t-test.html)

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 :-)

Activity

  1. dengemann commented on Dec 7, 2015

    @dengemann
    Contributor

    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:

    This is either a "implement such a test" or a "document it better":

    I'm currently looking for the statsmodel equivalent of (from
    http://statistic-on-air.blogspot.de/2009/07/paired-students-t-test.html)

    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
    http://statsmodels.sourceforge.net/devel/generated/statsmodels.stats.weightstats.ttost_paired.html#statsmodels.stats.weightstats.ttost_paired.
    Is there simple 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 :-)

    —
    Reply to this email directly or view it on GitHub
    #2725.

  2. josef-pkt commented on Dec 7, 2015

    @josef-pkt
    Member

    Yes, as @dengemann pointed out it's just a one sample t-test on the difference

    >>> a = np.array([12.9, 13.5, 12.8, 15.6, 17.2, 19.2, 12.6, 15.3, 14.4, 11.3])
    >>> b = np.array([12.7, 13.6, 12.0, 15.2, 16.8, 20.0, 12.0, 15.9, 16.0, 11.1])
    >>> stats.ttest_1samp(a - b, popmean=0)
    (-0.21330847512739051, 0.83584000571392769)
    >>> stats.ttest_rel(a, b)
    (-0.21330847512739051, 0.83584000571392769)
    
    >>> from statsmodels.stats import weightstats as sms
    >>> d = sms.DescrStatsW(a - b)
    >>> d.ttest_mean()
    (-0.21330847512739051, 0.83584000571392769, 9.0)
    >>> d.tconfint_mean()
    (-0.58025487182119562, 0.48025487182119597)
    

    edit
    stats is scipy.stats, added ttest_rel also

  3. josef-pkt commented on Dec 7, 2015

    @josef-pkt
    Member

    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.

  4. josef-pkt commented on Dec 7, 2015

    @josef-pkt
    Member

    labeled as FAQ

  5. jankatins commented on Dec 7, 2015

    @jankatins
    ContributorAuthor

    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...

  6. josef-pkt commented on Dec 7, 2015

    @josef-pkt
    Member

    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.

  7. jankatins commented on Dec 7, 2015

    @jankatins
    ContributorAuthor

    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.

  8. josef-pkt commented on Dec 7, 2015

    @josef-pkt
    Member

    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.

  9. josef-pkt commented on Dec 7, 2015

    @josef-pkt
    Member

    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.

  10. jankatins commented on Dec 8, 2015

    @jankatins
    ContributorAuthor

    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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions