[R] Imputing NAs using transcan(); impute()

gerhard.krennrich at basf.com
Fri, 24 Mar 2006 13:26:13 -0000

Dear all,
I'm trying to impute NAs by conditional medians using transcan() in
conjunction with impute.transcan().
... see and run attached example..

Everything works fine, however impute() returns saying

Under WINDOWS
> x.imputed <- impute(trans)
Fehler in assign(nam, v, where = where.out) :
        unbenutzte(s) Argument(e) (where ...)
Zus?tzlich: Warnmeldung:
variable X1 does not have a names() attribute
and data does not have row.names. Assuming row names are integers. in:
impute.transcan(trans)
>

Under LINUX
> x.imputed <- impute(trans)
Error in impute.transcan(trans) : names attribute of X1 is not all numeric
and original observations did not have names
In addition: Warning message:
variable X1 does not have a names() attribute
and data does not have row.names. Assuming row names are integers. in:
impute.transcan(trans)



What wrong here ??

Thanks for helping
Gerhard



##############################

library(Hmisc)

n.row <- 60
n.col <- 40

dim.name  <-
list(paste("S",(1:n.row),sep=""),paste("X",(1:n.col),sep=""))

na.pointer  <-  matrix(FALSE,nrow=n.row,ncol=n.col)                 #
initialize
random      <-  matrix(runif(n.row*n.col),nrow=n.row,ncol=n.col)    #
random uniform
na.pointer[random < 0.1]  <- TRUE                                   # 10%
missings at random



x.mat <-
matrix(runif(n.row*(n.col/2),min=-5,max=+5),nrow=n.row,ncol=(n.col/2))  #
make basis dim=20


B       <-
matrix(runif((n.col/2)*(n.col/2),min=-1,max=10),nrow=(n.col/2),ncol=(n.col/2))
 # fudge coefficients B
noise   <- matrix(rnorm(n.row*(n.col/2)),nrow=n.row,ncol=(n.col/2))
# noise

y  <- x.mat%*%B + 5*noise            # linear dependencies

x <- cbind(x.mat,y)                   # augment => ill conditioned matrix

dimnames(x) <- dim.name


x[na.pointer]  <- NA                # assign 10% NAs at random



attach(as.data.frame(x))


date()
trans <-
transcan(x,data=as.data.frame(x),imputed=TRUE,transformed=TRUE,pr=FALSE,pl=FALSE)
date()


x.imputed <- impute(trans)

detach(as.data.frame(x))


############################