serrsBayes

R package serrsBayes

https://github.com/mooresm/serrsbayes

Science Score: 20.0%

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

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org, zenodo.org
  • Committers with academic emails
    2 of 8 committers (25.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.0%) to scientific vocabulary

Keywords

bayesian chemometrics raman sequential-monte-carlo spectroscopy
Last synced: 6 months ago · JSON representation

Repository

R package serrsBayes

Basic Info
  • Host: GitHub
  • Owner: mooresm
  • License: gpl-2.0
  • Language: R
  • Default Branch: main
  • Size: 8.21 MB
Statistics
  • Stars: 8
  • Watchers: 4
  • Forks: 3
  • Open Issues: 1
  • Releases: 0
Topics
bayesian chemometrics raman sequential-monte-carlo spectroscopy
Created about 8 years ago · Last pushed over 4 years ago
Metadata Files
Readme License

README.Rmd

---
output: github_document
---

# serrsBayes



```{r, echo = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  warning = FALSE,
  message = FALSE,
  comment = "#>",
  fig.path = "inst/image/README-"
)
```

[![cran version](https://www.r-pkg.org/badges/version/serrsBayes)](https://cran.r-project.org/package=serrsBayes)
[![DOI](https://zenodo.org/badge/121410558.svg)](https://zenodo.org/badge/latestdoi/121410558)
[![rstudio mirror downloads](https://cranlogs.r-pkg.org/badges/grand-total/serrsBayes)](https://github.com/r-hub/cranlogs.app)

```{r hexSticker, echo=FALSE, message=FALSE, warning=FALSE, fig.align='right', fig.asp=1, out.width='100px',out.height='100px'}
tmp <- tempfile()
download.file("https://pure.strath.ac.uk/portal/files/43595106/Figure_2.zip", tmp)
tmp2 <- unzip(tmp, "Figure 2/T20 SERS spectra/T20_1_ REP1  Well_A1.SPC")
library(hyperSpec)
spcT20 <- read.spc (tmp2)
spectra <- spcT20[1,,600~1800]
wavenumbers <- wl(spectra)
nWL <- length(wavenumbers)
library(serrsBayes)
data("result", package = "serrsBayes")
samp.idx <- sample.int(length(result$weights), 50, prob=result$weights)
samp.mat <- resid.mat <- matrix(0,nrow=length(samp.idx), ncol=nWL)
samp.sigi <- samp.lambda <- numeric(length=nrow(samp.mat))
spectra <- as.matrix(spectra)
library(hexSticker)
sticker(expression({plot(wavenumbers, spectra[1,], type='l', ann=FALSE, xaxt='n', yaxt='n', bty='n', lwd=2, col="#000000C0", xlim=c(1100,1800))
for (pt in 1:length(samp.idx)) {
    k <- samp.idx[pt]
    samp.mat[pt,] <- mixedVoigt(result$location[k,], result$scale_G[k,],
                                result$scale_L[k,], result$beta[k,], wavenumbers)
    samp.sigi[pt] <- result$sigma
    samp.lambda[pt] <- result$lambda
    
    Obsi <- spectra[1,] - samp.mat[pt,]
    g0_Cal <- length(Obsi) * samp.lambda[pt] * result$priors$bl.precision
    gi_Cal <- crossprod(result$priors$bl.basis) + g0_Cal
    mi_Cal <- as.vector(solve(gi_Cal, crossprod(result$priors$bl.basis, Obsi)))
    
    bl.est <- result$priors$bl.basis %*% mi_Cal # smoothed residuals = estimated basline
    lines(wavenumbers, bl.est, col="#0000FF40")
    lines(wavenumbers, bl.est + samp.mat[pt,], col="#FF00002F", lwd=0.5)
    resid.mat[pt,] <- Obsi - bl.est[,1]
}}),package="serrsBayes",p_size=8, s_x=0.75, s_y=.75, s_width=2.7, s_height=2.5, p_color = 2, h_color = "#0000FFC0", h_fill ="#FFFFFFFF", filename = "inst/image/README-logo.png", p_y=0.7,
url="https://mooresm.github.io/serrsBayes/", u_x=0.92, u_y=0.08)
knitr::include_graphics("inst/image/README-logo.png", dpi=600)
```

`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.](https://arxiv.org/abs/1604.07299)" 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](https://gtr.ukri.org/projects?ref=EP%2FL014165%2F1)" (ref: EP/L014165/1).

# Installation Instructions

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

* 

```{r eval=FALSE}
install.packages("serrsBayes")
```

The current development version can be installed from GitHub:
```{r eval=FALSE}
devtools::install_github("mooresm/serrsBayes")
```

# Example Usage

To simulate a synthetic Raman spectrum with known parameters:

```{r example}
set.seed(1234)
library(serrsBayes)

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:

```{r SMC, results='hide'}
lPriors <- list(scale.mu=log(11.6) - (0.4^2)/2, scale.sd=0.4, bl.smooth=10^11, bl.knots=50,
                 beta.mu=5000, beta.sd=5000, noise.sd=200, noise.nu=4)
tm <- system.time(result <- fitSpectraSMC(wavenumbers, spectra, peakLocations, lPriors))
```

Sample 200 particles from the posterior distribution:

```{r plotting}
print(tm)
samp.idx <- sample.int(length(result$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")
}
```

Owner

  • Name: Matt
  • Login: mooresm
  • Kind: user
  • Location: Wollongong, Australia
  • Company: National Institute for Applied Statistics Research Australia

I’m a lecturer in statistics at the University of Wollongong, in Australia. I work on Bayesian computational methods for image analysis and Raman spectroscopy.

GitHub Events

Total
Last Year

Committers

Last synced: about 2 years ago

All Time
  • Total Commits: 69
  • Total Committers: 8
  • Avg Commits per committer: 8.625
  • Development Distribution Score (DDS): 0.652
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Matt Moores M****s@w****k 24
Matt Moores m****s@g****m 20
Matt Moores m****s@u****e 10
Matt Moores m****s@u****u 8
Matt Moores m****t@e****e 3
Matt Moores m****s@e****e 2
Matt m****m 1
Dirk Eddelbuettel e****d@d****g 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 1
  • Total pull requests: 1
  • Average time to close issues: N/A
  • Average time to close pull requests: 3 days
  • Total issue authors: 1
  • Total pull request authors: 1
  • Average comments per issue: 0.0
  • Average comments per pull request: 3.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • mooresm (1)
Pull Request Authors
  • eddelbuettel (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 318 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 8
  • Total maintainers: 1
cran.r-project.org: serrsBayes

Bayesian Modelling of Raman Spectroscopy

  • Versions: 8
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 318 Last month
Rankings
Forks count: 14.9%
Stargazers count: 22.5%
Dependent packages count: 29.8%
Average: 31.1%
Dependent repos count: 35.5%
Downloads: 52.8%
Maintainers (1)
Last synced: 6 months ago

Dependencies

DESCRIPTION cran
  • Matrix * depends
  • R >= 3.5.0 depends
  • splines * depends
  • truncnorm * depends
  • Rcpp >= 0.11.3 imports
  • methods * imports
  • Hmisc * suggests
  • knitr * suggests
  • rmarkdown * suggests
  • testthat * suggests