Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
pdeffebach committed Jun 8, 2020
1 parent d3993fa commit af6965d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
7 changes: 7 additions & 0 deletions src/HypothesisTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ If `tail` is `:both` (default), then the p-value for the two-sided test is retur
"""
function pvalue end

"""
stderror(test::HypothesisTest)
Compute the standard error for the point estimate of interest for a test.
"""
function stderror end

# Basic function for finding a p-value given a distribution and tail
pvalue(dist::ContinuousUnivariateDistribution, x::Number; tail=:both) =
if tail == :both
Expand Down
2 changes: 1 addition & 1 deletion src/binomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ probability is not equal to `p`.
Computed confidence intervals ([`confint`](@ref)) by default are Clopper-Pearson intervals.
Implements: [`pvalue`](@ref), [`confint(::BinomialTest)`](@ref)
Implements: [`pvalue`](@ref), [`confint(::BinomialTest)`](@ref), [`stderror`](@ref)
"""
BinomialTest(x::AbstractVector{Bool}, p=0.5) =
BinomialTest(sum(x), length(x), p)
Expand Down
2 changes: 1 addition & 1 deletion src/correlation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export CorrelationTest
Perform a t-test for the hypothesis that ``\\text{Cor}(x,y|Z=z) = 0``, i.e. the partial
correlation of vectors `x` and `y` given the matrix `Z` is zero.
Implements `pvalue` for the t-test.
Implements `pvalue` for the t-test, as well as `stderror`.
Implements `confint` using an approximate confidence interval based on Fisher's
``z``-transform.
Expand Down
10 changes: 5 additions & 5 deletions src/t.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Perform a one sample t-test of the null hypothesis that `n` values with mean `xb
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`](@ref), [`confint`](@ref)
Implements: [`pvalue`](@ref), [`confint`](@ref), [`stderror`](@ref)
"""
function OneSampleTTest(xbar::Real, stddev::Real, n::Int, μ0::Real=0)
stderr = stddev/sqrt(n)
Expand All @@ -95,7 +95,7 @@ Perform a one sample t-test of the null hypothesis that the data in vector `v` c
a distribution with mean `μ0` against the alternative hypothesis that the distribution
does not have mean `μ0`.
Implements: [`pvalue`](@ref), [`confint`](@ref)
Implements: [`pvalue`](@ref), [`confint`](@ref), [`stderror`](@ref)
"""
OneSampleTTest(v::AbstractVector{T}, μ0::Real=0) where {T<:Real} = OneSampleTTest(mean(v), std(v), length(v), μ0)

Expand All @@ -106,7 +106,7 @@ Perform a paired sample t-test of the null hypothesis that the differences betwe
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`](@ref), [`confint`](@ref)
Implements: [`pvalue`](@ref), [`confint`](@ref), [`stderror`](@ref)
"""
function OneSampleTTest(x::AbstractVector{T}, y::AbstractVector{S}, μ0::Real=0) where {T<:Real, S<:Real}
check_same_length(x, y)
Expand Down Expand Up @@ -144,7 +144,7 @@ Perform a two-sample t-test of the null hypothesis that `x` and `y` come from di
with equal means and variances against the alternative hypothesis that the distributions
have different means but equal variances.
Implements: [`pvalue`](@ref), [`confint`](@ref)
Implements: [`pvalue`](@ref), [`confint`](@ref), [`stderror`](@ref)
"""
function EqualVarianceTTest(x::AbstractVector{T}, y::AbstractVector{S}, μ0::Real=0) where {T<:Real,S<:Real}
nx, ny = length(x), length(y)
Expand Down Expand Up @@ -186,7 +186,7 @@ equation:
\\frac{(k_i s_i^2)^2}{ν_i}}
```
Implements: [`pvalue`](@ref), [`confint`](@ref)
Implements: [`pvalue`](@ref), [`confint`](@ref), [`stderror`](@ref)
"""
function UnequalVarianceTTest(x::AbstractVector{T}, y::AbstractVector{S}, μ0::Real=0) where {T<:Real,S<:Real}
nx, ny = length(x), length(y)
Expand Down
10 changes: 5 additions & 5 deletions src/z.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Perform a one sample z-test of the null hypothesis that `n` values with mean `xb
population standard deviation `stddev` come from a distribution with mean `μ0` against the
alternative hypothesis that the distribution does not have mean `μ0`.
Implements: [`pvalue`](@ref), [`confint`](@ref)
Implements: [`pvalue`](@ref), [`confint`](@ref), [`stderror`](@ref)
"""
function OneSampleZTest(xbar::Real, stddev::Real, n::Int, μ0::Real=0)
stderr = stddev/sqrt(n)
Expand All @@ -92,7 +92,7 @@ Perform a one sample z-test of the null hypothesis that the data in vector `v` c
a distribution with mean `μ0` against the alternative hypothesis that the distribution
does not have mean `μ0`.
Implements: [`pvalue`](@ref), [`confint`](@ref)
Implements: [`pvalue`](@ref), [`confint`](@ref), [`stderror`](@ref)
"""
OneSampleZTest(v::AbstractVector{T}, μ0::Real=0) where {T<:Real} = OneSampleZTest(mean(v), std(v), length(v), μ0)

Expand All @@ -103,7 +103,7 @@ Perform a paired sample z-test of the null hypothesis that the differences betwe
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`](@ref), [`confint`](@ref)
Implements: [`pvalue`](@ref), [`confint`](@ref), [`stderror`](@ref)
"""
function OneSampleZTest(x::AbstractVector{T}, y::AbstractVector{S}, μ0::Real=0) where {T<:Real, S<:Real}
check_same_length(x, y)
Expand Down Expand Up @@ -139,7 +139,7 @@ Perform a two-sample z-test of the null hypothesis that `x` and `y` come from di
with equal means and variances against the alternative hypothesis that the distributions
have different means but equal variances.
Implements: [`pvalue`](@ref), [`confint`](@ref)
Implements: [`pvalue`](@ref), [`confint`](@ref), [`stderror`](@ref)
"""
function EqualVarianceZTest(x::AbstractVector{T}, y::AbstractVector{S}, μ0::Real=0) where {T<:Real,S<:Real}
nx, ny = length(x), length(y)
Expand Down Expand Up @@ -171,7 +171,7 @@ Perform an unequal variance two-sample z-test of the null hypothesis that `x` an
from distributions with equal means against the alternative hypothesis that the
distributions have different means.
Implements: [`pvalue`](@ref), [`confint`](@ref)
Implements: [`pvalue`](@ref), [`confint`](@ref), [`stderror`](@ref)
"""
function UnequalVarianceZTest(x::AbstractVector{T}, y::AbstractVector{S}, μ0::Real=0) where {T<:Real,S<:Real}
nx, ny = length(x), length(y)
Expand Down

0 comments on commit af6965d

Please sign in to comment.