Skip to content

Commit

Permalink
allow manual df specification re JuliaStats#181
Browse files Browse the repository at this point in the history
  • Loading branch information
birm authored Mar 14, 2020
1 parent a891917 commit 7b490c6
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/t.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,17 @@ function show_params(io::IO, x::OneSampleTTest, ident="")
end

"""
OneSampleTTest(xbar::Real, stddev::Real, n::Int, μ0::Real = 0)
OneSampleTTest(xbar::Real, stddev::Real, n::Int, μ0::Real = 0, df::Int = n-1)
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`](@ref), [`confint`](@ref)
"""
function OneSampleTTest(xbar::Real, stddev::Real, n::Int, μ0::Real=0)
function OneSampleTTest(xbar::Real, stddev::Real, n::Int, μ0::Real=0, df::Int=n-1)
stderr = stddev/sqrt(n)
t = (xbar-μ0)/stderr
df = n-1
OneSampleTTest(n, xbar, df, stderr, t, μ0)
end

Expand Down Expand Up @@ -144,13 +143,12 @@ have different means but equal variances.
Implements: [`pvalue`](@ref), [`confint`](@ref)
"""
function EqualVarianceTTest(x::AbstractVector{T}, y::AbstractVector{S}, μ0::Real=0) where {T<:Real,S<:Real}
function EqualVarianceTTest(x::AbstractVector{T}, y::AbstractVector{S}, μ0::Real=0, df::Int=length(x)+length(y)-2) where {T<:Real,S<:Real}
nx, ny = length(x), length(y)
xbar = mean(x) - mean(y)
stddev = sqrt(((nx - 1) * var(x) + (ny - 1) * var(y)) / (nx + ny - 2))
stderr = stddev * sqrt(1/nx + 1/ny)
t = (xbar - μ0) / stderr
df = nx + ny - 2
EqualVarianceTTest(nx, ny, xbar, df, stderr, t, μ0)
end

Expand Down

0 comments on commit 7b490c6

Please sign in to comment.