Presentation is loading. Please wait.

Presentation is loading. Please wait.

JAGS. Learning Objectives Be able to represent ecological systems as a network of known and unknowns linked by deterministic and stochastic relationships.

Similar presentations


Presentation on theme: "JAGS. Learning Objectives Be able to represent ecological systems as a network of known and unknowns linked by deterministic and stochastic relationships."— Presentation transcript:

1 JAGS

2 Learning Objectives Be able to represent ecological systems as a network of known and unknowns linked by deterministic and stochastic relationships. Understand the basis for factoring simple Bayesian models using laws of probability. Be able to derive conditional probabilities from networks (DAGS). Use conditional probabilities as basis for writing JAGS code.

3 Exercise: write a Bayesian model for the model of light Limitation of Trees ϒ= max. growth rate at high light c=minimum light requirement α=slope of curve at low light

4 Bayesian Networks The heads of the arrows specify variables on the left hand side of the conditioning in the joint distribution; the tails are on the right hand Side. Anything without an arrow leading to it is either known as data or “known” as a prior with numeric arguments. If the prior is uninformative, these quantities are “known unknowns”. They are also called “directed acyclic graphs (DAG)” and “Bayesian belief networks”

5 Process model Parameter model

6 BUGS [GUI interface] Bayesian inference Using Gibbs Sampling WinBUGS (Windows) OpenBUGS (cross-platform) GeoBUGS JAGS [command line] Just Another Gibbs Sampler JAGS (cross-platform) R2WinBUGS R2OpenBUGS Others… rjags R2jags Others… BUGS JAGS ImperativeDeclarative

7 From R: 1.Specify initial conditions 2.Specify data 3.Specify model 4.Specify run conditions 5.Call JAGS 6.Manipulate JAGS output (rjags, coda others) JAGS From JAGS: 1.Choose algorithm 2.Generate chains 3.Send chain output back to R IMPERATIVE DECLARATIVE

8 tree.data<-read.csv("Hemlock-light-data.csv") # Specify initial condition. mod.inits<-function(){ list(a=rnorm(1,40,2), b=ruinf(1,1.5,2.5), c=runif(1,-5,5), tau=0.001) } # Specify data; must be a list. data=list( n=nrow(tree.data), x=as.numeric(tree.data$Light), y=as.numeric(tree.data$Observed.growth.rate ) )

9 # JAGS model model{ for (i in 1:n) { mu[i]<-(a*x[i]+c)/((a/b)+x[i]+c) # prediction/scientific model y[i]~ dnorm(mu[i],tau) # likelihood } # Prior distributions tau~dgamma(0.001,.001) a~dgamma(0.001,.001) c~dunif(-10, 10) b~dgamma(.001,.001) sigma<-1/sqrt(tau) } # end of model The JAGS model can be inserted inside of R code or saved as a text file and called from R.

10 # Set run conditions: number of iterations for adaptation & runs, number of chains, etc n.adapt=500 n.update = 1000 n.iter = 3000 # Call to JAGS jm=jags.model(“jags_light_example.R",data=data,mod.inits,n.chains=3,n.adapt = n.adapt) # Burnin the chain (we normally throw these out) update(jm, n.iter=n.update) # Generate coda and jags objects for parameters to monitor and deviance. zm<-coda.samples(jm,variable.names=c("a", "b", "c","mu“, “deviance”),n.iter=n.iter, n.thin=10) zj<-jags.samples(jm,variable.names=c("a", "b","c","mu“, “deviance”), n.iter=n.iter, n.thin=10)

11 # Plot parameters plot(zm,,ask = dev.interactive()) xyplot(zm,ask = dev.interactive()) densityplot(zm,ask = dev.interactive()) # Plot predictions b=summary(zj$mu,quantile,c(.025,.5,.976))$stat plot(tree.data$Light, tree.data$Observed.growth.rate, xlab="Light", ylab="Growth Rate", pch=16, col="blue") lines(tree.data$Light, b[2,]) lines(tree.data$Light, b[1,], lty="dashed") lines(tree.data$Light, b[3,], lty="dashed") # Convergence diagnostics rejectionRate(zm) # sampling conjugate gelman.diag(zm) # var in chains, stable=1, want r < 1.2 heidel.diag(zm) # requires convergence raftery.diag(zm) # how many iter you need for convergence

12 The gang Kiona Ogle Mevin Hooten Tom Hobbs


Download ppt "JAGS. Learning Objectives Be able to represent ecological systems as a network of known and unknowns linked by deterministic and stochastic relationships."

Similar presentations


Ads by Google