Package: BGmisc 1.8.0

S. Mason Garrison

BGmisc: An R Package for Extended Behavior Genetics Analysis

Provides functions for behavior genetics analysis, including variance component model identification [Hunter et al. (2021) <doi:10.1007/s10519-021-10055-x>], calculation of relatedness coefficients using path-tracing methods [Wright (1922) <doi:10.1086/279872>; McArdle & McDonald (1984) <doi:10.1111/j.2044-8317.1984.tb00802.x>], inference of relatedness, pedigree conversion, and simulation of multi-generational family data [Lyu et al. (2025) <doi:10.1007/s10519-025-10225-1>]. For a full overview, see [Garrison et al. (2024) <doi:10.21105/joss.06203>]. For a big data application see [Burt et al. (2025) <doi:10.1016/j.ebiom.2025.105911>].

Authors:S. Mason Garrison [aut, cre], Michael D. Hunter [aut], Xuanyu Lyu [aut], Rachel N. Good [ctb], Jonathan D. Trattner [aut], S. Alexandra Burt [aut]

BGmisc_1.8.0.tar.gz
BGmisc_1.8.0.zip(r-4.7)BGmisc_1.8.0.zip(r-4.6)BGmisc_1.8.0.zip(r-4.5)
BGmisc_1.8.0.tgz(r-4.6-any)BGmisc_1.8.0.tgz(r-4.5-any)
BGmisc_1.8.0.tar.gz(r-4.7-any)BGmisc_1.8.0.tar.gz(r-4.6-any)
BGmisc_1.8.0.tgz(r-4.6-emscripten)
manual.pdf |manual.html
DESCRIPTION |NEWS
card.svg |card.png
BGmisc/json (API)

# Install 'BGmisc' in R:
install.packages('BGmisc', repos = c('https://r-computing-lab.r-universe.dev', 'https://cloud.r-project.org'))

Bug tracker:https://github.com/r-computing-lab/bgmisc/issues

Pkgdown/docs site:https://r-computing-lab.github.io

Datasets:
  • hazard - Simulated pedigree with two extended families and an age-related hazard
  • inbreeding - Artificial pedigree data on eight families with inbreeding
  • potter - Fictional pedigree data on a wizarding family
  • royal92 - Royal pedigree data from 1992

On CRAN:

Conda:

behavior-genetics

8.99 score 3 stars 1 packages 137 scripts 1.1k downloads 70 exports 14 dependencies

Last updated from:f08cbe64cf. Checks:9 OK. Indexed: yes.

TargetResultTimeFilesSyslog
linux-devel-x86_64OK252
source / vignettesOK307
linux-release-x86_64OK240
macos-release-arm64OK122
macos-oldrel-arm64OK128
windows-develOK239
windows-releaseOK201
windows-oldrelOK186
wasm-releaseOK147

Exports:addPersonToPedalignPhenToMatrixbuildFamilyGroupsbuildOneFamilyGroupbuildPedigreeModelCovariancebuildPedigreeMxbuildTreeGridcalcAllGenscalcFamilySizecalculateCIscalculateRelatednesscheckIDscheckParentIDscheckPedigreeNetworkcheckSexcom2linkscomp2vechcomputeParentAdjacencycreateGenDataFramedetermineSexdropLinkfindLeavesfitComponentModelfitPedigreeModelgetGenDistgetWikiTreeSummaryidentifyComponentModelinferRelatednessmakeInbreedingmakeTwinsped2addped2addFocalped2ceped2cnped2cnFocalped2comped2famped2focalped2genped2genDistped2genDistFocalped2genFocalped2graphped2maternalped2mitped2mitFocalped2paternalreadGedreadgedcomreadGedcomreadWikifamilytreerecodeSexrelated_coefrepairIDsrepairSexSimPedsimulatePedigreesimulatePedigreessliceFamiliessummariseFamiliessummariseMatrilinessummarisePatrilinessummarisePedigreessummarizeFamiliessummarizeMatrilinessummarizePatrilinessummarizePedigreestraceTreePathstrimPedigreevech

Dependencies:clicpp11data.tableglueigraphlatticelifecyclemagrittrMatrixpkgconfigrlangstringistringrvctrs

Fitting Pedigree-Based Variance Component Models
Introduction | Prerequisites | Data Requirements at a Glance | Pedigree data frame | Relatedness matrices | Phenotype data format | Missing phenotypes | Part 1: Single-Family Model | Step 1: Subset to one family and inspect | Step 2: Compute relatedness matrices | Step 3: Prepare the phenotype data | Step 4: Subset matrices to observed individuals | Step 5: Check model identification | Step 6: Build and fit the model | Part 2: Two-Family Multi-Group Model | Family 2: matrices | Family 2: phenotype data | Family 2: subset matrices | Check identification across both families | Build and fit the two-family model | Part 3: Scaling Up — Many Families and Parameter Recovery | Simulate pedigrees and data | Build and fit the multi-family model | Compare estimates to true values | Using the high-level wrapper | Understanding the Covariance Structure | Summary

