From c80b9643f00a6ca8f97cf8c2577f50779b203776 Mon Sep 17 00:00:00 2001 From: Mason Garrison Date: Fri, 23 Feb 2024 11:23:52 -0500 Subject: [PATCH] prepping for rcran update --- cran-comments.md | 14 +-- tests/testthat/test-network.R | 2 +- vignettes/pedigree.Rmd | 22 ++-- vignettes/pedigree.html | 217 +++++++++++++++++----------------- 4 files changed, 122 insertions(+), 133 deletions(-) diff --git a/cran-comments.md b/cran-comments.md index a26dd32..e481b99 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -2,15 +2,15 @@ Description ----------------------------------------------- -This is a hotfix for the BGmisc package, as we discovered that the plotPedigree wrapper function broke for pedigrees that contained multiple families. +This update reflects a substantial improvement in the codebase as part of the peer review process for JOSS, including the addition of numerous function checks, increased code coverage to 85%, and the replacement of sapply usage. We also added a new function to simulate twins and the ability to trace paternal and maternal lines. We also added a Harry Potter pedigree. + Test Environments ----------------------------------------------- -1. Local OS: Windows 10, R version 4.2.3 -2. Local OS: Windows 10, R version 4.3.1 -3. **GitHub Actions**: - - [Link](https://github.com/R-Computing-Lab/BGmisc/actions/runs/6317831880) +1. Local OS: Windows 11, R version 4.3.2 +2. **GitHub Actions**: + - [Link](https://github.com/R-Computing-Lab/BGmisc/actions/runs/8008686394) - macOS (latest version) with the latest R release. - Windows (latest version) with the latest R release. - Ubuntu (latest version) with: @@ -20,8 +20,8 @@ Test Environments ## R CMD check results -──────────────────────── BGmisc 1.0.1 ──── -Duration: 1m 1.4s +── R CMD check results BGmisc 1.2.0 ──── +Duration: 1m 0.6s 0 errors ✔ | 0 warnings ✔ | 0 notes ✔ diff --git a/tests/testthat/test-network.R b/tests/testthat/test-network.R index 7af6e05..d5ecbfe 100755 --- a/tests/testthat/test-network.R +++ b/tests/testthat/test-network.R @@ -175,6 +175,6 @@ test_that("ped2maternal/paternal produces correct matrix dims", { pat <- ped2paternal(hazard) expect_equal(dim(pat), c(nrow(hazard), ncol(hazard)+1)) - expect_less_than(cor(pat$patID, mat$matID), 1) + expect_lt(cor(pat$patID, mat$matID), 1) }) diff --git a/vignettes/pedigree.Rmd b/vignettes/pedigree.Rmd index 00df241..aa029e1 100644 --- a/vignettes/pedigree.Rmd +++ b/vignettes/pedigree.Rmd @@ -15,28 +15,20 @@ knitr::opts_chunk$set( options(rmarkdown.html_vignette.check_title = FALSE) ``` - # Introduction -This vignette provides a detailed guide to the pedigree-related functions within the `BGmisc` package. - -## Loading Required Libraries - -```{r setup} -library(BGmisc) -``` - -# Simulating Pedigrees - - - Unlike Tolstoy, where *only* happy families are alike, all pedigrees are alike -- or at least, all simulated pedigrees are alike. The `simulatePedigree` function generates a pedigree with a user-specified number of generations and individuals per generation. This function provides users the opportunity to test family models in pedigrees with a customized pedigree length and width. These pedigrees can be simulated as a function of several parameters, including the number of children per mate, generations, sex ratio of newborns, and mating rate. Given that large family pedigrees are difficult to collect or access, simulated pedigrees serve as an efficient tool for researchers. These simulated pedigrees are useful for building family-based statistical models, and evaluating their statistical properties, such as power, bias, and computational efficiency. -To illustrate this, let us generate a pedigree. This pedigree has a total of four generations, in which each person who "mates", grows a family with four offspring. In our scenario, the number of male and female newborns is equal. In this illustration 70% of individuals will mate and bear offspring. Such a pedigree structure can be simulated by running: + +To illustrate this functionality, let us generate a pedigree. This pedigree has a total of four generations (`Ngen`), in which each person who "mates", grows a family with four offspring (`kpc`). In our scenario, the number of male and female newborns is equal, but can be adjusted via (`sexR`). In this illustration 70% of individuals will mate and bear offspring (`marR`). Such a pedigree structure can be simulated by running the following code: ```{r} + +## Loading Required Libraries +library(BGmisc) + set.seed(5) df_ped <- simulatePedigree( kpc = 4, @@ -58,7 +50,7 @@ The columns represents the individual's family ID, the individual's personal ID, ## Plotting Pedigree -Pedigrees are visual diagrams that represent family relationships across generations. They are commonly used in genetics to trace the inheritance of specific traits or conditions. This vignette will guide you through visualizing simulated pedigrees using the `plotPedigree` function. This function is a wrapper function for Kinship2's base R plotting. +Pedigrees are visual diagrams that represent family relationships across generations. They are commonly used in genetics to trace the inheritance of specific traits or conditions. This vignette will guide you through visualizing simulated pedigrees using the `plotPedigree` function. This function is a wrapper function for `Kinship2`'s base R plotting. ### Single Pedigree Visualization diff --git a/vignettes/pedigree.html b/vignettes/pedigree.html index 18ad2f0..0b13234 100644 --- a/vignettes/pedigree.html +++ b/vignettes/pedigree.html @@ -343,15 +343,6 @@

Pedigree Simulation and Visualization with

Introduction

-

This vignette provides a detailed guide to the pedigree-related -functions within the BGmisc package.

-
-

Loading Required Libraries

-
library(BGmisc)
-
-
-
-

Simulating Pedigrees

Unlike Tolstoy, where only happy families are alike, all pedigrees are alike – or at least, all simulated pedigrees are alike. The simulatePedigree function generates a pedigree with a @@ -366,41 +357,47 @@

Simulating Pedigrees

building family-based statistical models, and evaluating their statistical properties, such as power, bias, and computational efficiency.

-

To illustrate this, let us generate a pedigree. This pedigree has a -total of four generations, in which each person who “mates”, grows a -family with four offspring. In our scenario, the number of male and -female newborns is equal. In this illustration 70% of individuals will -mate and bear offspring. Such a pedigree structure can be simulated by -running:

-
set.seed(5)
-df_ped <- simulatePedigree(
-  kpc = 4,
-  Ngen = 4,
-  sexR = .5,
-  marR = .7
-)
-summary(df_ped)
-#>      fam                  ID              gen            dadID       
-#>  Length:57          Min.   : 10011   Min.   :1.000   Min.   : 10012  
-#>  Class :character   1st Qu.: 10036   1st Qu.:3.000   1st Qu.: 10024  
-#>  Mode  :character   Median :100312   Median :3.000   Median : 10037  
-#>                     Mean   : 59171   Mean   :3.298   Mean   : 42859  
-#>                     3rd Qu.:100416   3rd Qu.:4.000   3rd Qu.:100311  
-#>                     Max.   :100432   Max.   :4.000   Max.   :100320  
-#>                                                      NA's   :13      
-#>      momID             spt             sex           
-#>  Min.   : 10011   Min.   : 10011   Length:57         
-#>  1st Qu.: 10022   1st Qu.: 10025   Class :character  
-#>  Median : 10036   Median : 10036   Mode  :character  
-#>  Mean   : 42859   Mean   : 40124                     
-#>  3rd Qu.:100316   3rd Qu.:100311                     
-#>  Max.   :100318   Max.   :100320                     
-#>  NA's   :13       NA's   :33
+

To illustrate this functionality, let us generate a pedigree. This +pedigree has a total of four generations (Ngen), in which +each person who “mates”, grows a family with four offspring +(kpc). In our scenario, the number of male and female +newborns is equal, but can be adjusted via (sexR). In this +illustration 70% of individuals will mate and bear offspring +(marR). Such a pedigree structure can be simulated by +running the following code:

+

+## Loading Required Libraries
+library(BGmisc)
+
+set.seed(5)
+df_ped <- simulatePedigree(
+  kpc = 4,
+  Ngen = 4,
+  sexR = .5,
+  marR = .7
+)
+summary(df_ped)
+#>      fam                  ID              gen            dadID       
+#>  Length:57          Min.   : 10011   Min.   :1.000   Min.   : 10012  
+#>  Class :character   1st Qu.: 10036   1st Qu.:3.000   1st Qu.: 10024  
+#>  Mode  :character   Median :100312   Median :3.000   Median : 10037  
+#>                     Mean   : 59171   Mean   :3.298   Mean   : 42859  
+#>                     3rd Qu.:100416   3rd Qu.:4.000   3rd Qu.:100311  
+#>                     Max.   :100432   Max.   :4.000   Max.   :100320  
+#>                                                      NA's   :13      
+#>      momID             spt             sex           
+#>  Min.   : 10011   Min.   : 10011   Length:57         
+#>  1st Qu.: 10022   1st Qu.: 10025   Class :character  
+#>  Median : 10036   Median : 10036   Mode  :character  
+#>  Mean   : 42859   Mean   : 40124                     
+#>  3rd Qu.:100316   3rd Qu.:100311                     
+#>  Max.   :100318   Max.   :100320                     
+#>  NA's   :13       NA's   :33

The simulation output is a data.frame with 57 rows and 7 columns. Each row corresponds to a simulated individual.

-
df_ped[21, ]
-#>      fam     ID gen dadID momID    spt sex
-#> 21 fam 1 100312   3 10024 10022 100317   M
+
df_ped[21, ]
+#>      fam     ID gen dadID momID    spt sex
+#> 21 fam 1 100312   3 10024 10022 100317   M

The columns represents the individual’s family ID, the individual’s personal ID, the generation the individual is in, the IDs of their father and mother, the ID of their spouse, and the biological sex of the @@ -412,14 +409,14 @@

Plotting Pedigree

inheritance of specific traits or conditions. This vignette will guide you through visualizing simulated pedigrees using the plotPedigree function. This function is a wrapper function -for Kinship2’s base R plotting.

+for Kinship2’s base R plotting.

Single Pedigree Visualization

To visualize a single simulated pedigree, use the plotPedigree() function.

-
# Plot the simulated pedigree
-plotPedigree(df_ped)
-

+
# Plot the simulated pedigree
+plotPedigree(df_ped)
+

#> Did not plot the following people: 10032
 #> $plist
 #> $plist$n
@@ -538,70 +535,70 @@ 

Visualizing Multiple Pedigrees Side-by-Side

If you wish to compare different pedigrees side by side, you can plot them together. For instance, let’s visualize pedigrees for families spanning three and four generations, respectively.

-
set.seed(8)
-# Simulate a family with 3 generations
-df_ped_3 <- simulatePedigree(Ngen = 3)
-
-# Simulate a family with 4 generations
-df_ped_4 <- simulatePedigree(Ngen = 4)
-
-# Set up plotting parameters for side-by-side display
-par(mfrow = c(1, 2))
-
-# Plot the 3-generation pedigree
-plotPedigree(df_ped_3, width = 3)
-#> $plist
-#> $plist$n
-#> [1] 2 5 6
-#> 
-#> $plist$nid
-#>      [,1] [,2] [,3] [,4] [,5] [,6]
-#> [1,]    2    1    0    0    0    0
-#> [2,]    3    5    4    6    7    0
-#> [3,]    8   10   11    9   12   13
-#> 
-#> $plist$pos
-#>              [,1]     [,2] [,3] [,4] [,5] [,6]
-#> [1,] 1.166667e+00 2.166667    0    0    0    0
-#> [2,] 2.047042e-09 1.000000    2    3    4    0
-#> [3,] 0.000000e+00 1.000000    2    3    4    5
-#> 
-#> $plist$fam
-#>      [,1] [,2] [,3] [,4] [,5] [,6]
-#> [1,]    0    0    0    0    0    0
-#> [2,]    1    1    0    0    1    0
-#> [3,]    2    2    2    4    4    4
-#> 
-#> $plist$spouse
-#>      [,1] [,2] [,3] [,4] [,5] [,6]
-#> [1,]    1    0    0    0    0    0
-#> [2,]    0    1    0    1    0    0
-#> [3,]    0    0    0    0    0    0
-#> 
-#> 
-#> $x
-#>  [1] 2.166667e+00 1.166667e+00 2.047042e-09 2.000000e+00 1.000000e+00
-#>  [6] 3.000000e+00 4.000000e+00 0.000000e+00 3.000000e+00 1.000000e+00
-#> [11] 2.000000e+00 4.000000e+00 5.000000e+00
-#> 
-#> $y
-#>  [1] 1 1 2 2 2 2 2 3 3 3 3 3 3
-#> 
-#> $boxw
-#> [1] 0.2006421
-#> 
-#> $boxh
-#> [1] 0.0565539
-#> 
-#> $call
-#> kinship2::plot.pedigree(x = p3, cex = cex, col = col, symbolsize = symbolsize, 
-#>     branch = branch, packed = packed, align = align, width = width, 
-#>     density = density, angle = angle, keep.par = keep.par, pconnect = pconnect, 
-#>     mar = mar)
-
-# Plot the 4-generation pedigree
-plotPedigree(df_ped_4, width = 1)
-

+
set.seed(8)
+# Simulate a family with 3 generations
+df_ped_3 <- simulatePedigree(Ngen = 3)
+
+# Simulate a family with 4 generations
+df_ped_4 <- simulatePedigree(Ngen = 4)
+
+# Set up plotting parameters for side-by-side display
+par(mfrow = c(1, 2))
+
+# Plot the 3-generation pedigree
+plotPedigree(df_ped_3, width = 3)
+#> $plist
+#> $plist$n
+#> [1] 2 5 6
+#> 
+#> $plist$nid
+#>      [,1] [,2] [,3] [,4] [,5] [,6]
+#> [1,]    2    1    0    0    0    0
+#> [2,]    3    5    4    6    7    0
+#> [3,]    8   10   11    9   12   13
+#> 
+#> $plist$pos
+#>              [,1]     [,2] [,3] [,4] [,5] [,6]
+#> [1,] 1.166667e+00 2.166667    0    0    0    0
+#> [2,] 2.047042e-09 1.000000    2    3    4    0
+#> [3,] 0.000000e+00 1.000000    2    3    4    5
+#> 
+#> $plist$fam
+#>      [,1] [,2] [,3] [,4] [,5] [,6]
+#> [1,]    0    0    0    0    0    0
+#> [2,]    1    1    0    0    1    0
+#> [3,]    2    2    2    4    4    4
+#> 
+#> $plist$spouse
+#>      [,1] [,2] [,3] [,4] [,5] [,6]
+#> [1,]    1    0    0    0    0    0
+#> [2,]    0    1    0    1    0    0
+#> [3,]    0    0    0    0    0    0
+#> 
+#> 
+#> $x
+#>  [1] 2.166667e+00 1.166667e+00 2.047042e-09 2.000000e+00 1.000000e+00
+#>  [6] 3.000000e+00 4.000000e+00 0.000000e+00 3.000000e+00 1.000000e+00
+#> [11] 2.000000e+00 4.000000e+00 5.000000e+00
+#> 
+#> $y
+#>  [1] 1 1 2 2 2 2 2 3 3 3 3 3 3
+#> 
+#> $boxw
+#> [1] 0.2006421
+#> 
+#> $boxh
+#> [1] 0.0565539
+#> 
+#> $call
+#> kinship2::plot.pedigree(x = p3, cex = cex, col = col, symbolsize = symbolsize, 
+#>     branch = branch, packed = packed, align = align, width = width, 
+#>     density = density, angle = angle, keep.par = keep.par, pconnect = pconnect, 
+#>     mar = mar)
+
+# Plot the 4-generation pedigree
+plotPedigree(df_ped_4, width = 1)
+

#> $plist
 #> $plist$n
 #> [1]  2  5 10 12