# NOT RUN {
# Don't run because it takes too long on a single core
# }
# NOT RUN {
# extract simulated obsData from example data
obsData <- miExample$obsData
# extract crwMLE inputs from example data
inits <- miExample$inits # initial state
err.model <- miExample$err.model # error ellipse model
# create crwData object by fitting crwMLE models to obsData and predict locations
# at default intervals for both individuals
crwOut <- crawlWrap(obsData=obsData,ncores=1,
theta=c(4,0),fixPar=c(1,1,NA,NA),
initial.state=inits,
err.model=err.model)
# HMM specifications
nbStates <- 2
stepDist <- "gamma"
angleDist <- "vm"
mu0 <- c(20,70)
sigma0 <- c(10,30)
kappa0 <- c(1,1)
stepPar0 <- c(mu0,sigma0)
anglePar0 <- c(-pi/2,pi/2,kappa0)
formula <- ~cov1+cos(cov2)
nbCovs <- 2
beta0 <- matrix(c(rep(-1.5,nbStates*(nbStates-1)),rep(0,nbStates*(nbStates-1)*nbCovs)),
nrow=nbCovs+1,byrow=TRUE)
# first fit HMM to best predicted position process
bestData<-prepData(crwOut,covNames=c("cov1","cov2"))
bestFit<-fitHMM(bestData,
nbStates=nbStates,dist=list(step=stepDist,angle=angleDist),
Par0=list(step=stepPar0,angle=anglePar0),beta0=beta0,
formula=formula,estAngleMean=list(angle=TRUE))
print(bestFit)
# extract estimates from 'bestFit'
bPar0 <- getPar(bestFit)
# Fit nSims=5 imputations of the position process
miFits<-MIfitHMM(miData=crwOut,nSims=5,ncores=1,
nbStates=nbStates,dist=list(step=stepDist,angle=angleDist),
Par0=bPar0$Par,beta0=bPar0$beta,delta0=bPar0$delta,
formula=formula,estAngleMean=list(angle=TRUE),
covNames=c("cov1","cov2"))
# print pooled estimates
print(miFits)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab