-
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 all 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,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``, 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 |
---|---|---|
|
@@ -32,7 +32,7 @@ using Rmath: pwilcox, psignrank | |
|
||
import StatsBase.confint | ||
|
||
export testname, pvalue, confint | ||
export testname, pvalue, confint, tail, alpha | ||
@compat abstract type HypothesisTest end | ||
|
||
check_same_length(x::AbstractVector, y::AbstractVector) = if length(x) != length(y) | ||
|
@@ -72,32 +72,38 @@ 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 % | ||
format_detail(label::String, value::Any, len::Int) = # len is max length of label | ||
" " * label * " "^max(len - length(label), 0) * string(value) | ||
|
||
# population details | ||
has_ci = applicable(StatsBase.confint, test) | ||
has_ci = applicable(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, format_detail("parameter of interest:", param_name, 32)) | ||
println(io, format_detail("value under h_0:", param_under_h0, 32)) | ||
println(io, format_detail("point estimate:", param_estimate, 32)) | ||
if has_ci | ||
println(io, " 95% confidence interval: $(StatsBase.confint(test))") | ||
println(io, format_detail(conf_string*"% confidence interval:", confint(test), 32)) | ||
end | ||
println(io) | ||
|
||
# test summary | ||
p = pvalue(test) | ||
outcome = if p > 0.05 "fail to reject" else "reject" end | ||
tail = default_tail(test) | ||
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") | ||
testtail = tail(test) | ||
p = pvalue(test) # obeys value of tail(test) if applicable | ||
outcome = p > alpha(test) ? "fail to reject" : "reject" | ||
if testtail == :both | ||
plabel ="two-sided p-value:" | ||
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. Missing space. |
||
elseif testtail == :left || testtail == :right | ||
plabel = "one-sided p-value ($(string(testtail)) tail):" | ||
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.
|
||
else | ||
println(io, " p-value: $p") | ||
plabel = "p-value:" | ||
end | ||
println(io, "Test summary:") | ||
println(io, format_detail("outcome with "*conf_string*"% confidence:", outcome*" h_0", 36)) | ||
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. Add spaces around |
||
println(io, format_detail(plabel, p, 36)) | ||
println(io) | ||
|
||
# further details | ||
|
@@ -108,8 +114,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.
alpha
andtail
should be exported if they are shown here.