You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
warning("The 'SimPed' function is deprecated. Please use 'simulatePedigree' instead.")
981
996
simulatePedigree(...)
982
997
}
998
+
999
+
#' Simulate Multiple Pedigrees
1000
+
#'
1001
+
#' This function simulates multiple "balanced" pedigrees and returns them
1002
+
#' combined into a single data frame. It is a convenience wrapper around
1003
+
#' \code{\link{simulatePedigree}} that makes it easy to simulate many families
1004
+
#' at once, with unique IDs across all families.
1005
+
#'
1006
+
#' @param n_fam Integer. Number of families to simulate. Default is 2.
1007
+
#' @param remap_ids Logical. If TRUE (default), all ID columns (personID, momID, dadID, spouseID) will be remapped to sequential integers starting at 1 across the combined data frame. This ensures tidy consecutive IDs regardless of fam_shift offsets. If FALSE, IDs will retain their original values from each pedigree simulation, which may include gaps or non-sequential values due to fam_shift.
1008
+
#' @inheritParams simulatePedigree
1009
+
#' @return A \code{data.frame} containing all simulated individuals from all
1010
+
#' families combined, with the same columns as \code{\link{simulatePedigree}}.
1011
+
#' The \code{fam} column uniquely identifies each family (e.g., "fam1",
1012
+
#' "fam2", ...). Individual IDs are sequential integers starting at 1
1013
+
#' (i.e., \code{1:nrow(result)}), and all parent/spouse ID references are
1014
+
#' remapped to match.
1015
+
#' @export
1016
+
#' @examples
1017
+
#' set.seed(5)
1018
+
#' df_peds <- simulatePedigrees(
1019
+
#' n_fam = 3,
1020
+
#' kpc = 4,
1021
+
#' Ngen = 4,
1022
+
#' sexR = .5,
1023
+
#' marR = .7
1024
+
#' )
1025
+
#' summary(df_peds)
1026
+
simulatePedigrees<-function(n_fam=2,
1027
+
kpc=3,
1028
+
Ngen=4,
1029
+
sexR=.5,
1030
+
marR=2/3,
1031
+
rd_kpc=FALSE,
1032
+
balancedSex=TRUE,
1033
+
balancedMar=TRUE,
1034
+
verbose=FALSE,
1035
+
personID="ID",
1036
+
momID="momID",
1037
+
dadID="dadID",
1038
+
spouseID="spouseID",
1039
+
code_male="M",
1040
+
code_female="F",
1041
+
remap_ids=TRUE,
1042
+
beta=FALSE
1043
+
) {
1044
+
n_fam<- as.integer(n_fam)
1045
+
if (is.na(n_fam) ||n_fam<1L) {
1046
+
stop("'n_fam' must be a positive integer.")
1047
+
}
1048
+
ped_list<- vector("list", n_fam)
1049
+
for (iin seq_len(n_fam)) {
1050
+
ped_i<- simulatePedigree(
1051
+
kpc=kpc,
1052
+
Ngen=Ngen,
1053
+
sexR=sexR,
1054
+
marR=marR,
1055
+
rd_kpc=rd_kpc,
1056
+
balancedSex=balancedSex,
1057
+
balancedMar=balancedMar,
1058
+
verbose=verbose,
1059
+
personID=personID,
1060
+
momID=momID,
1061
+
dadID=dadID,
1062
+
spouseID=spouseID,
1063
+
code_male=code_male,
1064
+
code_female=code_female,
1065
+
fam_shift=i,
1066
+
remap_ids=FALSE, # Keep original IDs for now; we'll remap after combining.
0 commit comments