Skip to content

Commit

Permalink
test-statistics.arr: brownplt#1732
Browse files Browse the repository at this point in the history
- check mulreg test on 1 var matches our linreg on same var
- add mulreg test for 2 vars
statistics.arr: add pointers to docs for formulas used
  • Loading branch information
ds26gte committed May 17, 2024
1 parent 7501262 commit d341e33
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/arr/trove/statistics.arr
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ fun linear-regression(x :: List<Number>, y :: List<Number>) -> (Number -> Number
end
end

# please see: https://online.stat.psu.edu/stat462/

fun multiple-regression(x_s_s :: List<Any>, y_s :: List<Number>) -> (Any -> Number):
doc: "multiple-regression"
MR.multiple-regression(x_s_s, y_s)
Expand Down Expand Up @@ -246,6 +248,10 @@ fun t-test-paired(l1 :: List, l2 :: List) -> Number:
end
end

# please see:
# https://en.wikipedia.org/wiki/Student's_t-test
# https://www.investopedia.com/terms/t/t-test.asp

fun t-test-pooled(l1 :: List, l2 :: List) -> Number:
doc: "t-test-pooled"
n1 = l1.length()
Expand Down
19 changes: 14 additions & 5 deletions tests/pyret/tests/test-statistics.arr
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,20 @@ check "linear regression":
end

check "multiple regression":
# multiple-regression function for single independent variable
x-s-s = [list: {4}, {4.5}, {5}, {5.5}, {6}, {6.5}, {7}]
y-s = [list: 33, 42, 45, 51, 53, 61, 62]
pf = multiple-regression(x-s-s, y-s)
pf({8}) is%(within-abs(0.001)) 73.3214
pf1 = multiple-regression(x-s-s, y-s)
pf1({8}) is-roughly 73.3214
#
# check it matches linear-regression function on the same single variable
x-s = [list: 4, 4.5, 5, 5.5, 6, 6.5, 7]
pf2 = linear-regression(x-s, y-s)
pf2(8) is-roughly 73.3214
#
# multiple-regression with two independent variables
x-s-s-i = [list: {4; 3}, {4.5; 2}, {5; 1.2}, {5.5; 4.5}, {6; 3.3}, {6.5; 10}, {7; 0}]
y-s-i = [list: 33, 42, 45, 51, 53, 61, 62]
pf-i = multiple-regression(x-s-s-i, y-s-i)
pf-i({8; 9}) is-roughly 74.52888
end



0 comments on commit d341e33

Please sign in to comment.