-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subtypes of HypothesisTest can have optional fields :tail and :alpha #100
base: master
Are you sure you want to change the base?
Changes from 18 commits
ef60cb7
5f82c9c
14f15d1
c3363a1
596444f
15282b5
8007b1e
e63c378
c882e25
c1ac852
36a9e76
e6bc7a6
bda80a7
480e152
96eb8cf
7f66aa8
86626ec
1938ffb
5d38a50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,12 @@ | |
Confidence Interval | ||
============================================== | ||
|
||
.. function:: confint(test::HypothesisTest, alpha=0.05; tail=:both) | ||
.. function:: confint(test::HypothesisTest, alpha=alpha(test); tail=tail(test)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
Compute a confidence interval C with coverage 1-``alpha``. | ||
Compute a confidence interval C with coverage 1-``alpha`` | ||
(``alpha=0.05`` is the default for all tests). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 0.05 is the default for all tests unless overridden when creating the object. |
||
|
||
If ``tail`` is ``:both`` (default), then a two-sided confidence | ||
If ``tail`` is ``:both`` (default for most tests), then a two-sided confidence | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "most" isn't precise enough: give a list of tests for which it is the case below. Same remark for |
||
interval is returned. If ``tail`` is ``:left`` or | ||
``:right``, then a one-sided confidence interval is returned | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,11 @@ | |
p-value | ||
============================================== | ||
|
||
.. function:: pvalue(test::HypothesisTest; tail=:both) | ||
.. function:: pvalue(test::HypothesisTest; tail=tail(test)) | ||
|
||
Compute the p-value for a given significance test. | ||
|
||
If ``tail`` is ``:both`` (default), then the p-value for the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to mention that the default tail depends on the specific test, and give a list of tests with their default. |
||
If ``tail`` is ``:both`` (default for most hypothesis tests), then the p-value for the | ||
two-sided test is returned. If ``tail`` is ``:left`` or | ||
``:right``, then a one-sided test is performed. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,57 @@ | ||
T-test | ||
============================================= | ||
|
||
.. function:: OneSampleTTest(v::AbstractVector{T<:Real}, mu0::Real=0) | ||
.. function:: OneSampleTTest(v::AbstractVector{T<:Real}, mu0::Real=0; tail::Symbol=:both, alpha::Real=0.05) | ||
|
||
Perform a one sample t-test of the null hypothesis that the data | ||
in vector ``v`` comes from a distribution with mean ``mu0`` against | ||
the alternative hypothesis that the distribution does not have mean | ||
``mu0``. | ||
|
||
``tail`` and ``alpha`` specify the defaults for the application of | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "for the application of" is an unusual vocabulary. Maybe "when calling"? |
||
:ref:`pvalue<pvalue>` and :ref:`confint<confint>`. | ||
|
||
Implements: :ref:`pvalue<pvalue>`, :ref:`confint<confint>` | ||
|
||
.. function:: OneSampleTTest(xbar::Real, stdev::Real, n::Int, mu0::Real=0) | ||
.. function:: OneSampleTTest(xbar::Real, stdev::Real, n::Int, mu0::Real=0; tail::Symbol=:both, alpha::Real=0.05) | ||
|
||
Perform a one sample t-test of the null hypothesis that ``n`` | ||
values with mean ``xbar`` and sample standard deviation | ||
``stdev`` come from a distribution with ``mu0`` against | ||
the alternative hypothesis that the distribution does not have mean | ||
``mu0``. | ||
|
||
``tail`` and ``alpha`` specify the defaults for the application of | ||
:ref:`pvalue<pvalue>` and :ref:`confint<confint>`. | ||
|
||
Implements: :ref:`pvalue<pvalue>`, :ref:`confint<confint>` | ||
|
||
.. function:: OneSampleTTest(x::AbstractVector{T<:Real}, y::AbstractVector{T<:Real}, mu0::Real=0) | ||
.. function:: OneSampleTTest(x::AbstractVector{T<:Real}, y::AbstractVector{T<:Real}, mu0::Real=0; tail::Symbol=:both, alpha::Real=0.05) | ||
|
||
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 ``mu0`` against the | ||
alternative hypothesis that the distribution does not have mean | ||
``mu0``. | ||
|
||
``tail`` and ``alpha`` specify the defaults for the application of | ||
:ref:`pvalue<pvalue>` and :ref:`confint<confint>`. | ||
|
||
Implements: :ref:`pvalue<pvalue>`, :ref:`confint<confint>` | ||
|
||
.. function:: EqualVarianceTTest(x::AbstractVector{T<:Real}, y::AbstractVector{T<:Real}) | ||
.. function:: EqualVarianceTTest(x::AbstractVector{T<:Real}, y::AbstractVector{T<:Real}; tail::Symbol=:both, alpha::Real=0.05) | ||
|
||
Perform a two-sample t-test of the null hypothesis that | ||
``x`` and ``y`` come from a distributions with the same mean | ||
and equal variances against the alternative hypothesis that the | ||
distributions have different means and but equal variances. | ||
|
||
``tail`` and ``alpha`` specify the defaults for the application of | ||
:ref:`pvalue<pvalue>` and :ref:`confint<confint>`. | ||
|
||
Implements: :ref:`pvalue<pvalue>`, :ref:`confint<confint>` | ||
|
||
.. function:: UnequalVarianceTTest(x::AbstractVector{T<:Real}, y::AbstractVector{T<:Real}) | ||
.. function:: UnequalVarianceTTest(x::AbstractVector{T<:Real}, y::AbstractVector{T<:Real}; tail::Symbol=:both, alpha::Real=0.05) | ||
|
||
Perform an unequal variance two-sample t-test of the null | ||
hypothesis that ``x`` and ``y`` come from a distributions with | ||
|
@@ -54,5 +66,8 @@ T-test | |
.. math:: | ||
\nu_{\chi'} \approx \frac{\left(\sum_{i=1}^n k_i s_i^2\right)^2} | ||
{\sum_{i=1}^n \frac{(k_i s_i^2)^2}{\nu_i}} | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove trailing spaces here and elsewhere. |
||
``tail`` and ``alpha`` specify the defaults for the application of | ||
:ref:`pvalue<pvalue>` and :ref:`confint<confint>`. | ||
|
||
Implements: :ref:`pvalue<pvalue>`, :ref:`confint<confint>` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,32 +72,35 @@ end | |
function Base.show{T<:HypothesisTest}(io::IO, test::T) | ||
println(io, testname(test)) | ||
println(io, repeat("-", length(testname(test)))) | ||
|
||
# utilities for pretty-printing | ||
conf_string = string(floor((1 - alpha(test)) * 100, 6)) # limit to 6 decimals in % | ||
prettify_detail(label::String, value::Any, len::Int) = # len is max length of label | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say "format" rather than "prettify". |
||
" " * label * " "^max(len - length(label), 0) * string(value) | ||
|
||
# population details | ||
has_ci = applicable(StatsBase.confint, test) | ||
(param_name, param_under_h0, param_estimate) = population_param_of_interest(test) | ||
println(io, "Population details:") | ||
println(io, " parameter of interest: $param_name") | ||
println(io, " value under h_0: $param_under_h0") | ||
println(io, " point estimate: $param_estimate") | ||
println(io, prettify_detail("parameter of interest:", param_name, 32)) | ||
println(io, prettify_detail("value under h_0:", param_under_h0, 32)) | ||
println(io, prettify_detail("point estimate:", param_estimate, 32)) | ||
if has_ci | ||
println(io, " 95% confidence interval: $(StatsBase.confint(test))") | ||
println(io, prettify_detail(conf_string*"% confidence interval:", StatsBase.confint(test), 32)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for |
||
end | ||
println(io) | ||
|
||
# test summary | ||
p = pvalue(test) | ||
outcome = if p > 0.05 "fail to reject" else "reject" end | ||
tail = default_tail(test) | ||
tail = HypothesisTests.tail(test) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
p = pvalue(test) # obeys value of HypothesisTests.tail(test) if applicable | ||
outcome = if p > alpha(test) "fail to reject" else "reject" end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's more standard to use |
||
tailvalue = | ||
if tail == :both "two-sided p-value:" | ||
elseif tail == :left || tail == :right "one-sided p-value ($(string(tail)) tail):" | ||
else "p-value:" end | ||
println(io, "Test summary:") | ||
println(io, " outcome with 95% confidence: $outcome h_0") | ||
if tail == :both | ||
println(io, " two-sided p-value: $p") | ||
elseif tail == :left || tail == :right | ||
println(io, " one-sided p-value: $p") | ||
else | ||
println(io, " p-value: $p") | ||
end | ||
println(io, prettify_detail("outcome with "*conf_string*"% confidence:", outcome*" h_0", 36)) | ||
println(io, prettify_detail(tailvalue, p, 36)) | ||
println(io) | ||
|
||
# further details | ||
|
@@ -108,8 +111,9 @@ end | |
# parameter of interest: name, value under h0, point estimate | ||
population_param_of_interest{T<:HypothesisTest}(test::T) = ("not implemented yet", NaN, NaN) | ||
|
||
# is the test one- or two-sided | ||
default_tail(test::HypothesisTest) = :undefined | ||
# is the test one- or two-sided? | ||
tail(test::HypothesisTest) = :undefined # overloaded for defaults or field access | ||
alpha(test::HypothesisTest) = 0.05 | ||
|
||
function show_params{T<:HypothesisTest}(io::IO, test::T, ident="") | ||
fieldidx = find(Bool[t<:Number for t in T.types]) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
using Base: @deprecate | ||
|
||
@deprecate ci(args...) confint(args...) | ||
@deprecate default_tail(test::HypothesisTest) tail(test) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please leave this as it was, it's not an issue if the CI fails for this version (we're not robots).