{"id":18014334,"url":"https://github.com/egarpor/ridgetorus","last_synced_at":"2025-10-25T08:41:46.422Z","repository":{"id":65063204,"uuid":"580743557","full_name":"egarpor/ridgetorus","owner":"egarpor","description":"PCA on the torus using density ridges. Software companion for \"Toroidal PCA via density ridges\"","archived":false,"fork":false,"pushed_at":"2025-07-27T17:05:06.000Z","size":340323,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-27T17:19:21.987Z","etag":null,"topics":["circular-statistics","dimensionality-reduction","directional-statistics","r"],"latest_commit_sha":null,"homepage":"","language":"R","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/egarpor.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-12-21T10:36:45.000Z","updated_at":"2025-07-27T17:05:10.000Z","dependencies_parsed_at":"2023-02-09T03:00:14.570Z","dependency_job_id":null,"html_url":"https://github.com/egarpor/ridgetorus","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/egarpor/ridgetorus","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egarpor%2Fridgetorus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egarpor%2Fridgetorus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egarpor%2Fridgetorus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egarpor%2Fridgetorus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/egarpor","download_url":"https://codeload.github.com/egarpor/ridgetorus/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egarpor%2Fridgetorus/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274211007,"owners_count":25241893,"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-09-08T02:00:09.813Z","response_time":121,"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":["circular-statistics","dimensionality-reduction","directional-statistics","r"],"created_at":"2024-10-30T04:07:50.453Z","updated_at":"2025-10-25T08:41:41.404Z","avatar_url":"https://github.com/egarpor.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput:\n  md_document:\n    variant: gfm\n---\n\n```{r, opts, echo = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE, comment = \"#\u003e\", fig.path = \"README/README-\",\n  message = FALSE, warning = FALSE, fig.asp = 1, fig.align = 'center'\n)\n```\n\nridgetorus\n==========\n\n[![License:\nGPLv3](https://img.shields.io/badge/license-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)\n[![R build\nstatus](https://github.com/egarpor/ridgetorus/workflows/R-CMD-check/badge.svg)](https://github.com/egarpor/ridgetorus/actions)\n[![R build\nstatus](https://github.com/egarpor/ridgetorus/workflows/test-coverage/badge.svg)](https://github.com/egarpor/ridgetorus/actions)\n[![](https://codecov.io/gh/egarpor/ridgetorus/branch/main/graph/badge.svg)](https://app.codecov.io/gh/egarpor/ridgetorus)\n[![](https://www.r-pkg.org/badges/version/ridgetorus?color=green)](https://cran.r-project.org/package=ridgetorus)\n[![](http://cranlogs.r-pkg.org/badges/grand-total/ridgetorus)](https://cran.r-project.org/package=ridgetorus)\n[![](http://cranlogs.r-pkg.org/badges/last-month/ridgetorus)](https://cran.r-project.org/package=ridgetorus)\n\n\u003c!-- # ```{r, badges, echo = FALSE, results = 'asis'} --\u003e\n\u003c!-- # cat( --\u003e\n\u003c!-- #   badger::badge_license(license = \"GPLv3\", color = \"blue\", --\u003e\n\u003c!-- #                         url = \"https://www.gnu.org/licenses/gpl-3.0\"), --\u003e\n\u003c!-- #   badger::badge_github_actions(action = \"R-CMD-check\"), --\u003e\n\u003c!-- #   badger::badge_github_actions(action = \"test-coverage\"), --\u003e\n\u003c!-- #   badger::badge_codecov(ref = NULL), --\u003e\n\u003c!-- #   badger::badge_cran_release(color = \"green\"), --\u003e\n\u003c!-- #   badger::badge_cran_download(pkg = NULL, type = \"grand-total\"), --\u003e\n\u003c!-- #   badger::badge_cran_download(pkg = NULL, type = \"last-month\") --\u003e\n\u003c!-- # ) --\u003e\n\u003c!-- # ``` --\u003e\n\n\u003c!-- \u003cimg src=\"\" alt=\"ridgetorus  hexlogo\" align=\"right\" width=\"200\" style=\"padding: 0 15px; float: right;\"/\u003e --\u003e\n\n## Overview\n\nImplementation of principal component analysis on the two-dimensional torus $\\mathbb{T}^2=[-\\pi,\\pi)^2$ via density ridges. Software companion for the paper \"*Toroidal PCA via density ridges*\" (García-Portugués and Prieto-Tirado, 2023).\n\n## Installation\n\nGet the latest version from GitHub:\n\n```{r, install-devtools, eval = FALSE}\n# Install the package\nlibrary(devtools)\ninstall_github(\"egarpor/ridgetorus\")\n\n# Load package\nlibrary(ridgetorus)\n```\n\n```{r, load, echo = FALSE}\n# Load package\nlibrary(ridgetorus)\n```\n\n## Usage\n\nThe main functionality of `ridgetorus` is the function `ridge_pca()`, which can be employed to do dimension reduction via the bivariate sine von Mises (Singh et al., 2002) and the bivariate wrapped Cauchy (Kato and Pewsey, 2015) models, as the following examples show.\n\n### Bivariate sine von Mises\n\n```{r, bvm}\n# 1. Simulate data from r_bvm()\ndata \u003c- r_bvm(n = 1000, mu = c(1, 2), kappa = c(5, 2, 1.5))\n\n# 2. Do ridge_pca()\nrpca \u003c- ridge_pca(x = data, type = \"bvm\")\n\n# 3. Plot simulated data with ridge fit using show_ridge_pca()\nshow_ridge_pca(rpca, col_data = \"red\")\n\n# 4. Plot pairs plots of original data and scores with torus_pairs()\ntorus_pairs(data, col_data = \"red\", bwd = \"EMI\")\ntorus_pairs(rpca$scores, col_data = \"red\", bwd = \"EMI\", scales = rpca$scales)\n```\n\n### Bivariate wrapped Cauchy\n\n```{r, bwc}\n# 1. Simulate data from r_bwc()\ndata \u003c- r_bwc(n = 1000, mu = c(-1, 2), xi = c(0.3, 0.6, 0.25))\n\n# 2. Do ridge_pca()\nrpca \u003c- ridge_pca(x = data, type = \"bwc\")\n\n# 3. Plot simulated data with ridge fit using show_ridge_pca()\nshow_ridge_pca(rpca, col_data = \"red\")\n\n# 4. Plot pairs plots of original data and scores with torus_pairs()\ntorus_pairs(rpca$scores, col_data = \"red\", bwd = \"EMI\", scales = rpca$scales)\n```\n\n## Data application in oceanography\n\nThe data applications in García-Portugués and Prieto-Tirado (2023) can be reproduced through the script [data-application.R](https://github.com/egarpor/egarpor/blob/master/application/data-application.R). The code snippet below illustrates the toroidal PCA analysis onto currents of four zones at Santa Barbara strait. Zone A and B are on the northern coast of Santa Barbara Channel while zone C and D, are at the top and bottom ends of the interisland channel.\n\n```{r, santabarbara}\n# Load data\ndata(\"santabarbara\")\n\n# Example with zone A-B with automatic comparison between bvm and bwc\nrpca_AB \u003c- ridge_pca(x = santabarbara[c(\"A\", \"B\")], type = \"auto\")\nshow_ridge_pca(fit = rpca_AB, col_data = \"black\", n_max = 1e3)\ntorus_pairs(santabarbara[c(\"A\", \"B\")], col_data = \"black\")\ntorus_pairs(rpca_AB$scores, col_data = \"black\", scales = rpca_AB$scales)\nrpca_AB$type\nrpca_AB$var_exp\n\n# Example with zone C-D with automatic comparison between bvm and bwc\nrpca_CD \u003c- ridge_pca(x = santabarbara[c(\"C\", \"D\")], type = \"auto\")\nshow_ridge_pca(fit = rpca_CD, col_data = \"black\", n_max = 1e3)\ntorus_pairs(santabarbara[c(\"C\", \"D\")], col_data = \"black\")\ntorus_pairs(rpca_CD$scores, col_data = \"black\", scales = rpca_CD$scales)\nrpca_CD$type\nrpca_CD$var_exp\n```\n\nIt can be seen how the bivariate von Mises and the bivariate wrapped Cauchy are the most adequate fits for zones C--D and A--B, respectively. Toroidal PCA explains around 75% of the total variance in both cases, motivating its use for dimension reduction. The scores also transform the data distribution, reducing noise and allowing to check for groups or outliers, if any.\n\n## References\n\nGarcía-Portugués, E. and Prieto-Tirado, A. (2023). Toroidal PCA via density ridges. *Statistics and Computing*, 33(5):107. [doi:10.1007/s11222-023-10273-9](https://doi.org/10.1007/s11222-023-10273-9).\n\nKato, S. and Pewsey, A. (2015). A Möbius transformation-induced distribution on the torus. *Biometrika*, 102(2):359--370. [doi:10.1093/biomet/asv003](https://doi.org/10.1093/biomet/asv003).\n\nSingh, H., Hnizdo, V., and Demchuk, E. (2002). Probabilistic model for two dependent circular variables. *Biometrika*, 89(3):719--723. [doi:10.1093/biomet/89.3.719](https://doi.org/10.1093/biomet/89.3.719).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegarpor%2Fridgetorus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fegarpor%2Fridgetorus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegarpor%2Fridgetorus/lists"}