{"id":19769883,"url":"https://github.com/n-kall/priorsense","last_synced_at":"2025-04-05T07:04:55.271Z","repository":{"id":40468796,"uuid":"383790183","full_name":"n-kall/priorsense","owner":"n-kall","description":"priorsense: an R package for prior diagnostics and sensitivity","archived":false,"fork":false,"pushed_at":"2025-03-27T11:58:56.000Z","size":8916,"stargazers_count":59,"open_issues_count":8,"forks_count":9,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-29T06:04:35.038Z","etag":null,"topics":["bayes","bayesian","bayesian-data-analysis","bayesian-methods","prior-distribution","r","r-package","sensitivity-analysis","stan"],"latest_commit_sha":null,"homepage":"https://n-kall.github.io/priorsense/","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/n-kall.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-07T12:25:06.000Z","updated_at":"2025-03-28T09:53:50.000Z","dependencies_parsed_at":"2024-02-27T12:30:18.648Z","dependency_job_id":"66814536-0141-4fc2-b6e0-4d048c998c25","html_url":"https://github.com/n-kall/priorsense","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/n-kall%2Fpriorsense","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n-kall%2Fpriorsense/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n-kall%2Fpriorsense/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n-kall%2Fpriorsense/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/n-kall","download_url":"https://codeload.github.com/n-kall/priorsense/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247299831,"owners_count":20916190,"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":["bayes","bayesian","bayesian-data-analysis","bayesian-methods","prior-distribution","r","r-package","sensitivity-analysis","stan"],"created_at":"2024-11-12T04:45:00.970Z","updated_at":"2025-04-05T07:04:55.252Z","avatar_url":"https://github.com/n-kall.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, include = FALSE}\n\nggplot2::theme_set(bayesplot::theme_default(base_family = \"sans\"))\n\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# priorsense\n\n\u003c!-- badges: start --\u003e\n[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-green.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)\n[![CRAN status](https://www.r-pkg.org/badges/version/priorsense)](https://CRAN.R-project.org/package=priorsense)\n[![R-CMD-check](https://github.com/n-kall/priorsense/workflows/R-CMD-check/badge.svg)](https://github.com/n-kall/priorsense/actions)\n\u003c!-- badges: end --\u003e\n\n## Overview\n\npriorsense provides tools for prior diagnostics and sensitivity\nanalysis.\n\nIt currently includes functions for performing power-scaling\nsensitivity analysis on Stan models. This is a way to check how\nsensitive a posterior is to perturbations of the prior and likelihood\nand diagnose the cause of sensitivity. For efficient computation,\npower-scaling sensitivity analysis relies on Pareto smoothed\nimportance sampling (Vehtari et al., 2024) and importance weighted\nmoment matching (Paananen et al., 2021).\n\nPower-scaling sensitivity analysis and priorsense are described in\nKallioinen et al. (2023).\n\n## Installation\n\nDownload the stable version from CRAN with:\n\n```{r, eval = F}\ninstall.packages(\"priorsense\")\n```\n\n\nDownload the development version from [GitHub](https://github.com/) with:\n\n```{r, eval = F}\n# install.packages(\"remotes\")\nremotes::install_github(\"n-kall/priorsense\", ref = \"development\")\n```\n\n## Usage\n\npriorsense works with models created with rstan, cmdstanr or brms, or\nwith draws objects from the posterior package.\n\n### Example \n\nConsider a simple univariate model with unknown mu and sigma fit to\nsome data y (available\nvia`example_powerscale_model(\"univariate_normal\")`):\n\n```stan\ndata {\n  int\u003clower=1\u003e N;\n  array[N] real y;\n}\nparameters {\n  real mu;\n  real\u003clower=0\u003e sigma;\n}\nmodel {\n  // priors\n  target += normal_lpdf(mu | 0, 1);\n  target += normal_lpdf(sigma | 0, 2.5);\n  // likelihood\n  target += normal_lpdf(y | mu, sigma);\n}\ngenerated quantities {\n  vector[N] log_lik;\n  real lprior;\n  // log likelihood\n  for (n in 1:N) log_lik[n] =  normal_lpdf(y[n] | mu, sigma);\n  // joint log prior\n  lprior = normal_lpdf(mu | 0, 1) +\n\tnormal_lpdf(sigma | 0, 2.5);\n```\n\nWe first fit the model using Stan:\n\n```{r, eval = T, results = F, message = F, warning = F}\nlibrary(priorsense)\n\nnormal_model \u003c- example_powerscale_model(\"univariate_normal\")\n\nfit \u003c- rstan::stan(\n  model_code = normal_model$model_code,\n  data = normal_model$data,\n  refresh = FALSE,\n  seed = 123\n)\n```\n\nOnce fit, sensitivity can be checked as follows:\n```{r, eval = T}\npowerscale_sensitivity(fit)\n```\n\nTo visually inspect changes to the posterior, use one of the\ndiagnostic plot functions. Estimates with high Pareto-k values may be\ninaccurate and are indicated.\n\n```{r dens_plot, eval = T, out.width = '70%'}\npowerscale_plot_dens(fit)\n```\n\n```{r ecdf_plot, eval = T, out.width = '70%'}\npowerscale_plot_ecdf(fit)\n```\n\n```{r quants_plot, eval = T, out.width = '70%'}\npowerscale_plot_quantities(fit)\n```\n\nIn some cases, setting `moment_match = TRUE` will improve the\nunreliable estimates at the cost of some further computation. This\nrequires the [`iwmm` package](https://github.com/topipa/iwmm).\n\n\n## Contributing\n\nContributions are welcome! If you find an bug or have an idea for a feature, open an issue. If you are able to fix an issue, fork the repository and make a pull request to the `development` branch.\n\n## References\n\nNoa Kallioinen, Topi Paananen, Paul-Christian Bürkner, Aki Vehtari\n(2023).  Detecting and diagnosing prior and likelihood sensitivity\nwith power-scaling. Statistics and Computing. 34, 57.\nhttps://doi.org/10.1007/s11222-023-10366-5\n\nTopi Paananen, Juho Piironen, Paul-Christian Bürkner, Aki Vehtari (2021).\nImplicitly adaptive importance sampling. Statistics and Computing\n31, 16. https://doi.org/10.1007/s11222-020-09982-2\n\nAki Vehtari, Daniel Simpson, Andrew Gelman, Yuling Yao, Jonah Gabry (2024). \nPareto smoothed importance sampling. Journal of\nMachine Learning Research. 25, 72. https://jmlr.org/papers/v25/19-556.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fn-kall%2Fpriorsense","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fn-kall%2Fpriorsense","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fn-kall%2Fpriorsense/lists"}