This is a test version of Biostars. For the public version, visit https://www.biostars.org.
[cph] Error in `[.default`(y, , 3) : subscript out of bounds

Hi there, I'm trying to construct nomogram with my cancer data.

this is a summary of my data:

str(train)

'data.frame': 1323 obs. of 25 variables:

$ LYMPH_NODES_EXAMINED_POSITIVE: Factor w/ 3 levels "<=3","<=9",">10": 3 NA 1 2 NA 1 NA 1 3 1 ...

$ CELLULARITY : Factor w/ 3 levels "High","Low","Moderate": NA 1 3 1 3 3 1 3 NA 1 ...

$ MENOPAUSAL_STATE : Factor w/ 2 levels "Post","Pre": 1 2 2 1 1 1 1 1 NA 2 ...

$ ER_STATUS : Factor w/ 2 levels "Negative","Positive": 2 2 2 2 2 2 1 2 2 1 ...

$ OS_MONTHS : num 718 425 822 186 16 816 77 514 NA 821 ...

$ OS_STATUS : Factor w/ 2 levels "DECEASED","LIVING": 2 2 2 1 1 2 1 1 NA 2 ...

$ LATERALITY : Factor w/ 2 levels "Left","Right": 2 2 2 2 1 2 1 1 NA 2 ...

and this is my code:

attach(train);d <- datadist(CELLULARITY, MENOPAUSAL_STATE, ER_STATUS,
 LATERALITY, LYMPH_NODES_EXAMINED_POSITIVE)                   

 options(datadist = 'd')

 train$CELLULARITY <- train$CELLULARITY %>% factor()

 train$MENOPAUSAL_STATE <- train$MENOPAUSAL_STATE %>% factor()

 train$ER_STATUS <- train$ER_STATUS %>% factor()

 train$LATERALITY <- train$LATERALITY %>% factor() 

 train$LYMPH_NODES_EXAMINED_POSITIVE <- train$LYMPH_NODES_EXAMINED_POSITIVE %>% factor() 

 train$OS_MONTHS <- train$OS_MONTHS %>% as.numeric()

 mod.cox <- cph(formula(Surv(OS_MONTHS, OS_STATUS) ~ CELLULARITY + MENOPAUSAL_STATE + ER_STATUS + LATERALITY +LYMPH_NODES_EXAMINED_POSITIVE),
                    data=train, x= TRUE, y= TRUE, surv = TRUE)

Right now, I got the error:

Error in [.default(y, , 3) : subscript out of bounds

I did some researches and found this previous issue and this related, which solved by Prof.Harrelfe. But, It seems not working to me.

Any helps would be appreciated

cph nomogram r

At which step you are getting the error? Provide the example data that produces the same error.

General note, your code could be simplified/prettified as:

train <- train %>% 
  mutate(CELLULARITY = factor(CELLULARITY),
         ER_STATUS = factor(ER_STATUS),
         etc...
         )

Also, read about mutate_at and mutate_if.

or indeed, train %>% mutate_at(c("CELLULARITY", "MENOPAUSAL_STATUS", ...), factor) %>% mutate(as.numeric(OS_MONTHS))

find out what is throwing the error: use debug(cph) , then make your cph call as above, and step through the interactive debugger (as described here https://adv-r.hadley.nz/debugging.html#browser), then if it actually is a bug, and not just some inappropriate data that you've passed in (the most likely case), send an issue to the relevant bug tracker for cph or whichever dependency is bugged out. (But make a small reproducible example that captures the bug if you do post an issue to bioconductor or github)

Could you summarise what solved the error, in case it happens to anyone else.

0 answers

No answers yet.

Log in to answer this question.