The 4 chains for baypass are not converging, so I am now rerunning analyses by standardizing the data and rerunning the analysis. I am trying this for altitude first. I have created another folder called altitude in analyses/baypass/climate/altitude. This is where the output files will be created. I have changed the values for npilot, nthreads, nval and also standardized the environment variables.
Here is R code to standardize the altitude data (environfile 1 in analyses/baypass/environfiles):
#read in the files
bart1<-read.table("bart1.txt", header=FALSE)
cali1<-read.table("cali1.txt", header=FALSE)
chum1<-read.table("chum1.txt", header=FALSE)
cris1<-read.table("cris1.txt", header=FALSE)
knul1<-read.table("knul1.txt", header=FALSE)
land1<-read.table("land1.txt", header=FALSE)
popp1<-read.table("popp1.txt", header=FALSE)
podu1<-read.table("podu1.txt", header=FALSE)
#defining the normalization function
normFunc<-function(x){(x-mean(x,na.rm=T))/sd(x,na.rm = T)}
#normalizing for each species
bartn<-apply(bart1[1,],1,normFunc)
calin<-apply(cali1[1,],1,normFunc)
chumn<-apply(chum1[1,],1,normFunc)
crisn<-apply(cris1[1,],1,normFunc)
knuln<-apply(knul1[1,],1,normFunc)
landn<-apply(land1[1,],1,normFunc)
poppn<-apply(popp1[1,],1,normFunc)
podun<-apply(podu1[1,],1,normFunc)
#writeout the files
write.table(t(bartn), file = "bart1n.txt", sep="\t", row.names=FALSE, col.names=FALSE, quote=FALSE)
write.table(t(calin), file = "cali1n.txt", sep="\t", row.names=FALSE, col.names=FALSE, quote=FALSE)
write.table(t(chumn), file = "chum1n.txt", sep="\t", row.names=FALSE, col.names=FALSE, quote=FALSE)
write.table(t(crisn), file = "cris1n.txt", sep="\t", row.names=FALSE, col.names=FALSE, quote=FALSE)
write.table(t(knuln), file = "knul1n.txt", sep="\t", row.names=FALSE, col.names=FALSE, quote=FALSE)
write.table(t(landn), file = "land1n.txt", sep="\t", row.names=FALSE, col.names=FALSE, quote=FALSE)
write.table(t(poppn), file = "popp1n.txt", sep="\t", row.names=FALSE, col.names=FALSE, quote=FALSE)
write.table(t(podun), file = "podu1n.txt", sep="\t", row.names=FALSE, col.names=FALSE, quote=FALSE)
######same for latitude and repeat same for longitude##########
bart<-read.table("lat-bart_environfile.txt", header=FALSE)
cali<-read.table("lat-cali_environfile.txt", header=FALSE)
chum<-read.table("lat-chum_environfile.txt", header=FALSE)
cris<-read.table("lat-cris_environfile.txt", header=FALSE)
knul<-read.table("lat-knul_environfile.txt", header=FALSE)
land<-read.table("lat-land_environfile.txt", header=FALSE)
podu<-read.table("lat-podu_environfile.txt", header=FALSE)
popp<-read.table("lat-popp_environfile.txt", header=FALSE)
#defining the normalization function
normFunc<-function(x){(x-mean(x,na.rm=T))/sd(x,na.rm = T)}
#call function for each species
bartn<-apply(bart[1,],1,normFunc)
calin<-apply(cali[1,],1,normFunc)
chumn<-apply(chum[1,],1,normFunc)
crisn<-apply(cris[1,],1,normFunc)
knuln<-apply(knul[1,],1,normFunc)
landn<-apply(land[1,],1,normFunc)
poppn<-apply(popp[1,],1,normFunc)
podun<-apply(podu[1,],1,normFunc)
#writeout the files
write.table(t(bartn), file = "bartstd.txt", sep="\t", row.names=FALSE, col.names=FALSE, quote=FALSE)
write.table(t(calin), file = "calistd.txt", sep="\t", row.names=FALSE, col.names=FALSE, quote=FALSE)
write.table(t(chumn), file = "chumstd.txt", sep="\t", row.names=FALSE, col.names=FALSE, quote=FALSE)
write.table(t(crisn), file = "crisstd.txt", sep="\t", row.names=FALSE, col.names=FALSE, quote=FALSE)
write.table(t(knuln), file = "knulstd.txt", sep="\t", row.names=FALSE, col.names=FALSE, quote=FALSE)
write.table(t(landn), file = "landstd.txt", sep="\t", row.names=FALSE, col.names=FALSE, quote=FALSE)
write.table(t(poppn), file = "poppstd.txt", sep="\t", row.names=FALSE, col.names=FALSE, quote=FALSE)
write.table(t(podun), file = "podustd.txt", sep="\t", row.names=FALSE, col.names=FALSE, quote=FALSE)
#standardizing all the climate layer files
#list all the files in the folder
filenames<-Sys.glob("*")
#defining the normalization function
normFunc<-function(x){(x-mean(x,na.rm=T))/sd(x,na.rm = T)}
#call function for each species
for (i in filenames){
sps<-read.table(i, header=F)
sps_std<-apply(sps[1,],1,normFunc)
filename <- paste(i, "std", sep="")
write.table(t(sps_std), filename, sep="\t", row.names=FALSE, col.names=FALSE, quote=FALSE)
}
#outside R