PLSR colMeans(Y) : 'x' must be numeric
2
0
Entering edit mode
7.1 years ago

I want to perform PLS analysis. When I write

Result <- plsr (X ~ Y, 10, data = xxx, validation = "LOO")

showing the following error

Error in colMeans (Y): 'x' must be numeric In addition: Warning message: In model.response (mf, "numeric"): Using type = "numeric" with a factor response will be ignored

X <- 0.954242509 0 1.579783597 0 1.51851394 <na> 1.397940009 1.079181246 1.079181246 0 0.698970004   [12] 0.301029996 <na> 0.84509804 0 0.698970004 0.602059991 0.954242509 0.698970004 0.301029996 <na> 1.230448921   [23] 2.103803721 <na> 1.944482672 <na> 0 0.777815125 1.041392685 <na> 0.301029996 <na> 0.602059991 Y <- 0.000760376 0.026700304 0.014669871 0.000169903 0.020560227 <na> 0.000205013 0.033492921 0.025880333 5.26211E-05 0.012691444

Can someone help me, please?

Gabriela Vera

R • 7.6k views
ADD COMMENT
0
Entering edit mode
7.1 years ago

Your x must be numeric. I am guessing that it is a factor. Run class(x) and if it returns value other than numeric / integer, you need to coerce it to numeric. BTW, if you are reading a data.frame in R using read.table(), then you should use stringsAsFactors = FALSE else all the numeric values will be read as factors.

ADD COMMENT
0
Entering edit mode

I did everything you told me, but I did not solve it, the same error appears.

Previously, he had tried to transform the variables by: X.num <- as.numeric (tdata $ X), however it changes the number of quantification.

I run again and I get a result but I do not know if this way is correct?

ADD REPLY
0
Entering edit mode

what is your whole code like?

ADD REPLY
0
Entering edit mode

Data.1 <- read.csv("File.csv",header = TRUE, sep = ";")

valid = !is.na(Data.1$variable1)|is.na(Data.1$variable2)) Datareduced = Data.1[valid,c("variable1","variable2")]

Result <- plsr(variable1~ variable2, 10, data = Datareduced, validation = "LOO")

class(Data.1$variable1) [1] "factor"

variable1<- 0.000760376 0.026700304 0.014669871 0.000169903 0.020560227 0.000205013 0.033492921 0.025880333 5.26211E-05 0.01269144

x.num <- as.numeric(Datareduced$variable1) is.numeric(x.num) 15 42 28 2 35 3 47 41 85 22 26 4 11 1 84 14 63 33 56 86 62 49 8

ADD REPLY
0
Entering edit mode
7.1 years ago

Add stringsAsFactors = FALSE in read.csv

Data.1 <- read.csv("File.csv",header = TRUE, sep = ";", stringsAsFactors = FALSE)

Then check the variable1 and variable2. The output of both of these commands should be printed TRUE.

is.numeric(Data.1$variable1)  
Is.numeric(Data.1$variable2)

If the output is not TRUE, you should check your data if there are string values, instead of numeric

PS: Please do proper formatting of your code using the formatting menu, else it will be difficult to read.

ADD COMMENT
0
Entering edit mode

Thank you Santonsh

my output is FALSE.

I am beginning in R and I don't know as I can change to numeric value

ADD REPLY
0
Entering edit mode

Hi Gabriela, Your data type is not numeric. Ask some of your colleagues to have a look at your data. The thing you are doing is simple, but without some basic knowledge of working of R, it will be difficult for you to follow the steps. So I would suggest you to take some introductory course in R online (Coursera / youtube or just google it).

ADD REPLY
0
Entering edit mode

thank you very much Santosh

ADD REPLY

Login before adding your answer.

Traffic: 1952 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6