Skip to content

Commit

Permalink
Merge pull request #23 from l-ramirez-lopez/v0.2.1
Browse files Browse the repository at this point in the history
Version 0.2.1 available on CRAN
  • Loading branch information
l-ramirez-lopez authored Oct 25, 2020
2 parents 06984fe + 608294a commit f04f7b7
Show file tree
Hide file tree
Showing 86 changed files with 1,508 additions and 906 deletions.
22 changes: 7 additions & 15 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
^.*\.Rproj$
^\.Rproj\.user$
^README\.md
.Rhistory
.gitignore
figure
whittaker.r
logo_prospectr.xcf
prospectr-intro\.html
prospectr-intro\.bib
prospectr-intro\.md
^.*\.tex
^.*\.pdf
code_ex.R
.Rhistory
.travis.yml
^appveyor\.yml$
cran-comments.md
code_ex.R
^Rscript*
^packrat/
^\.Rprofile$c
TODO
^appveyor\.yml$
cran-comments.md
^doc$
^Meta$
epo.R

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ prospectr-intro\.html
prospectr-intro\.md
doc
Meta
vignettes/prospectr.html
18 changes: 9 additions & 9 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Type: Package
Title: Miscellaneous Functions for Processing
and Sample Selection of Spectroscopic Data
Version: 0.2.1
Date: 2020-09-24
Date: 2020-10-23
Author:
Antoine Stevens [aut, cre],
Leonardo Ramirez-Lopez [aut, cre],
Guillaume Hans [ctb]
Antoine Stevens [aut, cre] (<https://orcid.org/0000-0002-1588-7519>),
Leonardo Ramirez-Lopez [aut, cre] (<https://orcid.org/0000-0002-5369-5120>),
Guillaume Hans [ctb] (<https://orcid.org/0000-0002-6503-5760>)
Maintainer:
Leonardo Ramirez-Lopez <[email protected]>
BugReports:
Expand All @@ -21,7 +21,8 @@ Suggests:
knitr,
rmarkdown,
formatR,
testthat
testthat,
bookdown
LinkingTo:
Rcpp,
RcppArmadillo
Expand All @@ -32,13 +33,12 @@ Imports:
iterators,
Rcpp (>= 1.0.1),
mathjaxr (>= 1.0),
lifecycle (>= 0.2.0),
RdMacros:
mathjaxr,
lifecycle
lifecycle (>= 0.2.0)
RdMacros: mathjaxr
RoxygenNote: 7.1.1
NeedsCompilation: yes
LazyData: true
LazyDataCompression: xz
Repository: CRAN
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export(standardNormalVariate)
import(Rcpp)
import(foreach)
import(iterators)
import(lifecycle)
import(mathjaxr)
importFrom(grDevices,chull)
importFrom(graphics,legend)
importFrom(graphics,matplot)
Expand Down
11 changes: 9 additions & 2 deletions R/AAA.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

.onAttach <- function(lib, pkg) {
# assign("gpclib", FALSE, envir=.prospectr_CACHE)
prospectr.v <- read.dcf(file = system.file("DESCRIPTION", package = pkg), fields = "Version")
prospectr.v <- read.dcf(
file = system.file("DESCRIPTION", package = pkg),
fields = "Version"
)
packageStartupMessage(paste(pkg, "version", prospectr.v, "-- 'seville'"))
packageStartupMessage("check the github repository at http://github.com/l-ramirez-lopez/prospectr")
mss2 <- paste0(
"check the github repository at: ",
"http://github.com/l-ramirez-lopez/prospectr"
)
packageStartupMessage(mss2)
}

# .onUnload <- function(libpath) {
Expand Down
1 change: 0 additions & 1 deletion R/Cul.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#' @title Cochran C critical value
#'
#' @description
#' \lifecycle{stable}
#' Upper limit critical value Cul for one-sided test on balanced design
#' @usage
#' Cul(a,n,N)
Expand Down
34 changes: 17 additions & 17 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' @title Resample to given band position and fwhm
#' @description
#' Resample, written in C++
#' @param X matrix to resample
#' @param wav a numeric \code{vector} giving the original band positions
#' @param new_wav a numeric \code{vector} giving the new band positions
#' @param fwhm numeric \code{vector} giving the full width half maximums of the new band positions.
#' @keywords internal
#' @useDynLib prospectr
resample_fwhm <- function(X, wav, new_wav, fwhm) {
.Call('_prospectr_resample_fwhm', PACKAGE = 'prospectr', X, wav, new_wav, fwhm)
}

resample_fwhm_vec <- function(X, wav, new_wav, fwhm) {
.Call('_prospectr_resample_fwhm_vec', PACKAGE = 'prospectr', X, wav, new_wav, fwhm)
}

#' @title bitwise operations
#' @description
#' bitwise operations in C++
Expand Down Expand Up @@ -87,6 +70,23 @@ get_msc_coeff <- function(X, reference_spc) {
.Call('_prospectr_get_msc_coeff', PACKAGE = 'prospectr', X, reference_spc)
}

#' @title Resample to given band position and fwhm
#' @description
#' Resample, written in C++
#' @param X matrix to resample
#' @param wav a numeric \code{vector} giving the original band positions
#' @param new_wav a numeric \code{vector} giving the new band positions
#' @param fwhm numeric \code{vector} giving the full width half maximums of the new band positions.
#' @keywords internal
#' @useDynLib prospectr
resample_fwhm <- function(X, wav, new_wav, fwhm) {
.Call('_prospectr_resample_fwhm', PACKAGE = 'prospectr', X, wav, new_wav, fwhm)
}

resample_fwhm_vec <- function(X, wav, new_wav, fwhm) {
.Call('_prospectr_resample_fwhm_vec', PACKAGE = 'prospectr', X, wav, new_wav, fwhm)
}

residLm <- function(Yr, Xr) {
.Call('_prospectr_residLm', PACKAGE = 'prospectr', Yr, Xr)
}
Expand Down
52 changes: 29 additions & 23 deletions R/binning.R
Original file line number Diff line number Diff line change
@@ -1,49 +1,55 @@
#' @title Signal binning
#' @description
#' \lifecycle{stable}
#' Compute average values of a signal in pre-determined bins (col-wise subsets).
#' The bin size can be determined either directly or by specifying the number of bins.
#' Sometimes called boxcar transformation in signal processing
#' The bin size can be determined either directly or by specifying the number of
#' bins. Sometimes called boxcar transformation in signal processing
#' @usage
#' binning(X, bins, bin.size)
#' @param X a numeric matrix or vector to process (optionally a data frame that can
#' be coerced to a numerical matrix).
#' @param X a numeric matrix or vector to process (optionally a data frame that
#' can be coerced to a numerical matrix).
#' @param bins the number of bins.
#' @param bin.size the desired size of the bins.
#' @author Antoine Stevens & Leonardo Ramirez-Lopez
#' @author Antoine Stevens & \href{https://orcid.org/0000-0002-5369-5120}{Leonardo Ramirez-Lopez}
#' @examples
#' data(NIRsoil)
#' wav <- as.numeric(colnames(NIRsoil$spc))
#'
#' # 5 first spectra
#' matplot(wav, t(NIRsoil$spc[1:5, ]),
#' type = "l",
#' xlab = "Wavelength /nm",
#' ylab = "Absorbance")
#'
#' type = "l",
#' xlab = "Wavelength /nm",
#' ylab = "Absorbance"
#' )
#'
#' NIRsoil$spc_binned <- binning(NIRsoil$spc, bin.size = 20)
#'
#' # bin means
#' matpoints(as.numeric(colnames(NIRsoil$spc_binned)),
#' t(NIRsoil$spc_binned[1:5, ]),
#' pch = 1:5)
#' matpoints(as.numeric(colnames(NIRsoil$spc_binned)),
#' t(NIRsoil$spc_binned[1:5, ]),
#' pch = 1:5
#' )
#'
#' NIRsoil$spc_binned <- binning(NIRsoil$spc, bins = 20)
#' dim(NIRsoil$spc_binned) # 20 bins
#'
#' # 5 first spectra
#' matplot(wav,
#' t(NIRsoil$spc[1:5, ]),
#' type = "l",
#' xlab = "Wavelength /nm",
#' ylab = "Absorbance")
#'
#' matplot(wav,
#' t(NIRsoil$spc[1:5, ]),
#' type = "l",
#' xlab = "Wavelength /nm",
#' ylab = "Absorbance"
#' )
#'
#' # bin means
#' matpoints(as.numeric(colnames(NIRsoil$spc_binned)),
#' t(NIRsoil$spc_binned[1:5, ]),
#' pch = 1:5)
#' @return a matrix or vector with average values per bin.
#' @seealso \code{\link{savitzkyGolay}}, \code{\link{movav}},
#' t(NIRsoil$spc_binned[1:5, ]),
#' pch = 1:5
#' )
#'
#' @return
#' a matrix or vector with average values per bin.
#' @seealso
#' \code{\link{savitzkyGolay}}, \code{\link{movav}},
#' \code{\link{gapDer}}, \code{\link{continuumRemoval}}
#' @export
#'
Expand Down
21 changes: 14 additions & 7 deletions R/blockNorm.R
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
#' @title Sum of squares block weighting
#' @description
#' \lifecycle{stable}
#' Sum of squares block weighting: allows to scale blocks of variables,
#' but keeping the relative weights of the variables inside a block.
#' @usage
#' blockNorm(X, targetnorm = 1)
#' @param X a numeric matrix to transform (optionally a data frame that can
#' be coerced to a numerical matrix).
#' @param targetnorm desired sum of squares for a block of variables (default = 1)
#' @return a list with components `Xscaled`, the scaled matrix and `f`, the scaling factor
#' @param targetnorm desired sum of squares for a block of variables
#' (default = 1)
#' @return a list with components `Xscaled`, the scaled matrix and `f`, the
#' scaling factor
#' @author Antoine Stevens
#' @examples
#' X <- matrix(rnorm(100), ncol = 10)
#' # Block normalize to sum of square equals to 1
#' res <- blockNorm(X, targetnorm = 1)
#' sum(res$Xscaled^2) # check
#' @seealso \code{\link{blockScale}}, \code{\link{standardNormalVariate}},
#'
#' @seealso
#' \code{\link{blockScale}}, \code{\link{standardNormalVariate}},
#' \code{\link{detrend}}
#' @references Eriksson, L., Johansson, E., Kettaneh, N., Trygg, J.,
#' @references
#' Eriksson, L., Johansson, E., Kettaneh, N., Trygg, J.,
#' Wikstrom, C., and Wold, S., 2006. Multi- and Megavariate Data Analysis.
#' MKS Umetrics AB.
#' @details The function computes a scaling factor, which, multiplied by the
#' @details
#' The function computes a scaling factor, which, multiplied by the
#' input matrix,
#' produces a matrix with a pre--determined sum of squares.
#' @note
#' This is a \R port of the \file{MBnorm.m} function of the MB matlab toolbox
#' by Fran van den Berg (<http://www.models.life.ku.dk/~courses/MBtoolbox/mbtmain.htm>)
#' by Fran van den Berg which can be found at:
#' \href{http://www.models.life.ku.dk/~courses/MBtoolbox/mbtmain.htm}{http://www.models.life.ku.dk/~courses/MBtoolbox/mbtmain.htm}
#'
#' @export
blockNorm <- function(X, targetnorm = 1) {
if (!any(class(X) %in% c("matrix", "data.frame"))) {
Expand Down
12 changes: 7 additions & 5 deletions R/blockScale.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#' @title Hard or soft block scaling
#'
#' @description
#' \lifecycle{stable}
#' Hard or soft block scaling of a spectral matrix to constant group variance.
#' In multivariate calibration, block scaling is used to down-weight variables,
#' when one block of variables dominates other blocks.
Expand All @@ -11,20 +10,23 @@
#' root of the number of variables in a particular block.
#' @usage
#' blockScale(X, type = 'hard', sigma2 = 1)
#' @param X a numeric matrix or vector to process (optionally a data frame that can
#' be coerced to a numerical matrix).
#' @param X a numeric matrix or vector to process (optionally a data frame that
#' can be coerced to a numerical matrix).
#' @param type the type of block scaling: 'hard' or 'soft'.
#' @param sigma2 the desired total variance of a block (ie sum of the variances
#' of all variables, default = 1), applicable when `type = 'hard'`.
#' @return a `list` with `Xscaled`, the scaled matrix and `f`, the scaling factor.
#' @return a `list` with `Xscaled`, the scaled matrix and `f`, the scaling
#' factor.
#' @author Antoine Stevens
#' @examples
#' X <- matrix(rnorm(100), ncol = 10)
#' # Hard block scaling
#' res <- blockScale(X)
#' # sum of column variances == 1
#' apply(res$Xscaled, 2, var)
#' @seealso \code{\link{blockNorm}}, \code{\link{standardNormalVariate}},
#'
#' @seealso
#' \code{\link{blockNorm}}, \code{\link{standardNormalVariate}},
#' \code{\link{detrend}}
#' @references Eriksson, L., Johansson, E., Kettaneh, N., Trygg, J.,
#' Wikstrom, C., and Wold, S., 2006. Multi- and Megavariate Data Analysis.
Expand Down
7 changes: 3 additions & 4 deletions R/cochranTest.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#' @title Cochran *C* Test
#' @description
#' \lifecycle{stable}
#' \loadmathjax
#' Detects and removes replicate outliers in data series based on the Cochran
#' *C* test for homogeneity in variance.
Expand All @@ -19,14 +18,14 @@
#' \item{'`outliers`'}{ numeric vector giving the row indices of the input
#' data that have been flagged as outliers}
#' }
#'
#'
#' @details
#' The Cochran *C* test is test whether a single estimate of variance is
#' significantly larger than a a group of variances.
#' It can be computed as:
#'
#'
#' \mjdeqn{RMSD = \sqrt{\frac{1}{n} \sum_{i=1}^n {(y_i - \ddot{y}_i)^2}}}{RMSD = sqrt{{1}/{n} sum (y_i - ddot{y}_i)^2}}
#'
#'
#' where \mjeqn{y_i}{y_i} is the value of the side variable of the \mjeqn{i}{i}th sample,
#' \mjeqn{\ddot{y}_i}{\ddot{y}_i} is the value of the side variable of the nearest neighbor
#' of the \mjeqn{i}{i}th sample and \mjeqn{n}{n} is the total number of observations.
Expand Down
Loading

0 comments on commit f04f7b7

Please sign in to comment.