{"id":27204510,"url":"https://github.com/simonrolph/matrix-functions","last_synced_at":"2025-04-09T22:58:34.818Z","repository":{"id":119113268,"uuid":"83778306","full_name":"simonrolph/Matrix-Functions","owner":"simonrolph","description":"R scripts working with matrix population models (MPMs).","archived":false,"fork":false,"pushed_at":"2018-06-28T16:05:06.000Z","size":13,"stargazers_count":1,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T22:58:32.636Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/simonrolph.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2017-03-03T08:54:58.000Z","updated_at":"2018-06-28T16:05:08.000Z","dependencies_parsed_at":"2023-10-21T00:15:09.760Z","dependency_job_id":null,"html_url":"https://github.com/simonrolph/Matrix-Functions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonrolph%2FMatrix-Functions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonrolph%2FMatrix-Functions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonrolph%2FMatrix-Functions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonrolph%2FMatrix-Functions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonrolph","download_url":"https://codeload.github.com/simonrolph/Matrix-Functions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125566,"owners_count":21051767,"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":[],"created_at":"2025-04-09T22:58:34.293Z","updated_at":"2025-04-09T22:58:34.804Z","avatar_url":"https://github.com/simonrolph.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\n# Matrix-Functions\nR scripts working with matrix population models (MPMs)\n\n## Correcting seed stage error\n\n[`convert2post(mat,matF)`](https://raw.githubusercontent.com/simonrolph/Matrix-Functions/master/convert2post.R) - Convert a matrix model with seed stage error to a post-reproductive census without the error\nAssuming:\n* Stage 1 is the first stage of the lifecycle\n* Matrix is split so that we have matA and matF\n\n[`convert2pre(mat,matF)`](https://raw.githubusercontent.com/simonrolph/Matrix-Functions/master/convert2pre.R) - Convert a matrix model with seed stage error to a pre-reproductive census without the error\nAssuming:\n* Stage 1 is the first stage of the lifecycle\n* Matrix is split so that we have matA and matF\n\n## MPMs as Markov chains\n\nThis is stuff to do with:\nhttp://journals.plos.org/plosone/article?id=10.1371/journal.pone.0020809\n\nIt is code adapted from MATLAB scripts provided at a couse taught by Hal Caswell at the Max Plank Institute for Demographic Research.\n\nI haven't touched this conde in ages, **use at your own risk**.\n\nPackage requirements:\n\n* expm\n\n[`Umat_to_Pmat(matU)`](https://raw.githubusercontent.com/simonrolph/Matrix-Functions/master/Umat_to_Pmat.R) - Convert transient transition matrix (U) to discrete-time markov chain with absorbing states for each stage (P)\n\n* P:\n\n| U | 0 |\n|---|---|\n| M | I |\n\n[`occupancy_time_analysis(U)`](https://raw.githubusercontent.com/simonrolph/Matrix-Functions/master/occupancy_time_analysis.R) - Produce statistics (expected, variance, standard deviation and coefficient of variation) of occupancy tie\n\n* Inputs: U matrix\n* Requires `Umat_to_Pmat()`\n\n[`longevity_analysis(U)`](https://raw.githubusercontent.com/simonrolph/Matrix-Functions/master/longevity_analysis.R) - Produce statistics (expected, variance, standard deviation and coefficient of variation) of longevity\n\n* Inputs: U matrix\n* Requires `Umat_to_Pmat()`\n\n[`generate_R1(P,s,type = \"occupancy\",death_contrib = 0.5)`](https://raw.githubusercontent.com/simonrolph/Matrix-Functions/master/generate_R1.R) - Generate first moment reward matrix (R1)\n\n* Inputs: P matrix, number of transient states, what type of reward (only ocupancy implemented at the moment), death_contrib (reward given upon death, default = 0.5)\n\n[`generate_R123(R1,distri = \"fixed\")`](https://raw.githubusercontent.com/simonrolph/Matrix-Functions/master/generate_R123.R) - From R1, generate the 2nd and 3rd moment reward matrices\n\n* Imputs: First moment reward matrix, type of distribution (bernoulli, fixed, poisson)\n\n[`reward_analysis(P,s,R123)`](https://raw.githubusercontent.com/simonrolph/Matrix-Functions/master/reward_analysis.R) - Produce statistics (expected, variance, standard deviation and coefficient of variation) of lifetime reproductive output\n\n* Inputs: U matrix, reward matrices (1st, 2nd, 3rd moments, often: R1 = R2 = R3)\n\n### Example Code\n\n```\n\nU \u003c- matrix(c(0.2,0.5,0,0,0,0.8,0,0,0.9),nrow = 3)\ns \u003c- dim(U)[1]\nP \u003c- Umat_to_Pmat(U)\nR1 \u003c- generate_R1(P,s,type = \"occupancy\",death_contrib = 0.5)\nR123 \u003c- generate_R123(R1,distri = \"bernoulli\")\nresults \u003c- reward_analysis(P,s,R123)\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonrolph%2Fmatrix-functions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonrolph%2Fmatrix-functions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonrolph%2Fmatrix-functions/lists"}