List Members,
I am using R 1.3.1 for windows and trying to capture the output of some
summaries using textConnection. I then want to incorporate the text with
summary graphics output. The code below works (captures the output) when it is
not used in a loop or function. When placed in a loop or function, the cat
outputs are captured to 'foo' but the summary outputs are not. The help
mentions something about writing to the user's environment but I'm
afraid I
don't know enough to know if this is the problem. Any help would be
appreciated.
aov.diagnostic <- function(x)
{
dat.tmp <- na.exclude(cbind(Time,Site,get(x)))
layout(matrix(c(1,5,2,5,3,5,4,5),4,2,T), c(2,2), T)
interaction.plot(dat.tmp[,1],dat.tmp[,2],dat.tmp[,3],fun=median,type='p',pch=c('
C','1','3'),col=seq(1:3),legend=F,xlab=dimnames(dat.tmp)[[2]][1],ylab=paste('med
ian(',x,')',sep=''))
title(paste('Interaction Plot ',x,', Time*Site',sep=''))
par(new=T)
interaction.plot(dat.tmp[,1],dat.tmp[,2],dat.tmp[,3],fun=median,na.rm=T,pch=c('C
','1','3'),col=seq(1:3),legend=F,xlab='',ylab='')
dat <- get(x)
tmp.aov <- aov(dat~Time*Site)
hist(resid(tmp.aov),xlab=paste('resid(',x,'.aov)',sep=''))
qqnorm(resid(tmp.aov))
plot(fitted(tmp.aov),resid(tmp.aov),xlab=paste('fitted(',x,'.aov)',sep=''),ylabpaste('resid(',x,'.aov)',sep=''))
title('Fitted vs. Reduals')
plot(seq(0,28),seq(0,28),type='n',axes=F,xlab="",ylab="")
zz <- textConnection("foo", "w")
sink(zz)
cat('Diagnostics and Summary\n')
shapiro.test(get(x))
bartlett.test(get(x),Site)
bartlett.test(get(x),Time)
cat(paste('ANOVA ',x,'~Time*Site\n',sep=''))
summary(tmp.aov)
sink()
close(zz)
print(length(foo))
for(y in 0:(length(foo)-1))# by=.1){
print(y)
print(foo[y+1])
text(3,(length(foo)-y),foo[y+1],pos=4,cex=0.75)
}
mtext(paste('ANOVA and Diagnostics for ',trfm,'
',x,sep=''),side=3,outer=T)
}
Thanks,
Joel Allen
Institute of Applied Sciences
University of North Texas
hjallen at unt.edu
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._