priorsense

priorsense: an R package for prior diagnostics and sensitivity

https://github.com/n-kall/priorsense

Science Score: 57.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 6 DOI reference(s) in README
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.1%) to scientific vocabulary

Keywords

bayes bayesian bayesian-data-analysis bayesian-methods prior-distribution r r-package sensitivity-analysis stan
Last synced: 6 months ago · JSON representation ·

Repository

priorsense: an R package for prior diagnostics and sensitivity

Basic Info
Statistics
  • Stars: 64
  • Watchers: 5
  • Forks: 9
  • Open Issues: 4
  • Releases: 0
Topics
bayes bayesian bayesian-data-analysis bayesian-methods prior-distribution r r-package sensitivity-analysis stan
Created over 4 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog Contributing License Citation Codemeta

README.md

priorsense

Lifecycle:
stable CRAN
status R-CMD-check <!-- badges: end -->

Overview

priorsense provides tools for prior diagnostics and sensitivity analysis.

It currently includes functions for performing power-scaling sensitivity analysis on Stan models. This is a way to check how sensitive a posterior is to perturbations of the prior and likelihood and diagnose the cause of sensitivity. For efficient computation, power-scaling sensitivity analysis relies on Pareto smoothed importance sampling (Vehtari et al., 2024) and importance weighted moment matching (Paananen et al., 2021).

Power-scaling sensitivity analysis and priorsense are described in Kallioinen et al. (2023).

Installation

Download the stable version from CRAN with:

r install.packages("priorsense")

Download the development version from GitHub with:

``` r

install.packages("remotes")

remotes::install_github("n-kall/priorsense", ref = "development") ```

Usage

priorsense works with models created with rstan, cmdstanr, brms, R2jags, or with draws objects from the posterior package.

Example

Consider a simple univariate model with unknown mu and sigma fit to some data y (available viaexample_powerscale_model("univariate_normal")):

