[R] rms::cr.setup and Hmisc::fit.mult.impute
Christian Lerch
t.c.l at gmx.net
Mon May 28 15:54:15 CEST 2012
I have fitted a proportional odds model, but would like to compare it to
a continuation ratio model. However, I am unable to fit the CR model
_including_ imputated data.
I guess my troubles start with settuping the data for the CR model.
Any hint is appreciated!
Christian
library(Hmisc)
library(rms)
library(mice)
## simulating data (taken from rms::residuals.lrm)
set.seed(1)
n <- 400
age <- rnorm(n, 50, 10)
blood.pressure <- rnorm(n, 120, 15)
L <- .05*(age-50) + .03*(blood.pressure-120)
p12 <- plogis(L)
p2 <- plogis(L-1)
p <- cbind(1-p12, p12-p2, p2)
cp <- matrix(cumsum(t(p)) - rep(0:(n-1), rep(3,n)), byrow=TRUE, ncol=3)
y <- (cp < runif(n)) %*% rep(1,3)
y <- as.vector(y)
## generating missing data
age[1:40]<-NA
blood.pressure[30:70]<-NA
## multiple imputation using mice::mice
d <- as.matrix(cbind(y, age, blood.pressure))
imp <- mice(d,seed=123)
## some cleanup
rm(y, age, blood.pressure)
d <-as.data.frame(d)
## proportional odds model
b<-fit.mult.impute(y~age+blood.pressure, lrm, xtrans=imp, data=d)
## continuation ratio model
attach(d)
u <- cr.setup(y)
detach(d)
attach(d[u$subs,])
y <-u$y
cohort<-u$cohort
c <- lrm(y~cohort*(age+blood.pressure))
## CR model with imputed data
q <- fit.mult.impute(y~cohort*(age+blood.pressure), lrm, xtrans=imp)
Error in model.frame.default (formula = formula, data = completed.data, :
variable length differ (found for 'cohort')
More information about the R-help
mailing list