Skip to content

Commit

Permalink
test: closes #80
Browse files Browse the repository at this point in the history
  • Loading branch information
aravindhebbali committed Nov 8, 2024
1 parent ec1ee27 commit 35be6d6
Show file tree
Hide file tree
Showing 32 changed files with 979 additions and 833 deletions.
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Depends:
License: MIT + file LICENSE
URL: https://rsquaredacademy.github.io/inferr/, https://github.com/rsquaredacademy/inferr
BugReports: https://github.com/rsquaredacademy/inferr/issues
Imports:
Imports:
data.table,
magrittr,
Rcpp,
Expand All @@ -22,10 +22,11 @@ Suggests:
covr,
knitr,
rmarkdown,
testthat,
testthat (>= 3.0.0),
xplorerr
Encoding: UTF-8
LazyData: true
VignetteBuilder: knitr
RoxygenNote: 7.1.1
RoxygenNote: 7.3.2
LinkingTo: Rcpp
Config/testthat/edition: 3
8 changes: 8 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html

library(testthat)
library(inferr)

Expand Down
28 changes: 28 additions & 0 deletions tests/testthat/_snaps/anova.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# output from one way anova is as expected

Code
ifr_oneway_anova(mtcars, mpg, cyl)
Output
ANOVA
--------------------------------------------------------------------
Sum of
Squares DF Mean Square F Sig.
--------------------------------------------------------------------
Between Groups 824.785 2 412.392 39.699 0
Within Groups 301.263 29 10.388
Total 1126.048 31
--------------------------------------------------------------------
Report
----------------------------------------
Category N Mean Std. Dev.
----------------------------------------
4 11 26.664 4.510
6 7 19.743 1.454
8 14 15.100 2.560
----------------------------------------
Number of obs = 32 R-squared = 0.7325
Root MSE = 3.2231 Adj R-squared = 0.714

44 changes: 44 additions & 0 deletions tests/testthat/_snaps/binom.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# output from ifr_binom_calc is as expected when k < exp_k

Code
ifr_binom_calc(32, 8)
Output
Binomial Test
--------------------------------------
Group N Obs. Prop Exp. Prop
--------------------------------------
0 24 0.75 0.500
1 8 0.25 0.500
--------------------------------------
Test Summary
------------------------------------------
Tail Prob p-value
------------------------------------------
Lower Pr(k <= 8) 0.0035
Upper Pr(k >= 8) 0.998949
------------------------------------------

# output from ifr_binom_calc is as expected when k > exp_k

Code
ifr_binom_calc(32, 20)
Output
Binomial Test
--------------------------------------
Group N Obs. Prop Exp. Prop
--------------------------------------
0 12 0.375 0.500
1 20 0.625 0.500
--------------------------------------
Test Summary
--------------------------------------------
Tail Prob p-value
--------------------------------------------
Lower Pr(k <= 20) 0.944908
Upper Pr(k >= 20) 0.107664
--------------------------------------------

34 changes: 34 additions & 0 deletions tests/testthat/_snaps/chisq.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# ouput from ifr_chisq_assoc_test is as expected

Code
ifr_chisq_assoc_test(hsb, female, schtyp)
Output
Chi Square Statistics
Statistics DF Value Prob
----------------------------------------------------
Chi-Square 1 0.0470 0.8284
Likelihood Ratio Chi-Square 1 0.0471 0.8282
Continuity Adj. Chi-Square 1 0.0005 0.9822
Mantel-Haenszel Chi-Square 1 0.0468 0.8287
Phi Coefficient 0.0153
Contingency Coefficient 0.0153
Cramer's V 0.0153
----------------------------------------------------

# ouput from ifr_chisq_assoc_test 2 is as expected

Code
ifr_chisq_assoc_test(hsb, female, ses)
Output
Chi Square Statistics
Statistics DF Value Prob
----------------------------------------------------
Chi-Square 2 4.5765 0.1014
Likelihood Ratio Chi-Square 2 4.6789 0.0964
Phi Coefficient 0.1513
Contingency Coefficient 0.1496
Cramer's V 0.1513
----------------------------------------------------

22 changes: 22 additions & 0 deletions tests/testthat/_snaps/chisqgof.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# output from ifr_chisq_gof_test is as expected

Code
ifr_chisq_gof_test(hsb, race, c(20, 20, 20, 140))
Output
Test Statistics
-----------------------
Chi-Square 5.0286
DF 3
Pr > Chi Sq 0.1697
Sample Size 200
Variable: race
-----------------------------------------------------------------
Category Observed Expected % Deviation Std. Residuals
-----------------------------------------------------------------
1 24 20 20.00 0.89
2 11 20 -45.00 -2.01
3 20 20 0.00 0.00
4 145 140 3.57 0.42
-----------------------------------------------------------------

13 changes: 13 additions & 0 deletions tests/testthat/_snaps/cochran.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# output from cochran test is as expected

Code
ifr_cochran_qtest(exam, exam1, exam2, exam3)
Output
Test Statistics
----------------------
N 15
Cochran's Q 4.75
df 2
p value 0.093
----------------------

153 changes: 153 additions & 0 deletions tests/testthat/_snaps/indttest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# output from independent sample t test is as expected when alternative is less