Last update: 2026-06-02
Started: 2026-03-31

Pedigree Simulation and Visualization with BGmisc
Introduction | Summarizing Pedigrees | Plotting Pedigree | Single Pedigree Visualization | Visualizing Multiple Pedigrees Side-by-Side

Last update: 2026-05-27
Started: 2025-05-29

Understanding and Computing Relatedness from Pedigree Data
Introduction | Relatedness Coefficient | Inferring r from Observed Phenotypic Correlation | Computing Relatedness from Pedigree Data | Hazard Data Example | Introducing Missingness: Remove a Parent | Removing the Father Instead | Inbreeding Dataset: Family-Level Evaluation | Example: Family r famIDs[1] | Summary

Last update: 2026-04-01
Started: 2025-05-29

Modeling variance components
Introduction | Loading Required Libraries | Working with Variance Component Models | Using comp2vech Function | Using identifyComponentModel Function | Extended Pedigrees

Last update: 2026-04-01
Started: 2025-05-29

ASOIAF: How related are Jon and Danny?
Introduction | Load Packages and Data | Prepare and Validate Sex Codes | Compute Relatedness Matrices | Convert to Pairwise Format | Locate Jon and Daenerys | Plotting the Pedigree with Incomplete Parental Information | Visualize the Pedigree | Conclusion

Last update: 2026-02-19
Started: 2025-05-29

Network tools for finding extended pedigrees and path tracing
Introduction | Loading Required Libraries and Data | Finding Extended Families | Computing Relatedness | Other relatedness measures | Computing mitochondrial relatedness | Computing relatedness through common nuclear environment | Computing relatedness through common extended family environment | Subsetting Pedigrees

Last update: 2026-02-19
Started: 2025-05-29

Validating and Repairing Pedigree Data with BGmisc
Introduction | Identifying and Repairing ID Issues | A Clean Dataset | What checkIDs() Reports | A Tale of Two Duplicates | Repairing Between-Row Duplicates | Oedipus ID | Identifying and Repairing Sex Coding Issues | Best Practices for Pedigree Validation

Last update: 2026-01-08
Started: 2025-05-29

Readme and manuals

Help Manual

