Package: bayesiansurpriser 0.1.0

bayesiansurpriser: Bayesian Surprise for De-Biasing Thematic Maps

Implements Bayesian Surprise methodology for data visualization, based on Correll and Heer (2017) <doi:10.1109/TVCG.2016.2598839> "Surprise! Bayesian Weighting for De-Biasing Thematic Maps". Provides tools to weight event data relative to spatio-temporal models, highlighting unexpected patterns while de-biasing against known factors like population density or sampling variation. Integrates seamlessly with 'sf' for spatial data and 'ggplot2' for visualization. Supports temporal/streaming data analysis.

Authors:Dmitry Shkolnik [aut, cre]

bayesiansurpriser_0.1.0.tar.gz
bayesiansurpriser_0.1.0.zip(r-4.7)bayesiansurpriser_0.1.0.zip(r-4.6)bayesiansurpriser_0.1.0.zip(r-4.5)
bayesiansurpriser_0.1.0.tgz(r-4.6-any)bayesiansurpriser_0.1.0.tgz(r-4.5-any)
bayesiansurpriser_0.1.0.tar.gz(r-4.7-any)bayesiansurpriser_0.1.0.tar.gz(r-4.6-any)
bayesiansurpriser_0.1.0.tgz(r-4.6-emscripten)
manual.pdf |manual.html
DESCRIPTION |NEWS
card.svg |card.png
bayesiansurpriser/json (API)

# Install 'bayesiansurpriser' in R:
install.packages('bayesiansurpriser', repos = c('https://dshkol.r-universe.dev', 'https://cloud.r-project.org'))

Bug tracker:https://github.com/dshkol/bayesiansurpriser/issues

Pkgdown/docs site:https://dshkol.github.io

Datasets:

On CRAN:

Conda:

5.30 score 494 downloads 63 exports 29 dependencies

Last updated from:83e5f8b06e. Checks:9 OK. Indexed: yes.

TargetResultTimeFilesSyslog
linux-devel-x86_64OK142
source / vignettesOK209
linux-release-x86_64OK175
macos-release-arm64OK132
macos-oldrel-arm64OK143
windows-develOK121
windows-releaseOK125
windows-oldrelOK109
wasm-releaseOK133

Exports:add_modelauto_surprisebayesian_updatebs_model_baseratebs_model_baserate_colbs_model_bootstrapbs_model_funnelbs_model_funnel_colbs_model_gaussianbs_model_gaussian_mixturebs_model_sampledbs_model_uniformcompute_funnel_datacompute_surprisecumulative_bayesian_updatedefault_model_spacefunnel_pvaluefunnel_zscoregeom_surprisegeom_surprise_densitygeom_surprise_histogramget_model_spaceget_surpriseget_surprise_at_timekl_divergencelog_sum_expmodel_namesmodel_spacen_modelsnormalize_minmaxnormalize_probnormalize_ratenormalize_robustnormalize_zscoreremove_modelscale_color_surprisescale_color_surprise_binnedscale_color_surprise_divergingscale_color_surprise_thresholdsscale_colour_surprisescale_colour_surprise_binnedscale_colour_surprise_divergingscale_colour_surprise_thresholdsscale_fill_surprisescale_fill_surprise_binnedscale_fill_surprise_divergingscale_fill_surprise_diverging_binnedscale_fill_surprise_manualscale_fill_surprise_thresholdsset_priorst_aggregate_surprisest_densityst_density_atst_surprisestat_surprisestat_surprise_sfStatSurpriseStatSurpriseSfsurprisesurprise_animatesurprise_rollingsurprise_temporalupdate_surprise

Dependencies:classclassIntclicpp11DBIe1071farverggplot2gluegtableisobandKernSmoothlabelinglifecycleMASSproxyR6RColorBrewerRcpprlangs2S7scalessfunitsvctrsviridisLitewithrwk

Bayesian Surprise with Canadian Census Data (cancensus)
Introduction | Prerequisites | Understanding cancensus Data Structure | Example 1: Low Income Rates by Census Division | Fetch Census Data | Compute Bayesian Surprise | Visualize Surprising Regions | Identify Most Surprising Regions | Example 2: Housing Analysis in Metro Vancouver | Example 3: Language at Home Analysis | Example 4: Provincial Comparison with Funnel Plot | Example 5: Comparing Census Years | Example 6: Custom Model Space for Census Data | Interpreting Surprise Values | Session Info

Last update: 2026-04-13
Started: 2025-12-30