stan data { int<lower=1> N; array[N] real y; } parameters { real mu; real<lower=0> sigma; } model { // priors target += normal_lpdf(mu | 0, 1); target += normal_lpdf(sigma | 0, 2.5); // likelihood target += normal_lpdf(y | mu, sigma); } generated quantities { vector[N] log_lik; real lprior; // log likelihood for (n in 1:N) log_lik[n] = normal_lpdf(y[n] | mu, sigma); // joint log prior lprior = normal_lpdf(mu | 0, 1) + normal_lpdf(sigma | 0, 2.5);

We first fit the model using Stan:

``` r library(priorsense)

normalmodel <- examplepowerscalemodel("univariatenormal")

fit <- rstan::stan( modelcode = normalmodel$modelcode, data = normalmodel$data, refresh = FALSE, seed = 123 ) ```

Once fit, sensitivity can be checked as follows:

r powerscale_sensitivity(fit)

Sensitivity based on cjs_dist
Prior selection: all priors
Likelihood selection: all data

 variable prior likelihood                     diagnosis
       mu  0.43       0.64 potential prior-data conflict
    sigma  0.36       0.67 potential prior-data conflict

To visually inspect changes to the posterior, use one of the diagnostic plot functions. Estimates with high Pareto-k values may be inaccurate and are indicated.

r powerscale_plot_dens(fit)

r powerscale_plot_ecdf(fit)

r powerscale_plot_quantities(fit)

In some cases, setting moment_match = TRUE will improve the unreliable estimates at the cost of some further computation. This requires the iwmm package.

Contributing

Contributions 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.

References

Noa Kallioinen, Topi Paananen, Paul-Christian Bürkner, Aki Vehtari (2023). Detecting and diagnosing prior and likelihood sensitivity with power-scaling. Statistics and Computing. 34, 57. https://doi.org/10.1007/s11222-023-10366-5

Topi Paananen, Juho Piironen, Paul-Christian Bürkner, Aki Vehtari (2021). Implicitly adaptive importance sampling. Statistics and Computing 31, 16. https://doi.org/10.1007/s11222-020-09982-2

Aki Vehtari, Daniel Simpson, Andrew Gelman, Yuling Yao, Jonah Gabry (2024). Pareto smoothed importance sampling. Journal of Machine Learning Research. 25, 72. https://jmlr.org/papers/v25/19-556.html

Owner

  • Login: n-kall
  • Kind: user

Citation (CITATION.cff)

cff-version: "1.2.0"
message: If you use this software, please cite our article in Statistics and Computing.
preferred-citation:
  type: article
  authors:
  - family-names: Kallioinen
    given-names: Noa
    orcid: "https://orcid.org/0000-0003-1586-8382"
  - family-names: Paananen
    given-names: Topi
    orcid: "https://orcid.org/0000-0002-6542-407X"
  - family-names: Bürkner
    given-names: Paul-Christian
    orcid: "https://orcid.org/0000-0001-5765-8995"
  - family-names: Vehtari
    given-names: Aki
    orcid: "https://orcid.org/0000-0003-2164-9469"
  year: 2023
  doi: 10.1007/s11222-023-10366-5
  pages: 57
  journal: Statistics and Computing
  publisher:
    name: Springer Nature
  volume: 34
  title: "Detecting and diagnosing prior and likelihood sensitivity with power-scaling"
  url: "https://link.springer.com/article/10.1007/s11222-023-10366-5"

CodeMeta (codemeta.json)

{
  "@context": "https://doi.org/10.5063/schema/codemeta-2.0",
  "@type": "SoftwareSourceCode",
  "identifier": "priorsense",
  "description": "Provides functions for prior and likelihood sensitivity analysis in Bayesian models. Currently it implements methods to determine the sensitivity of the posterior to power-scaling perturbations of the prior and likelihood.",
  "name": "priorsense: Prior Diagnostics and Sensitivity Analysis",
  "relatedLink": [
    "https://n-kall.github.io/priorsense/",
    "https://CRAN.R-project.org/package=priorsense"
  ],
  "codeRepository": "https://github.com/n-kall/priorsense",
  "issueTracker": "https://github.com/n-kall/priorsense/issues",
  "license": "https://spdx.org/licenses/GPL-3.0",
  "version": "1.1.0",
  "programmingLanguage": {
    "@type": "ComputerLanguage",
    "name": "R",
    "url": "https://r-project.org"
  },
  "runtimePlatform": "R version 4.4.3 (2025-02-28)",
  "provider": {
    "@id": "https://cran.r-project.org",
    "@type": "Organization",
    "name": "Comprehensive R Archive Network (CRAN)",
    "url": "https://cran.r-project.org"
  },
  "author": [
    {
      "@type": "Person",
      "givenName": "Noa",
      "familyName": "Kallioinen",
      "email": "noa.kallioinen@aalto.fi"
    },
    {
      "@type": "Person",
      "givenName": "Topi",
      "familyName": "Paananen"
    },
    {
      "@type": "Person",
      "givenName": "Paul-Christian",
      "familyName": "Brkner"
    },
    {
      "@type": "Person",
      "givenName": "Aki",
      "familyName": "Vehtari"
    }
  ],
  "contributor": [
    {
      "@type": "Person",
      "givenName": "Frank",
      "familyName": "Weber"
    }
  ],
  "copyrightHolder": [
    {
      "@type": "Person",
      "givenName": "Noa",
      "familyName": "Kallioinen",
      "email": "noa.kallioinen@aalto.fi"
    }
  ],
  "maintainer": [
    {
      "@type": "Person",
      "givenName": "Noa",
      "familyName": "Kallioinen",
      "email": "noa.kallioinen@aalto.fi"
    }
  ],
  "softwareSuggestions": [
    {
      "@type": "SoftwareApplication",
      "identifier": "R2jags",
      "name": "R2jags",
      "version": ">= 0.8",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=R2jags"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "bayesplot",
      "name": "bayesplot",
      "version": ">= 1.11.1",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=bayesplot"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "brms",
      "name": "brms",
      "version": ">= 2.22.0",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=brms"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "cmdstanr",
      "name": "cmdstanr",
      "version": ">= 0.8.1"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "iwmm",
      "name": "iwmm",
      "version": ">= 0.0.1"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "quarto",
      "name": "quarto",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=quarto"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "philentropy",
      "name": "philentropy",
      "version": ">= 0.8.0",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=philentropy"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "rstan",
      "name": "rstan",
      "version": ">= 2.32.6",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=rstan"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "testthat",
      "name": "testthat",
      "version": ">= 3.0.0",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=testthat"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "transport",
      "name": "transport",
      "version": ">= 0.15",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=transport"
    }
  ],
  "softwareRequirements": {
    "1": {
      "@type": "SoftwareApplication",
      "identifier": "checkmate",
      "name": "checkmate",
      "version": ">= 2.3.1",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=checkmate"
    },
    "2": {
      "@type": "SoftwareApplication",
      "identifier": "ggdist",
      "name": "ggdist",
      "version": ">= 3.3.2",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=ggdist"
    },
    "3": {
      "@type": "SoftwareApplication",
      "identifier": "ggh4x",
      "name": "ggh4x",
      "version": ">= 0.2.5",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=ggh4x"
    },
    "4": {
      "@type": "SoftwareApplication",
      "identifier": "ggplot2",
      "name": "ggplot2",
      "version": ">= 3.5.1",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=ggplot2"
    },
    "5": {
      "@type": "SoftwareApplication",
      "identifier": "grDevices",
      "name": "grDevices",
      "version": ">= 3.6.2"
    },
    "6": {
      "@type": "SoftwareApplication",
      "identifier": "matrixStats",
      "name": "matrixStats",
      "version": ">= 1.3.0",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=matrixStats"
    },
    "7": {
      "@type": "SoftwareApplication",
      "identifier": "posterior",
      "name": "posterior",
      "version": ">= 1.6.0",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=posterior"
    },
    "8": {
      "@type": "SoftwareApplication",
      "identifier": "rlang",
      "name": "rlang",
      "version": ">= 1.1.4",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=rlang"
    },
    "9": {
      "@type": "SoftwareApplication",
      "identifier": "stats",
      "name": "stats"
    },
    "10": {
      "@type": "SoftwareApplication",
      "identifier": "tibble",
      "name": "tibble",
      "version": ">= 3.2.1",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=tibble"
    },
    "11": {
      "@type": "SoftwareApplication",
      "identifier": "utils",
      "name": "utils"
    },
    "12": {
      "@type": "SoftwareApplication",
      "identifier": "R",
      "name": "R",
      "version": ">= 3.6.0"
    },
    "SystemRequirements": null
  },
  "fileSize": "2273.618KB",
  "citation": [
    {
      "@type": "ScholarlyArticle",
      "datePublished": "2023",
      "author": [
        {
          "@type": "Person",
          "givenName": "Noa",
          "familyName": "Kallioinen"
        },
        {
          "@type": "Person",
          "givenName": "Topi",
          "familyName": "Paananen"
        },
        {
          "@type": "Person",
          "givenName": "Paul-Christian",
          "familyName": "Brkner"
        },
        {
          "@type": "Person",
          "givenName": "Aki",
          "familyName": "Vehtari"
        }
      ],
      "name": "Detecting and diagnosing prior and likelihood sensitivity with power-scaling",
      "identifier": "10.1007/s11222-023-10366-5",
      "@id": "https://doi.org/10.1007/s11222-023-10366-5",
      "sameAs": "https://doi.org/10.1007/s11222-023-10366-5",
      "isPartOf": {
        "@type": "PublicationIssue",
        "datePublished": "2023",
        "isPartOf": {
          "@type": [
            "PublicationVolume",
            "Periodical"
          ],
          "volumeNumber": "34",
          "name": "Statistics and Computing"
        }
      }
    },
    {
      "@type": "ScholarlyArticle",
      "datePublished": "2024",
      "author": [
        {
          "@type": "Person",
          "givenName": "Aki",
          "familyName": "Vehtari"
        },
        {
          "@type": "Person",
          "givenName": "Daniel",
          "familyName": "Simpson"
        },
        {
          "@type": "Person",
          "givenName": "Andrew",
          "familyName": "Gelman"
        },
        {
          "@type": "Person",
          "givenName": "Yuling",
          "familyName": "Yao"
        },
        {
          "@type": "Person",
          "givenName": "Jonah",
          "familyName": "Gabry"
        }
      ],
      "name": "Pareto smoothed importance sampling",
      "isPartOf": {
        "@type": "PublicationIssue",
        "datePublished": "2024",
        "isPartOf": {
          "@type": [
            "PublicationVolume",
            "Periodical"
          ],
          "volumeNumber": "25",
          "name": "Journal of Machine Learning Research"
        }
      }
    },
    {
      "@type": "ScholarlyArticle",
      "datePublished": "2021",
      "author": [
        {
          "@type": "Person",
          "givenName": "Topi",
          "familyName": "Paananen"
        },
        {
          "@type": "Person",
          "givenName": "Juho",
          "familyName": "Piironen"
        },
        {
          "@type": "Person",
          "givenName": "Paul-Christian",
          "familyName": "Brkner"
        },
        {
          "@type": "Person",
          "givenName": "Aki",
          "familyName": "Vehtari"
        }
      ],
      "name": "Implicitly adaptive importance sampling",
      "identifier": "10.1007/s11222-020-09982-2",
      "pagination": "1--19",
      "@id": "https://doi.org/10.1007/s11222-020-09982-2",
      "sameAs": "https://doi.org/10.1007/s11222-020-09982-2",
      "isPartOf": {
        "@type": "PublicationIssue",
        "datePublished": "2021",
        "isPartOf": {
          "@type": [
            "PublicationVolume",
            "Periodical"
          ],
          "volumeNumber": "31",
          "name": "Statistics and Computing"
        }
      }
    }
  ],
  "releaseNotes": "https://github.com/n-kall/priorsense/blob/master/NEWS.md",
  "readme": "https://github.com/n-kall/priorsense/blob/main/README.md",
  "contIntegration": "https://github.com/n-kall/priorsense/actions",
  "developmentStatus": "https://lifecycle.r-lib.org/articles/stages.html#stable",
  "keywords": [
    "bayesian-data-analysis",
    "bayesian-methods",
    "prior-distribution",
    "r-package",
    "sensitivity-analysis",
    "stan",
    "bayesian",
    "r",
    "bayes"
  ]
}

GitHub Events

Total
  • Issues event: 22
  • Watch event: 8
  • Delete event: 8
  • Issue comment event: 16
  • Push event: 123
  • Pull request event: 46
  • Fork event: 4
  • Create event: 9
Last Year
  • Issues event: 22
  • Watch event: 8
  • Delete event: 8
  • Issue comment event: 16
  • Push event: 123
  • Pull request event: 46
  • Fork event: 4
  • Create event: 9

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 544
  • Total Committers: 7
  • Avg Commits per committer: 77.714
  • Development Distribution Score (DDS): 0.283
Past Year
  • Commits: 149
  • Committers: 3
  • Avg Commits per committer: 49.667
  • Development Distribution Score (DDS): 0.242
Top Committers
Name Email Commits
n-kall n****l@g****m 390
n-kall 3****l 117
fweber144 f****4@p****m 14
Rantaharju Jarno j****u@a****i 12
Andrew Johnson a****n@a****m 7
Sam A.S. Welch 1****A 3
Andrey Akinshin a****n@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 34
  • Total pull requests: 86
  • Average time to close issues: 7 months
  • Average time to close pull requests: 10 days
  • Total issue authors: 14
  • Total pull request authors: 8
  • Average comments per issue: 1.71
  • Average comments per pull request: 0.09
  • Merged pull requests: 72
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 12
  • Pull requests: 52
  • Average time to close issues: about 1 month
  • Average time to close pull requests: 2 days
  • Issue authors: 3
  • Pull request authors: 3
  • Average comments per issue: 1.17
  • Average comments per pull request: 0.0
  • Merged pull requests: 41
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • n-kall (14)
  • avehtari (4)
  • rantahar (2)
  • jflournoy (2)
  • paul-buerkner (2)
  • maxbiostat (1)
  • dirknbr (1)
  • fweber144 (1)
  • TeemuSailynoja (1)
  • Sandhu-SS (1)
  • AndHofma (1)
  • bcs-alexander (1)
  • lcgodoy (1)
  • fraupflaume (1)
  • cmgoold (1)
Pull Request Authors
  • n-kall (99)
  • samawelch (6)
  • rantahar (3)
  • AndreyAkinshin (2)
  • GiorgioMB (2)
  • andrjohns (1)
  • harris-yh-wong (1)
  • fweber144 (1)
Top Labels
Issue Labels
ro-hackathon-2025 (7) good first issue (5) help wanted (4) documentation (1) bug (1) enhancement (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 1,429 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 7
  • Total maintainers: 1
cran.r-project.org: priorsense

Prior Diagnostics and Sensitivity Analysis

  • Versions: 7
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 1,429 Last month
Rankings
Dependent packages count: 28.7%
Dependent repos count: 35.4%
Average: 50.1%
Downloads: 86.3%
Maintainers (1)
Last synced: 6 months ago

Dependencies

DESCRIPTION cran
  • R >= 3.6.0 depends
  • cetcolor * imports
  • checkmate * imports
  • ggplot2 * imports
  • loo * imports
  • matrixStats * imports
  • methods * imports
  • philentropy * imports
  • posterior * imports
  • stats * imports
  • tibble * imports
  • transport * imports
  • utils * imports
  • brms * suggests
  • knitr * suggests
  • rmarkdown * suggests
  • rstan * suggests
  • testthat >= 3.0.0 suggests
.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v2 composite
  • n1hility/cancel-previous-runs v2 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/render-rmarkdown.yaml actions
  • actions/checkout v2 composite
  • n1hility/cancel-previous-runs v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite