################################################################################ # Example for Batch 1 SES, using dive covariate log(MAX_DEP) ################################################################################ library(R2WinBUGS) #------------------------------------------------------------------------------- # (1) load Argos location and dive variable .csv files # 'argos': an R data.frame of Argos tracking data. # Contains the following columns: "id","time", "lc", "lon", "lat". # "id" is a unique identifier for the tracking dataset. # "time" is the GMT date-time of each observation with the following format: "2001-11-13 07:59:59". # "lc" is the Argos location quality class of each observation. Values in ascending order of quality are: # "Z", "B", "A", "0", "1", "2", "3". # "lon" is the observed longitude in decimal degrees. # "lat" is the observed latitude in decimal degress. argos <- read.csv(file="argos.csv",header=TRUE) argos$time <- as.POSIXct(argos$time, format = "%Y-%m-%d %H:%M:%S",tz = "GMT") argos$lc <- factor(argos$lc, levels = c("3", "2", "1","0", "A", "B", "Z"), ordered=T) # 'dive': an R data.frame containing the following columns: "id","time", "any_covariate". dive <- read.csv(file="dive.csv",header=TRUE) dive$time <- as.POSIXct(dive$time, format = "%Y-%m-%d %H:%M:%S",tz = "GMT") #------------------------------------------------------------------------------- # (2) Data into dat4bugsCOV.R for processing (Prepares and writes input data for DCRWSmeta_cov model) source("dat4bugsCOV.R") tstep <- 6/24 # The time step to be assumed for the state-space model, specified in days. datafile <- list(argos=argos,covar1=dive) data <- dat4bugsCOV(datafile, tstep=tstep, loess_fill=TRUE) #------------------------------------------------------------------------------- # (3) Fit covariate state-space model to data out.file <- "SES_SSMhCov1_Batch1_run3_6h" model.file <- "DCRWSmeta_cov1oneway.txt" # WinBUGS model script source("ssmMeta.R") out <- ssmMeta(data, model = "DCRWSmeta_cov", model.file = model.file, n.iter = 40000, n.burnin = 20000, n.thin = 2000, n.chains = 2, working.directory = getwd(), bugs.seed = sample(1:1e+05, 1), debug = FALSE) # reference the R package 'coda' for suitable convergence diagnostic tests save("out","datafile","data","model.file", file=paste(out.file ,".Rdata",sep="")) ################################################################################