|
1 | | -defmodule Exstatic.Distribution.TTest do |
| 1 | +defmodule Exstatic.Distribution.StandardizedTTest do |
2 | 2 | use ExUnit.Case, async: true |
3 | 3 |
|
4 | | - alias Exstatic.Distribution.T |
| 4 | + alias Exstatic.Distribution.StandardizedT |
5 | 5 |
|
6 | | - doctest Exstatic.Distribution.T |
| 6 | + doctest Exstatic.Distribution.StandardizedT |
7 | 7 |
|
8 | | - describe "new/3" do |
9 | | - test "creates a valid t-distribution" do |
10 | | - assert {:ok, _t} = T.new(0.0, 1.0, 5.0) |
11 | | - end |
12 | | - |
13 | | - test "returns error for invalid std_dev" do |
14 | | - assert {:error, :invalid_std_dev} = T.new(0.0, 0.0, 5.0) |
| 8 | + describe "new/1" do |
| 9 | + test "creates a valid standardized t-distribution" do |
| 10 | + assert {:ok, _t} = StandardizedT.new(5.0) |
15 | 11 | end |
16 | 12 |
|
17 | 13 | test "returns error for invalid degrees of freedom" do |
18 | | - assert {:error, :invalid_df} = T.new(0.0, 1.0, 0.0) |
19 | | - assert {:error, :invalid_df} = T.new(0.0, 1.0, -5.0) |
| 14 | + assert {:error, :invalid_df} = StandardizedT.new(1.0) |
| 15 | + assert {:error, :invalid_df} = StandardizedT.new(0.0) |
| 16 | + assert {:error, :invalid_df} = StandardizedT.new(-5.0) |
20 | 17 | end |
21 | 18 | end |
22 | 19 |
|
23 | 20 | describe "mean/1" do |
24 | | - test "returns the mean when df > 1" do |
25 | | - {:ok, t} = T.new(5.0, 1.0, 3.0) |
26 | | - assert T.mean(t) == 5.0 |
27 | | - end |
| 21 | + test "returns 0.0 for any valid standardized t-distribution" do |
| 22 | + {:ok, t} = StandardizedT.new(3.0) |
| 23 | + assert StandardizedT.mean(t) == 0.0 |
28 | 24 |
|
29 | | - test "returns :undefined when df = 1" do |
30 | | - {:ok, t} = T.new(5.0, 1.0, 1.0) |
31 | | - assert T.mean(t) == :undefined |
32 | | - end |
33 | | - |
34 | | - test "returns :undefined when df < 1" do |
35 | | - {:ok, t} = T.new(5.0, 1.0, 0.5) |
36 | | - assert T.mean(t) == :undefined |
| 25 | + {:ok, t} = StandardizedT.new(10.0) |
| 26 | + assert StandardizedT.mean(t) == 0.0 |
37 | 27 | end |
38 | 28 | end |
39 | 29 |
|
40 | 30 | describe "variance/1" do |
41 | 31 | test "returns a finite variance when df > 2" do |
42 | | - {:ok, t} = T.new(0.0, 2.0, 5.0) |
43 | | - expected_variance = 5.0 / (5.0 - 2.0) * (2.0 * 2.0) |
44 | | - assert TestHelper.assert_in_delta(T.variance(t), expected_variance) |
| 32 | + {:ok, t} = StandardizedT.new(5.0) |
| 33 | + expected_variance = 5.0 / (5.0 - 2.0) |
| 34 | + assert TestHelper.assert_in_delta(StandardizedT.variance(t), expected_variance) |
45 | 35 | end |
46 | 36 |
|
47 | 37 | test "returns :infinity when 1 < df ≤ 2" do |
48 | | - {:ok, t} = T.new(0.0, 1.0, 1.5) |
49 | | - assert T.variance(t) == :infinity |
50 | | - end |
51 | | - |
52 | | - test "returns :undefined when df ≤ 1" do |
53 | | - {:ok, t} = T.new(0.0, 1.0, 1.0) |
54 | | - assert T.variance(t) == :undefined |
| 38 | + {:ok, t} = StandardizedT.new(1.5) |
| 39 | + assert StandardizedT.variance(t) == :infinity |
55 | 40 | end |
56 | 41 | end |
57 | 42 |
|
58 | 43 | describe "pdf/2" do |
59 | 44 | test "computes valid PDF values" do |
60 | | - {:ok, t} = T.new(0.0, 1.0, 5.0) |
61 | | - assert TestHelper.assert_in_delta(T.pdf(t, 0.0), 0.37960669, 1.0e-6) |
62 | | - assert TestHelper.assert_in_delta(T.pdf(t, 1.0), 0.219679797, 1.0e-6) |
| 45 | + {:ok, t} = StandardizedT.new(5.0) |
| 46 | + assert TestHelper.assert_in_delta(StandardizedT.pdf(t, 0.0), 0.37960669, 1.0e-6) |
| 47 | + assert TestHelper.assert_in_delta(StandardizedT.pdf(t, 1.0), 0.219679797, 1.0e-6) |
63 | 48 | end |
64 | 49 | end |
65 | 50 |
|
66 | 51 | describe "cdf/2" do |
67 | 52 | test "computes valid CDF values" do |
68 | | - {:ok, t} = T.new(0.0, 1.0, 5.0) |
| 53 | + {:ok, t} = StandardizedT.new(5.0) |
| 54 | + |
| 55 | + assert TestHelper.assert_in_delta(StandardizedT.cdf(t, 0.0), 0.5, 1.0e-9) |
| 56 | + assert TestHelper.assert_in_delta(StandardizedT.cdf(t, -100.0), 0.0, 1.0e-9) |
| 57 | + assert TestHelper.assert_in_delta(StandardizedT.cdf(t, 100.0), 1.0, 1.0e-9) |
| 58 | + end |
| 59 | + end |
| 60 | + |
| 61 | + describe "sf/2" do |
| 62 | + test "computes valid SF values" do |
| 63 | + {:ok, t} = StandardizedT.new(5.0) |
69 | 64 |
|
70 | | - assert TestHelper.assert_in_delta(T.cdf(t, 0.0), 0.5, 1.0e-9) |
71 | | - assert TestHelper.assert_in_delta(T.cdf(t, -100.0), 0.0, 1.0e-9) |
72 | | - assert TestHelper.assert_in_delta(T.cdf(t, 100.0), 1.0, 1.0e-9) |
| 65 | + assert TestHelper.assert_in_delta(StandardizedT.sf(t, 0.0), 0.5, 1.0e-9) |
| 66 | + assert TestHelper.assert_in_delta(StandardizedT.sf(t, -100.0), 1.0, 1.0e-9) |
| 67 | + assert TestHelper.assert_in_delta(StandardizedT.sf(t, 100.0), 0.0, 1.0e-9) |
73 | 68 | end |
74 | 69 | end |
75 | 70 | end |
| 71 | + |
0 commit comments