[R] problem with using transace

anne.piotet@urbanet.ch anne.piotet at urbanet.ch
Thu Dec 2 09:34:01 CET 2004


Frank, thank you very much for your answer, as it fixed up nicely my problem. I am really sorry to have asked a question which you already answered a long time ago, but I am a bit overwhelmed with the R, contributed packages and help list documentation....Anyway  thanks again


Anne


PS isn't it fun to use packages developped for biostats in metal industry applications? 

>anne.piotet at urbanet.ch wrote:
>>>I am trying to use the Hmisc function transace to transform predictors
>>>
>>>test<-cbind(flowstress,pressres,alloy)
>>>xtrans<-transace(x,binary=pressres',monotonic='flowstress', categorical='alloy')
>>>
>>>
>>>and I am getting the following message¨
>>>Error in ace(x[, -i], x[, i], monotone = im, categorical = ic) : 
>>>	unused argument(s) (monotone ...)
>>>
>>>Any idea?
>> 
>> 
>> thanks anne
>> 
>>>thank for your help
>>>Anne
>
>The corrected version (below) will fix that problem but note that there 
>is a bug in ace causing it not to allow a monotonicity constraint when a 
>variable is on the left hand side.  This is inconsistent with the ace 
>documentation.  There are other problems in ace in which it checks 
>column numbers against the number of rows in the x matrix instead of the 
>number of columns.  The internal version of ace defined inside areg.boot 
>fixes the latter problem.  Note that I reported these problems a long 
>time ago.
>
>Frank
>
>transace <- function(x, monotonic=NULL, categorical=NULL, binary=NULL, 
>pl=TRUE) {
>   if(.R.) require('acepack')  # provides ace, avas
>
>nam <- dimnames(x)[[2]]
>omit <- is.na(x %*% rep(1,ncol(x)))
>omitted <- (1:nrow(x))[omit]
>if(length(omitted)) x <- x[!omit,]
>p <- ncol(x)
>xt <- x  # binary variables retain original coding
>if(!length(nam)) stop("x must have column names")
>rsq <- rep(NA, p)
>names(rsq) <- nam
>
>
>for(i in (1:p)[!(nam %in% binary)])	{
>   lab <- nam[-i]
>   w <- 1:(p-1)
>   im <- w[lab %in% monotonic]
>   ic <- w[lab %in% categorical]
>   if(nam[i] %in% monotonic) im <- c(0, im)
>   if(nam[i] %in% categorical) ic <- c(0, ic)
>   m <- 10*(length(im)>0)+(length(ic)>0)
>   if(m==11) a <- ace(x[,-i], x[,i], mon=im, cat=ic)
>   else if (m==10) a <- ace(x[,-i], x[,i], mon=im)
>   else if(m==1) a <- ace(x[,-i], x[,i], cat=ic)
>   else a <- ace(x[,-i], x[,i])
>   xt[,i] <- a$ty
>   rsq[i] <- a$rsq
>   if(pl)plot(x[,i], xt[,i], xlab=nam[i], ylab=paste("Transformed",nam[i]))
>}	
>
>cat("R-squared achieved in predicting each variable:\n\n")
>print(rsq)
>
>attr(xt, "rsq") <- rsq
>attr(xt, "omitted") <- omitted
>invisible(xt)
>}
>
>>>
>>>
>> 
>> 
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>> 
>
>
>-- 
>Frank E Harrell Jr   Professor and Chair           School of Medicine
>                      Department of Biostatistics   Vanderbilt University
>
>




More information about the R-help mailing list