Appendix A. WinBUGS code for SSM fit in first example.This Appendix provides the WinBUGS code required to fit the SSM presented in the first example. Data and initial values for this model are included at the end. The contents of this appendix, below this line can be copied and pasted into a blank file in WinBUGS (see software manual for details).
model rwalk; { ## Random Movement Dependent Upon the Environment
## Process Error (eta_t):
## ---------------------
# eta_t ~ N(mean = 0, variance = (sigma*exp(-beta*temp))^2 )
# log(1/(sigma^2))~N(mean = 0, variance = 10^3): This is a vague prior for the precision.
# isigma = exp(1/(sigma^2))
isigma~dlnorm(0,.001)
# convert isigma to sigma (Note: This changes the precision to the standard deviation)
sigma<-1/sqrt(isigma)
# beta describes how rapidly movement variance declines with increasing temperature
# beta~N(mean = 0, variance = 1000): This is a vague prior
beta~dnorm(0,.001)
## Observation error (epsilon_t):
## -----------------------------
# epsilon_t~N(mean = 0, variance = tau^2)
# log(1/(tau^2))~N(-1.386294, variance= 1): This is an informative prior for the precision.
itau~dlnorm(-1.386294,10)
# convert itau to tau (Note: This changes the precision to the standard deviation)
tau<-1/sqrt(itau)
## Initializations:
## ---------------
## Y -> True locations (alpha_t)
## Y1 -> Observed locations (y_t)
# In order to get first true location equal to the observed location (i.e. where released) we do the following:
Y[1,1]~dnorm(Y1[1,1],100000000)
Y[1,2]~dnorm(Y1[1,2],100000000)
isig.temp[1,1]<-0
isig.temp[1,2]<-0
## Interate transition equation:
for(i in 2:N){ # cycles through locations
for(j in 1:2){ # two dimensions (x & y directions)
isig.temp[i,j]<-(isigma*pow(exp(-1*beta*temp[i-1]),-2))
Y[i,j]~dnorm(Y[i-1,j],isig.temp[i,j])
}
}
## Iterate measurement equation:
for(i in 1:N){
for(j in 1:2){
Y1[i,j]~dnorm(Y[i,j],itau)
}
}
}# These are the data required to fit the above model. The dataset contains the observed locations (Y1) and SST sampled at each location (temp)
Data
list(Y1=structure(.Data=c(20,35,19.855022890216,19.6698742350975,15.7086065789012,23.8382510521393,18.5976304366155,22.6076358016155,19.8646721185899,22.7612929880127,23.2496391780058,26.5898512578803,22.4404116960421,27.1734895758413,24.0920933757481,27.3228749261844,28.5932675352096,26.5171953514024,26.6072485638212,31.962849208448,28.9591251674744,33.2797424172519,25.0758387684227,32.0740051698846,27.0739647305293,38.948032722988,35.7771388094642,37.8319492984922,37.9858090735734,36.1098735600917,33.1201510467572,36.1965011928447,35.4250146782634,34.7460463633695,36.4336985029782,39.9401794255513,36.8143143859608,35.0618257150559,39.1145966946458,33.3032091921272,38.8894268799563,32.7936204513402,40.5393333585532,36.1665098477191,41.2207279399686,32.4330554855467,36.6964486202615,31.162623445969,41.6324341752997,27.4913473348003,41.4973421335572,32.7254955661669,36.6054756997536,31.8097583038101,37.4155365111385,28.2271979592695,39.1659872817691,29.7077120092169,40.0706593620588,32.6275843545612,39.3634972585767,32.3012077800215,37.5034177548941,33.180434895581,42.811116839829,30.9513911417621,34.816782006993,33.3391730596076,42.5499096913818,35.4995528935992,39.2059836450256,34.7416999468408,37.0396007913549,34.4029769902048,37.8775251077087,32.7028528025422,36.0086174953959,35.5695104892158,38.3452115797779,33.4450770724678,40.2905602392252,34.6746322669149,41.4861049975276,40.5567794233164,38.1751601379341,34.9308859545687,39.0806415319249,36.5242160530569,40.7623294328671,32.3964936874113,39.674825170817,34.1353773112599,41.3273562344635,34.7463943023152,38.2398799657419,35.8495618472602,39.3614036434583,35.367673945307,39.7195230074206,35.4256235029048,40.7849873981495,31.4828518370136,39.8343027911761,32.1923320063168,38.9540589484908,33.2591063318141,36.911537742713,36.0079935333458,38.6940633232077,34.2660411144809,35.152368130993,33.9051324678723,40.6750713835349,34.1919687373168,42.7867500730223,30.3649226409439,39.0914843935991,30.7056155833084,43.9455211753684,33.9519599179862,37.9348256893004,36.3045221354367,41.6809429748844,29.5451239573728,40.6739919516563,33.9404546807824,37.4550476249474,32.7868439677911,40.5701690202412,32.6599305087301,40.6882378365987,33.615000600831,42.0304675986395,34.0519674695287,43.118753922073,36.571066599208,43.2224847349811,32.0768650566799,45.824109317032,32.823290626346,41.3373517336619,33.271812239535,45.1276236380673,33.5906001955417,43.8823342434866,33.9216599321873,45.3449326248097,36.7981329124248,48.4301682262657,31.9984371430456,42.2302343284954,36.5166529902756,43.0020092679743,35.6973474885577,47.7595699682826,39.33338408709,48.5431277748494,41.2919493580959,44.781304351554,41.3662229055265,44.4556996854895,43.6182406158363,41.0679540182838,44.0248541792074,43.5273574583745,39.6580067781027,47.7632282289692,44.2917426191302,46.5978812081247,45.1652093892542,43.7769464802538,44.5682130670977,44.9011470597363,47.8434959535784,46.078186732518,48.7168158810261,46.9187332117737,48.1213344658024,42.578746144294,46.8236672287591,47.9202442524498,45.8637528662262,44.8898837416816,43.4738717031102,43.648586189137,45.1165476775627,40.7937560981562,44.7622402040878,50.4326082245204,45.1143952019959,42.5149934548928,45.2476379186594,44.6103359310638,45.8713476229019,51.4775832984129,44.1228837923696,42.5825237424816,45.8553194185278,44.2895006640801,47.0429706891603,42.7829128254167,49.2339800973784,51.4439805047652,47.6151395960774,46.5087643398542,44.1747114641196,50.6622771018873,45.8375625360715,55.3897875796891,45.7479017652905,55.7559725383753,47.7717815741417,47.5631012529631,49.2994051536018,50.7604631791051,47.1436381416517,49.5156568584486,50.8443187876003,46.7394908488479,46.1785060630502,53.631709602449,45.3394007776354,51.2920658070045,48.3969615968056,48.4242278824246,47.4073521734675,48.5116490284731,50.0538155594996,48.198602912288,48.1150009912585,46.7751318240025,48.751470081086,45.1302154428013,49.3138888487068,46.3819321293845,44.6700978702601,48.0574266679832,45.0121141752507,49.3404585687841,49.0534175683301,47.4594915491045,46.530030846432,48.7120540340005,48.4934306104025,50.6471976301967,47.9398063025277,52.5678164783831,46.6483047880306,53.4076342531158,49.0423655380348,54.5869465390347,47.0970108164772,56.4402914906497,50.7277455124202,53.8758739232432,55.8877149960647,52.4301784320746,52.6127063172193,54.7409885710579,50.4755530381515,51.3462429616192,50.7549346313129,56.3503606722895,52.2732711652695,50.7974994419634,51.3641485899625,52.2240965132644,49.1032745468786,56.4208727708462,52.6427536673168,53.5484846275706,53.6364705483955,55.7594733447806,47.3382365463927,53.3997526110904,49.0374575512877,52.8339410467328,48.1153521384625,52.0843478093182,50.4590291777265,53.4328228912622,52.5432879899524,54.2950162666841,54.9420224853164,51.4531755027451,53.950282139866,56.9572841676188,50.4776549046165,53.9141086878302,49.0795044739558,53.1606326057436,51.1782341382871,54.6994460176697,51.8937231265399,51.2467822328628,50.425019072677,55.1281100498708,53.0843154968043,51.1086394704219,48.9591563716715,51.2107722734912,50.6838922592372,57.1959393255521,51.6688593687276,54.8050161124662,51.1529661738125,55.9794375409628,50.7901191614552,56.9210812111326,46.3812350345038,56.9548156813867,47.9697558271015,51.9144950474725,51.4681941833254,54.1553570389136,51.6181246106213,56.261917040358,52.7682856918831,55.7501208926078,48.5422369735697,50.0322434264711,49.2995085361306,55.191558123965,47.3851687418624,56.6075803566865,49.8350852578292,57.4879292964035,52.2005040382405,57.4754079496453,51.1709622708758,55.0100011413503,54.8630331174957,54.4055721952818,53.658684708688,58.1559864021594,53.112808793222,55.5745973889493,49.7448375654229,59.8740364130984,51.5204338939632,57.9070808531192,48.0773775797349,59.8168064178174,51.7638325433433,61.9870535286567,50.4158322929566,63.0661195075449,56.3584858087833,57.6208241954947,48.5134183918589,63.5624370867372,52.5991238262978,58.1017343825015,50.7375201356161,57.1145942315546,50.9983685659943,60.1712366085803,57.2545966169285,61.8489055164923,51.5980872025366,60.9900331589978,51.9194878555114,61.2574848178722,54.4969524314693,62.464662126726,56.0685786172454,60.3397918628829,53.2099940033209,61.7490484135651,56.3156961554476,61.8525795115145,54.3473984482935,59.9472901350261,52.7215048328743,61.6436670240051,54.2012063962838,61.9636108979272,55.1530156483414,60.5564695395568,56.6701987456758,60.8343880056392,53.7424583565518,61.069170876497,55.0371419062911,64.4212014163419,50.1231208641501,57.3887622299017,54.5835767181495,59.4849141137924,52.0849233797318,57.7293714477375,51.3313285393062,62.2885144024687,51.8101329999936,62.1502567715678,50.3516056528556,60.2404657872352,52.3338701923978,58.5036027606961,50.680100973578),.Dim=c(200,2)),temp= c(-2.68668082330986,-0.513840681799355,-0.512535491688892,-0.25110476790048,-0.16261076050524,-0.48931087942129,-1.25483575487058,-1.37920512912954,-0.84655513056658,-0.981616101152233,-1.45779712166752,-1.13951740411627,-1.90190416714048,0.314438992097792,0.314438992097792,-0.0555120287666164,-0.149991615349674,-0.316840619227353,0.824690442996708,0.824690442996708,0.824690442996708,0.824690442996708,0.764942329896565,0.764942329896565,0.764942329896565,0.817555476947914,0.817555476947914,0.817555476947914,0.764942329896565,0.764942329896565,0.817555476947914,0.824690442996708,0.817555476947914,0.68545105041715,-0.0214028307565616,0.783318237944173,0.0414585256998555,1.00323839640431,0.79350213645145,1.00323839640431,0.4729888021324,0.4729888021324,0.4729888021324,1.00323839640431,0.820845886153157,0.358564524520343,0.358564524520343,0.79350213645145,1.00323839640431,0.79350213645145,0.358564524520343,0.358564524520343,0.68545105041715,0.68545105041715,0.68545105041715,0.824690442996708,0.68545105041715,-0.0214028307565616,0.136013621110065,-0.121849022576295,0.0414585256998555,0.0466482569731305,-0.121849022576295,-0.121849022576295,0.0414585256998555,0.0158328142071326,0.0318312928160347,-0.735576218069346,0.782310649489799,0.782310649489799,0.512012541551376,0.782310649489799,0.0318312928160347,0.0318312928160347,-0.161305504128841,-1.36815904530765,-1.46443386147554,-1.20919866085943,-0.403919473343396,0.134248878236365,0.271733161601515,0.271733161601515,0.134248878236365,-0.650564506560245,0.261836886783941,0.667181979419748,0.720149637216922,0.720149637216922,0.720149637216922,0.305926530873289,0.305926530873289,0.348216456736968,0.183154536978576,0.441576820496172,0.441576820496172,-0.173949807669506,0.261836886783941,0.369584193066576,0.348216456736968,0.348216456736968,0.144085283291225,0.0708644493773207,-0.0388639483279403,-1.04217381855273,-0.791378882570287,-1.06636230066842,0.0191940649407187,0.8323061940258,0.0359379092244671,-0.434808031041209,-0.665378857583671,0.39781045260733,0.0359379092244671,0.55762447934874,0.341623912800685,0.341623912800685,0.404031852431892,0.377005888636493,0.0688561088400107,-0.152801837657703,-0.152801837657703,0.0688561088400107,0.0688561088400107,-0.495415347875342,0.0359379092244671,-0.486861237401721,-0.0218737001517727,1.17710118151658,1.17710118151658,1.03839258114781,1.17710118151658,1.17710118151658,1.17710118151658,1.31434100403704,1.31434100403704,1.17710118151658,1.17710118151658,1.17710118151658,1.17710118151658,1.31434100403704,0.960780533889061,0.960780533889061,0.960780533889061,1.22938823555997,1.22938823555997,1.22938823555997,1.31434100403704,1.17710118151658,1.22938823555997,1.22938823555997,1.22938823555997,1.22938823555997,0.512435129001344,0.512435129001344,0.512435129001344,-0.145959113402268,1.22938823555997,1.22938823555997,1.22938823555997,0.295363516052078,0.295363516052078,0.512435129001344,0.512435129001344,0.187373630265053,0.561683486990005,0.47946426401304,0.617374772380316,0.617374772380316,0.561683486990005,0.600646154065334,0.0400547784360411,0.931096442224465,0.931096442224465,0.931096442224465,0.931096442224465,1.24211632074958,1.24211632074958,0.931096442224465,1.29287950035746,1.42340894375417,1.42340894375417,1.42340894375417,1.42340894375417,1.42340894375417,1.42340894375417,1.42340894375417,1.42340894375417,1.42340894375417,1.42340894375417,0.942958217680212,1.42340894375417,1.42340894375417,1.42340894375417,1.42340894375417,1.29287950035746,1.42340894375417,1.42340894375417,1.42340894375417,1.29287950035746,1.29287950035746),N=200)
#These are 2 sets of initial values required by the MCMC sampler to run 2 chains simultaneously
Inits
list(Y=structure(.Data=c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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