Migrating from using S-Plus Design package to R RMS package

191 views Asked by At

I am inheriting some code from S+ that fits a Cox Proportional Hazard model with imputed data. It then uses the Design package to get predicted values and confidence intervals.

set.seed(23)

somedata<- data.frame(
  col1 = sample(c(1,2), 10, replace = TRUE),
  col2 = sample(10000),
  col8 = rnorm(10000, 54, 5 ),
  col22 = rbinom(10000, 1, .5)
)

sd<-datadist(somedata)
options(datadist="sd")

formula1 <- ~ col2 + col1 + col22  + col8
formula2 <- Surv(col2, col1) ~  col22 + rcs(col8, 3)

a <- aregImpute(formula1, data=somedata, n.impute=5)
f <- fit.mult.impute(formula2, cph, a, data=somedata)
p1 <- plot(f, conf.int=T, ref.zero=T, fun=exp, col8=c(18:70), xlab=c("Recipient age"), 
           ylab=c("RR of Mortality"))
write.table(p1$x.xbeta,file=afilename,sep=",",dimnames.write=F)

I am now doing this in R. I keep getting an error using the Predict function from the RMS package. Can anyone help?

set.seed(23)

somedata<- data.frame(
  col1 = sample(c(1,2), 10, replace = TRUE),
  col2 = sample(10000),
  col8 = rnorm(10000, 54, 5 ),
  col22 = rbinom(10000, 1, .5)
)

sd<-datadist(somedata)
options(datadist="sd")

formula1 <- ~ col2 + col1 + col22  + col8
formula2 <- Surv(col2, col1) ~  col22 + rcs(col8, 3)

a<-aregImpute(formula1, data=somedata, n.impute=5)
f<-fit.mult.impute( formula2, cph, a, data=somedata)
p2<-Predict(f ,col8,conf.int=0.95 ,ref.zero=TRUE ,fun=exp )

on evaluating Predict, the logs shows:

Error in matxv(adjto, coeff, kint = kint) : columns in a (4) must be <= length of b (3)

0

There are 0 answers