{"id":20817829,"url":"https://github.com/daijiang/phyr","last_synced_at":"2025-05-07T14:06:46.281Z","repository":{"id":41364436,"uuid":"113221373","full_name":"daijiang/phyr","owner":"daijiang","description":"Functions for phylogenetic analyses","archived":false,"fork":false,"pushed_at":"2024-02-21T21:00:11.000Z","size":36081,"stargazers_count":31,"open_issues_count":35,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-07T14:06:31.166Z","etag":null,"topics":["bayesian","glmm","inla","phylogeny","r","rpackage","species-distribution-modeling"],"latest_commit_sha":null,"homepage":"https://daijiang.github.io/phyr/","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/daijiang.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"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}},"created_at":"2017-12-05T19:00:50.000Z","updated_at":"2025-01-23T12:37:00.000Z","dependencies_parsed_at":"2023-11-27T13:07:32.885Z","dependency_job_id":"aef4af36-2737-4713-9ffc-a16e2e247ac8","html_url":"https://github.com/daijiang/phyr","commit_stats":{"total_commits":486,"total_committers":11,"mean_commits":44.18181818181818,"dds":0.5102880658436214,"last_synced_commit":"3b49dda9fdaf7970fd80228f8605f6384b379b23"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daijiang%2Fphyr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daijiang%2Fphyr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daijiang%2Fphyr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daijiang%2Fphyr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daijiang","download_url":"https://codeload.github.com/daijiang/phyr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252892503,"owners_count":21820648,"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","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":["bayesian","glmm","inla","phylogeny","r","rpackage","species-distribution-modeling"],"created_at":"2024-11-17T21:44:25.650Z","updated_at":"2025-05-07T14:06:46.236Z","avatar_url":"https://github.com/daijiang.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r setup, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"##\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n\u003c!-- [![Travis build status](https://travis-ci.org/daijiang/phyr.svg?branch=master)](https://travis-ci.org/daijiang/phyr) [![Coverage status](https://codecov.io/gh/daijiang/phyr/branch/master/graph/badge.svg)](https://codecov.io/gh/daijiang/phyr) --\u003e\n\n# phyr \u003cimg src=\"man/figures/logo.png\" align=\"right\" height=\"138\" /\u003e\n\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/daijiang/phyr/workflows/R-CMD-check/badge.svg)](https://github.com/daijiang/phyr/actions)\n[![Codecov test coverage](https://codecov.io/gh/daijiang/phyr/branch/master/graph/badge.svg)](https://app.codecov.io/gh/daijiang/phyr?branch=master)\n\u003c!-- badges: end --\u003e\n\n# Installation\n\nTo install this package:\n\n```{r eval = F}\noptions(repos = c(\n  phyr = 'https://daijiang.r-universe.dev',\n  CRAN = 'https://cloud.r-project.org'))\ninstall.packages('phyr')\n\n# or\ndevtools::install_github(\"daijiang/phyr\")\n```\n\n# Main functions\n\nThe phyr package has three groups of functions:\n\n1. community phylogenetic diversity metrics (alpha: `psv`, `psr`, `pse`, etc. and beta: `pcd`), which were included in the `picante` package originally. They were updated with c++ to improve speed.\n2. models to estimate correlation between functional traits while accounting for phylogenetic relationships (`cor_phylo`), which was included in the `ape` package originally. It has new syntax, much improved performance (c++), and bootstrapping option.\n3. phylogenetic generalized linear mixed models (`pglmm`), which was originally included in the `pez` package. It has new model formula syntax that allows straightforward model set up, a faster version of maximum likelihood implementation via c++, and a Bayesian model fitting framework based on INLA. \n    + We hope the model formula proposed here can be used to standardize PGLMMs set up across different tools (e.g. `brms` for Stan).\n    + PGLMM for comparative data (`pglmm.compare`), which was originally from `ape::binaryPGLMM()` but has more features.\n\n# Usage examples of `pglmm()`\n\n`pglmm` use similar syntax as `lme4::lmer` to specify random terms: add `__` (two underscores) at the end of grouping variable (e.g. `sp`) to specify both phylogenetic and non-phylogenetic random terms; use `(1|sp__@site)` to specify nested term (i.e. species phylogenetic matrix `V_sp` nested within the diagonal of site matrix `I_site`) to test phylogenetic overdispersion or underdispersion. This should be the most commonly used one and is equal to `kronecker(I_site, V_sp)`. \n\nWe can also use a second phylogeny for bipartite questions. For example, `(1|parasite@host__)` will be converted to `kronecker(V_host, I_parasite)`; `(1|parasite__@host__)` will be converted to `kronecker(V_host, V_parasite)`.\n\nFor details about model formula, see documentation `?phyr::pglmm`. More application examples can be found in [Ives 2018 Chapter 4](https://leanpub.com/correlateddata).\n\n```{r message=FALSE}\nlibrary(phyr)\n```\n\n```{r eval = T}\nlibrary(dplyr)\ncomm = comm_a\ncomm$site = row.names(comm)\ndat = tidyr::gather(comm, key = \"sp\", value = \"freq\", -site) %\u003e% \n  left_join(envi, by = \"site\") %\u003e% \n  left_join(traits, by = \"sp\")\ndat$pa = as.numeric(dat$freq \u003e 0)\nhead(dat)\n# phy-LMM\ntest1 = phyr::pglmm(freq ~ 1 + shade + (1|sp__) + (1|site) + (1|sp__@site), \n                    data = dat, family = \"gaussian\", REML = FALSE,\n                    cov_ranef = list(sp = phylotree))\ntest1\n# phy-GLMM\ntest2 = phyr::pglmm(pa ~ 1 + shade + (1|sp__) + (1|site) + (1|sp__@site), \n                    data = dat, family = \"binomial\", REML = FALSE,\n                    cov_ranef = list(sp = phylotree))\ntest2\n# bipartite\ntree_site = ape::rtree(n = n_distinct(dat$site), tip.label = sort(unique(dat$site)))\nz_bipartite = phyr::pglmm(freq ~ 1 + shade + (1|sp__) + (1|site__) + \n                            (1|sp__@site) + (1|sp@site__) + (1|sp__@site__), \n                          data = dat, family = \"gaussian\",REML = TRUE,\n                          cov_ranef = list(sp = phylotree, site = tree_site))\nz_bipartite\n```\n\n# Licenses\n\nLicensed under the [GPL-3 license](https://www.gnu.org/licenses/gpl-3.0.en.html).\n\n# Contributing\n\nContributions are welcome. You can provide comments and feedback or ask questions by filing an issue on Github [here](https://github.com/daijiang/phyr/issues) or making pull requests.\n\n# Code of conduct\n\nPlease note that the 'phyr' project is released with a [Contributor Code of Conduct](https://github.com/daijiang/phyr/blob/master/CODE_OF_CONDUCT.md). By contributing to this project, you agree to abide by its terms.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaijiang%2Fphyr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaijiang%2Fphyr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaijiang%2Fphyr/lists"}