serrsBayes v0.4-0


Monthly downloads



Bayesian Modelling of Raman Spectroscopy

Sequential Monte Carlo (SMC) algorithms for fitting a generalised additive mixed model (GAMM) to surface-enhanced resonance Raman spectroscopy (SERRS), using the method of Moores et al. (2016) <arXiv:1604.07299>. Multivariate observations of SERRS are highly collinear and lend themselves to a reduced-rank representation. The GAMM separates the SERRS signal into three components: a sequence of Lorentzian, Gaussian, or pseudo-Voigt peaks; a smoothly-varying baseline; and additive white noise. The parameters of each component of the model are estimated iteratively using SMC. The posterior distributions of the parameters given the observed spectra are represented as a population of weighted particles.



version rstudio mirror
downloads Travis-CI Build
Status Coverage

serrsBayes provides model-based quantification of surface-enhanced resonance Raman spectroscopy (SERRS) using sequential Monte Carlo (SMC) algorithms. The details of the Bayesian model and informative priors are provided in the arXiv preprint, Moores et al. (2016; v2 2018) “Bayesian modelling and quantification of Raman spectroscopy.” Development of this software was supported by the UK Engineering & Physical Sciences Research Council (EPSRC) programme grant “In Situ Nanoparticle Assemblies for Healthcare Diagnostics and Therapy” (ref: EP/L014165/1).

Installation Instructions

Stable releases, including binary packages for Windows & Mac OS, are available from CRAN:


The current development version can be installed from GitHub:


Example Usage

To simulate a synthetic Raman spectrum with known parameters:


wavenumbers <- seq(700,1400,by=2)
spectra <- matrix(nrow=1, ncol=length(wavenumbers))
peakLocations <- c(840,  960, 1140, 1220, 1290)
peakAmplitude <- c(11500, 2500, 4000, 3000, 2500)
peakScale <- c(10, 15, 20, 10, 12)
signature <- weightedLorentzian(peakLocations, peakScale, peakAmplitude, wavenumbers)
baseline <- 1000*cos(wavenumbers/200) + 2*wavenumbers
spectra[1,] <- signature + baseline + rnorm(length(wavenumbers),0,200)
plot(wavenumbers, spectra[1,], type='l', xlab=expression(paste("Raman shift (cm"^{-1}, ")")), ylab="Intensity (a.u.)")
lines(wavenumbers, baseline, col=2, lty=4)
lines(wavenumbers, baseline + signature, col=4, lty=2, lwd=2)

Fit the model using SMC:

lPriors <- list( - (0.4^2)/2,, bl.smooth=10^11, bl.knots=50,
tm <- system.time(result <- fitSpectraSMC(wavenumbers, spectra, peakLocations, lPriors))

Sample 200 particles from the posterior distribution:

#>    user  system elapsed 
#> 217.139   2.145 220.691
samp.idx <-$weights), 200, prob=result$weights)
plot(wavenumbers, spectra[1,], type='l', xlab=expression(paste("Raman shift (cm"^{-1}, ")")), ylab="Intensity (a.u.)")
for (pt in samp.idx) {
  bl.est <- result$basis %*% result$alpha[,1,pt]
  lines(wavenumbers, bl.est, col="#C3000009")
  lines(wavenumbers, bl.est + result$expFn[pt,], col="#0000C309")

Functions in serrsBayes

Name Description
effectiveSampleSize Compute the effective sample size (ESS) of the particles.
mixedVoigt Compute the spectral signature using Voigt peaks.
sumDnorm Sum log-likelihoods of Gaussian.
weightedGaussian Compute the spectral signature using Gaussian peaks.
mhUpdateVoigt Update the parameters of the Voigt peaks using marginal Metropolis-Hastings.
methanol Raman spectrum of methanol (CH3OH)
reWeightParticles Update the importance weights of each particle.
weightedVariance Compute the weighted variance of the particles.
residualResampling Compute an ancestry vector for residual resampling of the SMC particles.
weightedLorentzian Compute the spectral signature using Lorentzian peaks.
fitSpectraMCMC Fit the model using Markov chain Monte Carlo.
sumDlogNorm Sum log-likelihoods of i.i.d. lognormal.
weightedMean Compute the weighted arithmetic means of the particles.
fitSpectraSMC Fit the model using Sequential Monte Carlo (SMC).
result2 SMC particles for methanol (CH3OH)
result SMC particles for TAMRA+DNA (T20)
getBsplineBasis Compute cubic B-spline basis functions for the given wavenumbers.
computeLogLikelihood Compute the log-likelihood.
fitVoigtPeaksSMC Fit the model with Voigt peaks using Sequential Monte Carlo (SMC).
getVoigtParam Compute the pseudo-Voigt mixing ratio for each peak.
copyLogProposals Initialise the vector of Metropolis-Hastings proposals.
TAMRA Surface-enhanced Raman spectram of tetramethylrhodamine+DNA (T20)
resampleParticles Resample in place to avoid expensive copying of data structures, using a permutation of the ancestry vector.
serrsBayes Bayesian modelling and quantification of Raman spectroscopy
marginalMetropolisUpdate Update all of the parameters using a single Metropolis-Hastings step.
No Results!

Vignettes of serrsBayes

No Results!

Last month downloads


Type Package
Date 2019-04-29
License GPL (>= 2) | file LICENSE
LinkingTo Rcpp, RcppEigen
LazyData true
RoxygenNote 6.1.1
VignetteBuilder knitr
NeedsCompilation yes
Packaged 2019-04-29 10:52:00 UTC; mmoores
Repository CRAN
Date/Publication 2019-04-29 11:30:04 UTC

Include our badge in your README