Help pageTopics
Construct Adjacency Matrix for Parent-Child Relationships Using Beta Methods This function constructs an adjacency matrix for parent-child relationships using a method in beta testing. It identifies parent-child pairs based on the specified component of relatedness..adjBeta
Construct Adjacency Matrix for Parent-Child Relationships Using Direct Method.adjDirect
Construct Adjacency Matrix for Parent-Child Relationships Using Indexed Method.adjIndexed
Assign parent values based on component type.assignParentValue
Compute the transpose multiplication for the relatedness matrix.computeTranspose
Load or compute the isChild matrix.loadOrComputeIsChild
Post-process GEDCOM Data Frame.postProcessGedcom.legacy
Create a properly formatted parent row for the pedigreeaddParentRow
addPersonToPedaddPersonToPed
Add addRowlessParentsaddRowlessParents
Align Phenotype Vector to Matrix Format for OpenMxalignPhenToMatrix
Apply Tag Mappings to a LineapplyTagMappings
Process Generation ConnectionsbuildBtwnGenerations
Build family group modelsbuildFamilyGroups
Build one family group modelbuildOneFamilyGroup
Create an mxModel for a pedigreebuildPedigreeModelCovariance
Build Pedigree mxModelbuildPedigreeMx
Process Generations for Pedigree SimulationbuildWithinGenerations
calcAllGens A function to calculate the number of individuals in each generation. This is a supporting function for 'simulatePedigree'.allGens calcAllGens
calcFamilySize A function to calculate the total number of individuals in a pedigree given parameters. This is a supporting function for function 'simulatePedigree'calcFamilySize famSizeCal
calcFamilySizeByGen An internal supporting function for 'simulatePedigree'.calcFamilySizeByGen sizeAllGens
Confidence Intervals for Correlations with Optional Design-Effect AdjustmentcalculateCIs
Falconer's FormulacalculateH
Calculate Relatedness CoefficientcalculateRelatedness related_coef
Validates and Optionally Repairs Unique IDs in a Pedigree DataframecheckIDs
Check for duplicated individual IDscheckIDuniqueness
Validates and Optionally Repairs Parent IDs in a Pedigree DataframecheckParentIDs
Check Parental Role Sex ConsistencycheckParentSex
Validate Pedigree Network StructurecheckPedigreeNetwork
Validates and Optionally Repairs Sex Coding in a Pedigree DataframecheckSex
Check for within-row duplicates (self-parents, same mom/dad)checkWithinRowDuplicates
collapse NamescollapseNames
Convert Sparse Relationship Matrices to Kinship Linkscom2links
comp2vech Turn a variance component relatedness matrix into its half-vectorizationcomp2vech
Compute Parent Adjacency Matrix with Multiple ApproachescomputeParentAdjacency
Condense Matrix Slots in an OpenMx ModelcondenseMatrixSlots
Count GEDCOM Pattern RowscountPatternRows
Create Data Frame for GenerationcreateGenDataFrame createGenDataFrame_beta
Determine Sex of OffspringdetermineSex determineSex_beta
Drop Identical Duplicate IDs from Pedigree Data FramedropIdenticalDuplicateIDs
dropLinkdropLink
Function to find the biggest families in a pedigree This function finds the biggest families in a pedigree. It is supposed to be used internally by the 'summarize_pedigree' function.findBiggest findbiggest
Find Leaf Nodes in a PedigreefindLeaves
Function to find the oldest individuals in a pedigree This function finds the oldest families in a pedigree. It is supposed to be used internally by the 'summarize_pedigree' function.findOldest findoldest
fitComponentModel Fit the estimated variance components of a model to covariance datafitComponentModel
Fit an OpenMx pedigree model to observed datafitPedigreeModel
Fuse MZ twin pairs in a pedigree dataset for path tracing This function identifies MZ twin pairs in the pedigree dataset and merges their IDs for path tracing purposes. The second twin in each pair is made a founder (with NA parents), and all children of the second twin are redirected to the first twin. This allows for correct relatedness calculations without diagonal or downstream artifacts.fuseTwins
Compute the generational distance between two individualsgetGenDist
Simulated pedigree with two extended families and an age-related hazardhazard
identifyComponentModel Determine if a variance components model is identifiedidentifyComponentModel
Artificial pedigree data on eight families with inbreedinginbreeding
Initialize an Empty Individual RecordinitializeRecord
evenInsert A function to insert m elements evenly into a length n vector.evenInsert insertEven
makeInbreedingmakeInbreeding
makeTwinsmakeTwins
Create a Mapping from Family IDs to Parent IDsmapFAMS2parents
Mark and Assign childrenmarkPotentialChildren markPotentialChildren_beta
Parse Name LineparseNameLine
Take a pedigree and turn it into an additive genetics relatedness matrixped2add
Add a focal-person additive relatedness column to a pedigreeped2addFocal
Take a pedigree and turn it into an extended environmental relatedness matrixped2ce
Take a pedigree and turn it into a common nuclear environmental matrixped2cn
Add a focal-person common nuclear relatedness column to a pedigreeped2cnFocal
Take a pedigree and turn it into a relatedness matrixped2com
Segment Pedigree into Extended Familiesped2fam
Compute relatedness between all individuals and a focal personped2focal
Take a pedigree and turn it into a generation relatedness matrix. It computes the rank of the generation matrix, which is the number of generations separating two individualsped2gen
Compute a full pairwise generational distance matrixped2genDist
Compute generational distances from a focal individual to all othersped2genDistFocal
Add a focal-person generation relatedness column to a pedigree. It computes the rank of the generation matrix, which is the number of generations separating two individualsped2genFocal
Turn a pedigree into a graphped2graph
Add a maternal line ID variable to a pedigreeped2maternal
Take a pedigree and turn it into a mitochondrial relatedness matrixped2mit ped2mt
Add a focal-person mitochondrial relatedness column to a pedigreeped2mitFocal ped2mtFocal
Add a paternal line ID variable to a pedigreeped2paternal
Post-process GEDCOM Data FramepostProcessGedcom
Fictional pedigree data on a wizarding familypotter
Function to prepare the pedigree for summarization This function prepares the pedigree for summarization by ensuring that the necessary IDs are present and that the pedigree is built correctly.prepSummarizePedigrees
Process Event Lines (Birth or Death)processEventLine
Process Parents Information from GEDCOM DataprocessParents
Read a GEDCOM FilereadGed readGedcom readgedcom
Read Wiki Family TreereadWikifamilytree
Recodes Sex Variable in a Pedigree DataframerecodeSex
Repair Missing IDsrepairIDs
Repair Parent IDsrepairParentIDs
Repairs Sex Coding in a Pedigree DataframerepairSex
Restore Original Column Names in a Pedigree DataframerestorePedColnames
Royal pedigree data from 1992royal92
Simulate Pedigrees 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.SimPed simulatePedigree
Simulate Multiple PedigreessimulatePedigrees
sliceFamiliessliceFamilies
Summarize the families in a pedigreesummariseFamilies summarisefamilies summarizeFamilies summarizefamilies
Summarize the maternal lines in a pedigreesummariseMatrilines summarisematrilines summarizeMatrilines summarizematrilines
Summarize the paternal lines in a pedigreesummarisePatrilines summarisepatrilines summarizePatrilines summarizepatrilines
Summarize Pedigree DatasummarisePedigrees summarisepedigrees summarizePedigrees summarizepedigrees
Trace paths between individuals in a family tree gridtraceTreePaths
Iteratively Trim Leaf Nodes from a PedigreetrimPedigree
validate_and_convert_matrixvalidate_and_convert_matrix
vech Create the half-vectorization of a matrixvech