l-ramirez-lopez / resemble

resemble is an R package which implements functions dedicated to non-linear modelling of complex spectroscopy data
Other
20 stars 14 forks source link

error in `pls_projection()` ehn using `pc_selection = list("cumvar", ...)` #37

Closed l-ramirez-lopez closed 1 year ago

l-ramirez-lopez commented 1 year ago
library(prospectr)
library(resemble)

data("NIRsoil")

# Proprocess the data using SNV followed by first derivative with Savitzky and
# Golay smoothing filter
NIRsoil$spc_pr <- NIRsoil$spc |> 
  standardNormalVariate() |>  
  savitzkyGolay(
  m = 1,
  p = 1,
  w = 7
)

# ---- split into training and testing sets ----
# ---- split into training and testing sets ----
test_x <- NIRsoil$spc_pr[NIRsoil$train == 0, ]

train_x <- NIRsoil$spc_pr[NIRsoil$train == 1, ]
train_y <- NIRsoil[NIRsoil$train == 1, c("Ciso", "Nt")]

# ---- STEP 1 (fixed): get your projection model ----
# A principal component analysis using 5 components
pls_projected <- pls_projection(train_x, Yr = train_y, pc_selection = list("cumvar", 0.98))
l-ramirez-lopez commented 1 year ago

This error is procured when the number of response variables is larger than 1. The origin is in the opls_for_projection() function. A set of coefficients is produced for each Y. However, only the ones for the first Y are retained and later in the code when the full set of coefficients for all the Ys is required the function crashes.

l-ramirez-lopez commented 1 year ago

The internal C++ function opls_for_projection() is now fixed