PLSDA with categorical predictors

I am performing a PLS-DA but there are a few predictors in my model are categorical (0/1). When I format them as integer or numeric, then things are fine, but if I format them as factor then the program produce the following error:

plsda.fert<-plsda(X,Y,ncomp = ccomp,scale = TRUE)
Error in Check.entry.pls(X, Y, ncomp, keepX, keepY, mode = mode, scale = scale, :
‘X’ and/or ‘Y’ must be a numeric matrix.
In this case, it is ok /meaningful to format the categorical predictor as numeric (i.e. 0 mean unfavorable while 1 mean favarable), but what happens when the categorical predictors with let’s say values 0, 1,2,3 just indicates 4 different groups. I would I handle this with mixOmics PLSDA.

Many thanks,

hi Phuong,

Indeed our methods only consider variables as numeric, and as you highlighted, that may pose a problem for variables with 4 different groups. One work around would be to transform your variables into dummy matrices using the unmap function available in the package, then concatenate your variables.

Y = unmap(nutrimouse$diet)

That would work ok if you do not select variables (so PLS-DA only). For sparse PLS-DA you may have to work on the interpretation.

let us know if you have further enquiries.


Thanks a lot Kim Anh, at this moment I do not think we perform variable selection, so the working-around approach you suggested should be ok for us.
Take care,