11context(" phenotypes" )
22
3- test_that(" asCategorical_converts_correctly" ,{
3+ test_that(" asCategorical_converts_correctly" , {
44 cont = matrix (data = 0 , nrow = 7 , ncol = 3 )
55 cont [, 1 ] = c(- 3 , - 2 , - 1 , 0 , 1 , 2 , 3 )
66 cont [, 2 ] = c(- 3 , - 2 , - 1 , 0 , 1 , 2 , 3 )
77 cont [, 3 ] = c(- 3 , - 2 , - 1 , 0 , 1 , 2 , 3 )
88
9- expect_equal(asCategorical(x = cont [, 1 ]),
10- matrix (c(1 , 1 , 1 , 2 , 2 , 2 , 2 )))
11- expect_equal(asCategorical(x = cont [, 1 ], threshold = c(- 1 , 0 , 1 )),
12- matrix (c(NA , NA , 1 , 2 , 2 , NA , NA )))
13- expect_equal(asCategorical(x = cont [, 1 ], threshold = c(- Inf , - 1 , 0 , 1 , Inf )),
14- matrix (c(1 , 1 , 2 , 3 , 4 , 4 , 4 )))
9+ expect_equal(asCategorical(x = cont [, 1 ]), matrix (c(1 , 1 , 1 , 2 , 2 , 2 , 2 )))
10+ expect_equal(
11+ asCategorical(x = cont [, 1 ], threshold = c(- 1 , 0 , 1 )),
12+ matrix (c(NA , NA , 1 , 2 , 2 , NA , NA ))
13+ )
14+ expect_equal(
15+ asCategorical(x = cont [, 1 ], threshold = c(- Inf , - 1 , 0 , 1 , Inf )),
16+ matrix (c(1 , 1 , 2 , 3 , 4 , 4 , 4 ))
17+ )
1518
1619 expect_warning(asCategorical(x = cont [, 1 ], p = 0.5 ))
17- expect_equal(suppressWarnings(asCategorical(x = cont [, 1 ], p = 0.5 )),
18- asCategorical(x = cont [, 1 ], p = c(0.5 , 0.5 )))
20+ expect_equal(
21+ suppressWarnings(asCategorical(x = cont [, 1 ], p = 0.5 )),
22+ asCategorical(x = cont [, 1 ], p = c(0.5 , 0.5 ))
23+ )
1924
2025 trtMean = apply(X = cont , MARGIN = 2 , FUN = mean )
2126 trtVar = apply(X = cont , MARGIN = 2 , FUN = var )
22- expect_equal(asCategorical(x = cont [, 1 ], p = c(0.5 , 0.5 ), var = trtVar [1 ]),
23- matrix (c(1 , 1 , 1 , 2 , 2 , 2 , 2 )))
24- expect_equal(asCategorical(x = cont [, 1 ], p = c(2 / 7 , 1 / 7 , 1 / 7 , 3 / 7 ), var = trtVar [1 ]),
25- matrix (c(1 , 1 , 2 , 3 , 4 , 4 , 4 )))
27+ expect_equal(
28+ asCategorical(x = cont [, 1 ], p = c(0.5 , 0.5 ), var = trtVar [1 ]),
29+ matrix (c(1 , 1 , 1 , 2 , 2 , 2 , 2 ))
30+ )
31+ expect_equal(
32+ asCategorical(
33+ x = cont [, 1 ],
34+ p = c(2 / 7 , 1 / 7 , 1 / 7 , 3 / 7 ),
35+ var = trtVar [1 ]
36+ ),
37+ matrix (c(1 , 1 , 2 , 3 , 4 , 4 , 4 ))
38+ )
2639
2740 expect_error(asCategorical(x = cont ))
28- cont2 = asCategorical(x = cont ,
29- threshold = list (NULL ,
30- c(- Inf , 0 , Inf ),
31- NULL ))
41+ cont2 = asCategorical(x = cont , threshold = list (NULL , c(- Inf , 0 , Inf ), NULL ))
3242 cont2Exp = cont
3343 cont2Exp [, 2 ] = c(1 , 1 , 1 , 2 , 2 , 2 , 2 )
3444 expect_equal(cont2 , cont2Exp )
@@ -37,8 +47,35 @@ test_that("asCategorical_converts_correctly",{
3747 pList = list (NULL , c(0.5 , 0.5 ), NULL )
3848 expect_error(asCategorical(x = cont , p = pList ))
3949 expect_error(asCategorical(x = cont , p = pList , mean = trtMean ))
40- cont2 = asCategorical(x = cont , p = pList , mean = trtMean , var = trtVar )
50+ cont2 = asCategorical(x = cont , p = pList , mean = trtMean , var = trtVar )
4151 cont2Exp = cont
4252 cont2Exp [, 2 ] = c(1 , 1 , 1 , 2 , 2 , 2 , 2 )
4353 expect_equal(cont2 , cont2Exp )
4454})
55+
56+ test_that(" pop@gv and genParam(pop)@gv match" , {
57+ founderPop = quickHaplo(nInd = 10 , nChr = 1 , segSites = 10 , ploidy = 1 )
58+ SP = SimParam $ new(founderPop )
59+ SP $ addTraitA(nQtlPerChr = 10 , mean = 0 , var = 1 , name = " addTraitA_allQTLs" )
60+ SP $ addTraitAE(
61+ nQtlPerChr = 10 ,
62+ relAA = 0 ,
63+ mean = 0 ,
64+ var = 1 ,
65+ useVarA = FALSE ,
66+ name = " addTraitAE_allQTLs"
67+ )
68+ SP $ addTraitA(nQtlPerChr = 2 , mean = 0 , var = 1 , name = " addTraitA_2QTLs" )
69+ SP $ addTraitAE(
70+ nQtlPerChr = 2 ,
71+ relAA = 0 ,
72+ mean = 0 ,
73+ var = 1 ,
74+ useVarA = FALSE ,
75+ name = " addTraitAE_2QTLs"
76+ )
77+ pop = newPop(founderPop , simParam = SP )
78+ diff = pop @ gv - genParam(pop , simParam = SP )$ gv
79+ test = abs(diff ) < .Machine $ double.eps ^ 0.5
80+ expect_true(all(test ))
81+ })
0 commit comments