Bayesian Surprise with US Census Data (tidycensus)
Introduction | When to Use Bayesian Surprise | Prerequisites | Example 1: State-Level Poverty Analysis | Visualize State-Level Results | Example 2: Funnel Plot Visualization | County-Level Funnel (Classic Shape) | Example 3: Tract-Level Analysis (Same-Scale Comparison) | Example 4: Large Counties Only | Understanding the Methodology | Why Small Regions Can Be Misleading | Recommendations | Session Info

Last update: 2026-04-13
Started: 2025-12-30

Complete Function Reference with Examples
bayesiansurpriser: Complete Reference | 1. Core Surprise Computation | 1.1 surprise() - Main Function | 1.2 auto_surprise() - Simple Vector API | 1.3 compute_surprise() - Low-Level Function | 2. Model Types | 2.1 bs_model_uniform() - Uniform Distribution | 2.2 bs_model_baserate() - Base Rate Model | 2.3 bs_model_gaussian() - Normal Distribution | 2.4 bs_model_sampled() - KDE Model | 2.5 bs_model_funnel() - de Moivre Funnel | 2.6 bs_model_bootstrap() - Bootstrap Model | 2.7 bs_model_gaussian_mixture() - Mixture Model | 3. Model Space Operations | 3.1 model_space() - Create Model Space | 3.2 default_model_space() - Quick Default | 3.3 Model Space Manipulation | 3.4 bayesian_update() - Update Posterior | 3.5 cumulative_bayesian_update() - Sequential Updates | 4. Accessor Functions | 4.1 get_surprise() and get_model_space() | 5. Temporal and Streaming Analysis | 5.1 surprise_temporal() - Panel Data | 5.2 update_surprise() - Streaming Updates | 5.3 surprise_rolling() - Rolling Window | 5.4 get_surprise_at_time() - Extract Time Slice | 5.5 surprise_animate() - Animation-Ready Data | 6. Funnel Analysis Functions | 6.1 compute_funnel_data() | 6.2 funnel_zscore() and funnel_pvalue() | 7. Normalization Utilities | 7.1 normalize_prob() - Probability Distribution | 7.2 normalize_rate() - Per-Capita Rates | 7.3 normalize_zscore() - Z-Score | 7.4 normalize_minmax() - Min-Max Scaling | 7.5 normalize_robust() - Robust Scaling | 8. Mathematical Utilities | 8.1 kl_divergence() - KL-Divergence | 8.2 log_sum_exp() - Numerically Stable | 9. ggplot2 Integration | 9.1 Color Scales | Sequential Scale | Diverging Scale | Binned Scale | Diverging Binned Scale | 9.2 stat_surprise() - Compute in ggplot2 | 9.3 Histogram and Density Geoms | 10. sf Spatial Functions | 10.1 st_surprise() - Convenience Wrapper | 10.2 st_density() - Spatial KDE | 10.3 st_aggregate_surprise() - Aggregate to Larger Regions | 11. Base R Plot Methods | 11.1 plot.bs_surprise_sf() | 11.2 plot.bs_surprise() | 11.3 plot.bs_model_space() | 11.4 plot.bs_surprise_temporal() | 12. Summary Statistics | 12.1 summary.bs_surprise() | 13. Included Datasets | 13.1 canada_mischief | 13.2 example_counties | Session Info

Last update: 2026-04-12
Started: 2025-12-29

Introduction to bayesiansurpriser
Overview | The Problem: Cognitive Biases in Data Visualization | The Solution: Bayesian Surprise | Quick Start | Basic Usage with sf Objects | Plotting Results | Understanding the Output | Customizing Models | Next Steps

Last update: 2026-04-12
Started: 2025-12-29

Spatial Data Workflows with sf
Overview | Basic sf Workflow | Loading Spatial Data | Computing Surprise | Convenience Function: st_surprise | Accessing Results | Extracting Surprise Values | Accessing the Model Space | Working with the sf Object | Visualization | ggplot2 Integration | Comparing Time Periods | Advanced: Custom Model Spaces | Integration with dplyr | Tips for Large Datasets

Last update: 2026-04-12
Started: 2025-12-29

Temporal and Streaming Analysis
Overview | Temporal Analysis with surprise_temporal() | Streaming Updates | Cumulative Bayesian Updates | Rolling Window Analysis | Anomaly Detection Over Time | Best Practices

Last update: 2026-04-12
Started: 2025-12-29

