data(Trip1GPS)
data(Trip1DR)
###Bayesian Melding correction of DR path for this data set.
## Not run:
# ###Additional File for Animal Bio-telemetry
# ###Working with a thinned version of Trip 1 data set.
# #First install our R package
# install.packages("BayesianAnimalTracker")
#
# #Load the package
# library(BayesianAnimalTracker)
# #Require version 1.1 or higher.
#
# ##Load the uncorrected DR path
# data(Trip1DR)
# #this result is produced by the TrackReconstruction package
#
# ##Load the GPS observations
# data(Trip1GPS)
#
# ##Processng the GPS observations to get northing and easting in KM
# Trip1GPSformat <- GPStable(Trip1GPS)
# #GPStable is from TrackReconstruction
# Trip1GPSinKM <- DegToKM(Trip1GPSformat)
# #Get the northing and easting in km
#
# ###Analyze the Northing direction
# ##Prepare the data list that will be used in our Baysian Melding
# ndl <- as.dataList(Trip1DR$Ydim/1000, Trip1GPSinKM$Northing,
# Ytime=strptime(Trip1GPS$DateTime, "%d-%b-%Y %H:%M:%S"),
# Xtime=strptime(Trip1DR$DateTime, "%d-%b-%Y %H:%M:%S"),
# s2G=0.0625, timeUnit=60, betaOrder=1)
# #Please notice that the DR is in meter.
# #Need to convert it into kilometer.
# #Notice here the Xtime is not regularly spaced.
# #It must be converted to the dateTime format
# #Before further operations.
# ##The Bayesian Melding to correct bias and qualify uncertianty
# nPost <- BMAnimalTrack(ndl, BMControl(print=TRUE, returnParam=TRUE))
# #nPost is a list with two components
# #first is the parameter estimates of sigma^2_D and sigma^2_H
# #second is a matrix of the posterior mean and variance of eta.
# #If only eta is needed, you can chagne returnParam into FALSE.
#
# ##Plot the results in Easting direction.
# ##Produce Figure 4 in our paper
# nYlim <- c(min(min(ndl$XMx[, 1]),min(nPost$etaMar[,1])),
# max(max(ndl$XMx[, 1]),max(nPost$etaMar[,1])))
# #Find the limits in y-axis.
# par(mar=c(4, 4, 1, 1))
# plot(ndl$XMx[, 2], ndl$XMx[, 1], col="blue",
# xlab="Time (min)", ylab="Northing (KM)",
# type="l", lwd=2, ylim=nYlim)
# #Plot the uncorrected DR path
# lines(ndl$XMx[, 2], nPost$etaMar[,1], lwd=2)
# #Add the posterior mean of eta
# #the corrected path from our Bayesian Melding approach
# lines(ndl$XMx[, 2], nPost$etaMar[,1] +
# 1.96*sqrt(nPost$etaMar[,2]), lwd=2, col="grey70")
# #Add the upper bound of the 95% credible interval
# lines(ndl$XMx[, 2], nPost$etaMar[,1] -
# 1.96*sqrt(nPost$etaMar[,2]), lwd=2, col="grey70")
# #Add the lower bound
# legend("topleft", bty="n", legend=c("Posterior Mean",
# "95% Credible Interval", "GPS Observations",
# "Uncorrected DRA Results"),text.col=c(1, "grey70", 2, 4),
# lty=c(1, 1, -1, 1), pch=c(-1, -1, 16, -1),
# col=c(1, "grey70", 2, 4))
# #Add a legend
# points(ndl$glist$Gtime, ndl$g$Y, col="red", pch=16, cex=0.7)
# #Add the original GPS observations.
#
#
# ###Analyze the Easting direction
# ##Prepare the data list that will be used in our Baysian Melding
# edl <- as.dataList(Trip1DR$Xdim/1000, Trip1GPSinKM$Easting,
# Ytime=strptime(Trip1GPS$DateTime, "%d-%b-%Y %H:%M:%S"),
# Xtime=strptime(Trip1DR$DateTime, "%d-%b-%Y %H:%M:%S"),
# s2G=0.0625, timeUnit=60, betaOrder=1)
#
# ##The Bayesian Melding to correct bias and qualify uncertianty
# ePost <- BMAnimalTrack(edl, BMControl(print=TRUE, returnParam=TRUE))
# #A list similar to nPost
#
# ##Plot the results in Easting direction.
# ##Produce a plot similar to Figure 4 in our paper
# eYlim <- c(min(min(edl$XMx[, 1]),min(ePost$etaMar[,1])),
# max(max(edl$XMx[, 1]),max(ePost$etaMar[,1])))
# #Find the limits in y-axis.
# par(mar=c(4, 4, 1, 1))
# plot(edl$XMx[, 2], edl$XMx[, 1], col="blue",
# xlab="Time (min)", ylab="Easting (KM)",
# type="l", lwd=2, ylim=eYlim)
# #Plot the uncorrected DR path
# lines(edl$XMx[, 2], ePost$etaMar[,1], lwd=2)
# #Add the posterior mean of eta
# #the corrected path from our Bayesian Melding approach
# lines(edl$XMx[, 2], ePost$etaMar[,1] +
# 1.96*sqrt(ePost$etaMar[,2]), lwd=2, col="grey70")
# #Add the upper bound of the 95% credible interval
# lines(edl$XMx[, 2], ePost$etaMar[,1] -
# 1.96*sqrt(ePost$etaMar[,2]), lwd=2, col="grey70")
# #Add the lower bound
# legend("bottomright", bty="n", legend=c("Posterior Mean",
# "95% Credible Interval", "GPS Observations",
# "Uncorrected DRA Results"),text.col=c(1, "grey70", 2, 4),
# lty=c(1, 1, -1, 1), pch=c(-1, -1, 16, -1),
# col=c(1, "grey70", 2, 4))
# #Add a legend
# points(edl$glist$Gtime, edl$g$Y, col="red", pch=16, cex=0.7)
# #Add the original GPS observations.
#
# ###Combine the results in both dimensions,
# ###and calculate the corrected path in degrees.
# cPathInKM <- cbind(ePost$etaMar[,1], nPost$etaMar[,1])
# #first column is easting and second column northing in KM.
# cPathInDeg <- KMToDeg(cPathInKM, Trip1GPSformat [1, c(3, 2)])
# #Get the longitude and latitude of the starting points
# #first longitude and then latitude.
#
# ##Produce a plot similar to Figure 2 of Liu et al. (2014b)
# plot(cPathInDeg[, ], type="l", lwd=2)
# #plot the corrected path
# points(Trip1GPSformat [, c(3, 2)], col="red", pch=16)
# #add the original GPS observations.
#
#
# ## End(Not run)
Run the code above in your browser using DataLab