Add more R scripts

This commit is contained in:
mattbk
2015-08-16 14:58:49 -05:00
parent e69edb519a
commit 52198ac043
4 changed files with 120 additions and 0 deletions

31
confplotd.R Normal file
View File

@ -0,0 +1,31 @@
# Requires plotrix library and split.file() output files.
# See Burton-Kelly (2008) for complete documentation.
confplotd <- function(path, pattern, vardis="Disparity", smoo=c(1:20), reps=1000, ext="-confplotd.txt", probs=c(0.025,0.975))
{
files<-list.files(path=path,pattern=pattern,full.names=TRUE);
for(i in files)
#Loop through files and assign variable names
{
x <- read.table(i,header=TRUE);
assign(i, x);
}
for(j in 1:length(files))
{
SOV <- get(files[j]);
bootSOV <- numeric(reps); #creates place for bootstrap values
for (k in 1:reps) {bootSOV[k] <- sum(diag(var(sample(SOV,replace=TRUE))))};
conf<-quantile(bootSOV,probs=probs);
toplot<-paste(smoo[j],mean(bootSOV),conf[2],conf[1]);
write.table(toplot,file=paste(substring(files[1],1, nchar(files[1])-4), ext, sep=""),quote=FALSE,append=TRUE, row.names=FALSE, col.names=FALSE)
}
tableback<-read.table(file=paste(substring(files[1],1,nchar(files[1])-4), ext, sep=""));
x<-unlist(tableback[1]);
y<-unlist(tableback[2]);
cui<-unlist(tableback[3]);
cli<-unlist(tableback[4]);
plotCI(x,y,ui=cui,li=cli,xlab=c("Smoothing"),ylab=vardis, ylim=c(0,0.025));
pdf(paste(substring(files[1],1,nchar(files[1])-4), ext, c(".pdf"), sep=""));
plotCI(x,y,ui=cui,li=cli,xlab=c("Smoothing"),ylab=vardis, ylim=c(0,0.025));
dev.off();
}