
Add animals to an existing breeding group or forms groups:
Source:R/groupAddAssign.R
groupAddAssign.Rd
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.
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 withincandidates
.- 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 incandidates
.- 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 leastminAge
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.
Examples
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] "NSIC4I" "TXZUKC" "CMMUKU" "PJ72W1" "D9P18Y" "GAS52W" "87AQLF" "DPXEQE"
#> [9] "DRXMW4" "WI38KZ" "92UG4N" "0IIAEN" "CS23RV" "YTJ2UL" "EMV4P6" "MH88T6"
#> [17] "QCENKM" "G25E3F" "NN3GDQ" "7NE2UT" "BKWE4D" "6KWVRI" "WTE53B" "3DTD2N"
#> [25] "1QVS67" "PVY432" "QWKFBH" "1VP3UC" "S5H1GC" "N79QXB" "1SPLS8"
#>
#> [[2]]
#> [1] "3MMZD4" "GIIEUD" "NK802Y" "QQMBT1" "F7I2ED" "HE0SCR" "Q7U139" "465ERA"
#> [9] "PI4VHT" "RVHVTZ" "FB5L3N" "QRZK48" "99BMJW" "3GECJJ" "PYPM1W" "S7IWWA"
#> [17] "CLSVU6" "1GF3GM" "CHK1ZX" "AR5U44" "WJXIH9" "9MG040" "01QRQ4" "0SGJ12"
#> [25] "50D77I" "WK89I9" "Y6DB6L" "B1WVCN" "Q17CG3" "N4NV8B" "SCFSBF" "W6MDVK"
#> [33] "0XTZQ1" "XYRDKV" "ILVQVB" "EX5K0S" "5W621W"
#>
#> [[3]]
#> [1] "FTVE03" "M9PVG5" "7B9CA6" "5EDIEE" "9P0DES" "1KJ2MG" "3SKITJ" "SHG3RB"
#> [9] "PU7RSG" "ZATMEE" "5ERY5Z" "F45799" "QW2Z3R" "46ZHKN" "YLRNIK" "DCJJYS"
#> [17] "ZPS15A" "G8MCV7" "0HYZ23" "DH9WJQ" "30J3CQ" "H2J6UA" "BCJJKN" "JLFKV8"
#> [25] "W5WIRP" "ZQXZYB" "IH1KPA" "5KWNMZ" "T3QPW5" "MTCAIG"
#>
#> [[4]]
#> [1] "XZH41H" "13B1QL" "S056D5" "3YJIMV" "N5QBWD" "1CZM30" "BS3RLE" "6F9FB8"
#> [9] "414N7M" "LYSLPP" "KZY6PD" "D4B0RM" "WLMGS1" "K3TNHP" "FJS7RQ" "QCA36T"
#> [17] "AP1YLW" "Q8U9LB" "DI4AHD" "B134XZ" "XEC0M5" "C18V6I" "G58RGY" "ZH3YG1"
#> [25] "MFKT9C" "MPIQ4N" "5EDLL7" "MKY9TK" "967Y3D" "FL170P" "GCBYDW" "38K2SR"
#> [33] "2Z4YLY"
#>
#> [[5]]
#> [1] "BW10CL" "R5AYJK" "AW400C" "J3F6PD" "83HQBN" "5IAFMK" "I5CI33" "WKY2SZ"
#> [9] "6X6BG9" "Y0TCYX" "AZ3L0D" "D33J06" "KEA4QG" "E5Q33K" "TYEWF1" "KX0RJ3"
#> [17] "7RA57Q" "MYUMMX" "1SSCJC" "X694YR" "S3EBGZ" "72LYDE" "AIHJ8Z" "YFCIHJ"
#> [25] "GTLA8R" "PBAFJF" "TEACA3" "LVYYNY" "MX4J7G" "DKIM6U"
#>
#> [[6]]
#> [1] "NHWTJ9" "1CIRC9" "W0GUKI" "EZ2F8A" "AR17R5" "CRPXY7" "8JUUJ9" "Z904TJ"
#> [9] "7ZNY75" "5BPBUI" "RJ4JPC" "1FAZ0K" "MB6NYQ" "321LLB" "SH3FB7" "TQEMY6"
#> [17] "S222R3" "B228Q6" "XFWVVX" "LS184H" "VWC5ZH" "2F6J3U" "ESUIAF" "WNEAS6"
#> [25] "I8ABC7" "DHNQ1W" "0X4W26" "AFZKBS" "FG0SFA"
#>
#> [[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] "RJ4JPC" "A6A1M1" "WKY2SZ" "N5QBWD" "EMV4P6" "8JUUJ9" "FJS7RQ" "PI4VHT"
#> [9] "X694YR" "I5CI33" "967Y3D" "B228Q6" "6X6BG9" "JSAP3H" "414N7M" "DPXEQE"
#> [17] "SCFSBF" "5EDIEE" "G58RGY" "KZY6PD" "QRZK48" "M9PVG5" "1SSCJC" "DH9WJQ"
#> [25] "3MMZD4" "QCENKM" "C18V6I" "CMMUKU" "0X4W26" "6KWVRI"
#>
#> [[2]]
#> [1] "FL170P" "FFGPS4" "QQMBT1" "TXZUKC" "WNEAS6" "FG0SFA" "N79QXB" "S3EBGZ"
#> [9] "XEC0M5" "1KJ2MG" "MB6NYQ" "GCBYDW" "92UG4N" "SXSVEH" "CRPXY7" "WTE53B"
#> [17] "5ERY5Z" "2Z4YLY" "MFKT9C" "PYPM1W" "JLFKV8" "ZPS15A" "EZ2F8A" "9MG040"
#> [25] "K7900I" "TYEWF1" "W6MDVK" "87AQLF" "AIHJ8Z" "WK89I9" "0XTZQ1" "6F9FB8"
#> [33] "S7IWWA" "GIIEUD" "9FRCIE"
#>
#> [[3]]
#> [1] "LYSLPP" "BW10CL" "321LLB" "DCJJYS" "46ZHKN" "WI38KZ" "N4NV8B" "T3QPW5"
#> [9] "PBAFJF" "BKWE4D" "B134XZ" "VWC5ZH" "S056D5" "XX0GYV" "IH1KPA" "QWKFBH"
#> [17] "FB5L3N" "D4B0RM" "ILVQVB" "BS3RLE" "DI4AHD" "Q17CG3" "1GF3GM" "5BPBUI"
#> [25] "R6HV9A" "GTLA8R"
#>
#> [[4]]
#> [1] "50D77I" "XZH41H" "3GECJJ" "0HYZ23" "SHG3RB" "YTJ2UL" "Y6DB6L" "38K2SR"
#> [9] "3SKITJ" "AW400C" "YFCIHJ" "MYUMMX" "1VP3UC" "AZ4D19" "1SPLS8" "ESUIAF"
#> [17] "7NE2UT" "CLSVU6" "TQEMY6" "HE0SCR" "SH3FB7" "BCJJKN" "R5AYJK" "Q8U9LB"
#> [25] "IZDV8K" "ZATMEE" "Y0TCYX" "F45799" "W0GUKI" "7B9CA6"
#>
#> [[5]]
#> [1] "72LYDE" "G2GYST" "AZ3L0D" "MKY9TK" "MPIQ4N" "7RA57Q" "WLMGS1" "13B1QL"
#> [9] "B1WVCN" "1CZM30" "D9P18Y" "83HQBN" "S5H1GC" "KXHGRH" "LS184H" "YLRNIK"
#> [17] "5IAFMK" "Q7U139" "MH88T6" "I8ABC7" "01QRQ4" "PU7RSG" "ZH3YG1" "0IIAEN"
#> [25] "GDXWJ1" "AR17R5" "F7I2ED" "S222R3" "AR5U44" "E5Q33K" "LVYYNY" "99BMJW"
#> [33] "QW2Z3R" "WJXIH9" "NHWTJ9"
#>
#> [[6]]
#> [1] "EX5K0S" "1E8KD1" "G25E3F" "5EDLL7" "QCA36T" "J3F6PD" "30J3CQ" "3YJIMV"
#> [9] "AFZKBS" "NN3GDQ" "CS23RV" "7ZNY75" "W5WIRP" "4LHK19" "K3TNHP" "5W621W"
#> [17] "DHNQ1W" "5KWNMZ" "3DTD2N" "G8MCV7" "MX4J7G" "ZQXZYB" "DKIM6U" "D33J06"
#> [25] "KZM9RB" "2F6J3U"
#>
#> [[7]]
#> [1] "HLQ9SY" "XFWVVX" "B2CKHA" "TR5L57" "XC304E" "Z7NBA2" "1QVS67" "5KFB90"
#> [9] "5PW7WT" "AEP5EG" "CFD12A" "CHJ9D2" "FTVE03" "IRFJ09" "LMJWTN" "PVY432"
#> [17] "Q9LWGX" "RNQU14" "TEACA3" "09LFE4" "1CIRC9" "3QHAFI" "55BPSE" "5XVTVH"
#> [25] "8IG767" "ER464J" "FG6L7S" "H2J6UA" "P7RBPI" "RVHVTZ" "TBCE78" "YI16QD"
#> [33] "1FAZ0K" "2F1IV1" "59NYZE" "5IYDXN" "6KLWVC" "80F2MI" "8TV4MT" "A98D7P"
#> [41] "BTTHAJ" "CHK1ZX" "CHSCFG" "DRXMW4" "EEGLWY" "FX9E4X" "G91ZM6" "J1R2EW"
#> [49] "KX0RJ3" "LDND6J" "LN1DLY" "MQT080" "MTCAIG" "NK802Y" "NSIC4I" "PHB6TE"
#> [57] "PJ72W1" "QRWYQZ" "RY1AZM" "WHQLH5" "WQUN84" "XL658N" "XYRDKV" "YHHVC7"
#> [65] "YP910X" "Z904TJ" "0SGJ12" "0V4SAC" "0X1RZ9" "3YHBC1" "465ERA" "55VDSQ"
#> [73] "653J82" "6MEP2C" "76DIT4" "80KACX" "9P0DES" "AP1YLW" "B2YJJP" "E3JP0C"
#> [81] "FLIZQI" "GAS52W" "GM371F" "KEA4QG" "MEUZ85" "PA9F3J" "T38W6H" "TJN1AD"
#> [89] "WNKKW3" "XY2CK7" "YDRD81" "Z25D52" "ZDRSG0" "3P9BX6" "7D09WH" "DGZLV3"
#> [97] "S63QDN" "ZW2X4N"
#>