{"id":22463710,"url":"https://github.com/poissonconsulting/smbr","last_synced_at":"2025-08-02T05:32:23.526Z","repository":{"id":21056271,"uuid":"91713714","full_name":"poissonconsulting/smbr","owner":"poissonconsulting","description":"R package to facilitate analyses using STAN","archived":false,"fork":false,"pushed_at":"2024-11-12T17:12:33.000Z","size":8499,"stargazers_count":1,"open_issues_count":10,"forks_count":1,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-11-12T18:24:22.087Z","etag":null,"topics":["mbr","rstats","stan"],"latest_commit_sha":null,"homepage":"https://poissonconsulting.github.io/smbr/","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":"2017-05-18T16:11:35.000Z","updated_at":"2024-11-01T15:54:05.000Z","dependencies_parsed_at":"2024-11-12T18:23:07.734Z","dependency_job_id":"4d042994-d1b2-45a3-8352-ef3f3ccc6743","html_url":"https://github.com/poissonconsulting/smbr","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poissonconsulting%2Fsmbr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poissonconsulting%2Fsmbr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poissonconsulting%2Fsmbr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poissonconsulting%2Fsmbr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/poissonconsulting","download_url":"https://codeload.github.com/poissonconsulting/smbr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228439452,"owners_count":17920026,"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","stan"],"created_at":"2024-12-06T09:13:50.262Z","updated_at":"2024-12-06T09:13:50.880Z","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# smbr\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/smbr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/poissonconsulting/smbr/actions/workflows/R-CMD-check.yaml)\n[![Codecov test coverage](https://codecov.io/gh/poissonconsulting/smbr/graph/badge.svg)](https://app.codecov.io/gh/poissonconsulting/smbr)\n[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/license/mit/)\n\u003c!-- badges: end --\u003e\n\n## Introduction\n\n`smbr` (pronounced simber) is an R package to facilitate analyses using [`STAN`](http://mc-stan.org).\nIt is part of the [embr](https://github.com/poissonconsulting/embr) family of packages.\n\n## Demonstration\n\n```{r, message = FALSE}\nlibrary(bauw)\nlibrary(ggplot2)\nlibrary(magrittr)\nlibrary(embr)\nlibrary(smbr)\n```\n\n```{r}\n# define model in Stan language\nmodel \u003c- model(\"\n  data {\n      int nAnnual;\n      int nObs;\n      int Annual[nObs];\n      int Pairs[nObs];\n      real Year[nObs];\n  }\n  parameters {\n      vector[nAnnual] bAnnual;\n      real log_sAnnual;\n      real alpha;\n      real beta1;\n      real beta2;\n      real beta3;\n  }\n  transformed parameters {\n    real sAnnual;\n    sAnnual = exp(log_sAnnual);\n  }\n  model {\n      vector[nObs] ePairs;\n\n      log_sAnnual ~ normal(0, 10);\n      bAnnual ~ normal(0, sAnnual);\n\n      alpha ~ normal(0, 10);\n      beta1 ~ normal(0, 10);\n      beta2 ~ normal(0, 10);\n      beta3 ~ normal(0, 10);\n\n      for (i in 1:nObs) {\n        ePairs[i] = exp(alpha + beta1 * Year[i] + beta2 * Year[i]^2 +\n                      beta3 * Year[i]^3 + bAnnual[Annual[i]]);\n      }\n      target += poisson_lpmf(Pairs | ePairs);\n  }\")\n\n# add R code to calculate derived parameters\nmodel %\u003c\u003e% update_model(new_expr = \"\n  for (i in 1:length(Pairs)) {\n    prediction[i] \u003c- exp(alpha + beta1 * Year[i] + beta2 * Year[i]^2 +\n                       beta3 * Year[i]^3 + bAnnual[Annual[i]])\n  }\n\")\n\n# define data types and center year\nmodel %\u003c\u003e% update_model(\n  select_data = list(\n    \"Pairs\" = integer(), \"Year*\" = integer(),\n    Annual = factor()\n  ),\n  derived = \"sAnnual\",\n  random_effects = list(bAnnual = \"Annual\")\n)\n\ndata \u003c- bauw::peregrine\ndata$Annual \u003c- factor(data$Year)\n\nset.seed(42)\n\n# analyse\nanalysis \u003c- analyse(model, data = data, seed = 3L, glance = FALSE)\n\n# coefficient table\ncoef(analysis, simplify = TRUE)\n\n# trace plots\nplot(analysis)\n```\n```{r, message = FALSE}\n# make predictions by varying year with other predictors including the random effect of Annual held constant\nyear \u003c- predict(analysis, new_data = \"Year\")\n\n# plot those predictions\nggplot(data = year, aes(x = Year, y = estimate)) +\n  geom_point(data = bauw::peregrine, aes(y = Pairs)) +\n  geom_line() +\n  geom_line(aes(y = lower), linetype = \"dotted\") +\n  geom_line(aes(y = upper), linetype = \"dotted\") +\n  expand_limits(y = 0)\n```\n\n## Installation\n\n```{r gh-installation, eval = FALSE}\n# install.packages(\"devtools\")\ndevtools::install_github(\"poissonconsulting/smbr\")\n```\n\n## Citation\n\n```{r, comment=\"\", echo=FALSE}\ncitation(package = \"smbr\")\n```\n\n## Contribution\n\nPlease report any [issues](https://github.com/poissonconsulting/smbr/issues).\n\n[Pull requests](https://github.com/poissonconsulting/smbr/pulls) are always welcome.\n\n## Code of Conduct\n\nPlease note that the smbr 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\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoissonconsulting%2Fsmbr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpoissonconsulting%2Fsmbr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoissonconsulting%2Fsmbr/lists"}