How to use ropls package to split into 80%-20% training and test sets?

176 views Asked by At

I'm trying to use for the first time the ropls package to perform PLS-DA and OPLS-DA predictive models, and as I saw on its documentation, the algorithm provides the option subset="odd", which splits the data into two equal sizes, so 50%-50%. The problem is that I need to split my data into 80% train and 20% test, and as I read, it says that you can use the indexes of the needed subset, but I haven't been able to do it. I've tried performing the split manually, then extracting the indexes and using that subset in the algorithm, but as I'm really new to programming I'm afraid I'm not doing it right... It always tells me: Error: 'subset' must be either set to 'odd' or an integer vector of 'x' row numbers

Can someone help me? Thank you so much!!

The code I've tried so far looks like something like this (sorry if it's a mess!):

set.seed(12345)

n_train<-0.8

n<-nrow(cancerx)

train<-sample(n,floor(n*n_train))

trainrf<-cancerx[train,]

testrf<-cancerx[-train,]

#PLS-DA predict

plsda1<-opls(cancerx[-1], cancerx$label, predI=1, subset="train")
0

There are 0 answers