Skip to contents

Core Functions

Main functions for computing Bayesian Surprise

surprise()
Compute Bayesian Surprise
compute_surprise()
Compute Per-Region Surprise
auto_surprise()
Compute Surprise with Automatic Model Selection
st_surprise()
Compute Surprise for sf Object

Model Constructors

Create probability models for the model space

bs_model_uniform()
Create a Uniform Model
bs_model_baserate()
Create a Base Rate Model
bs_model_baserate_col()
Create Base Rate Model from Column
bs_model_gaussian()
Create a Gaussian Model
bs_model_gaussian_mixture()
Create Multi-Modal Gaussian Mixture Model
bs_model_sampled()
Create a Sampled Subset Model (KDE)
bs_model_funnel()
Create a de Moivre Funnel Model
bs_model_funnel_col()
Create Funnel Model from Column
bs_model_bootstrap()
Create a Bootstrap Sample Model

Model Space

Combine models and manage priors

model_space()
Create a Model Space
default_model_space()
Default Model Space
add_model()
Add Model to Space
remove_model()
Remove Model from Space
set_prior()
Set Prior Probabilities
model_names()
Get Model Names
n_models()
Get Number of Models

Bayesian Updates

Update beliefs with new data

bayesian_update()
Bayesian Update of Model Space
cumulative_bayesian_update()
Global Bayesian Update Across All Regions
update_surprise()
Update Surprise with New Data (Streaming)

Temporal Analysis

Analyze surprise over time

surprise_temporal()
Compute Temporal Surprise
surprise_rolling()
Rolling Window Surprise
surprise_animate()
Create Animation-Ready Data from Temporal Results
get_surprise_at_time()
Get Surprise at Specific Time

Funnel Plot Utilities

Tools for funnel plot analysis

compute_funnel_data()
Compute Funnel Plot Data
funnel_zscore()
Funnel Z-Score (de Moivre)
funnel_pvalue()
Compute P-Value from Funnel Z-Score

Result Accessors

Extract values from surprise results

get_surprise()
Extract surprise values from result objects
get_model_space()
Get the model space from a surprise result

Plot Methods

Base R plotting methods for surprise objects

plot(<bs_surprise>)
Plot Surprise Result
plot(<bs_surprise_sf>)
Plot Surprise Map (sf)
plot(<bs_surprise_temporal>)
Plot Temporal Surprise
plot(<bs_model_space>)
Plot Model Space

Spatial Functions

Integration with sf spatial data

st_surprise()
Compute Surprise for sf Object
st_density()
Spatial Density Estimation for sf Objects
st_density_at()
Evaluate Density at sf Feature Locations
st_aggregate_surprise()
Aggregate Surprise to Larger Regions

ggplot2 Scales

Color scales for visualizing surprise

ggplot2 Geoms and Stats

Geometric objects and statistics for ggplot2

geom_surprise()
Surprise Map Geom
geom_surprise_histogram()
Surprise Histogram
geom_surprise_density()
Surprise Density Plot
stat_surprise()
Compute Surprise as ggplot2 Stat
stat_surprise_sf()
Stat for Surprise with sf Geometries
StatSurprise
StatSurprise ggproto Object
StatSurpriseSf
StatSurpriseSf ggproto Object (for sf integration)

Normalization Utilities

Data normalization functions

normalize_prob()
Normalize to Probability Distribution
normalize_rate()
Normalize to Rate (Per Capita)
normalize_zscore()
Z-Score Normalization
normalize_minmax()
Min-Max Normalization
normalize_robust()
Robust Normalization (using quantiles)

Mathematical Utilities

Low-level mathematical functions

kl_divergence()
Kullback-Leibler Divergence
log_sum_exp()
Log-Sum-Exp (Numerically Stable)

Sample Data

Example datasets included with the package

canada_mischief
Canadian Mischief Crime Data by Province
example_counties
Example County Data with Simulated Events