set.seed(1)
#Generating data from our model
dlist <- dataSim(T=100, K=10, s2H=1, s2D=0.1, betaVec=c(1))
gpsObs <- dlist$Y
gpsTime <- dlist$Ytime
drPath <- dlist$X
#Produce the data list required by BMAnimalTrack
wlist <- as.dataList(drPath, gpsObs, gpsTime,
timeUnit=1, s2G=0.01, dUnit=1, betaOrder=1)
#Calculate the posterior of eta with our Bayesian Melding approach
etaMar <- BMAnimalTrack(wlist, BMControl(print=TRUE))
## A real data example from package TrackReconstruction.
## Example from TrackReconstruction package.
## library(TrackReconstruction)
betas<-Standardize(1,1,-1,1,1,1,-57.8,68.76,-61.8,64.2,
-70.16,58.08, -10.1,9.55,-9.75,9.72, -9.91,9.43)
#get declination and inclination data for study area
decinc<-c(10.228,65.918)
#data set with 6 associated GPS fixes in the "gpsdata" data set
data(rawdata)
#Perform the Dead-Reckoning of the raw accelerometer and
# magnetometer data
DRoutput<-DeadReckoning(rawdata,betas,decinc,Hz=16,
RmL=2,DepthHz=1,SpdCalc=3,MaxSpd=3.5)
#prepare GPS data
data(gpsdata02)
#matching time of the GPS and DR
gpsdata <- gpsdata02[gpsdata02$DateTime %in% DRoutput$DateTime, ]
gpsformat<-GPStable(gpsdata)
K <- nrow(gpsformat)
T <- nrow(gpsformat)
#Cut out the periods of DR path with the GPS
DRstart <- min(which(DRoutput$DateTime==gpsformat$DateTime[1]))
DRend <- max(which(DRoutput$DateTime==gpsformat$DateTime[K]))
#Thin the data (Original 16Hz, for now only working with 1Hz)
DRworking <- DRoutput[c(DRstart:DRend)[c(DRstart:DRend)%%16==1], ]
#Calculate the northing in km##
GPSnorthing=c(0, cumsum(gpsformat$DistanceKm[-1]*cos(gpsformat$BearingRad[-T])))
DRnorthing <- (DRworking$Ydim - DRworking$Ydim[1])/1000
#Original unit of DR is in meters
#Data preparation for BM bias correction
ndl <- as.dataList(DRnorthing, GPSnorthing,
Ytime=gpsformat$DateTime,
Xtime=DRworking$DateTime,
s2G=0.0625, timeUnit=60, betaOrder=1)
#Bayesian Melding calculation.
nEtaMar <- BMAnimalTrack(ndl, BMControl(print=TRUE, returnParam=TRUE))
#Plots.
plot(ndl$XMx[,2], ndl$XMx[,1], type="l", col="blue", ylim=c(0, 2.5))
#uncorrected DR path
points(ndl$glist$Gtime, ndl$glist$Y, col="red", pch=16) #GPS points
lines(ndl$XMx[,2], nEtaMar$etaMar[,1], type="l") #Corrected path
lines(ndl$XMx[,2], nEtaMar$etaMar[,3], type="l", col="grey70") #Lower bound of CI
lines(ndl$XMx[,2], nEtaMar$etaMar[,4], type="l", col="grey70") #Upper bound of CI.Run the code above in your browser using DataLab