Skip to content

Commit 35be6d6

Browse files
test: closes #80
1 parent ec1ee27 commit 35be6d6

32 files changed

+979
-833
lines changed

DESCRIPTION

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Depends:
1212
License: MIT + file LICENSE
1313
URL: https://rsquaredacademy.github.io/inferr/, https://github.com/rsquaredacademy/inferr
1414
BugReports: https://github.com/rsquaredacademy/inferr/issues
15-
Imports:
15+
Imports:
1616
data.table,
1717
magrittr,
1818
Rcpp,
@@ -22,10 +22,11 @@ Suggests:
2222
covr,
2323
knitr,
2424
rmarkdown,
25-
testthat,
25+
testthat (>= 3.0.0),
2626
xplorerr
2727
Encoding: UTF-8
2828
LazyData: true
2929
VignetteBuilder: knitr
30-
RoxygenNote: 7.1.1
30+
RoxygenNote: 7.3.2
3131
LinkingTo: Rcpp
32+
Config/testthat/edition: 3

tests/testthat.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# This file is part of the standard setup for testthat.
2+
# It is recommended that you do not modify it.
3+
#
4+
# Where should you do additional test configuration?
5+
# Learn more about the roles of various files in:
6+
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
7+
# * https://testthat.r-lib.org/articles/special-files.html
8+
19
library(testthat)
210
library(inferr)
311

tests/testthat/_snaps/anova.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# output from one way anova is as expected
2+
3+
Code
4+
ifr_oneway_anova(mtcars, mpg, cyl)
5+
Output
6+
ANOVA
7+
--------------------------------------------------------------------
8+
Sum of
9+
Squares DF Mean Square F Sig.
10+
--------------------------------------------------------------------
11+
Between Groups 824.785 2 412.392 39.699 0
12+
Within Groups 301.263 29 10.388
13+
Total 1126.048 31
14+
--------------------------------------------------------------------
15+
16+
Report
17+
----------------------------------------
18+
Category N Mean Std. Dev.
19+
----------------------------------------
20+
4 11 26.664 4.510
21+
6 7 19.743 1.454
22+
8 14 15.100 2.560
23+
----------------------------------------
24+
25+
Number of obs = 32 R-squared = 0.7325
26+
Root MSE = 3.2231 Adj R-squared = 0.714
27+
28+

tests/testthat/_snaps/binom.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# output from ifr_binom_calc is as expected when k < exp_k
2+
3+
Code
4+
ifr_binom_calc(32, 8)
5+
Output
6+
Binomial Test
7+
--------------------------------------
8+
Group N Obs. Prop Exp. Prop
9+
--------------------------------------
10+
0 24 0.75 0.500
11+
1 8 0.25 0.500
12+
--------------------------------------
13+
14+
15+
Test Summary
16+
------------------------------------------
17+
Tail Prob p-value
18+
------------------------------------------
19+
Lower Pr(k <= 8) 0.0035
20+
Upper Pr(k >= 8) 0.998949
21+
------------------------------------------
22+
23+
# output from ifr_binom_calc is as expected when k > exp_k
24+
25+
Code
26+
ifr_binom_calc(32, 20)
27+
Output
28+
Binomial Test
29+
--------------------------------------
30+
Group N Obs. Prop Exp. Prop
31+
--------------------------------------
32+
0 12 0.375 0.500
33+
1 20 0.625 0.500
34+
--------------------------------------
35+
36+
37+
Test Summary
38+
--------------------------------------------
39+
Tail Prob p-value
40+
--------------------------------------------
41+
Lower Pr(k <= 20) 0.944908
42+
Upper Pr(k >= 20) 0.107664
43+
--------------------------------------------
44+

tests/testthat/_snaps/chisq.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# ouput from ifr_chisq_assoc_test is as expected
2+
3+
Code
4+
ifr_chisq_assoc_test(hsb, female, schtyp)
5+
Output
6+
Chi Square Statistics
7+
8+
Statistics DF Value Prob
9+
----------------------------------------------------
10+
Chi-Square 1 0.0470 0.8284
11+
Likelihood Ratio Chi-Square 1 0.0471 0.8282
12+
Continuity Adj. Chi-Square 1 0.0005 0.9822
13+
Mantel-Haenszel Chi-Square 1 0.0468 0.8287
14+
Phi Coefficient 0.0153
15+
Contingency Coefficient 0.0153
16+
Cramer's V 0.0153
17+
----------------------------------------------------
18+
19+
# ouput from ifr_chisq_assoc_test 2 is as expected
20+
21+
Code
22+
ifr_chisq_assoc_test(hsb, female, ses)
23+
Output
24+
Chi Square Statistics
25+
26+
Statistics DF Value Prob
27+
----------------------------------------------------
28+
Chi-Square 2 4.5765 0.1014
29+
Likelihood Ratio Chi-Square 2 4.6789 0.0964
30+
Phi Coefficient 0.1513
31+
Contingency Coefficient 0.1496
32+
Cramer's V 0.1513
33+
----------------------------------------------------
34+

