groupAddAssign finds the largest group that can be formed by adding unrelated animals from a set of candidate IDs to an existing group, to a new group it has formed from a set of candidate IDs or if more than 1 group is desired, it finds the set of groups with the largest average size.The function implements a maximal independent set (MIS) algorithm to find groups of unrelated animals. A set of animals may have many different MISs of varying sizes, and finding the largest would require traversing all possible combinations of animals. Since this could be very time consuming, this algorithm produces a random sample of the possible MISs, and selects from these. The size of the random sample is determined by the specified number of iterations.

groupAddAssign(
  candidates,
  currentGroups = list(character(0)),
  kmat,
  ped,
  threshold = 0.015625,
  ignore = list(c("F", "F")),
  minAge = 1,
  iter = 1000,
  numGp = 1,
  harem = FALSE,
  sexRatio = 0,
  withKin = FALSE,
  updateProgress = NULL
)

Arguments

candidates

Character vector of IDs of the animals available for use in forming the groups. The animals that may be present in currentGroups are not included within candidates.

currentGroups

List of character vectors of IDs of animals currently assigned to groups. Defaults to a list with character(0) in each sublist element (one for each group being formed) assuming no groups are prepopulated.

kmat

Numeric matrix of pairwise kinship values. Rows and columns are named with animal IDs.

ped

Dataframe that is the `Pedigree`. It contains pedigree information including the IDs listed in candidates.

threshold

Numeric value indicating the minimum kinship level to be considered in group formation. Pairwise kinship below this level will be ignored. The default value is 0.015625.

ignore

List of character vectors representing the sex combinations to be ignored. If provided, the vectors in the list specify if pairwise kinship should be ignored between certain sexes. Default is to ignore all pairwise kinship between females.

minAge

Integer value indicating the minimum age to consider in group formation. Pairwise kinships involving an animal of this age or younger will be ignored. Default is 1 year.

iter

Integer indicating the number of times to perform the random group formation process. Default value is 1000 iterations.

numGp

Integer value indicating the number of groups that should be formed from the list of IDs. Default is 1.

harem

Logical variable when set to TRUE, the formed groups have a single male at least minAge old.

sexRatio

Numeric value indicating the ratio of females to males x from 0.5 to 20 by increments of 0.5.

withKin

Logical variable when set to TRUE, the kinship matrix for the group is returned along with the group and score. Defaults to not return the kinship matrix. This maintains compatibility with earlier versions.

updateProgress

Function or NULL. If this function is defined, it will be called during each iteration to update a shiny::Progress object.

Value

A list with list items group, score and optionally groupKin. The list item group contains a list of the best group(s) produced during the simulation. The list item score provides the score associated with the group(s). The list item groupKin contains the subset of the kinship matrix that is specific for each group formed.

Details

Part of Group Formation

Examples

