model; { ##First difference CRW model # Created by Ian Jonsen # 10 March, 2004 # Last modified 29 October, 2004 pi <- 3.141592653589 pi2 <- 2*pi npi <- pi*-1 Omega[1,1] <- 1 Omega[1,2] <- 0 Omega[2,1] <- 0 Omega[2,2] <- 1 ## priors on process uncertainty iSigma[1:2,1:2] ~ dwish(Omega[,],2) Sigma[1:2,1:2] <- inverse(iSigma[,]) ## Priors for first location for(k in 1:2){ x[1,k] ~ dt(y[1,k], itau2[1,k], nu[1,k]) } ## Assume simple random walk to estimate 2nd regular position x[2,1:2] ~ dmnorm(x[1,], iSigma[,]) theta ~ dunif(npi,pi) ## prior for theta (mean turn angle) gamma ~ dbeta(1,1) ## prior for gamma (persistence) corr ~ dunif(0, 10) ## Transition equation for(t in 2:(RegN-1)){ ## Build transition matrix for rotational component T[t,1,1] <- cos(theta) T[t,1,2] <- -sin(theta) T[t,2,1] <- sin(theta) T[t,2,2] <- cos(theta) for(k in 1:2){ Tdx[t,k] <- T[t,k,1] * (x[t,1] - x[t-1,1]) + T[t,k,2] * (x[t,2] - x[t-1,2]) ## matrix multiplication x.mn[t,k] <- x[t,k] + gamma * Tdx[t,k] ## predict next location (no process error) } x[t+1,1:2] ~ dmnorm(x.mn[t,], iSigma[,]) ## predict next location (with process error) } ## Measurement equation for(t in 2:RegN){ ## loops over regular time intervals (t) for(i in idx[t-1]:(idx[t]-1)){ ## loops over observed locations within interval t for(k in 1:2){ itau2c[i,k] <- itau2[i,k] * corr zhat[i,k] <- (1 - j[i]) * x[t-1,k] + j[i]*x[t,k] ## interpolate irregularly observed locations y[i,k] ~ dt(zhat[i,k], itau2c[i,k], nu[i,k]) ## robust measurement equation } } } }