[BioC] How to write a text file of a pamr.confusion table ? - Solved

Giulio Di Giovanni perimessaggini at hotmail.com
Tue Nov 29 16:48:07 CET 2005


Thanks all.

I preferred not to write a modified pamr.confusion (even if I think a 
"return" of the table should be included by the maintainers of pamr 
package...or not?).
Setting "extra" parameter only removes error rates, but the resulting 
reduced table then is writeable as a file.
Anyway I would like to have the complete table with errors too, and so 
diverting the output via "sink" works best for me... !!!
Thanks a lot !!!

Giulio



>From: Björn Usadel <usadel at mpimp-golm.mpg.de>
>To: Giulio Di Giovanni <perimessaggini at hotmail.com>,  
>bioconductor at stat.math.ethz.ch
>Subject: Re: [BioC] How to write a text file of a pamr.confusion table ?
>Date: Tue, 29 Nov 2005 16:05:11 +0100
>
>Hi Giulio,
>
>you might try sink for diverting the output.
>
>Otherwise,....
>Having a look at pamr.confusion (> pamr.confusion on the command line)
>shows that only if the parameter extra is set to false you get a confusion 
>matrix returned.
>So either you set it extra to False, or you redefine the function
>
>pamr.Konfusion<- function (fit, threshold, extra = TRUE)
>{
>    ii <- (1:length(fit$threshold))[fit$threshold >= threshold]
>    ii <- ii[1]
>    predicted <- fit$yhat[, ii]
>    if (!is.null(fit$y)) {
>        true <- fit$y[fit$sample.subset]
>        tt <- table(true, predicted)
>    }
>    else {
>        true <- fit$proby[fit$sample.subset, ]
>        ytemp <- apply(true, 1, which.is.max)
>        temp <- c(predicted, names(table(ytemp)))
>        nams <- names(table(temp))
>        Yhat <- model.matrix(~factor(temp) - 1, data = list(y = temp))
>        Yhat <- Yhat[1:length(predicted), ]
>        tt <- matrix(NA, nrow = length(fit$prior), ncol = 
>length(fit$prior))
>        for (i in 1:length(fit$prior)) {
>            for (j in 1:length(fit$prior)) {
>                tt[i, j] <- sum(true[, i] * Yhat[, j])
>            }
>        }
>        dimnames(tt) <- list(names(table(ytemp)), nams)
>    }
>
>if (extra) {
>        tt1 <- tt
>        diag(tt1) <- 0
>        tt <- cbind(tt, apply(tt1, 1, sum)/apply(tt, 1, sum))
>        dimnames(tt)[[2]][ncol(tt)] <- "Class Error rate"
>       print(tt)    #<-****can go
>        cat(c("Overall error rate=", round(sum(tt1)/sum(tt),
>            3)), fill = TRUE)
>       return(tt)  # <-**** add this
>}
>    if (!extra) {
>        return(tt)
>    }
>}
>
>
>Cheers,
>Björn
>
>>Hi,
>>
>>really I hope this is not a stupid question. I would like to write a text 
>>file with the output of  pamr.confusion function. Obviously I tried first 
>>with the usual
>>
>>
>>
>>>write.table(file="test.txt",pamr.confusion(mysamplespamtrain, thr))
>>>
>>>
>>   K  N Class Error rate
>>K 26  4        0.1333333
>>N  2 23        0.0800000
>>Overall error rate= 0.109
>>
>>but all I write is an empty file. The same with "write" or assigning 
>>pamr.confusion to a variable (pc <- pamr.confusion(.....) ).
>>I also tried changing the device, to write a jpeg or whatelse; I tried to 
>>play with Device related commands. No way. I followed James McDonald 
>>suggestion
>>found in the mail archive.
>>
>>
>>
>>>pamr.confusion(mData.results, threshold=4.0)
>>>
>>>
>>(table)
>>
>>
>>>savePlot("Confusion", "wmf")
>>>
>>>
>>Error in savePlot("Confusion", "wmf") : no such device (...well, there's 
>>no graph device...).
>>
>>Anyway, there's anyone who has some hints ? I think that maybe is a simple 
>>command, but I don't know how to do it.
>>
>>Thanks in advance, and sorry if is a too banal question...
>>
>>Giulio
>>
>>_______________________________________________
>>Bioconductor mailing list
>>Bioconductor at stat.math.ethz.ch
>>https://stat.ethz.ch/mailman/listinfo/bioconductor
>>
>>
>



More information about the Bioconductor mailing list