Skip to content

Commit 965bf0d

Browse files
Merge pull request #41 from R-Computing-Lab/dev_main
added bonus tests
2 parents 0a4fa9b + fe35408 commit 965bf0d

4 files changed

Lines changed: 40 additions & 2 deletions

File tree

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# BGmisc 1.3.1.1
2+
* Added some more tests of identifyModel.R
3+
14
# BGmisc 1.3.1
25
* Confirmed that all orcids are correct
36
* Added gedcom importer

tests/testthat/test-identifyModel.R

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Test cases for model identification and fitting functions
2+
3+
# Test that a fully specified model with adequate parameters is correctly identified
4+
15
test_that("identified model is identified", {
26
set.seed(5)
37

@@ -14,6 +18,8 @@ test_that("identified model is identified", {
1418
)$identified)
1519
})
1620

21+
# Test for error when a model is underidentified due to insufficient parameters
22+
1723
test_that("underidentified model is unidentified", {
1824
set.seed(5)
1925

@@ -24,7 +30,9 @@ test_that("underidentified model is unidentified", {
2430
)$identified)
2531
})
2632

33+
# Test that fitComponentModel returns expected coefficients with valid input data
2734
test_that("fitComponentModel work", {
35+
# Initial example using commented out real data loading
2836
# data(twinData, package = "OpenMx")
2937
# selVars <- c("ht1", "ht2")
3038
# mzData <- subset(twinData, zyg %in% c(1), c(selVars, "zyg"))
@@ -51,3 +59,28 @@ test_that("fitComponentModel work", {
5159
)
5260
expect_equal(result$coefficients, c(compmA = 0.0036404, compmC = 0.0002317, compmE = 0.0006713), tolerance = 1e-4)
5361
})
62+
63+
# Test for incorrect input types in comp2vech
64+
test_that("comp2vech handles incorrect input types", {
65+
expect_error(comp2vech("some non-matrix input"), "x is neither a list nor a matrix")
66+
})
67+
68+
# Ensure default names are correctly assigned
69+
test_that("default names are assigned correctly", {
70+
result <- identifyComponentModel(matrix(1, 2, 2), matrix(1, 2, 2))
71+
expect_equal(result$nidp, c("Comp1", "Comp2"))
72+
})
73+
74+
75+
76+
# Test for list handling in comp2vech
77+
test_that("comp2vech handles lists correctly", {
78+
list_input <- list(matrix(c(1, 0.5, 0.5, 1), 2, 2), matrix(1, 2, 2))
79+
expect_length(comp2vech(list_input, include.zeros = TRUE), 10) # Adjust based on expected vector length
80+
})
81+
82+
83+
# Test for incorrect input types in comp2vech
84+
test_that("comp2vech handles incorrect input types", {
85+
expect_error(comp2vech("some non-matrix input"), "x is neither a list nor a matrix")
86+
})

vignettes/analyticrelatedness.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ calculateRelatedness(generations = 1, full = FALSE)
4646

4747
# Inferring Relatedness Coefficient
4848

49-
The `inferRelatedness` function is designed to infer the relatedness coefficient between two groups based on the observed correlation between their additive genetic variance and shared environmental variance. This function leverages the ACE framework.
49+
The `inferRelatedness` function is designed to infer the relatedness coefficient between two groups based on the observed correlation between their additive genetic variance and shared environmental variance. This function leverages the `ACE` framework.
5050

5151
```{r}
5252
# Example usage:

vignettes/validation.Rmd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ library(tidyverse)
8989
9090
summarizeFamilies(df, famID = "newFamID", personID = "personID")$family_summary %>% glimpse()
9191
```
92+
9293
If we didn't know to look for duplicates, we might not notice the issue. Indeed, only of the duplicates was selected as are founder member. However, the `checkIDs` function can help us identify and repair these errors:
9394

9495
```{r}
@@ -106,6 +107,7 @@ df %>% filter(personID %in% result$non_unique_ids) %>%
106107
arrange(personID)
107108
108109
```
110+
109111
Yep, these are definitely the duplicates.
110112

111113
```{r}
@@ -155,7 +157,7 @@ results <- checkSex(potter, code_male = 1, code_female = 0, verbose = TRUE, repa
155157
print(results)
156158
```
157159

158-
In this example, the checkSex function checks the unique values in the sex column and identifies any inconsistencies in the sex coding of parents. The function returns a list containing validation results, such as the unique values found in the sex column and any inconsistencies in the sex coding of parents.
160+
In this example, the `checkSex` function checks the unique values in the sex column and identifies any inconsistencies in the sex coding of parents. The function returns a list containing validation results, such as the unique values found in the sex column and any inconsistencies in the sex coding of parents.
159161

160162
If incorrect sex codes are found, you can attempt to repair them automatically using the repair argument:
161163

0 commit comments

Comments
 (0)