Error in dimnames(X)[[2]] = X.names : 'dimnames' must be a list

Create issue
Issue #77 resolved
Arnaud created an issue

I'm trying to use the block.spls function with 2 blocks/data sets measured on the same samples (15 samples and respectively 4313 and 952 variables). The list of X/blocks has the following structure :

str(data) List of 2 $ transcripto: num [1:15, 1:4313] 1107 827 1337 561 750 ... ..- attr(, "dimnames")=List of 2 .. ..$ : chr [1:15] "O_30_A_1h30_R1" "O_30_B_1h30_R1" "O_30_C_1h30_R1" ... .. ..$ : chr [1:4313] "BAE76026" "BAB96579" "BAB96580" "BAB96581" ... $ lipido : num [1:15, 1:952] -0.03308 -0.85659 1.55854 0.96536 0.00349 ... ..- attr(, "dimnames")=List of 2 .. ..$ : chr [1:15] "O_30_A_4h_R1" "O_30_B_4h_R1" "O_30_C_4h_R1" ... .. ..$ : chr [1:952] "M885.78848_T1381.39_Pos_4h" "M880.83215_T1381.26_Pos_4h" ...

So there seems to exist "dimnames" which are lists of 2 elements for the 2 blocks (transcripto and lipido). But when I run the following code, inspired by the manual :

design = matrix(1,ncol=length(data), nrow=length(data), dimnames=list(names(data),names(data))) diag(design)=0 ncomp=c(2) o.130.bspls <- block.spls(X = data, Y=trilip.o.130$Trilipid.pc, ncomp=ncomp, design =design)

I get the error message in the title of this issue ...

Any help would be much appreciated ! Thanks in advance, Arno

Comments (5)

  1. Florian Rohart

    Hi Arno,

    so the following gives you a list?

    is.list(data) # TRUE?
    is.list(dimnames(data[[1]])) # TRUE?
    length(dimnames(data[[1]])) # 2?
    is.list(dimnames(data[[2]])) # TRUE?
    length(dimnames(data[[2]])) # 2?
    
    dim(trilip.o.130$Trilipid.pc) #?
    

    If everything is at it is supposed to, then we will need more details (and maybe your data under confidentiality) to sort this out.

    Keep us posted and we'll see what we can do next :)

  2. Arnaud reporter

    Hi Florian,

    Thank you for your quick answer.

    So I indeed get the "right" answers to your 5 first questions above (ie TRUE to is.list(data) etc). And for : dim(trilip.o.130$Trilipid.pc), I get "NULL". trilip.o.130$Trilipid.pc is a vector of "numeric" elements, because the "Y" is a continuous univariate response.

    What other details shall I give you ? Thanks in advance, Arnaud

  3. Arnaud reporter

    Update : I managed to make it work by changing the "Y" from a vector to a matrix of 15 (the nb of samples) rows by 1 column, with the rownames of the matrix being the same rownames as those of the X/blocks.

    It would be nice that you mention in the manual that if Y is univariate you have to cast it into a matrix with only 1 column like this.

    Also what's strange is that in the block.splsda function the "Y" can be a vector (I've tried it and got no error message) ...

    Anyway thanks again for your quick answer and have a nice week-end !

    Arnaud

  4. Florian Rohart

    Hi Arnaud,

    All the DA methods require a factor as Y (if it's only a vector, it's transformed as a factor). Similarly, for spls, if Y is univariate, it is transformed as a matrix nb samples*1. However, you're right as it is not transformed for a block.spls method.

    Thanks for your input, we'll update the help files (or work something out so it's done internally in the case of univariate blocks)

    Florian

  5. Log in to comment