Code
ifr_ts_ind_ttest(hsb, female, write, alternative = "less")
Output
Group Statistics
-----------------------------------------------------------------------------
Group Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
-----------------------------------------------------------------------------
0 91 50.121 1.080 10.305 47.97539 52.26661
1 109 54.991 0.779 8.134 53.44689 56.53511
-----------------------------------------------------------------------------
combined 200 52.775 0.67 9.479 51.45379 54.09621
-----------------------------------------------------------------------------
diff 200 -4.87 1.304 9.231 -7.42623 -2.31377
-----------------------------------------------------------------------------
Independent Samples Test
------------------------
Ho: mean(0) - mean(1) = diff = 0
Ha: diff < 0
---------------------------------------------------------------------
Variable Method Variances DF t Value P < t
---------------------------------------------------------------------
write Pooled Equal 198 -3.7341 0.0001
write Satterthwaite Unequal 170 -3.6564 0.0002
---------------------------------------------------------------------
Test for Equality of Variances
---------------------------------------------------------------
Variable Method Num DF Den DF F Value P > F
---------------------------------------------------------------
write Folded F 90 108 1.605 0.0188
---------------------------------------------------------------

# output from independent sample t test is as expected when alternative is greater

Code
ifr_ts_ind_ttest(hsb, female, write, alternative = "greater")
Output
Group Statistics
-----------------------------------------------------------------------------
Group Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
-----------------------------------------------------------------------------
0 91 50.121 1.080 10.305 47.97539 52.26661
1 109 54.991 0.779 8.134 53.44689 56.53511
-----------------------------------------------------------------------------
combined 200 52.775 0.67 9.479 51.45379 54.09621
-----------------------------------------------------------------------------
diff 200 -4.87 1.304 9.231 -7.42623 -2.31377
-----------------------------------------------------------------------------
Independent Samples Test
------------------------
Ho: mean(0) - mean(1) = diff = 0
Ha: diff > 0
---------------------------------------------------------------------
Variable Method Variances DF t Value P > t
---------------------------------------------------------------------
write Pooled Equal 198 -3.7341 0.9999
write Satterthwaite Unequal 170 -3.6564 0.9998
---------------------------------------------------------------------
Test for Equality of Variances
---------------------------------------------------------------
Variable Method Num DF Den DF F Value P > F
---------------------------------------------------------------
write Folded F 90 108 1.605 0.0188
---------------------------------------------------------------

# output from independent sample t test is as expected when alternative is both

Code
ifr_ts_ind_ttest(hsb, female, write, alternative = "both")
Output
Group Statistics
-----------------------------------------------------------------------------
Group Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
-----------------------------------------------------------------------------
0 91 50.121 1.080 10.305 47.97539 52.26661
1 109 54.991 0.779 8.134 53.44689 56.53511
-----------------------------------------------------------------------------
combined 200 52.775 0.67 9.479 51.45379 54.09621
-----------------------------------------------------------------------------
diff 200 -4.87 1.304 9.231 -7.42623 -2.31377
-----------------------------------------------------------------------------
Independent Samples Test
------------------------
Ho: mean(0) - mean(1) = diff = 0
Ha: diff ~= 0
---------------------------------------------------------------------
Variable Method Variances DF t Value P > |t|
---------------------------------------------------------------------
write Pooled Equal 198 -3.7341 0.0002
write Satterthwaite Unequal 170 -3.6564 0.0003
---------------------------------------------------------------------
Test for Equality of Variances
---------------------------------------------------------------
Variable Method Num DF Den DF F Value P > F
---------------------------------------------------------------
write Folded F 90 108 1.605 0.0188
---------------------------------------------------------------

# output from independent sample t test is as expected when alternative is all

Code
ifr_ts_ind_ttest(hsb, female, write, alternative = "all")
Output
Group Statistics
-----------------------------------------------------------------------------
Group Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
-----------------------------------------------------------------------------
0 91 50.121 1.080 10.305 47.97539 52.26661
1 109 54.991 0.779 8.134 53.44689 56.53511
-----------------------------------------------------------------------------
combined 200 52.775 0.67 9.479 51.45379 54.09621
-----------------------------------------------------------------------------
diff 200 -4.87 1.304 9.231 -7.42623 -2.31377
-----------------------------------------------------------------------------
Independent Samples Test
------------------------
Ho: mean(0) - mean(1) = diff = 0
Ha: diff < 0 Ha: diff ~= 0 Ha: diff > 0
Pooled
------------------------------------------------------------------------
t = -3.7341 t = -3.7341 t = -3.7341
P < t = 0.0001 P > |t| = 0.0002 P > t = 0.9999
Satterthwaite
------------------------------------------------------------------------
t = -3.6564 t = -3.6564 t = -3.6564
P < t = 0.0002 P > |t| = 0.0003 P > t = 0.9998
Test for Equality of Variances
---------------------------------------------------------------
Variable Method Num DF Den DF F Value P > F
---------------------------------------------------------------
write Folded F 90 108 1.605 0.0188
---------------------------------------------------------------

25 changes: 25 additions & 0 deletions tests/testthat/_snaps/levene.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# output from levene test is as expected

Code
ifr_levene_test(hsb, read, group_var = race)
Output
Summary Statistics
Levels Frequency Mean Std. Dev
-----------------------------------------
1 24 46.67 10.24
2 11 51.91 7.66
3 20 46.8 7.12
4 145 53.92 10.28
-----------------------------------------
Total 200 52.23 10.25
-----------------------------------------
Test Statistics
-------------------------------------------------------------------------
Statistic Num DF Den DF F Pr > F
-------------------------------------------------------------------------
Brown and Forsythe 3 196 3.44 0.0179
Levene 3 196 3.4792 0.017
Brown and Forsythe (Trimmed Mean) 3 196 3.3936 0.019
-------------------------------------------------------------------------

Loading

0 comments on commit 35be6d6

Please sign in to comment.