Understanding Model Types
Overview | The Five Model Types | 1. Uniform Model (bs_model_uniform) | 2. Base Rate Model (bs_model_baserate) | 3. Gaussian Model (bs_model_gaussian) | 4. Sampled/KDE Model (bs_model_sampled) | 5. de Moivre Funnel Model (bs_model_funnel) | Combining Models: Model Space | How Models Affect Surprise | Global Model Updates | Guidelines for Model Selection

Last update: 2026-04-12
Started: 2025-12-29

Visualization with ggplot2
Overview | Loading Example Data | Basic Workflow: Compute then Plot | Color Scales | Sequential Scale: scale_fill_surprise() | Diverging Scale: scale_fill_surprise_diverging() | Binned Scale: scale_fill_surprise_binned() | Combining with Other ggplot2 Elements | Adding Labels | Faceting | Theme Customization | Non-Spatial Data | Best Practices

Last update: 2026-04-12
Started: 2025-12-29

Readme and manuals

Help Manual

Help pageTopics
Add Model to Spaceadd_model
Compute Surprise with Automatic Model Selectionauto_surprise
Bayesian Update of Model Spacebayesian_update
Create a Base Rate Modelbs_model_baserate
Create Base Rate Model from Columnbs_model_baserate_col
Create a Bootstrap Sample Modelbs_model_bootstrap
Create a de Moivre Funnel Modelbs_model_funnel
Create Funnel Model from Columnbs_model_funnel_col
Create a Gaussian Modelbs_model_gaussian
Create Multi-Modal Gaussian Mixture Modelbs_model_gaussian_mixture
Create a Sampled Subset Model (KDE)bs_model_sampled
Create a Uniform Modelbs_model_uniform
Canadian Mischief Crime Data by Provincecanada_mischief
Compute Funnel Plot Datacompute_funnel_data
Compute Per-Region Surprisecompute_surprise
Global Bayesian Update Across All Regionscumulative_bayesian_update
Default Model Spacedefault_model_space
Example County Data with Simulated Eventsexample_counties
Compute P-Value from Funnel Z-Scorefunnel_pvalue
Funnel Z-Score (de Moivre)funnel_zscore
Surprise Map Geomgeom_surprise
Surprise Density Plotgeom_surprise_density
Surprise Histogramgeom_surprise_histogram
Get the model space from a surprise resultget_model_space
Extract surprise values from result objectsget_surprise
Get Surprise at Specific Timeget_surprise_at_time
Kullback-Leibler Divergencekl_divergence
Log-Sum-Exp (Numerically Stable)log_sum_exp
Get Model Namesmodel_names
Create a Model Spacemodel_space
Get Number of Modelsn_models
Min-Max Normalizationnormalize_minmax
Normalize to Probability Distributionnormalize_prob
Normalize to Rate (Per Capita)normalize_rate
Robust Normalization (using quantiles)normalize_robust
Z-Score Normalizationnormalize_zscore
Plot Model Spaceplot.bs_model_space
Plot Surprise Resultplot.bs_surprise
Plot Surprise Map (sf)plot.bs_surprise_sf
Plot Temporal Surpriseplot.bs_surprise_temporal
Remove Model from Spaceremove_model
Surprise Color Scale (Sequential)scale_color_surprise scale_colour_surprise scale_fill_surprise
Binned Surprise Scalescale_color_surprise_binned scale_colour_surprise_binned scale_fill_surprise_binned
Signed Surprise Color Scale (Diverging)scale_color_surprise_diverging scale_colour_surprise_diverging scale_fill_surprise_diverging
Binned Diverging Surprise Scalescale_fill_surprise_diverging_binned
Manual Surprise Breaks Scalescale_fill_surprise_manual
Signed Surprise Scale with Meaningful Thresholdsscale_color_surprise_thresholds scale_colour_surprise_thresholds scale_fill_surprise_thresholds
Set Prior Probabilitiesset_prior
Spatial Density Estimation for sf Objectsst_density
Evaluate Density at sf Feature Locationsst_density_at
Compute Surprise for sf Objectst_surprise
Compute Surprise as ggplot2 Statstat_surprise
Stat for Surprise with sf Geometriesstat_surprise_sf
Create Animation-Ready Data from Temporal Resultssurprise_animate
Rolling Window Surprisesurprise_rolling
Compute Temporal Surprisesurprise_temporal
Compute Bayesian Surprisesurprise surprise.data.frame surprise.sf surprise.tbl_df
Update Surprise with New Data (Streaming)update_surprise