Lee Spector <lspec...@hampshire.edu> writes:

> I need to do some pretty simple statistics in a Clojure program and
> Incanter produces results that I think must be wrong (details
> below). So I don't think I can trust it.

I agree, those all look weird to me.

> Is there other code for statistical testing out there?

I'd reach for commons-math, but I don't have much experience.

> If I understand correctly the t-test should produce a p-value which
> ranges from 0 to 1. If it's less than 0.05 we can say that the means
> differ. (Again, there would be more to say here about what's
> statistically meaningful, but that discussion isn't relevant to my
> question).

This is true.

> => (t-test (range 1 11) :mu 0)
> {:conf-int [3.33414941027723 7.66585058972277],
> :x-mean 5.5,
> :t-stat 5.744562646538029,
> :p-value 1.9997218039889517,
> :n1 10,
> :df 9,
> :n2 nil,
> :y-var nil,
> :x-var 9.166666666666666,
> :y-mean nil}

This looks wrong to me.  At least according to R, the p-value is
0.00278.  Interestingly, this is 2 - [incanter's p].

> => (t-test '(40 5 2) :y '(1 5 1))
> {:conf-int [-39.46068349230474 66.12735015897141],
>  :x-mean 15.666666666666666,
>  :t-stat 1.0866516498483223,
>  :p-value 1.6115506955016772,
>  :n1 3,
>  :df 2.0477900396893336,
>  :n2 3,
>  :y-var 5.333333333333332,
>  :x-var 446.33333333333337,
>  :y-mean 2.3333333333333335}

R gives 0.3884, which is again 2 - [incanter's p].  Fishy.

I would say that there's a bug in Incanter's distribution function, at
least when calculating values in the tails.

> If not, then does anyone have a pointer to more reliable statistics
> code in Clojure? Or pointers to using a Java library? I see that there
> are libraries out there --
> e.g. 
> http://commons.apache.org/math/api-1.2/org/apache/commons/math/stat/inference/TTest.html
> -- but Java interop is not my strong suit and I'm not sure how to call
> this from my Clojure code.

There may be an easier way to do this, but this worked for me:

  user=> (org.apache.commons.math.stat.inference.TestUtils/tTest
    (into-array Double/TYPE [40 5 2]) (into-array Double/TYPE [1 5 1]))
  0.3884493044983227

Hope that helps,
Johann

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to