# \donttest{ library(nprcgenekeepr) examplePedigree <- nprcgenekeepr::examplePedigree breederPed <- qcStudbook(examplePedigree, minParentAge = 2, reportChanges = FALSE, reportErrors = FALSE) focalAnimals <- breederPed$id[!(is.na(breederPed$sire) & is.na(breederPed$dam)) & is.na(breederPed$exit)] ped <- setPopulation(ped = breederPed, ids = focalAnimals) trimmedPed <- trimPedigree(focalAnimals, breederPed) probands <- ped$id[ped$population] ped <- trimPedigree(probands, ped, removeUninformative = FALSE, addBackParents = FALSE) geneticValue <- reportGV(ped, guIter = 50, # should be >= 1000 guThresh = 3, byID = TRUE, updateProgress = NULL) trimmedGeneticValue <- reportGV(trimmedPed, guIter = 50, # should be >= 1000 guThresh = 3, byID = TRUE, updateProgress = NULL) candidates <- trimmedPed$id[trimmedPed$birth < as.Date("2013-01-01") & !is.na(trimmedPed$birth) & is.na(trimmedPed$exit)] haremGrp <- groupAddAssign(candidates = candidates, kmat = trimmedGeneticValue[["kinship"]], ped = trimmedPed, iter = 10, # should be >= 1000 numGp = 6, harem = TRUE) haremGrp$group
#> [[1]] #> [1] "IRFJ09" "SHG3RB" "CMMUKU" "NN3GDQ" "D9P18Y" "KEA4QG" "87AQLF" "DPXEQE" #> [9] "FG0SFA" "WI38KZ" "92UG4N" "0IIAEN" "CS23RV" "YLRNIK" "EMV4P6" "MH88T6" #> [17] "QCENKM" "GTLA8R" "PYPM1W" "8JUUJ9" "F7I2ED" "6KWVRI" "WTE53B" "3DTD2N" #> [25] "50D77I" "PBAFJF" "RJ4JPC" "YFCIHJ" "S5H1GC" "R5AYJK" "1SPLS8" "MKY9TK" #> #> [[2]] #> [1] "XZH41H" "G25E3F" "ILVQVB" "Q17CG3" "465ERA" "PI4VHT" "RVHVTZ" "FB5L3N" #> [9] "QRZK48" "99BMJW" "3GECJJ" "PJ72W1" "S7IWWA" "CLSVU6" "1KJ2MG" "CHK1ZX" #> [17] "321LLB" "T3QPW5" "B1WVCN" "01QRQ4" "0SGJ12" "5ERY5Z" "ZATMEE" "Y6DB6L" #> [25] "DHNQ1W" "TXZUKC" "N5QBWD" "SCFSBF" "WLMGS1" "0XTZQ1" "WNEAS6" "N79QXB" #> [33] "C18V6I" "5W621W" "2Z4YLY" #> #> [[3]] #> [1] "6MEP2C" "7B9CA6" "3YJIMV" "9P0DES" "1GF3GM" "3SKITJ" "S056D5" "PU7RSG" #> [9] "1QVS67" "AW400C" "FL170P" "Q7U139" "46ZHKN" "XYRDKV" "DCJJYS" "Y0TCYX" #> [17] "G8MCV7" "1SSCJC" "DH9WJQ" "30J3CQ" "HE0SCR" "BCJJKN" "JLFKV8" "TEACA3" #> [25] "Z904TJ" "LVYYNY" "5KWNMZ" "WJXIH9" "NK802Y" #> #> [[4]] #> [1] "A6A1M1" "0X4W26" "QW2Z3R" "5EDIEE" "N4NV8B" "1CZM30" "BS3RLE" "6F9FB8" #> [9] "414N7M" "LYSLPP" "KZY6PD" "D4B0RM" "W6MDVK" "K3TNHP" "FJS7RQ" "QCA36T" #> [17] "AP1YLW" "PVY432" "DRXMW4" "B134XZ" "XEC0M5" "EX5K0S" "GIIEUD" "ZH3YG1" #> [25] "MFKT9C" "MPIQ4N" "5EDLL7" "MTCAIG" "967Y3D" "QQMBT1" "IH1KPA" "38K2SR" #> [33] "7NE2UT" "MB6NYQ" "I8ABC7" #> #> [[5]] #> [1] "6KLWVC" "J3F6PD" "83HQBN" "5IAFMK" "I5CI33" "WKY2SZ" "6X6BG9" "ZPS15A" #> [9] "AZ3L0D" "D33J06" "GAS52W" "E5Q33K" "TYEWF1" "KX0RJ3" "7RA57Q" "MX4J7G" #> [17] "1VP3UC" "X694YR" "S3EBGZ" "72LYDE" "AIHJ8Z" "0HYZ23" "BKWE4D" "MYUMMX" #> [25] "W5WIRP" "M9PVG5" "1CIRC9" "XFWVVX" "Q8U9LB" "GCBYDW" #> #> [[6]] #> [1] "FTVE03" "13B1QL" "W0GUKI" "EZ2F8A" "AR17R5" "CRPXY7" "9MG040" "YTJ2UL" #> [9] "7ZNY75" "5BPBUI" "SH3FB7" "1FAZ0K" "QWKFBH" "AR5U44" "WK89I9" "TQEMY6" #> [17] "S222R3" "DKIM6U" "B228Q6" "LS184H" "VWC5ZH" "2F6J3U" "ESUIAF" "ZQXZYB" #> [25] "F45799" "G58RGY" "AFZKBS" "H2J6UA" "DI4AHD" #> #> [[7]] #> [1] NA #>
sexRatioGrp <- groupAddAssign(candidates = candidates, kmat = trimmedGeneticValue[["kinship"]], ped = trimmedPed, iter = 10, # should be >= 1000 numGp = 6, sexRatio = 9) sexRatioGrp$group
#> [[1]] #> [1] "JLFKV8" "PHB6TE" "VWC5ZH" "ESUIAF" "92UG4N" "N79QXB" "99BMJW" "967Y3D" #> [9] "0XTZQ1" "3DTD2N" "1CIRC9" "1VP3UC" "YLRNIK" "ZW2X4N" "X694YR" "S3EBGZ" #> [17] "9MG040" "C18V6I" "5W621W" "0IIAEN" "6X6BG9" "Y0TCYX" "FJS7RQ" "Q17CG3" #> [25] "KZM9RB" "G25E3F" "H2J6UA" "5IAFMK" "ILVQVB" "R5AYJK" "3SKITJ" "AZ3L0D" #> [33] "SHG3RB" "8JUUJ9" "KXHGRH" #> #> [[2]] #> [1] "6F9FB8" "ZDRSG0" "RJ4JPC" "PJ72W1" "MPIQ4N" "1SPLS8" "NN3GDQ" "LVYYNY" #> [9] "Z904TJ" "LS184H" "ZQXZYB" "DHNQ1W" "I8ABC7" "LN1DLY" "RVHVTZ" "1CZM30" #> [17] "321LLB" "EX5K0S" "MH88T6" "WJXIH9" "MTCAIG" "38K2SR" "XEC0M5" "465ERA" #> [25] "CFD12A" "QWKFBH" "XYRDKV" "I5CI33" "01QRQ4" #> #> [[3]] #> [1] "N4NV8B" "LMJWTN" "QQMBT1" "1KJ2MG" "DI4AHD" "1QVS67" "FL170P" "2F6J3U" #> [9] "S5H1GC" "6KWVRI" "F7I2ED" "30J3CQ" "DRXMW4" "9FRCIE" "ZH3YG1" "LYSLPP" #> [17] "1GF3GM" "DCJJYS" "7ZNY75" "5BPBUI" "S056D5" "S7IWWA" "SH3FB7" "MYUMMX" #> [25] "5KFB90" #> #> [[4]] #> [1] "46ZHKN" "Z7NBA2" "83HQBN" "7B9CA6" "DH9WJQ" "WI38KZ" "PI4VHT" "BS3RLE" #> [9] "72LYDE" "BKWE4D" "AFZKBS" "GTLA8R" "1FAZ0K" "A6A1M1" "QCENKM" "D4B0RM" #> [17] "AR5U44" "CHK1ZX" "GAS52W" "ZPS15A" "GIIEUD" "KZY6PD" "N5QBWD" "EMV4P6" #> [25] "A98D7P" #> #> [[5]] #> [1] "TYEWF1" "3QHAFI" "XFWVVX" "AIHJ8Z" "AR17R5" "PU7RSG" "QRZK48" "5EDLL7" #> [9] "QW2Z3R" "13B1QL" "50D77I" "WNEAS6" "CRPXY7" "K7900I" "PVY432" "W6MDVK" #> [17] "1SSCJC" "IH1KPA" "M9PVG5" "G8MCV7" "WKY2SZ" "MKY9TK" "414N7M" "7RA57Q" #> [25] "R6HV9A" #> #> [[6]] #> [1] "D33J06" "G2GYST" "Q8U9LB" "B1WVCN" "W5WIRP" "AP1YLW" "F45799" "7NE2UT" #> [9] "QCA36T" "Q7U139" "NK802Y" "0X4W26" "TQEMY6" "JSAP3H" "MX4J7G" "9P0DES" #> [17] "E5Q33K" "5ERY5Z" "WLMGS1" "B134XZ" "CMMUKU" "B228Q6" "0HYZ23" "W0GUKI" #> [25] "T38W6H" "ZATMEE" #> #> [[7]] #> [1] "WTE53B" "CLSVU6" "HLQ9SY" "B2CKHA" "BCJJKN" "DKIM6U" "FB5L3N" "GCBYDW" #> [9] "GDXWJ1" "MB6NYQ" "TR5L57" "WK89I9" "XC304E" "1E8KD1" "5PW7WT" "AEP5EG" #> [17] "AW400C" "BW10CL" "CHJ9D2" "D9P18Y" "EZ2F8A" "FTVE03" "IRFJ09" "J3F6PD" #> [25] "PBAFJF" "Q9LWGX" "RNQU14" "S222R3" "SCFSBF" "TEACA3" "09LFE4" "3GECJJ" #> [33] "3MMZD4" "55BPSE" "5XVTVH" "8IG767" "ER464J" "FFGPS4" "FG6L7S" "HE0SCR" #> [41] "NHWTJ9" "P7RBPI" "TBCE78" "YFCIHJ" "YI16QD" "2F1IV1" "2Z4YLY" "3YJIMV" #> [49] "4LHK19" "59NYZE" "5EDIEE" "5IYDXN" "6KLWVC" "80F2MI" "8TV4MT" "AZ4D19" #> [57] "BTTHAJ" "CHSCFG" "DPXEQE" "EEGLWY" "FG0SFA" "FX9E4X" "G58RGY" "G91ZM6" #> [65] "J1R2EW" "K3TNHP" "KX0RJ3" "LDND6J" "MFKT9C" "MQT080" "NSIC4I" "PYPM1W" #> [73] "QRWYQZ" "RY1AZM" "TXZUKC" "WHQLH5" "WQUN84" "XL658N" "XX0GYV" "YHHVC7" #> [81] "YP910X" "YTJ2UL" "0SGJ12" "0V4SAC" "0X1RZ9" "3YHBC1" "55VDSQ" "5KWNMZ" #> [89] "653J82" "6MEP2C" "76DIT4" "80KACX" "87AQLF" "B2YJJP" "CS23RV" "E3JP0C" #> [97] "FLIZQI" "GM371F" "IZDV8K" "KEA4QG" "MEUZ85" "PA9F3J" "SXSVEH" "T3QPW5" #> [105] "TJN1AD" "WNKKW3" "XY2CK7" "XZH41H" "Y6DB6L" "YDRD81" "Z25D52" "3P9BX6" #> [113] "7D09WH" "DGZLV3" "S63QDN" #>
# }