1
#############################################
2
# PLS fit/predict converter
3
#############################################
6
tmp <- .JNew('org.openscience.cdk.qsar.model.R.PLSRegressionModelFit',
7
obj$nobj, obj$nvar, obj$npred, obj$ncomp, obj$method)
9
obj$training$B, obj$training$Ypred, obj$training$RMS,
10
obj$training$Xscores, obj$training$Xload,
11
obj$training$Yscores, obj$training$Yload)
12
tmp$PLSRegressionModelSetTrain()
13
if ('validat' %in% names(obj)) {
14
# Add validation fields
15
tmp$setValidationData(
16
obj$valid$niter, obj$valid$nLV,
17
obj$valid$Ypred, obj$valid$RMS, obj$valid$RMS.sd, obj$valid$R2)
21
plsPredictConverter <-
23
class(obj) <- 'matrix'
24
.JNew('org.openscience.cdk.qsar.model.R.PLSRegressionModelPredict',ncol(obj),obj)
26
buildPLS <- function(modelname, params) {
28
paramlist <- hasmap.to.list(params)
31
x <- matrix(unlist(x), nrow=length(x), byrow=TRUE)
32
y <- matrix(unlist(y), nrow=length(y), byrow=TRUE)
33
if (nrow(x) != nrow(y)) { stop('The number of observations in x & y dont match') }
38
ncomp <- unlist(ncomp)
41
if (!(method %in% c('PCR','SIMPLS','kernelPLS'))) {
42
stop('Invalid methopd specification')
44
if (!(validation %in% c('none','CV'))) {
45
stop('Invalid validation sepcification')
48
if (niter == 0 && validation == 'CV') {
53
# We should do this since when both grpsize and niter are specified niter
54
# is used. So if grpsize comes in as 0 (which will be the default setting)
55
# we specify only niter and if not zero we use grpsize and ignore niter
58
pls(x=x,y=y,ncomp=ncomp,method=method,validation=validation,grpsize=grpsize),
62
pls(x=x,y=y,ncomp=ncomp,method=method,validation=validation,niter=niter),
68
predictPLS <- function(modelname, params) {
69
paramlist <- hashmap.to.list(params)
72
newX <- matrix(unlist(newX), nrow=length(x), byrow=TRUE)
73
model <- get(modelname)
74
if (ncol(newX) != model$nvar) {
75
stop('The number of independent variables in the new data does not match that specified during building')
78
preds <- predict(model, newX)
80
preds <- predict(model, newX, nlv)
82
class(preds) <- 'plsregressionprediction'