diff --git a/NAMESPACE b/NAMESPACE index 45965b2..85e062c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,5 @@ # Generated by roxygen2: do not edit by hand -export(PlotPedigree) export(SimPed) export(allGens) export(comp2vech) @@ -15,8 +14,10 @@ export(ped2com) export(ped2fam) export(ped2graph) export(ped2mit) +export(plotPedigree) export(related_coef) export(relatedness) +export(simulatePedigree) export(vech) import(kinship2) importFrom(stats,runif) diff --git a/R/famSizeCal.R b/R/famSizeCal.R index 2478b19..01af945 100644 --- a/R/famSizeCal.R +++ b/R/famSizeCal.R @@ -1,5 +1,5 @@ #' allGens -#' A function to calculate the number of individuals in each generation. This is a supporting function for \code{SimPed}. +#' A function to calculate the number of individuals in each generation. This is a supporting function for \code{simulatePedigree}. #' @param kpc Number of kids per couple (integer >= 2). #' @param Ngen Number of generations (integer >= 1). #' @param marR Mating rate (numeric value ranging from 0 to 1). @@ -27,7 +27,7 @@ allGens <- function(kpc, Ngen, marR) { #' sizeAllGens -#' An internal supporting function for \code{SimPed}. +#' An internal supporting function for \code{simulatePedigree}. #' @inheritParams allGens #' @return Returns a vector including the number of individuals in every generation. @@ -50,7 +50,7 @@ sizeAllGens <- function(kpc, Ngen, marR) { #' famSizeCal -#' A function to calculate the total number of individuals in a pedigree given parameters. This is a supporting function for function \code{SimPed} +#' A function to calculate the total number of individuals in a pedigree given parameters. This is a supporting function for function \code{simulatePedigree} #' @inheritParams allGens #' @return Returns a numeric value indicating the total pedigree size. #' @export diff --git a/R/helper.R b/R/helper.R index 077f876..6e678b3 100644 --- a/R/helper.R +++ b/R/helper.R @@ -63,3 +63,26 @@ Null <- function(M) { } return(qr.Q(tmp, complete = TRUE)[, set, drop = FALSE]) } + +#' SimPed (Deprecated) +#' +#' This function is a wrapper around the new `simulatePedigree` function. +#' `SimPed` has been deprecated, and it's advised to use `simulatePedigree` directly. +#' +#' @param ... Arguments to be passed to `simulatePedigree`. +#' @return The same result as calling `simulatePedigree`. +#' @seealso \code{\link{simulatePedigree}} for the updated function. +#' @description When calling this function, a warning will be issued about its deprecation. +#' @keywords deprecated +#' @examples +#' \dontrun{ +#' # This is an example of the deprecated function: +#' SimPed(...) +#' # It is recommended to use: +#' simulatePedigree(...) +#' } +#' @export +SimPed <- function(...) { + warning("The 'SimPed' function is deprecated. Please use 'simulatePedigree' instead.") + simulatePedigree(...) +} diff --git a/R/PlotPedigree.R b/R/plotPedigree.R similarity index 79% rename from R/PlotPedigree.R rename to R/plotPedigree.R index 42a4569..1861266 100644 --- a/R/PlotPedigree.R +++ b/R/plotPedigree.R @@ -1,13 +1,13 @@ -#' PlotPedigree -#' A wrapped function to plot simulated pedigree from function \code{SimPed}. This function require the installation of package \code{kinship2}. +#' plotPedigree +#' A wrapped function to plot simulated pedigree from function \code{simulatePedigree}. This function require the installation of package \code{kinship2}. #' @import kinship2 -#' @param ped The simulated pedigree data.frame from function \code{SimPed}. Or a pedigree dataframe with the same colnames as the dataframe simulated from function \code{SimPed}. +#' @param ped The simulated pedigree data.frame from function \code{simulatePedigree}. Or a pedigree dataframe with the same colnames as the dataframe simulated from function \code{simulatePedigree}. #' @param cex The font size of the IDs for each individual in the plot. #' @inheritParams kinship2::plot.pedigree #' @return A plot of the simulated pedigree #' @export -PlotPedigree <- function(ped, cex = .5, +plotPedigree <- function(ped, cex = .5, # optional inputs for the pedigree plot col = 1, symbolsize = 1, branch = 0.6, @@ -45,4 +45,4 @@ PlotPedigree <- function(ped, cex = .5, )) } -# PlotPedigree(SimPed(kpc = 2, Ngen = 6, marR = .8)) +# plotPedigree(simulatePedigree(kpc = 2, Ngen = 6, marR = .8)) diff --git a/R/SimPed.R b/R/simulatePedigree.R similarity index 99% rename from R/SimPed.R rename to R/simulatePedigree.R index dad2ebd..8033339 100644 --- a/R/SimPed.R +++ b/R/simulatePedigree.R @@ -25,7 +25,7 @@ #' } #' @export -SimPed <- function(kpc = 3, +simulatePedigree <- function(kpc = 3, Ngen = 4, sexR = .5, marR = 2 / 3, diff --git a/man/PlotPedigree.Rd b/man/PlotPedigree.Rd index 69339a0..27d4c42 100644 --- a/man/PlotPedigree.Rd +++ b/man/PlotPedigree.Rd @@ -1,11 +1,11 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/PlotPedigree.R -\name{PlotPedigree} -\alias{PlotPedigree} -\title{PlotPedigree -A wrapped function to plot simulated pedigree from function \code{SimPed}. This function require the installation of package \code{kinship2}.} +% Please edit documentation in R/plotPedigree.R +\name{plotPedigree} +\alias{plotPedigree} +\title{plotPedigree +A wrapped function to plot simulated pedigree from function \code{simulatePedigree}. This function require the installation of package \code{kinship2}.} \usage{ -PlotPedigree( +plotPedigree( ped, cex = 0.5, col = 1, @@ -22,7 +22,7 @@ PlotPedigree( ) } \arguments{ -\item{ped}{The simulated pedigree data.frame from function \code{SimPed}. Or a pedigree dataframe with the same colnames as the dataframe simulated from function \code{SimPed}.} +\item{ped}{The simulated pedigree data.frame from function \code{simulatePedigree}. Or a pedigree dataframe with the same colnames as the dataframe simulated from function \code{simulatePedigree}.} \item{cex}{The font size of the IDs for each individual in the plot.} @@ -72,12 +72,14 @@ were for plotting (useful for adding extras to the plot) to a large number will force the line to connect at the midpoint of the children.} -\item{...}{ Extra options that feed into the plot function} +\item{...}{ +Extra options that feed into the plot function. +} } \value{ A plot of the simulated pedigree } \description{ -PlotPedigree -A wrapped function to plot simulated pedigree from function \code{SimPed}. This function require the installation of package \code{kinship2}. +plotPedigree +A wrapped function to plot simulated pedigree from function \code{simulatePedigree}. This function require the installation of package \code{kinship2}. } diff --git a/man/SimPed.Rd b/man/SimPed.Rd index 35a94c6..1d70f0f 100644 --- a/man/SimPed.Rd +++ b/man/SimPed.Rd @@ -1,47 +1,33 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/SimPed.R +% Please edit documentation in R/helper.R \name{SimPed} \alias{SimPed} -\title{Simulate Pedigrees} +\title{SimPed (Deprecated)} \usage{ -SimPed( - kpc = 3, - Ngen = 4, - sexR = 0.5, - marR = 2/3, - balancedSex = TRUE, - balancedmar = TRUE -) +SimPed(...) } \arguments{ -\item{kpc}{Number of kids per couple. An integer >= 2 that determines how many kids each fertilized mated couple will have in the pedigree. Default value is 3. Returns an error when kpc equals 1.} - -\item{Ngen}{Number of generations. An integer >= 2 that determines how many generations the simulated pedigree will have. The first generation is always a fertilized couple. The last generation has no mated individuals.} - -\item{sexR}{Sex ratio of offspring. A numeric value ranging from 0 to 1 that determines the proportion of males in all offspring in this pedigree. For instance, 0.4 means 40 percent of the offspring will be male.} - -\item{marR}{Mating rate. A numeric value ranging from 0 to 1 which determines the proportion of mated (fertilized) couples in the pedigree within each generation. For instance, marR = 0.5 suggests 50 percent of the offspring in a specific generation will be mated and have their offspring.} - -\item{balancedSex}{Not fully developed yet. Always \code{TRUE} in the current version.} - -\item{balancedmar}{Not fully developed yet. Always \code{TRUE} in the current version.} +\item{...}{Arguments to be passed to `simulatePedigree`.} } \value{ -A \code{data.frame} with each row representing a simulated individual. The columns are as follows: -\itemize{ - \item{fam: The family id of each simulated individual. It is 'fam1' in a single simulated pedigree.} - \item{ID: The unique personal ID of each simulated individual. The first digit is the fam id; the fourth digit is the generation the individual is in; the following digits represent the order of the individual within his/her pedigree. For example, 100411 suggests this individual has a family id of 1, is in the 4th generation, and is the 11th individual in the 4th generation.} - \item{gen: The generation the simulated individual is in.} - \item{dadID: Personal ID of the individual's father.} - \item{momID: Personal ID of the individual's mother.} - \item{spt: Personal ID of the individual's mate.} - \item{sex: Biological sex of the individual. F - female; M - male.} -} +The same result as calling `simulatePedigree`. } \description{ -This function simulates "balanced" pedigrees based on a group of parameters: -1) k - Kids per couple; -2) G - Number of generations; -3) p - Proportion of males in offspring; -4) r - Mating rate. +When calling this function, a warning will be issued about its deprecation. +} +\details{ +This function is a wrapper around the new `simulatePedigree` function. +`SimPed` has been deprecated, and it's advised to use `simulatePedigree` directly. +} +\examples{ +\dontrun{ +# This is an example of the deprecated function: +SimPed(...) +# It is recommended to use: +simulatePedigree(...) +} +} +\seealso{ +\code{\link{simulatePedigree}} for the updated function. } +\keyword{deprecated} diff --git a/man/allGens.Rd b/man/allGens.Rd index b6d0d75..2f7efe0 100644 --- a/man/allGens.Rd +++ b/man/allGens.Rd @@ -3,7 +3,7 @@ \name{allGens} \alias{allGens} \title{allGens -A function to calculate the number of individuals in each generation. This is a supporting function for \code{SimPed}.} +A function to calculate the number of individuals in each generation. This is a supporting function for \code{simulatePedigree}.} \usage{ allGens(kpc, Ngen, marR) } @@ -19,5 +19,5 @@ Returns a vector containing the number of individuals in every generation. } \description{ allGens -A function to calculate the number of individuals in each generation. This is a supporting function for \code{SimPed}. +A function to calculate the number of individuals in each generation. This is a supporting function for \code{simulatePedigree}. } diff --git a/man/famSizeCal.Rd b/man/famSizeCal.Rd index 00eb2f8..60e20a9 100644 --- a/man/famSizeCal.Rd +++ b/man/famSizeCal.Rd @@ -3,7 +3,7 @@ \name{famSizeCal} \alias{famSizeCal} \title{famSizeCal -A function to calculate the total number of individuals in a pedigree given parameters. This is a supporting function for function \code{SimPed}} +A function to calculate the total number of individuals in a pedigree given parameters. This is a supporting function for function \code{simulatePedigree}} \usage{ famSizeCal(kpc, Ngen, marR) } @@ -19,5 +19,5 @@ Returns a numeric value indicating the total pedigree size. } \description{ famSizeCal -A function to calculate the total number of individuals in a pedigree given parameters. This is a supporting function for function \code{SimPed} +A function to calculate the total number of individuals in a pedigree given parameters. This is a supporting function for function \code{simulatePedigree} } diff --git a/man/hazard.Rd b/man/hazard.Rd index 374a134..8a29f3b 100755 --- a/man/hazard.Rd +++ b/man/hazard.Rd @@ -29,7 +29,7 @@ The variables are as follows: \item birthYr. Birth year for person \item onsetYr. Year of onset for person \item deathYr. Death year for person - \item available. logical. Whether + \item available. logical. Whether \item Gen. Generation of the person \item proband. logical. Whether the person is a proband or not } diff --git a/man/simulatePedigree.Rd b/man/simulatePedigree.Rd new file mode 100644 index 0000000..7e45068 --- /dev/null +++ b/man/simulatePedigree.Rd @@ -0,0 +1,47 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/simulatePedigree.R +\name{simulatePedigree} +\alias{simulatePedigree} +\title{Simulate Pedigrees} +\usage{ +simulatePedigree( + kpc = 3, + Ngen = 4, + sexR = 0.5, + marR = 2/3, + balancedSex = TRUE, + balancedmar = TRUE +) +} +\arguments{ +\item{kpc}{Number of kids per couple. An integer >= 2 that determines how many kids each fertilized mated couple will have in the pedigree. Default value is 3. Returns an error when kpc equals 1.} + +\item{Ngen}{Number of generations. An integer >= 2 that determines how many generations the simulated pedigree will have. The first generation is always a fertilized couple. The last generation has no mated individuals.} + +\item{sexR}{Sex ratio of offspring. A numeric value ranging from 0 to 1 that determines the proportion of males in all offspring in this pedigree. For instance, 0.4 means 40 percent of the offspring will be male.} + +\item{marR}{Mating rate. A numeric value ranging from 0 to 1 which determines the proportion of mated (fertilized) couples in the pedigree within each generation. For instance, marR = 0.5 suggests 50 percent of the offspring in a specific generation will be mated and have their offspring.} + +\item{balancedSex}{Not fully developed yet. Always \code{TRUE} in the current version.} + +\item{balancedmar}{Not fully developed yet. Always \code{TRUE} in the current version.} +} +\value{ +A \code{data.frame} with each row representing a simulated individual. The columns are as follows: +\itemize{ + \item{fam: The family id of each simulated individual. It is 'fam1' in a single simulated pedigree.} + \item{ID: The unique personal ID of each simulated individual. The first digit is the fam id; the fourth digit is the generation the individual is in; the following digits represent the order of the individual within his/her pedigree. For example, 100411 suggests this individual has a family id of 1, is in the 4th generation, and is the 11th individual in the 4th generation.} + \item{gen: The generation the simulated individual is in.} + \item{dadID: Personal ID of the individual's father.} + \item{momID: Personal ID of the individual's mother.} + \item{spt: Personal ID of the individual's mate.} + \item{sex: Biological sex of the individual. F - female; M - male.} +} +} +\description{ +This function simulates "balanced" pedigrees based on a group of parameters: +1) k - Kids per couple; +2) G - Number of generations; +3) p - Proportion of males in offspring; +4) r - Mating rate. +} diff --git a/man/sizeAllGens.Rd b/man/sizeAllGens.Rd index ee7a226..47e1afd 100644 --- a/man/sizeAllGens.Rd +++ b/man/sizeAllGens.Rd @@ -3,7 +3,7 @@ \name{sizeAllGens} \alias{sizeAllGens} \title{sizeAllGens -An internal supporting function for \code{SimPed}.} +An internal supporting function for \code{simulatePedigree}.} \usage{ sizeAllGens(kpc, Ngen, marR) } @@ -19,5 +19,5 @@ Returns a vector including the number of individuals in every generation. } \description{ sizeAllGens -An internal supporting function for \code{SimPed}. +An internal supporting function for \code{simulatePedigree}. } diff --git a/tests/testthat/test-pedigreesim.R b/tests/testthat/test-pedigreesim.R index 66fe807..d67abd6 100644 --- a/tests/testthat/test-pedigreesim.R +++ b/tests/testthat/test-pedigreesim.R @@ -1,6 +1,6 @@ test_that("simulated pedigree generates expected data structure", { set.seed(5) - results <- SimPed(kpc = 4, Ngen = 4, sexR = .5, marR = .7) + results <- simulatePedigree(kpc = 4, Ngen = 4, sexR = .5, marR = .7) expect_equal(length(results$ID), 57) expect_equal(length(results), 7) diff --git a/vignettes/vignette_pedigree.Rmd b/vignettes/vignette_pedigree.Rmd index 6d06025..912980e 100644 --- a/vignettes/vignette_pedigree.Rmd +++ b/vignettes/vignette_pedigree.Rmd @@ -38,7 +38,7 @@ For example, a pedigree that follows these conditions: There are a total of four ```{r} set.seed(5) -Ped <- SimPed(kpc = 4, Ngen = 4, sexR = .5, marR = .7) +Ped <- simulatePedigree(kpc = 4, Ngen = 4, sexR = .5, marR = .7) summary(Ped) ``` @@ -54,15 +54,15 @@ 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 -To visualize a single simulated pedigree, use the `PlotPedigree()` function. +To visualize a single simulated pedigree, use the `plotPedigree()` function. ```{r,fig.width=8,fig.height=6} # Plot the simulated pedigree -PlotPedigree(Ped) +plotPedigree(Ped) ``` @@ -75,19 +75,19 @@ If you wish to compare different pedigrees side by side, you can plot them toget ```{r,fig.width=8, fig.height=6} # Simulate a family with 3 generations -df_ped_3 <- SimPed(Ngen = 3) +df_ped_3 <- simulatePedigree(Ngen = 3) # Simulate a family with 4 generations -df_ped_4 <- SimPed(Ngen = 4) +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) +plotPedigree(df_ped_3, width = 3) # Plot the 4-generation pedigree -PlotPedigree(df_ped_4, width = 1) +plotPedigree(df_ped_4, width = 1) ``` By examining the side-by-side plots, you can contrast and analyze the structures of different families, tracing the inheritance of specific traits or conditions if needed. diff --git a/vignettes/vignette_pedigree.html b/vignettes/vignette_pedigree.html index 4ef6455..4c6ad9d 100644 --- a/vignettes/vignette_pedigree.html +++ b/vignettes/vignette_pedigree.html @@ -403,14 +403,14 @@
PlotPedigree
function. This function is a wrapper function
+plotPedigree
function. This function is a wrapper function
for Kinship2’s base R plotting.
To visualize a single simulated pedigree, use the
-PlotPedigree()
function.
plotPedigree()
function.
# Plot the simulated pedigree
-PlotPedigree(Ped)
+plotPedigree(Ped)
#> Pedigree object with 57 subjects, family id= 1
#> Bit size= 75