Learn R Programming

samplr: Tools To Compare Human Performance To Sampling Algorithms

The goal of samplr is to provide tools to understand human performance from the perspective of sampling, both looking at how people generate samples and how people use the samples they have generated. A longer overview and other resources can be found at sampling.warwick.ac.uk.

Installation

You can install samplr from CRAN:

install.packages("samplr")

or install the development version from Github with:

devtools::install_github("lucas-castillo/samplr")

or alternatively using the remotes package

remotes::install_github("lucas-castillo/samplr")

Installing development version on MacOS

If you are installing the development version on MacOS, you will need the following prior to installation:

  1. Apple’s ‘Command Line Tools’: these can be (re-)installed by running xcode-select --install in a terminal. You may also check if those are already installed by running pkgbuild::check_build_tools() in R.
  2. A Fortran compiler. Installers for gfortran are available here. This installs into /usr/local/gfortran.

Read more about it on the macOS Prerequisites section in the R Installation and Administration Manual.

Installing development version on Windows

If you are installing the development version on Windows, you will need to have RTools installed, which you can find here. Please make sure you install the version corresponding to your R version (i.e. for R 4.3.3, you’d need RTools 4.3).

Example

The samplr package provides tools to generate samples following particular algorithms

library(samplr)
set.seed(1)
chain <- sampler_mh(start = 1, distr_name = "norm", distr_params = c(0,1), sigma_prop = diag(1) * .5, iterations = 2048)
r <- plot_series(chain[[1]], change = FALSE)

As well as tools to diagnose the patterns both from samplers and participants:

v <- calc_all(chain[[1]][1:200])

Copy Link

Version

Install

install.packages('samplr')

Monthly Downloads

148

Version

1.1.0

License

CC BY 4.0

Maintainer

Lucas Castillo

Last Published

March 31st, 2025

Functions in samplr (1.1.0)

sampler_hmc

Hamiltonian Monte-Carlo Sampler (HMC)
sampler_rec

Recycled-Momentum HMC Sampler (REC)
sampler_mc3

Metropolis-coupled MCMC sampler (MC3)
sampler_mchmc

Metropolis-Coupled Hamiltonian Monte Carlo (MCHMC)
sampler_mh

Metropolis-Hastings (MH) Sampler
samplr-package

samplr: Compare Human Performance to Sampling Algorithms
plot_2d_density

Density Plotter
Bayesian_Sampler

Bayesian Sampler Model
CoreABS

CoreABS Object
calc_qqplot

QQ-Plot Calculator
calc_PSD

Power Spectral Density Calculator
Zhu23ABS

Auto-correlated Bayesian Sampler by Zhu (2023)
Z_identities

Z Identities
calc_all

Diagnostics Wrapper
calc_levy

Levy Flights Calculator
Mean_Variance

Mean Variance Estimates
calc_autocorr

Autocorrelation Calculator
sampler_mcrec

Metropolis-Coupled Recycled-Momentum HMC Sampler (MCREC)
calc_sigma_scaling

Sigma Scaling Calculator
plot_series

Series Plotter