1111# ' @return A data frame representing the initial structure for the individuals in the specified generation
1212# ' before any relationships (parental, spousal) are defined. The columns include family ID (`fam`),
1313# ' individual ID (`id`), generation number (`gen`), father's ID (`pat`), mother's ID (`mat`),
14- # ' spouse's ID (`spt `), and sex (`sex`), with NA values for paternal, maternal, and spouse IDs, and sex.
14+ # ' spouse's ID (`spID `), and sex (`sex`), with NA values for paternal, maternal, and spouse IDs, and sex.
1515# ' @examples
1616# ' sizeGens <- c(3, 5, 4) # Example sizes for 3 generations
1717# ' genIndex <- 2 # Creating data frame for the 2nd generation
@@ -26,7 +26,7 @@ createGenDataFrame <- function(sizeGens, genIndex, idGen) {
2626 gen = rep(genIndex , sizeGens [genIndex ]),
2727 pat = rep(NA , sizeGens [genIndex ]), # father id
2828 mat = rep(NA , sizeGens [genIndex ]), # mother id
29- spt = rep(NA , sizeGens [genIndex ]), # spouse id
29+ spID = rep(NA , sizeGens [genIndex ]), # spouse id
3030 sex = rep(NA , sizeGens [genIndex ])
3131 )
3232 return (df_Ngen )
@@ -35,13 +35,12 @@ createGenDataFrame <- function(sizeGens, genIndex, idGen) {
3535
3636# ' Determine Sex of Offspring
3737# '
38- # ' This function assigns sexes to the offspring in a generation based on the specified sex ratio.
38+ # ' This internal function assigns sexes to the offspring in a generation based on the specified sex ratio.
3939# '
4040# ' @param idGen Vector of IDs for the generation.
4141# ' @param sexR Numeric value indicating the sex ratio (proportion of males).
4242# ' @return Vector of sexes ("M" for male, "F" for female) for the offspring.
4343# ' @importFrom stats runif
44- # ' @export
4544determineSex <- function (idGen , sexR ) {
4645 if (runif(1 ) > .5 ) {
4746 sexVec1 <- rep(" M" , floor(length(idGen ) * sexR ))
@@ -66,16 +65,16 @@ assignCoupleIds <- function(df_Ngen) {
6665 usedCoupleIds <- character () # Initialize an empty character vector to track used IDs
6766
6867 for (j in seq_len(nrow(df_Ngen ))) {
69- if (! is.na(df_Ngen $ spt [j ]) && is.na(df_Ngen $ coupleId [j ])) {
68+ if (! is.na(df_Ngen $ spID [j ]) && is.na(df_Ngen $ coupleId [j ])) {
7069 # Construct a potential couple ID from sorted individual and spouse IDs
71- sortedIds <- sort(c(df_Ngen $ id [j ], df_Ngen $ spt [j ]))
70+ sortedIds <- sort(c(df_Ngen $ id [j ], df_Ngen $ spID [j ]))
7271 potentialCoupleId <- paste(sortedIds [1 ], sortedIds [2 ], sep = " _" )
7372
7473 # Check if the potentialCoupleId has not already been used
7574 if (! potentialCoupleId %in% usedCoupleIds ) {
7675 # Assign the new couple ID to both partners
7776 df_Ngen $ coupleId [j ] <- potentialCoupleId
78- spouseIndex <- which(df_Ngen $ id == df_Ngen $ spt [j ])
77+ spouseIndex <- which(df_Ngen $ id == df_Ngen $ spID [j ])
7978 df_Ngen $ coupleId [spouseIndex ] <- potentialCoupleId
8079
8180 # Add the new couple ID to the list of used IDs
@@ -137,7 +136,7 @@ adjustKidsPerCouple <- function(nMates, kpc, rd_kpc) {
137136# ' the assignment of roles and relationships within and between generations in a pedigree simulation.
138137# '
139138# ' @param df_Ngen A data frame for the current generation being processed.
140- # ' It must include columns for individual IDs (`id`), spouse IDs (`spt `), sex (`sex`),
139+ # ' It must include columns for individual IDs (`id`), spouse IDs (`spID `), sex (`sex`),
141140# ' and any previously assigned roles (`ifparent`, `ifson`, `ifdau`).
142141# ' @param i Integer, the index of the current generation being processed.
143142# ' @param Ngen Integer, the total number of generations in the simulation.
@@ -163,7 +162,7 @@ markPotentialChildren <- function(df_Ngen, i, Ngen, sizeGens, CoupleF) {
163162 # single person should all be sons or daus
164163 # change the ifson and ifdau based on coupleGirl and coupleBoy
165164 for (j in 1 : sizeGens [i ]) {
166- if (is.na(df_Ngen $ spt [j ])) {
165+ if (is.na(df_Ngen $ spID [j ])) {
167166 if (df_Ngen $ sex [j ] == " F" ) {
168167 df_Ngen $ ifdau [j ] <- TRUE
169168 # usedIds <- c(usedIds, df_Ngen$id[j])
0 commit comments