[BioC] How to write a text file of a pamr.confusion table ?
Björn Usadel
usadel at mpimp-golm.mpg.de
Tue Nov 29 16:05:11 CET 2005
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