Commit fb518484 authored by Daniel Falster's avatar Daniel Falster
Browse files

Tweak files for running jags locally

No related merge requests found
Showing with 54 additions and 24 deletions
+54 -24
...@@ -14,3 +14,4 @@ figs ...@@ -14,3 +14,4 @@ figs
*.rds *.rds
docs/metadata/sites docs/metadata/sites
.Rproj.user .Rproj.user
GROWTH.MODEL.*
########################### ###########################
########################### ###########################
##### FUNCTIONS USED IN FORMATTING DATA FOR JAGS AND RUN ANALYSIS ##### FUNCTIONS USED IN FORMATTING DATA FOR JAGS AND RUN ANALYSIS
source("R/packages.R")
check_packages(c("rjags", "R2jags"))
###### ######
###### ######
...@@ -165,7 +166,8 @@ return(jags.data) ...@@ -165,7 +166,8 @@ return(jags.data)
######################################### #########################################
### WRITE JAGS MODELS ### WRITE JAGS MODELS
write.jags.model.HD <- function(file = "GROWTH.MODEL.LOGLIN.HD"){
### LOG LIN HD ### LOG LIN HD
GROWTH.MODEL.LOGLIN.HD <- GROWTH.MODEL.LOGLIN.HD <-
"################################################################################ "################################################################################
...@@ -233,7 +235,10 @@ sigma.alpha ~ dunif(0.000001,5) ...@@ -233,7 +235,10 @@ sigma.alpha ~ dunif(0.000001,5)
} # End of the jags model } # End of the jags model
" "
cat(GROWTH.MODEL.LOGLIN.HD , file = "GROWTH.MODEL.LOGLIN.HD", sep=" ", fill = FALSE, labels = NULL, append = FALSE) cat(GROWTH.MODEL.LOGLIN.HD , file = file, sep=" ", fill = FALSE, labels = NULL, append = FALSE)
}
write.jags.model.AD <- function(file = "GROWTH.MODEL.LOGLIN.AD"){
### LOG LIN HD ### LOG LIN HD
GROWTH.MODEL.LOGLIN.AD <- GROWTH.MODEL.LOGLIN.AD <-
...@@ -302,8 +307,8 @@ sigma.alpha ~ dunif(0.000001,5) ...@@ -302,8 +307,8 @@ sigma.alpha ~ dunif(0.000001,5)
} # End of the jags model } # End of the jags model
" "
cat(GROWTH.MODEL.LOGLIN.AD , file = "GROWTH.MODEL.LOGLIN.AD", sep=" ", fill = FALSE, labels = NULL, append = FALSE) cat(GROWTH.MODEL.LOGLIN.AD , file = file, sep=" ", fill = FALSE, labels = NULL, append = FALSE)
}
################################################ ################################################
########################### ###########################
...@@ -455,3 +460,22 @@ n.chain <- dim(jags.output$BUGSoutput$sims.array)[2] ...@@ -455,3 +460,22 @@ n.chain <- dim(jags.output$BUGSoutput$sims.array)[2]
length.chain <- dim(jags.output$BUGSoutput$sims.array)[1] length.chain <- dim(jags.output$BUGSoutput$sims.array)[1]
plot(x,y,col=rep(1:n.chain,each=length.chain),xlab=param.name.1,ylab=param.name.2) plot(x,y,col=rep(1:n.chain,each=length.chain),xlab=param.name.1,ylab=param.name.2)
} }
get.ecoregions <- function(site){
sub(paste("./output/processed/",site,"/",sep=""),"",list.dirs(paste("./output/processed/",site,sep="")))[-1]
}
run.jags.for.trait <- function(site, trait, A1, A2, ecoregions = get.ecoregions(site)){
for (e in ecoregions)
try(fun.run.4models.jags(site=site,ecoregion.name=e,min.obs=10,
name.trait=trait,
A1=A1,
A2=A2,
n.chains=3,
n.iter=3000,
n.burnin=1000,
n.thin=1,
sample.size=2000,
na.action.traits="fill with global mean"))
}
##### #####
## run jags code
source("R/analysis/JAGS.fun.R")
source("./R/analysis/fun.analysis.R")
site <- "NVS" write.jags.model.HD()
write.jags.model.AD()
ecoregion.code <- sub(paste("./output/processed/",site,"/",sep=""),"",list.dirs(paste("./output/processed/",site,sep="")))[-1]
traits <- c("SLA", "Leaf.N","Seed.mass","SLA","Wood.density","Max.height")
for (i in ecoregion.code[1]){
fun.run.4models.jags(site=site,ecoregion.name=i,min.obs=10, for(this.trait in traits)
name.trait="SLA", run.jags.for.trait("France", trait = this.trait, A1 = "sgdd", A2 = "WB.s")
A1="MAT",
A2="MAP", for(this.trait in traits)
n.chains=3, run.jags.for.trait("NVS", trait = this.trait, A1 = "MAT", A2 = "MAP")
n.iter=3000,
n.burnin=1000, for(this.trait in traits)
n.thin=1, run.jags.for.trait("US", trait = this.trait, A1 = "MAT", A2 = "MAP")
sample.size=NA,
na.action.traits="fill with global mean") for(this.trait in traits)
} run.jags.for.trait("Spain", trait = this.trait, A1 = "MAT", A2 = "PP")
for(this.trait in traits)
run.jags.for.trait("Canada", trait = this.trait, A1 = "MAT", A2 = "MAP")
...@@ -33,6 +33,7 @@ We are making use of the following tools: ...@@ -33,6 +33,7 @@ We are making use of the following tools:
- [*markdown*](http://daringfireball.net/projects/markdown/) - [*markdown*](http://daringfireball.net/projects/markdown/)
- The [*knitr*](http://cran.r-project.org/web/packages/knitr/index.html) package in R, for generating documents with R and markdown. For a n intro see [here](http://nicercode.github.io/guides/reports/) - The [*knitr*](http://cran.r-project.org/web/packages/knitr/index.html) package in R, for generating documents with R and markdown. For a n intro see [here](http://nicercode.github.io/guides/reports/)
- version control via git (see next section) - version control via git (see next section)
- JAGS - Just another Gibbs Sampler. Install [here](http://sourceforge.net/projects/mcmc-jags/files/)
### Git ### Git
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment