Skip to content

Commit

Permalink
add: effsize_p1g()
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamWysokinski committed Feb 12, 2025
1 parent a2a7cdb commit b4f024e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
34 changes: 29 additions & 5 deletions src/statistics/effsize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export pooledstd
"""
effsize(x1, x2)
Calculate Cohen's d and Hedges g effect sizes.
Calculate effect sizes.
# Arguments
Expand All @@ -29,10 +29,34 @@ function effsize(x1::AbstractVector, x2::AbstractVector)::@NamedTuple{d::Float64

end

"""
effsize_p1g(p)
Calculate Cohen's h effect size for one proportion.
# Arguments
- `p::Float64`: proportion
# Returns
- `h::Float64`
"""
function effsize_p2g(p1::Float64, p2::Float64)::Float64

@assert p <= 1.0 "p must be ≤ 1.0."
@assert p >= 0.0 "p must be ≥ 1.0."

h = 2 * asin(sqrt(p))

return h

end

"""
effsize_p2g(p1, p2)
Calculate effect size for two proportions `p1` and `p2`.
Calculate Cohen's h effect size for two proportions `p1` and `p2`.
# Arguments
Expand All @@ -41,15 +65,15 @@ Calculate effect size for two proportions `p1` and `p2`.
# Returns
- `e::Float64`
- `h::Float64`
"""
function effsize_p2g(p1::Float64, p2::Float64)::Float64

@assert p1 + p2 == 1.0 "Proportions must add to 1.0."

e = 2 * asin(sqrt(p1)) - 2 * asin(sqrt(p2))
h = 2 * asin(sqrt(p1)) - 2 * asin(sqrt(p2))

return e
return h

end

Expand Down
3 changes: 3 additions & 0 deletions test/statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ _, _, _, _, df, _ = cor_test(ones(5), zeros(5))
@info "Test: meanw()"
@test meanw(ones(5), [1,2,3,4,5]) == 1.0

@info "Test: effsize_p1g()"
@test effsize_p1g(0.5) == 1.5707963267948968

@info "Test: effsize_p2g()"
@test effsize_p2g(0.5, 0.5) == 0.0

Expand Down

0 comments on commit b4f024e

Please sign in to comment.