[R] RMS, CPH: Error in X[, mmcolnames, drop = FALSE] : subscript out of bounds

tommy sheu tommydsheu at gmail.com
Sun Feb 21 01:09:19 CET 2016


I believe the error message started populating with a recent update of R or
RMS...unsure, as I tried to run an analysis with previously saved and
working code and got the same error message.

My command list:

    rm(list=ls(all=TRUE))
    library(boot)
    library(foreign)
    library(Hmisc,T)
    library(rms)
    valid = read.dta("file location.dta")
    Age=c(valid$dxage)
    N_Category<-factor(valid$Ntri,labels=c("N0","N1","N2","N3"))
    dd <- datadist(Age, N_Category)
    options(datadist='dd')
    f1=cph(Surv(valid$t3yr,valid$KM)~Age + factor(N_Category),
method="breslow",data=valid,surv=T, x=T, y=T)

Output:

    formula

    Surv(valid$t3yr, valid$KM) ~ Age + factor(N_Category)
         colnames(X)             mmcolnames      Design colnames
    [1,] "Age"                   "Age"           "Age"
    [2,] "factor(N_Category)N1"  "N_CategoryN1"  "N_Category=N1"
    [3,] "factor(N_Category)N2" "N_CategoryN2" "N_Category=N2"
    [4,] "factor(N_Category)N3"  "N_CategoryN3"  "N_Category=N3"
    Error in X[, mmcolnames, drop = FALSE] : subscript out of bounds

Here’s the test data set that I’m trouble shooting with:

    dxage     t3yr KM NTri Ntri1 nlab
    1     70 25.36667  1    0     1    1
    2     42 19.90000  1    2     3    3
    3     43  7.80000  1    2     3    3
    4     70 16.96667  1    1     2    2
    5     50 20.50000  1    2     3    3
    6     40 24.76667  1    2     3    3
    7     24  4.50000  1    0     1    1
    8     70 15.03333  1    1     2    2
    9     45 35.36666  1    1     2    2
    10    62 19.96667  1    3     4    4
    11    62 32.76667  1    0     1    1
    12    78 23.86667  1    2     3    3
    13    49 33.96667  1    2     3    3
    14    67 15.06667  0    0     1    1
    15    69 12.50000  0    1     2    2
    16    61  7.20000  0    0     1    1


I've also tried to recategorized the NTri column increasing all of the
values by 1 thinking that R was misreading the 0's but to no avail.

Greatly appreciate any help or guidance.

	[[alternative HTML version deleted]]



More information about the R-help mailing list