tests/testthat/_snaps/chisqgof.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# output from ifr_chisq_gof_test is as expected
2+
3+
Code
4+
ifr_chisq_gof_test(hsb, race, c(20, 20, 20, 140))
5+
Output
6+
Test Statistics
7+
-----------------------
8+
Chi-Square 5.0286
9+
DF 3
10+
Pr > Chi Sq 0.1697
11+
Sample Size 200
12+
13+
Variable: race
14+
-----------------------------------------------------------------
15+
Category Observed Expected % Deviation Std. Residuals
16+
-----------------------------------------------------------------
17+
1 24 20 20.00 0.89
18+
2 11 20 -45.00 -2.01
19+
3 20 20 0.00 0.00
20+
4 145 140 3.57 0.42
21+
-----------------------------------------------------------------
22+

tests/testthat/_snaps/cochran.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# output from cochran test is as expected
2+
3+
Code
4+
ifr_cochran_qtest(exam, exam1, exam2, exam3)
5+
Output
6+
Test Statistics
7+
----------------------
8+
N 15
9+
Cochran's Q 4.75
10+
df 2
11+
p value 0.093
12+
----------------------
13+

tests/testthat/_snaps/indttest.md

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# output from independent sample t test is as expected when alternative is less
2+
3+
Code
4+
ifr_ts_ind_ttest(hsb, female, write, alternative = "less")
5+
Output
6+
Group Statistics
7+
-----------------------------------------------------------------------------
8+
Group Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
9+
-----------------------------------------------------------------------------
10+
0 91 50.121 1.080 10.305 47.97539 52.26661
11+
1 109 54.991 0.779 8.134 53.44689 56.53511
12+
-----------------------------------------------------------------------------
13+
combined 200 52.775 0.67 9.479 51.45379 54.09621
14+
-----------------------------------------------------------------------------
15+
diff 200 -4.87 1.304 9.231 -7.42623 -2.31377
16+
-----------------------------------------------------------------------------
17+
18+
Independent Samples Test
19+
------------------------
20+
21+
Ho: mean(0) - mean(1) = diff = 0
22+
Ha: diff < 0
23+
24+
---------------------------------------------------------------------
25+
Variable Method Variances DF t Value P < t
26+
---------------------------------------------------------------------
27+
write Pooled Equal 198 -3.7341 0.0001
28+
write Satterthwaite Unequal 170 -3.6564 0.0002
29+
---------------------------------------------------------------------
30+
31+
Test for Equality of Variances
32+
---------------------------------------------------------------
33+
Variable Method Num DF Den DF F Value P > F
34+
---------------------------------------------------------------
35+
write Folded F 90 108 1.605 0.0188
36+
---------------------------------------------------------------
37+
38+
# output from independent sample t test is as expected when alternative is greater
39+
40+
Code
41+
ifr_ts_ind_ttest(hsb, female, write, alternative = "greater")
42+
Output
43+
Group Statistics
44+
-----------------------------------------------------------------------------
45+
Group Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
46+
-----------------------------------------------------------------------------
47+
0 91 50.121 1.080 10.305 47.97539 52.26661
48+
1 109 54.991 0.779 8.134 53.44689 56.53511
49+
-----------------------------------------------------------------------------
50+
combined 200 52.775 0.67 9.479 51.45379 54.09621
51+
-----------------------------------------------------------------------------
52+
diff 200 -4.87 1.304 9.231 -7.42623 -2.31377
53+
-----------------------------------------------------------------------------
54+
55+
Independent Samples Test
56+
------------------------
57+
58+
Ho: mean(0) - mean(1) = diff = 0
59+
Ha: diff > 0
60+
61+
---------------------------------------------------------------------
62+
Variable Method Variances DF t Value P > t
63+
---------------------------------------------------------------------
64+
write Pooled Equal 198 -3.7341 0.9999
65+
write Satterthwaite Unequal 170 -3.6564 0.9998
66+
---------------------------------------------------------------------
67+
68+
Test for Equality of Variances
69+
---------------------------------------------------------------
70+
Variable Method Num DF Den DF F Value P > F
71+
---------------------------------------------------------------
72+
write Folded F 90 108 1.605 0.0188
73+
---------------------------------------------------------------
74+
75+
# output from independent sample t test is as expected when alternative is both
76+
77+
Code
78+
ifr_ts_ind_ttest(hsb, female, write, alternative = "both")
79+
Output
80+
Group Statistics
81+
-----------------------------------------------------------------------------
82+
Group Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
83+
-----------------------------------------------------------------------------
84+
0 91 50.121 1.080 10.305 47.97539 52.26661
85+
1 109 54.991 0.779 8.134 53.44689 56.53511
86+
-----------------------------------------------------------------------------
87+
combined 200 52.775 0.67 9.479 51.45379 54.09621
88+
-----------------------------------------------------------------------------
89+
diff 200 -4.87 1.304 9.231 -7.42623 -2.31377
90+
-----------------------------------------------------------------------------
91+
92+
Independent Samples Test
93+
------------------------
94+
95+
Ho: mean(0) - mean(1) = diff = 0
96+
Ha: diff ~= 0
97+
98+
---------------------------------------------------------------------
99+
Variable Method Variances DF t Value P > |t|
100+
---------------------------------------------------------------------
101+
write Pooled Equal 198 -3.7341 0.0002
102+
write Satterthwaite Unequal 170 -3.6564 0.0003
103+
---------------------------------------------------------------------
104+
105+
Test for Equality of Variances
106+
---------------------------------------------------------------
107+
Variable Method Num DF Den DF F Value P > F
108+
---------------------------------------------------------------
109+
write Folded F 90 108 1.605 0.0188
110+
---------------------------------------------------------------
111+
112+
# output from independent sample t test is as expected when alternative is all
113+
114+
Code
115+
ifr_ts_ind_ttest(hsb, female, write, alternative = "all")
116+
Output
117+
Group Statistics
118+
-----------------------------------------------------------------------------
119+
Group Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
120+
-----------------------------------------------------------------------------
121+
0 91 50.121 1.080 10.305 47.97539 52.26661
122+
1 109 54.991 0.779 8.134 53.44689 56.53511
123+
-----------------------------------------------------------------------------
124+
combined 200 52.775 0.67 9.479 51.45379 54.09621
125+
-----------------------------------------------------------------------------
126+
diff 200 -4.87 1.304 9.231 -7.42623 -2.31377
127+
-----------------------------------------------------------------------------
128+
129+
Independent Samples Test
130+
------------------------
131+
132+
Ho: mean(0) - mean(1) = diff = 0
133+
134+
Ha: diff < 0 Ha: diff ~= 0 Ha: diff > 0
135+
136+
Pooled
137+
------------------------------------------------------------------------
138+
t = -3.7341 t = -3.7341 t = -3.7341
139+
P < t = 0.0001 P > |t| = 0.0002 P > t = 0.9999
140+
141+
Satterthwaite
142+
------------------------------------------------------------------------
143+
t = -3.6564 t = -3.6564 t = -3.6564
144+
P < t = 0.0002 P > |t| = 0.0003 P > t = 0.9998
145+
146+
147+
Test for Equality of Variances
148+
---------------------------------------------------------------
149+
Variable Method Num DF Den DF F Value P > F
150+
---------------------------------------------------------------
151+
write Folded F 90 108 1.605 0.0188
152+
---------------------------------------------------------------
153+

tests/testthat/_snaps/levene.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# output from levene test is as expected
2+
3+
Code
4+
ifr_levene_test(hsb, read, group_var = race)
5+
Output
6+
Summary Statistics
7+
Levels Frequency Mean Std. Dev
8+
-----------------------------------------
9+
1 24 46.67 10.24
10+
2 11 51.91 7.66
11+
3 20 46.8 7.12
12+
4 145 53.92 10.28
13+
-----------------------------------------
14+
Total 200 52.23 10.25
15+
-----------------------------------------
16+
17+
Test Statistics
18+
-------------------------------------------------------------------------
19+
Statistic Num DF Den DF F Pr > F
20+
-------------------------------------------------------------------------
21+
Brown and Forsythe 3 196 3.44 0.0179
22+
Levene 3 196 3.4792 0.017
23+
Brown and Forsythe (Trimmed Mean) 3 196 3.3936 0.019
24+
-------------------------------------------------------------------------
25+

0 commit comments

Comments
 (0)