Hi! I see that HypothesisTests.CorrelationTest makes a test for nonzero correlation. It prints the results of the test, including the two-sided p-value. How can I access that p-value? The output only has the fields k, n, r, and t, and none of them seems to be the p-value.
BTW it would be great if it was easy to access the p-value (and to degrees of freedom), as these are so often reported in publications.
using HypothesisTests
# One-sample t-test: test if mean differs from 0
data = [2.3, 1.8, 3.1, 2.5, 2.9, 1.7, 2.8, 3.0, 2.4, 2.6]
t = OneSampleTTest(data)
pvalue(t)
# Two-sample t-test
x = [2.3, 1.8, 3.1, 2.5, 2.9]
y = [1.2, 0.9, 1.5, 1.1, 1.3]
t2 = EqualVarianceTTest(x, y)
pvalue(t2)
# You can also test against a specific mean
t3 = OneSampleTTest(data, 2.0) # Hβ: ΞΌ = 2.0
pvalue(t3)
?help is your friend in this case to discover where itβs hidden.
help?> OneSampleTTest
search: OneSampleTTest OneSampleZTest OneSampleADTest TwoSampleTTest TwoSampleZTest ExactOneSampleKSTest KSampleADTest OneSampleHotellingT2Test OneWayANOVATest ApproximateOneSampleKSTest
OneSampleTTest(xbar::Real, stddev::Real, n::Int, ΞΌ0::Real = 0)
Perform a one sample t-test of the null hypothesis that n values with mean xbar and sample standard deviation stddev come from a distribution with mean ΞΌ0 against the alternative hypothesis
that the distribution does not have mean ΞΌ0.
Implements: pvalue, confint
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
OneSampleTTest(v::AbstractVector{T<:Real}, ΞΌ0::Real = 0)
Perform a one sample t-test of the null hypothesis that the data in vector v comes from a distribution with mean ΞΌ0 against the alternative hypothesis that the distribution does not have mean
ΞΌ0.
Implements: pvalue, confint
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
OneSampleTTest(x::AbstractVector{T<:Real}, y::AbstractVector{T<:Real}, ΞΌ0::Real = 0)
Perform a paired sample t-test of the null hypothesis that the differences between pairs of values in vectors x and y come from a distribution with mean ΞΌ0 against the alternative hypothesis
that the distribution does not have mean ΞΌ0.
Implements: pvalue, confint
β Note
β
β This test is also known as a t-test for paired or dependent samples, see paired difference test on Wikipedia.
julia>
Thanks. For those coming from other languages, where the p-value is the second output to a correlation function, maybe some illustrative examples (or even a cor() with two outputs) might be helpful.
Iβve found that designers of Julia packages tend to define functions like *nix command line utilitiesβdo one thing and do it well. In this case, the designer made a selection of the attributes of the t values, and itβs left to the user to add more. You could do this with a function or @macro or even refactor the package to make different choices. Itβs a part of the learning curve in new languages to get used to how it differs from familiar languages and adjust expectations accordingly.