Git Product home page Git Product logo

mlesnoff / rchemo Goto Github PK

View Code? Open in Web Editor NEW
14.0 1.0 2.0 3.62 MB

Archived repo (see Readme) - R package for regression and discrimination, with special focus on chemometrics and high-dimensional data.

License: GNU General Public License v3.0

R 100.00%
dimension-reduction discrimination chemometrics knn regression-models lwplsr kernel-methods ridge-regression pca partial-least-squares-regression

rchemo's Introduction

This repository is archived. Package rchemo has been moved to this new repository.

rchemo - Dimension reduction, Regression and Discrimination for Chemometrics

Version 0.0-18

Jchemo provides functions and pipelines for predictions in chemometrics or other domains, with focus on high dimensional data.

The package was initially about k-nearest neighbors locally weighted partial least squares regression and discrimination models (kNN-LWPLSR an kNN-LWPLSDA; e.g. Lesnoff et al 2021 https://doi.org/10.1002/cem.3209). It has now been expanded to other methods.

Generic functions such as transform, predict, coef and summary are available. Tuning the models is facilitated by functions gridscore (validation dataset) and gridcv (cross-validation), with faster versions for models based on latent variables (LVs) (gridscorelv and gridcvlv) and ridge regularization (gridscorelb and gridcvlb).

NOTE: This R package rchemo is currently only maintained. The new current and more expanded package is Jchemo in Julia language.

Available functions

Click HERE to see the list of the available functions

After the package installation, all the functions have a help page with documented examples.

News

Click HERE to see what changed in the last version

or write in the R console

news(package = "rchemo")

Dependent packages

rchemo is dependent to the following packages available on CRAN:

Package Which use in rchemo?
data.table Fast data management
FNN Fast search of nearest neighbours
signal Savitsky-Golay derivation, and signal interpolation
e1071 SVM models

Installation

Using Rstudio is recommended for installation and usage

1. Install package 'remotes' from CRAN

Use the Rstudio menu

or write in the R console

install.packages("remotes")

2. Install package 'rchemo'

a) Most recent version

Write in the R console

remotes::install_github("mlesnoff/rchemo", dependencies = TRUE, 
  build_vignettes = TRUE)

In case of the following question during installation process:

These packages have more recent versions available.
Which would you like to update?"

it is recommended to skip updates (usually choice 3 = None)

b) Any given tagged version

e.g. with tag "v1.9-0" (Be carefull, this is not the more recent version)

write in the R console

remotes::install_github("mlesnoff/[email protected]", dependencies = TRUE, 
  build_vignettes = TRUE)

3. Usage

Write in the R console

library(rchemo)

Author

Matthieu Lesnoff

[email protected]

How to cite

Lesnoff, M. 2021. R package rchemo: Dimension reduction, Regression and Discrimination for Chemometrics. https://github.com/mlesnoff/rchemo. CIRAD, UMR SELMET, Montpellier, France

rchemo's People

Contributors

mlesnoff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

hbinjm guifh

rchemo's Issues

predict.Lwplsrda: SVD returns infinite or missing values

Thank you for this great package!

I am using predict.Lwplsrda and on some of my validation datasets, the function was producing an error, something like “svd(t(tXY), nu = 1, nv = 0) returns infinite or missing values”.

I tracked down the issue and it turns out that for a few of my validation samples, the following line call in predict.Lwplsrda was returning weights that were almost all equal to 0:

 listw <- lapply(res$listd, wdist, h = object$h)

As described in the doc, this is because the corresponding distances were higher than median(d) + cri * mad(d)). This is likely because those particular spectra were fairly different from the calibration set but this may happen quite frequently in practice.

Consequently, in plskern, the line tXY <- crossprod(Xd, Y) returns tXY with all value equal to zero and in turn, w <- w / sqrt(sum(w * w)) produce NaN.

To temporally solve the issue I replaced (locally) line 60 to 68 in the locwlv function by the following:

if(is.null(listw))
  fm <- tryCatch({
    fun(Xtrain[s, , drop = FALSE], zYtrain, nlv = max(nlv), ...)},
    error=function(cond){return(NA)})
else
  fm <- tryCatch({
    fun(Xtrain[s, , drop = FALSE], zYtrain, weights = listw[[i]], nlv = max(nlv), ...)},
    error=function(cond){return(NA)})

if(any(is.na(fm))){
  res[i,,] <- NA
  warning(paste0("Prediction for sample ", i, " was skipped."))
}else{
  for(a in seq_len(le_nlv))
    res[i, , a] <- predict(fm, X[i, , drop = FALSE], nlv = nlv[a])$pred
}

Now predict.Lwplsrda complete successfully and returns NA when a sample cannot be predicted. Maybe this is a temporary fix rather than a permanent solution, if it becomes permanent, it should probably be implemented in other "loc" functions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.