Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8a1aadf
cran prep
smasongarrison Jan 7, 2026
6fdd2d3
Merge branch 'main' into dev_main
smasongarrison Jan 9, 2026
e1b35b8
Merge branch 'main' into dev_main
smasongarrison Jan 14, 2026
d8ea03d
Update buildComponent.R
smasongarrison Jan 23, 2026
385c01f
Rename helpPedigree.R to helpSimulatePedigree.R
smasongarrison Jan 23, 2026
18ff0e5
Optimize simulatePedigree within-generation logic
smasongarrison Jan 23, 2026
e5988bb
Update simulatePedigree.R
smasongarrison Jan 23, 2026
d6bbd71
DOC
smasongarrison Jan 23, 2026
f738092
Update simulatePedigree.R
smasongarrison Jan 24, 2026
3395da9
build in tests of optimized version
smasongarrison Jan 24, 2026
4f48947
Improve pedigree simulation and update benchmarks
smasongarrison Jan 24, 2026
f2344fc
Refactor pedigree simulation and add within-generation module
smasongarrison Jan 24, 2026
e442af0
Refactor and optimize pedigree simulation functions
smasongarrison Jan 25, 2026
e631152
Remove unimplemented 'indexed' beta option and improve tests
smasongarrison Jan 25, 2026
bbd4cfc
more resiliant
smasongarrison Jan 25, 2026
686bb9a
Optimize generation indexing in buildBetweenGenerations
smasongarrison Jan 25, 2026
1fee960
Refactor pedigree simulation functions for clarity
smasongarrison Jan 26, 2026
f4fbb4a
Refactor and optimize buildBetweenGenerations_optimized
smasongarrison Jan 27, 2026
538d2ee
Create benchmarkng nopointers.png
smasongarrison Jan 27, 2026
57784cf
Refactor and simplify pedigree simulation functions
smasongarrison Jan 27, 2026
50abd37
Add beta (optimized) versions of pedigree helper functions
smasongarrison Jan 27, 2026
c7b5a82
Refactor pedigree simulation helpers and add family ID prefix
smasongarrison Jan 27, 2026
99d4653
Refactor pedigree simulation helpers and add family ID prefix
smasongarrison Jan 27, 2026
0c54b00
Merge branch 'dev_main' of https://github.com/R-Computing-Lab/BGmisc …
smasongarrison Jan 27, 2026
06ca022
move
smasongarrison Jan 27, 2026
3ab04ac
Apply suggestions from code review
smasongarrison Jan 27, 2026
07a139a
Update markPotentialChildren.Rd
smasongarrison Jan 27, 2026
109e55c
Simplify documentation and enhance pedigree tests
smasongarrison Jan 28, 2026
7ee37c3
Normalize beta parameter string aliases before calling downstream fun…
Copilot Jan 28, 2026
d999d18
stylr
smasongarrison Jan 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: BGmisc
Title: An R Package for Extended Behavior Genetics Analysis
Version: 1.5.2
Version: 1.6.0
Authors@R: c(
person("S. Mason", "Garrison", , "garrissm@wfu.edu", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-4804-6003")),
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# BGmisc NEWS

# BGmisc 1.6
* Optimize simulatePedigree and helpers for speed and memory usage
* Major gains in speed for deeper pedigrees
* Added more tests for simulatePedigree
* Fix error when not enough single people available

# BGmisc 1.5.2
* More flexible ID generation for simulatePedigree
* Created ped2gen function to extract generation information from pedigree data.frames
Expand Down
26 changes: 19 additions & 7 deletions R/buildComponent.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#' Take a pedigree and turn it into a relatedness matrix
#' @param ped a pedigree dataset. Needs ID, momID, and dadID columns
#' @param component character. Which component of the pedigree to return. See Details.
#' @param max_gen the maximum number of generations to compute
#' (e.g., only up to 4th degree relatives). The default is 25. However it can be set to infinity.
#' `Inf` uses as many generations as there are in the data.
#' @param max_gen the maximum number of iterations that the adjacency matrix is multiplied to get the relatedness matrix. `Inf` uses as many iterations as there are in the data. Defaults to 25.
#' @param sparse logical. If TRUE, use and return sparse matrices from Matrix package
#' @param verbose logical. If TRUE, print progress through stages of algorithm
#' @param update_rate numeric. The rate at which to print progress
Expand Down Expand Up @@ -100,17 +98,22 @@ ped2com <- function(ped, component,
"tcrossprod", "crossprod", "star",
"tcross.alt.crossprod", "tcross.alt.star"
)

if (!config$transpose_method %in% transpose_method_options) {
stop(paste0(
"Invalid method specified. Choose from ",
paste(transpose_method_options, collapse = ", "), "."
))
}


if (!config$adjacency_method %in%
c("indexed", "loop", "direct", "beta")) {
stop("Invalid method specified. Choose from 'indexed', 'loop', 'direct', or 'beta'.")
# Validate the 'adjacency_method' argument
adjacency_method_options <- c("indexed", "loop", "direct", "beta")
if (!config$adjacency_method %in% adjacency_method_options
) {
stop(paste0(
"Invalid method specified. Choose from ",
paste(adjacency_method_options, collapse = ", "), "."
))
}

# standardize colnames
Expand Down Expand Up @@ -215,12 +218,21 @@ ped2com <- function(ped, component,
count <- 0
}
maxCount <- config$max_gen + 1

if (config$verbose == TRUE) {
cat("About to do RAM path tracing\n")
}

# r is I + A + A^2 + ... = (I-A)^-1 from RAM
# could trim, here
## it keeps going until it explains all of the relatedness with themselves (i.e., mtSum == 0)
# some of this precision is articifuial because we literally get to the point that the condon is eaither there or not. probabiliticy

# how much percision do we need to get unbiased estimates

# big matrix still happens here because the network is built. just less percise on inbreeding

# bias-precision tradeoff. how much percision do we need to get unbiased estimates? not a lot
Comment on lines 222 to +235
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These newly added inline comments are hard to parse and contain multiple spelling errors, which makes the algorithm rationale unclear. Please rewrite or remove them (keeping only a concise explanation of the stopping criterion and precision tradeoff).

Suggested change
# r is I + A + A^2 + ... = (I-A)^-1 from RAM
# could trim, here
## it keeps going until it explains all of the relatedness with themselves (i.e., mtSum == 0)
# some of this precision is articifuial because we literally get to the point that the condon is eaither there or not. probabiliticy
# how much percision do we need to get unbiased estimates
# big matrix still happens here because the network is built. just less percise on inbreeding
# bias-precision tradeoff. how much percision do we need to get unbiased estimates? not a lot
# r accumulates I + A + A^2 + ... ≈ (I - A)^-1 from RAM path tracing
# Iterate until no additional relatedness is contributed (mtSum == 0) or max_gen is reached.
# max_gen controls the bias–precision tradeoff: larger values give more precise but more expensive estimates.

Copilot uses AI. Check for mistakes.
while (mtSum != 0 && count < maxCount) {
r <- r + newIsPar
gen <- gen + (Matrix::rowSums(newIsPar) > 0)
Expand Down
196 changes: 0 additions & 196 deletions R/helpPedigree.R

This file was deleted.

Loading
Loading