{"id":28423878,"url":"https://github.com/bbuchsbaum/hrfals","last_synced_at":"2025-10-18T00:38:16.100Z","repository":{"id":295534032,"uuid":"990362304","full_name":"bbuchsbaum/hrfals","owner":"bbuchsbaum","description":null,"archived":false,"fork":false,"pushed_at":"2025-06-21T17:05:49.000Z","size":3079,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-21T18:22:32.253Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bbuchsbaum.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-26T02:17:02.000Z","updated_at":"2025-06-21T17:05:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"b181b04a-03a5-4d4b-a523-58577573f6b6","html_url":"https://github.com/bbuchsbaum/hrfals","commit_stats":null,"previous_names":["bbuchsbaum/hrfals"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bbuchsbaum/hrfals","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbuchsbaum%2Fhrfals","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbuchsbaum%2Fhrfals/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbuchsbaum%2Fhrfals/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbuchsbaum%2Fhrfals/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bbuchsbaum","download_url":"https://codeload.github.com/bbuchsbaum/hrfals/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbuchsbaum%2Fhrfals/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279002074,"owners_count":26083285,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-05T09:09:41.848Z","updated_at":"2025-10-09T21:09:22.949Z","avatar_url":"https://github.com/bbuchsbaum.png","language":"R","readme":"# hrfals\n\n[![R-CMD-check](https://github.com/bbuchsbaum/hrfals/workflows/R-CMD-check/badge.svg)](https://github.com/bbuchsbaum/hrfals/actions)\n\n## Overview\n\nThe `hrfals` package implements the Confound-Free Alternating Least Squares (CF-ALS) method for estimating hemodynamic response functions (HRFs) from fMRI data. This package provides fast, accurate, and robust alternatives for data-driven HRF estimation that work with any HRF basis from the `fmrireg` package.\n\n## Key Features\n\n- **CF-ALS Algorithm**: Implements the rank-1 decomposition model Y ≈ D(h)β^T for simultaneous estimation of HRF coefficients and activation amplitudes\n- **Multiple Estimation Methods**: Supports LS+SVD initialization, LS+SVD+1ALS refinement, and full CF-ALS alternating optimization\n- **HRF Basis Compatibility**: Works with any HRF basis from `fmrireg` (B-spline, SPM canonical, tent functions, etc.)\n- **Confound Projection**: Built-in QR-based orthogonal projection for nuisance regressor removal\n- **Regularization**: Separate L2 penalties for amplitude (λ_β) and HRF coefficient (λ_h) updates\n- **Efficient Implementation**: Optimized precomputation and vectorized operations\n\n## Installation\n\nYou can install the development version of hrfals from GitHub:\n\n```r\n# install.packages(\"devtools\")\ndevtools::install_github(\"bbuchsbaum/hrfals\")\n```\n\n## Quick Start\n\n```r\nlibrary(hrfals)\nlibrary(fmrireg)\n\n# Create sampling frame and event model\nsframe \u003c- fmrireg::sampling_frame(blocklens = 40, TR = 1)\nev_df \u003c- data.frame(onset = c(5, 15, 25), block = 1, cond = \"A\")\nemod \u003c- fmrireg::event_model(onset ~ hrf(cond, basis = fmrireg::HRF_SPMG3),\n                            data = ev_df, block = ~ block,\n                            sampling_frame = sframe)\n\n# Simulate some BOLD data\nY_matrix \u003c- matrix(rnorm(40 * 5), 40, 5) # 40 timepoints, 5 voxels\n\n# Fit using CF-ALS\ncfals_fit \u003c- hrfals(\n  fmri_data_obj = Y_matrix,\n  event_model = emod,\n  hrf_basis = fmrireg::HRF_SPMG3,\n  lam_beta = 5,\n  lam_h = 0.5,\n  max_alt = 1\n)\n\nprint(cfals_fit)\n```\n\n```r\n# Include a simple baseline model (runwise intercept + linear trend)\nbase_mod \u003c- fmrireg::baseline_model(sframe = sframe, degree = 1)\ncfals_baseline \u003c- hrfals(\n  fmri_data_obj = Y_matrix,\n  event_model = emod,\n  hrf_basis = fmrireg::HRF_SPMG3,\n  baseline_model = base_mod,\n  max_alt = 1\n)\n```\n\n## Main Functions\n\n- `hrfals()`: Main user-facing function for CF-ALS HRF estimation\n- `create_cfals_design()`: Design matrix creation leveraging fmrireg functionality\n- `estimate_hrf_cfals()`: Lower-level estimation function for single event terms\n\n## Algorithm Details\n\nThe CF-ALS method estimates HRFs and activation amplitudes simultaneously using:\n\n1. **Confound Projection**: Removes nuisance regressors using QR decomposition\n2. **SVD Initialization**: Robust starting values via regularized least squares + SVD\n3. **Alternating Updates**: \n   - β-update: Solves (G + λ_β I)β = D(h)^T y\n   - h-update: Solves (LHS + λ_h I)h = RHS\n4. **Identifiability**: Normalizes and aligns HRF estimates for consistency\n\n## Dependencies\n\n- R (\u003e= 3.5.0)\n- fmrireg (\u003e= 0.0.0.9000)\n- stats\n\n## License\n\nGPL-3\n\n## Citation\n\nIf you use this package in your research, please cite:\n\n```\nBuchsbaum, B. (2024). hrfals: HRF Estimation using Confound-Free Alternating Least Squares. \nR package version 0.0.0.9000. https://github.com/bbuchsbaum/hrfals\n```\n\n## Issues and Support\n\nPlease report bugs and feature requests at: https://github.com/bbuchsbaum/hrfals/issues ","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbuchsbaum%2Fhrfals","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbbuchsbaum%2Fhrfals","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbuchsbaum%2Fhrfals/lists"}