{"id":22463721,"url":"https://github.com/poissonconsulting/tmbr","last_synced_at":"2025-03-27T14:28:30.365Z","repository":{"id":46119018,"uuid":"68748448","full_name":"poissonconsulting/tmbr","owner":"poissonconsulting","description":"An R package to facilitate analyses using TMB","archived":false,"fork":false,"pushed_at":"2025-01-14T21:06:11.000Z","size":2240,"stargazers_count":0,"open_issues_count":7,"forks_count":1,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-02-01T18:42:59.358Z","etag":null,"topics":["mbr","rstats","tmb"],"latest_commit_sha":null,"homepage":"https://poissonconsulting.github.io/tmbr/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/poissonconsulting.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":".github/SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-20T19:57:03.000Z","updated_at":"2025-01-14T21:03:41.000Z","dependencies_parsed_at":"2022-09-24T17:33:46.945Z","dependency_job_id":"4b60efe4-7e42-4acb-be79-e25493b56a4d","html_url":"https://github.com/poissonconsulting/tmbr","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/poissonconsulting%2Ftmbr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poissonconsulting%2Ftmbr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poissonconsulting%2Ftmbr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poissonconsulting%2Ftmbr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/poissonconsulting","download_url":"https://codeload.github.com/poissonconsulting/tmbr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245862248,"owners_count":20684653,"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":["mbr","rstats","tmb"],"created_at":"2024-12-06T09:13:52.305Z","updated_at":"2025-03-27T14:28:30.344Z","avatar_url":"https://github.com/poissonconsulting.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, echo = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"tools/README-\"\n)\n```\n\n\u003c!-- badges: start --\u003e\n[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)\n[![R-CMD-check](https://github.com/poissonconsulting/tmbr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/poissonconsulting/tmbr/actions/workflows/R-CMD-check.yaml)\n[![Codecov test coverage](https://codecov.io/gh/poissonconsulting/tmbr/branch/master/graph/badge.svg)](https://codecov.io/gh/poissonconsulting/tmbr?branch=master)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/license/mit/)\n\n\u003c!-- badges: end --\u003e\n  \n# tmbr\n\n## Introduction\n\n`tmbr` (pronounced timber) is an R package to facilitate analyses using Template Model Builder ([`TMB`](https://github.com/kaskr/adcomp)).\nIt is part of the [mbr](https://github.com/poissonconsulting/mbr) family of packages.\n\n## Demonstration\n\n```{r, message = FALSE}\nlibrary(magrittr)\nlibrary(ggplot2)\nlibrary(mbr)\nlibrary(tmbr)\n```\n\n```{r}\nmodel \u003c- model(\"#include \u003cTMB.hpp\u003e\n\ntemplate\u003cclass Type\u003e\nType objective_function\u003cType\u003e::operator() () {\n\nDATA_VECTOR(Pairs);\nDATA_VECTOR(Year);\nDATA_FACTOR(Annual);\nDATA_INTEGER(nAnnual);\n\nPARAMETER(alpha);\nPARAMETER(beta1);\nPARAMETER(beta2);\nPARAMETER(beta3);\nPARAMETER_VECTOR(bAnnual);\nPARAMETER(log_sAnnual);\n\nType sAnnual = exp(log_sAnnual);\n\nvector\u003cType\u003e ePairs = Pairs;\n\nType nll = 0.0;\n\nfor(int i = 0; i \u003c nAnnual; i++){\n  nll -= dnorm(bAnnual(i), Type(0), sAnnual, true);\n}\n\nfor(int i = 0; i \u003c Pairs.size(); i++){\n  ePairs(i) = exp(alpha + beta1 * Year(i) + beta2 * pow(Year(i), 2) + beta3 * pow(Year(i), 3) + bAnnual(Annual(i)));\n  nll -= dpois(Pairs(i), ePairs(i), true);\n}\nADREPORT(sAnnual)\nreturn nll;\n}\")\n\n# add R code to calculate derived parameters\nmodel %\u003c\u003e% update_model(new_expr = \"\nfor (i in 1:length(Pairs)) {\n  log(prediction[i]) \u003c- alpha + beta1 * Year[i] + beta2 * Year[i]^2 + beta3 * Year[i]^3 + bAnnual[Annual[i]]\n}\")\n\n# define data types and center year\nmodel %\u003c\u003e% update_model(\n  gen_inits = function(data) list(alpha = 4, beta1 = 1, beta2 = 0, beta3 = 0, log_sAnnual = 0, bAnnual = rep(0, data$nAnnual)),\n  select_data = list(\"Pairs\" = integer(), \"Year*\" = integer(), Annual = factor()),\n  random_effects = list(bAnnual = \"Annual\")\n)\n\ndata \u003c- bauw::peregrine\ndata$Annual \u003c- factor(data$Year)\n\nanalysis \u003c- analyse(model, data = data)\n\ncoef(analysis)\n```\n\n```{r, message = FALSE}\nyear \u003c- predict(analysis, new_data = \"Year\")\n\nggplot(data = year, aes(x = Year, y = estimate)) +\n  geom_point(data = bauw::peregrine, aes(y = Pairs)) +\n  geom_line() +\n  expand_limits(y = 0)\n```\n\n## Installation\n\nTo install from GitHub\n```\ninstall.packages(\"devtools\")\ndevtools::install_github(\"poissonconsulting/tmbr\")\n```\n\n## Citation\n\n```{r, comment=\"\", echo=FALSE}\ncitation(package = \"tmbr\")\n```\n\n## Contribution\n\nPlease report any [issues](https://github.com/poissonconsulting/tmbr/issues).\n\n[Pull requests](https://github.com/poissonconsulting/tmbr/pulls) are always welcome.\n\n## Code of Conduct\n\nPlease note that the tmbr project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoissonconsulting%2Ftmbr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpoissonconsulting%2Ftmbr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoissonconsulting%2Ftmbr/lists"}