Error occured in designing a matrix
1
0
Entering edit mode
Rishav ▴ 20
@rishav-25031
Last seen 17 months ago
Patna

I am trying to design a matrix, but I got the following error. Please help me to understand this error.


# > design <- matrix(data=0,nrow=ncol(gene expression data), ncol=2)
> rownames(design) <- colnames(gene expression data)
> colnames(design) <- c("Carcinoma","Normal")
> cSamples <- rownames(phenodata)[grep("Tumor",HB$Condition)]
> nSamples <- rownames(phenodata)[grep("Non_neoplastic",HB$Condition)]
> design[cSamples,"Carcinoma"] <- 1
**Error in `[<-`(`*tmp*`, cSamples, "Carcinoma", value = 1) : 
  subscript out of bounds**

# This is my phenodata

Sample_id   Condition   Patient Batch
P105A   Non_neoplastic  P105    A
P105D    Tumor                  P105    A
P106A   Non_neoplastic  P106    B
P106D   Tumor                  P106     B 
P112A   Non_neoplastic  P112    C
P112D   Tumor                  P112         C 
P131A   Non_neoplastic  P131    D
P131D   Tumor                   P131    D
P138A   Non_neoplastic  P138    E
P138D   Tumor                  P138     E
P140A   Non_neoplastic  P140    F
P140D   Tumor                  P140     F
P152A   Non_neoplastic  P152    G
P152D   Tumor                  P152     G
P157A   Non_neoplastic  P157    H
P157D   Tumor                  P157     H
P158A   Non_neoplastic  P158    I
P158D   Tumor                  P158         I
P161A   Non_neoplastic  P161    J
P161D   Tumor                   P161    J
P16A    Non_neoplastic  P16         K
P16D    Tumor                    P16             K
P170A   Non_neoplastic  P170     L
P170D   Tumor                   P170    L
P171A   Non_neoplastic  P171    M
P171D   Tumor                   P171    M
P176A   Non_neoplastic  P176    N
P176D   Tumor                    P176   N
P179A   Non_neoplastic  P179    O
P179D   Tumor                   P179    O
P49A    Non_neoplastic  P49     P
P49D    Tumor                   P49         P
P62A    Non_neoplastic  P62         Q
P62D    Tumor                   P62         Q
P6A        Non_neoplastic    P6        R
P6D         Tumor                   P6           R
P75A    Non neoplastic  P75     S
P75D    Tumor                   P75         S
P94A    Non_neoplastic  P94         T
P94D    Tumor                   P94         T
P99A    Non_neoplastic  P99         U
P99D    Tumor                   P99     U
RNASeqR • 390 views
ADD COMMENT
0
Entering edit mode

> design <- matrix(data=0,nrow=ncol(gene expression data), ncol=2) > rownames(design) <- colnames(gene expression data) > colnames(design) <- c("Carcinoma","Normal") > cSamples <- rownames(phenodata)[grep("Tumor",phenodata$Condition)] > nSamples <- rownames(phenodata)[grep("Non_neoplastic",phenodata$Condition)] > design[cSamples,"Carcinoma"] <- 1

Error in [<-(*tmp*, cSamples, "Carcinoma", value = 1) : subscript out of bounds

please help me to sort out this error

ADD REPLY
1
Entering edit mode
@gordon-smyth
Last seen 1 hour ago
WEHI, Melbourne, Australia

There are examples of how to construct design matrices in the limma and edgeR documentation and it is much easier than what you are currently attempting. Your Tumor and Non_neoplastic samples are apparently paired by patient, so the design matrix would be:

design <- model.matrix(~ Condition + Patient, data=HB)
ADD COMMENT

Login before adding your answer.

Traffic: 395 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