Remove unnecessary columns before building model objects to reduce memory usage#46
Conversation
Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
|
@copilot 代码需要优化,变量提取有问题 报错代码是: 对 term (变量组合)的处理不够 |
|
@copilot 很明显 necessary_vars 要进行 unlist 处理 |
Fix issue in merge_vars() function where sapply() was returning a list instead of character vector when processing complex terms like "disp*hp". The issue occurred because sapply() returns a list when results have different lengths. Changed to call get_vars() on entire vector at once instead of element by element. Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
... Fixed the variable extraction issue in commit 9bb8383. The problem was in the |
…ion" This reverts commit 9bb8383.
... Fixed the issue by adding |
This PR implements an optimization to significantly reduce memory usage when working with datasets containing many columns that are not used in the regression models.
Problem
Previously, when using
bregrwith datasets containing many columns, each individual model object would store the entire dataset, including all unused columns. This led to substantial memory overhead, especially when running batch regression with many focal variables.For example, with a dataset containing 100+ columns but only using 4 for modeling, each model object would unnecessarily store all 100+ columns, resulting in memory usage that scales poorly with dataset width.
Solution
The optimization works by:
Identifying necessary columns: Before model construction, the system now identifies which columns are actually needed based on:
y)x)x2)Data subsetting: Only the necessary columns are passed to individual model construction, while the original full dataset is preserved in the main
bregobject for potential reuse.Smart variable extraction: Uses existing utility functions (
get_vars(),merge_vars()) to properly extract variable names from complex modeling terms likepoly(x, 2)or interaction terms likedisp*hp.Results
x*y), polynomial terms (poly(x, 2)), and other complex modeling expressionsExample
The optimization provides substantial memory savings when working with wide datasets containing many unused columns, which is common in real-world genomics, survey, and other high-dimensional data analysis scenarios.
Fixes #45.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.