{"id":23466233,"url":"https://github.com/kklot/gennet","last_synced_at":"2025-04-12T17:29:23.522Z","repository":{"id":89723162,"uuid":"108398122","full_name":"kklot/gennet","owner":"kklot","description":"Generating network age-specific","archived":false,"fork":false,"pushed_at":"2017-11-11T14:00:46.000Z","size":646,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-16T03:29:26.590Z","etag":null,"topics":["network","r"],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kklot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2017-10-26T10:40:24.000Z","updated_at":"2020-04-19T19:27:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"29ce213a-8ddf-4f51-9eb9-5eea76809d4a","html_url":"https://github.com/kklot/gennet","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kklot%2Fgennet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kklot%2Fgennet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kklot%2Fgennet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kklot%2Fgennet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kklot","download_url":"https://codeload.github.com/kklot/gennet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248604582,"owners_count":21131997,"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":["network","r"],"created_at":"2024-12-24T11:55:30.173Z","updated_at":"2025-04-12T17:29:23.497Z","avatar_url":"https://github.com/kklot.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gennet\nGenerating network age-specific\n\n# Licencing\n\n\u003ca rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc-sa/4.0/\"\u003e\u003cimg alt=\"Creative Commons License\" style=\"border-width:0\" src=\"https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png\" /\u003e\u003c/a\u003e\u003cbr /\u003eThis work is licensed under a \u003ca rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc-sa/4.0/\"\u003eCreative Commons Attribution-NonCommercial-ShareAlike 4.0 International License\u003c/a\u003e.\n\n[![DOI](https://zenodo.org/badge/108398122.svg)](https://zenodo.org/badge/latestdoi/108398122)\n\n## Requirements\n\n- a target population age-structure\n- contact distribution (Mossong et al Plos Medicine)\n- contact matrix (Mossong et al Plos Medicine)\n\n```R\nN    \u003c- 1000\nseed \u003c- 123\n```\n\n## Steps\n\nAssign age: depends on the target population age distribution\n\n```R\n  SR             \u003c- dget(\"./data/SR\")  # Sierra Leon population\n  if (!is.null(seed)) set.seed(seed)\n  age           \u003c- sample(SR$age, N, TRUE, SR$prob)\n  # add ages 70/80+\n  age[age==70] \u003c- sample(70:80, length(age[age==70]), replace=1)\n```\n\nAssign #contacts: depends on both target age and POLYMOD data\n```R\n  agecont      \u003c- orderBy(dget(\"./data/POLYMODtab1\"), 1) # POLYMOD Tab.1\n  agecont$rk   \u003c- rank(agecont$age)  # Rank age-group by contact\n  POLYMODbreak \u003c- c(0,4,9,14,19,29,39,49,59,69,80) \n  ageGrp \u003c- cut(age, breaks=POLYMODbreak, include.lowest=1)\n  ageGrp \u003c- as.numeric(ageGrp) # mapping age to ageGrp\n  agerk  \u003c- sapply(ageGrp, function(x) agecont$rk[x==agecont$nmr])\n  age    \u003c- rev(orderBy(cbind(age, agerk), 2)[, 1]) # large to small\n```\n\nSampling from contact distribution\n\n```R\n  distCont \u003c- dget(\"./data/distCont\")\n  ncont    \u003c- sort(sample(distCont$freq, N, 1, distCont$prob), TRUE)\n```\n\nLoad contact matrix (as probability) POLYMOD data: averaging all countries\n\n```R\n  M \u003c- dget(\"./data/M\")  # image(M)\n  Mbrk \u003c- c(0,4,9,14,19,24,29,34,39,44,49,54,59,64,69,70)\n  Mnmr \u003c- 1:15\n  Grp  \u003c- as.numeric(cut(age, breaks=Mbrk, include.lowest=1))\n  Grp[is.na(Grp)] \u003c- 15 # 70+ age-grp\n```\n\nRun\n\n```R\nsource(\"gennet.R\")\ng \u003c- genNet(N, age)\n```\n\n## Outputs\n\n```R\nplotNet(g)\n```\n\n![](./fig/g1.png)\n\n## Validate\n\nCompare age- and contact-distribution\n```R\nks.test(age, vertex_attr(g, \"age\"))\n\nTwo-sample Kolmogorov-Smirnov test\n\ndata:  age and vertex_attr(g, \"age\")\nD = 0, p-value = 1\n\nks.test(degree(g), ncont)\n\nTwo-sample Kolmogorov-Smirnov test\n\ndata:  degree(g) and ncont\nD = 0, p-value = 1\n\nput(1,2)\nqqplot(degree(g), ncont, main=\"QQ Plot\", ylab=\"Target contact distribution\")\nqqplot(age, vertex_attr(g, \"age\"), main=\"QQ Plot\", ylab=\"Target age distribution\")\n```\n![](./fig/qqplot.png)\n\n\nCompare contact-matrix\n![](./fig/matrixCompare.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkklot%2Fgennet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkklot%2Fgennet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkklot%2Fgennet/lists"}