Skip to content

Commit

Permalink
Added z-test impl & test brownplt#1732
Browse files Browse the repository at this point in the history
  • Loading branch information
ds26gte committed Apr 15, 2024
1 parent 2ba6dd1 commit 363038c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/arr/trove/statistics.arr
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ provide {
t-test-paired: t-test-paired,
t-test-pooled: t-test-pooled,
t-test-independent: t-test-independent,
z-test: z-test,
chi-square: chi-square
} end
provide-types *
Expand Down Expand Up @@ -268,6 +269,15 @@ fun t-test-independent(l1 :: List, l2 :: List) -> Number:
end
end

fun z-test(l1 :: List, l2 :: List, sd1 :: Number, sd2 :: Number) -> Number:
doc: "z-test"
n1 = l1.length()
n2 = l2.length()
x-bar-1 = mean(l1)
x-bar-2 = mean(l2)
(x-bar-1 - x-bar-2) / num-sqrt((num-expt(sd1, 2) / n1) + (num-expt(sd2, 2) / n2))
end

fun chi-square(obs :: List, exp :: List) -> Number:
doc: "chi-square"
math.sum(map2(lam(o, e): num-expt(o - e, 2) / e end, obs, exp))
Expand Down
2 changes: 2 additions & 0 deletions tests/pyret/tests/test-statistics.arr
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ check "numeric helpers":
t-test-independent([list: 1, 2, 3], [list: 4, 5, 6]) is%(within(0.01)) -3.674
t-test-independent([list: 1, 2, 3], [list: 4, 5, 6, 7]) is%(within(0.01)) -4.041

z-test([list: 1, 2, 3], [list: 4, 5, 6], 1.58, 2.58) is%(within(0.01)) -1.718

chi-square([list: 1, 2, 3, 4], [list: 1, 2, 3, 4]) is 0
chi-square([list: 1, 2, 3, 4], [list: 0.9, 1.8, 3.5, 4.7]) is%(within(0.01)) 0.209
end
Expand Down

0 comments on commit 363038c

Please sign in to comment.