{"id":32200364,"url":"https://github.com/lcbc-uio/galamm","last_synced_at":"2025-10-22T03:46:49.641Z","repository":{"id":37751740,"uuid":"356866236","full_name":"LCBC-UiO/galamm","owner":"LCBC-UiO","description":"An R package for estimating generalized additive mixed models with latent variables","archived":false,"fork":false,"pushed_at":"2025-10-01T13:45:37.000Z","size":29648,"stargazers_count":31,"open_issues_count":13,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-22T03:46:43.151Z","etag":null,"topics":["generalized-additive-models","hierarchical-models","item-response-theory","latent-variable-models","structural-equation-models"],"latest_commit_sha":null,"homepage":"https://lcbc-uio.github.io/galamm/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LCBC-UiO.png","metadata":{"files":{"readme":"README.Rmd","changelog":"news.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":"codemeta.json","zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-04-11T12:49:22.000Z","updated_at":"2025-10-05T21:15:48.000Z","dependencies_parsed_at":"2024-04-03T18:02:20.961Z","dependency_job_id":"12e4d0bf-fb7c-40a1-be08-7f613f92cdb6","html_url":"https://github.com/LCBC-UiO/galamm","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/LCBC-UiO/galamm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LCBC-UiO%2Fgalamm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LCBC-UiO%2Fgalamm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LCBC-UiO%2Fgalamm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LCBC-UiO%2Fgalamm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LCBC-UiO","download_url":"https://codeload.github.com/LCBC-UiO/galamm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LCBC-UiO%2Fgalamm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280376534,"owners_count":26320276,"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-22T02:00:06.515Z","response_time":63,"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":["generalized-additive-models","hierarchical-models","item-response-theory","latent-variable-models","structural-equation-models"],"created_at":"2025-10-22T03:46:41.666Z","updated_at":"2025-10-22T03:46:49.632Z","avatar_url":"https://github.com/LCBC-UiO.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: \n  github_document:\n    fig_width: 6\n    fig_height: 4\nbibliography: inst/REFERENCES.bib\nlink-citations: yes\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# Generalized Additive Latent and Mixed Models \u003ca href=\"https://lcbc-uio.github.io/galamm/\"\u003e\u003cimg src=\"man/figures/logo.png\" align=\"right\" height=\"139\" alt=\"galamm website\" /\u003e\u003c/a\u003e\n\n\u003c!-- badges: start --\u003e\n[![CRAN status](https://www.r-pkg.org/badges/version/galamm)](https://cran.r-project.org/package=galamm)\n[![Status at rOpenSci Software Peer Review](https://badges.ropensci.org/615_status.svg)](https://github.com/ropensci/software-review/issues/615)\n[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)\n[![R-CMD-check](https://github.com/LCBC-UiO/galamm/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/LCBC-UiO/galamm/actions/workflows/R-CMD-check.yaml)\n[![Codecov test coverage](https://codecov.io/gh/LCBC-UiO/galamm/branch/main/graph/badge.svg)](https://app.codecov.io/gh/LCBC-UiO/galamm?branch=main)\n\u003c!-- badges: end --\u003e\n\n```{r srr-tags1, eval = FALSE, echo = FALSE}\n#' @srrstats {G1.0} Primary and secondary references to literature in the paragraph below.\n#' @srrstats {G1.1} It is stated in the paragraph below that this is the first implementation of the algorithm developed in Sørensen, Fjell, and Walhovd (2023).\n#' @srrstats {G1.3} Statistical terminology defined in detail in the references in the paragraph below. The main paper, Sørensen, FJell, and Walhovd (2023) is open access.\n```\n\n\ngalamm estimates generalized additive latent and mixed models (GALAMMs). This is the first package implementing the model framework and the computational algorithms introduced in @sorensenLongitudinalModelingAgeDependent2023. It is an extension of the GLLAMM framework for multilevel latent variable modeling detailed in @rabe-heskethGeneralizedMultilevelStructural2004 and @skrondalGeneralizedLatentVariable2004, in particular by efficiently handling crossed random effects and semiparametric estimation.\n\n```{r srr-tags3, eval = FALSE, echo = FALSE}\n#' @srrstats {G1.3} Statistical terminology defined in the introductory vignette.\n```\n\nSome typical usage examples include:\n\n- Modeling how a latent trait of interest (e.g., general cognitive ability, anxiety, quality of life) depends nonlinearly on predictors of interest (e.g., age), and how this relationship is moderated by other variables of interest (e.g., educational attainment, genetics).\n- Analyzing data with mixed response types, e.g., when a latent trait is measured with a combination of continuous and binary responses.\n- Avoiding measurement error bias by utilizing replicate measurements of covariates of interest.\n\nTo get started, take a look at the [introductory vignette](https://lcbc-uio.github.io/galamm/articles/galamm.html).\n\n## What Can the Package Do?\n\nMany applications, particularly in the social sciences, require modeling capabilities beyond what is easily supported and computationally feasible with popular R packages like [mgcv](https://cran.r-project.org/package=mgcv) [@woodGeneralizedAdditiveModels2017], [lavaan](https://lavaan.ugent.be/) [@rosseelLavaanPackageStructural2012], [lme4](https://cran.r-project.org/package=lme4) [@batesFittingLinearMixedEffects2015], and [OpenMx](https://openmx.ssri.psu.edu/) [@nealeOpenMxExtendedStructural2016], as well as the Stata based [GLLAMM](http://www.gllamm.org/) software [@rabe-heskethGeneralizedMultilevelStructural2004;@rabe-heskethMaximumLikelihoodEstimation2005]. In particular, to maximally utilize large datasets available today, it is typically necessary to combine tools from latent variable modeling, hierarchical modeling, and semiparametric estimation. While this is possible with Bayesian hierarchical models and tools like [Stan](https://mc-stan.org/), it requires considerable expertise and may be beyond scope for a single data analysis project. \n\nThe goal of galamm is to enable estimation of models with an arbitrary number of grouping levels, both crossed and hierarchical, and any combination of the following features (click the links to go to the relevant vignette):\n\n- [Linear mixed models with factor structures](https://lcbc-uio.github.io/galamm/articles/lmm_factor.html).\n- [Generalized linear mixed models with factor structures](https://lcbc-uio.github.io/galamm/articles/glmm_factor.html).\n- [Linear mixed models with heteroscedastic residuals](https://lcbc-uio.github.io/galamm/articles/lmm_heteroscedastic.html).\n- [Mixed models with mixed response types](https://lcbc-uio.github.io/galamm/articles/mixed_response.html).\n- [Generalized additive mixed models with factor structures](https://lcbc-uio.github.io/galamm/articles/semiparametric.html).\n- [Interactions between latent and observed covariates](https://lcbc-uio.github.io/galamm/articles/latent_observed_interaction.html).\n\n```{r srr-tags2, eval = FALSE, echo = FALSE}\n#' @srrstats {G1.6} Code for comparing the performance of galamm to the of PLmixed for example models is provided in the vignette on linear mixed models with factor structures.\n```\n\n\nRandom effects are defined using [lme4](https://cran.r-project.org/package=lme4) syntax, and the syntax for factor structures are close to that of [PLmixed](https://cran.r-project.org/package=PLmixed) [@rockwoodEstimatingComplexMeasurement2019]. However, for the types of models supported by both PLmixed and galamm, galamm is usually considerably faster. Smooth terms, as in generalized additive mixed models, use the same syntax as [mgcv](https://cran.r-project.org/package=mgcv).\n\nFor most users, it should not be necessary to think about how the actual computations are performed, although they are detailed in the [optimization vignette](https://lcbc-uio.github.io/galamm/articles/optimization.html). In short, the core computations are done using sparse matrix methods supported by [RcppEigen](https://cran.r-project.org/package=RcppEigen) [@batesFastElegantNumerical2013] and automatic differentiation using the C++ library [autodiff](https://autodiff.github.io/) [@lealAutodiffModernFast2018]. Scaling of the algorithm is investigated further in [the vignette on computational scaling](https://lcbc-uio.github.io/galamm/articles/scaling.html).\n\n## Installation\n\nInstall the package from CRAN using\n\n``` r\ninstall.packages(\"galamm\")\n```\n\nYou can install the development version of galamm from [GitHub](https://github.com/) with:\n\n``` r\n# install.packages(\"remotes\")\nremotes::install_github(\"LCBC-UiO/galamm\")\n```\n\n## Examples\n\n```{r}\nlibrary(galamm)\n```\n\n\n### Mixed Response Model\n\nThe dataframe `mresp` contains simulated data with mixed response types.\n\n```{r}\nhead(mresp)\n```\n\nResponses in rows with `itemgroup = \"a\"` are normally distributed while those in rows with `itemgroup = \"b\"` are binomially distributed. For a given subject, identified by the `id` variable, both responses are associated with the same underlying latent variable. We hence need to model this process jointly, and the model is set up as follows:\n\n\n```{r, message=FALSE}\nmixed_resp \u003c- galamm(\n  formula = y ~ x + (0 + loading | id),\n  data = mresp,\n  family = gfam(list(gaussian, binomial)),\n  load_var = \"itemgroup\",\n  lambda = matrix(c(1, NA), ncol = 1),\n  factor = \"loading\"\n)\n```\n\nThe summary function gives some information about the model fit.\n\n```{r}\nsummary(mixed_resp)\n```\n\n\n### Generalized Additive Mixed Model with Factor Structures\n\nThe dataframe `cognition` contains simulated for which latent ability in three cognitive domains is measured across time. We focus on the first cognitive domain, and estimate a smooth trajectory for how the latent ability depends on time.\n\nWe start by reducing the data.\n\n```{r}\ndat \u003c- subset(cognition, domain == 1)\ndat$item \u003c- factor(dat$item)\n```\n\nNext we define the matrix of factor loadings, where `NA` denotes unknown values to be estimated.\n\n```{r}\nloading_matrix \u003c- matrix(c(1, NA, NA), ncol = 1)\n```\n\nWe then compute the model estimates, containing both a smooth term for the latent ability and random intercept for subject and timepoints.\n\n```{r}\nmod \u003c- galamm(\n  formula = y ~ 0 + item + sl(x, factor = \"loading\") +\n    (0 + loading | id / timepoint),\n  data = dat,\n  load_var = \"item\",\n  lambda = loading_matrix,\n  factor = \"loading\"\n)\n```\n\nWe finally plot the estimated smooth term.\n\n```{r}\nplot_smooth(mod)\n```\n\n\n## How to cite this package\n\n```{r}\ncitation(\"galamm\")\n```\n\n## Acknowledgement\n\nSome parts of the code base for galamm has been derived from internal functions of the R packages, [gamm4](https://cran.r-project.org/package=gamm4) (authors: Simon Wood and Fabian Scheipl), [lme4](https://cran.r-project.org/package=lme4) (authors: Douglas Bates, Martin Maechler, Ben Bolker, and Steven Walker), and [mgcv](https://cran.r-project.org/package=mgcv) (author: Simon Wood), as well the C++ library [autodiff](https://autodiff.github.io/) (author: Allan Leal). In accordance with the [CRAN Repository Policy](https://cran.r-project.org/web/packages/policies.html), all these authors are listed as contributors in the `DESCRIPTION` file. If you are among these authors, and don't want to be listed as a contributor to this package, please let me know, and I will remove you.\n\n## Contributing\n\nContributions are very welcome, see [CONTRIBUTING.md](https://github.com/LCBC-UiO/galamm/blob/main/.github/CONTRIBUTING.md) for general guidelines.\n\n## References\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flcbc-uio%2Fgalamm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flcbc-uio%2Fgalamm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flcbc-uio%2Fgalamm/lists"}