MIfitHMM {momentuHMM} | R Documentation |
Fit HMMs to multiple imputation data
Description
Fit a (multivariate) hidden Markov model to multiple imputation data. Multiple imputation is a method for accommodating missing data, temporal-irregularity, or location measurement error in hidden Markov models, where pooled parameter estimates reflect uncertainty attributable to observation error.
Usage
MIfitHMM(miData, ...)
## Default S3 method:
MIfitHMM(
miData,
nSims,
ncores = 1,
poolEstimates = TRUE,
alpha = 0.95,
na.rm = FALSE,
nbStates,
dist,
Par0,
beta0 = NULL,
delta0 = NULL,
estAngleMean = NULL,
circularAngleMean = NULL,
formula = ~1,
formulaDelta = NULL,
stationary = FALSE,
mixtures = 1,
formulaPi = NULL,
nlmPar = NULL,
fit = TRUE,
useInitial = FALSE,
DM = NULL,
userBounds = NULL,
workBounds = NULL,
betaCons = NULL,
betaRef = NULL,
deltaCons = NULL,
mvnCoords = NULL,
stateNames = NULL,
knownStates = NULL,
fixPar = NULL,
retryFits = 0,
retrySD = NULL,
optMethod = "nlm",
control = list(),
prior = NULL,
modelName = NULL,
covNames = NULL,
spatialCovs = NULL,
centers = NULL,
centroids = NULL,
angleCovs = NULL,
altCoordNames = NULL,
method = "IS",
parIS = 1000,
dfSim = Inf,
grid.eps = 1,
crit = 2.5,
scaleSim = 1,
quad.ask = FALSE,
force.quad = TRUE,
fullPost = TRUE,
dfPostIS = Inf,
scalePostIS = 1,
thetaSamp = NULL,
...
)
## S3 method for class 'hierarchical'
MIfitHMM(
miData,
nSims,
ncores = 1,
poolEstimates = TRUE,
alpha = 0.95,
na.rm = FALSE,
hierStates,
hierDist,
Par0,
hierBeta = NULL,
hierDelta = NULL,
estAngleMean = NULL,
circularAngleMean = NULL,
hierFormula = NULL,
hierFormulaDelta = NULL,
mixtures = 1,
formulaPi = NULL,
nlmPar = NULL,
fit = TRUE,
useInitial = FALSE,
DM = NULL,
userBounds = NULL,
workBounds = NULL,
betaCons = NULL,
deltaCons = NULL,
mvnCoords = NULL,
knownStates = NULL,
fixPar = NULL,
retryFits = 0,
retrySD = NULL,
optMethod = "nlm",
control = list(),
prior = NULL,
modelName = NULL,
covNames = NULL,
spatialCovs = NULL,
centers = NULL,
centroids = NULL,
angleCovs = NULL,
altCoordNames = NULL,
method = "IS",
parIS = 1000,
dfSim = Inf,
grid.eps = 1,
crit = 2.5,
scaleSim = 1,
quad.ask = FALSE,
force.quad = TRUE,
fullPost = TRUE,
dfPostIS = Inf,
scalePostIS = 1,
thetaSamp = NULL,
...
)
Arguments
miData |
A |
... |
further arguments passed to or from other methods |
nSims |
Number of imputations in which to fit the HMM using |
ncores |
Number of cores to use for parallel processing. Default: 1 (no parallel processing). |
poolEstimates |
Logical indicating whether or not to calculate pooled parameter estimates across the |
alpha |
Significance level for calculating confidence intervals of pooled estimates when |
na.rm |
Logical indicating whether or not to exclude model fits with |
nbStates |
Number of states of the HMM. See |
dist |
A named list indicating the probability distributions of the data streams. See |
Par0 |
A named list containing vectors of initial state-dependent probability distribution parameters for
each data stream specified in |
beta0 |
Initial matrix of regression coefficients for the transition probabilities. See |
delta0 |
Initial values for the initial distribution of the HMM. See |
estAngleMean |
An optional named list indicating whether or not to estimate the angle mean for data streams with angular
distributions ('vm' and 'wrpcauchy'). See |
circularAngleMean |
An optional named list indicating whether to use circular-linear or circular-circular
regression on the mean of circular distributions ('vm' and 'wrpcauchy') for turning angles. See |
formula |
Regression formula for the transition probability covariates. See |
formulaDelta |
Regression formula for the initial distribution. See |
stationary |
|
mixtures |
Number of mixtures for the state transition probabilities (i.e. discrete random effects *sensu* DeRuiter et al. 2017). Default: |
formulaPi |
Regression formula for the mixture distribution probabilities. See |
nlmPar |
List of parameters to pass to the optimization function |
fit |
|
useInitial |
Logical indicating whether or not to use parameter estimates for the first model fit as initial values for all subsequent model fits.
If |
DM |
An optional named list indicating the design matrices to be used for the probability distribution parameters of each data
stream. See |
userBounds |
An optional named list of 2-column matrices specifying bounds on the natural (i.e, real) scale of the probability
distribution parameters for each data stream. See |
workBounds |
An optional named list of 2-column matrices specifying bounds on the working scale of the probability distribution, transition probability, and initial distribution parameters. See |
betaCons |
Matrix of the same dimension as |
betaRef |
Numeric vector of length |
deltaCons |
Matrix of the same dimension as |
mvnCoords |
Character string indicating the name of location data that are to be modeled using a multivariate normal distribution. For example, if |
stateNames |
Optional character vector of length nbStates indicating state names. |
knownStates |
Vector of values of the state process which are known prior to fitting the
model (if any). See |
fixPar |
An optional list of vectors indicating parameters which are assumed known prior to fitting the model. See |
retryFits |
Non-negative integer indicating the number of times to attempt to iteratively fit the model using random perturbations of the current parameter estimates as the
initial values for likelihood optimization. See |
retrySD |
An optional list of scalars or vectors indicating the standard deviation to use for normal perturbations of each working scale parameter when |
optMethod |
The optimization method to be used. Can be “nlm” (the default; see |
control |
A list of control parameters to be passed to |
prior |
A function that returns the log-density of the working scale parameter prior distribution(s). See |
modelName |
An optional character string providing a name for the fitted model. If provided, |
covNames |
Names of any covariates in |
spatialCovs |
List of raster layer(s) for any spatial covariates. See |
centers |
2-column matrix providing the x-coordinates (column 1) and y-coordinates (column 2) for any activity centers (e.g., potential
centers of attraction or repulsion) from which distance and angle covariates will be calculated based on realizations of the position process.
See |
centroids |
List where each element is a data frame containing the x-coordinates ('x'), y-coordinates ('y'), and times (with user-specified name, e.g., ‘time’) for centroids (i.e., dynamic activity centers where the coordinates can change over time)
from which distance and angle covariates will be calculated based on the location data. See |
angleCovs |
Character vector indicating the names of any circular-circular regression angular covariates in |
altCoordNames |
Character string indicating an alternative name for the returned location data. See |
method |
Method for obtaining weights for movement parameter samples. See |
parIS |
Size of the parameter importance sample. See |
dfSim |
Degrees of freedom for the t approximation to the parameter posterior. See 'df' argument in |
grid.eps |
Grid size for |
crit |
Criterion for deciding "significance" of quadrature points
(difference in log-likelihood). See |
scaleSim |
Scale multiplier for the covariance matrix of the t approximation. See 'scale' argument in |
quad.ask |
Logical, for method='quadrature'. Whether or not the sampler should ask if quadrature sampling should take place. It is used to stop the sampling if the number of likelihood evaluations would be extreme. Default: FALSE. Ignored if |
force.quad |
A logical indicating whether or not to force the execution
of the quadrature method for large parameter vectors. See |
fullPost |
Logical indicating whether to draw parameter values as well to simulate full posterior. See |
dfPostIS |
Degrees of freedom for multivariate t distribution approximation to parameter posterior. See 'df' argument in |
scalePostIS |
Extra scaling factor for t distribution approximation. See 'scale' argument in |
thetaSamp |
If multiple parameter samples are available in |
hierStates |
A hierarchical model structure |
hierDist |
A hierarchical data structure |
hierBeta |
A hierarchical data structure |
hierDelta |
A hierarchical data structure |
hierFormula |
A hierarchical formula structure for the transition probability covariates for each level of the hierarchy. See |
hierFormulaDelta |
A hierarchical formula structure for the initial distribution covariates for each level of the hierarchy ('formulaDelta'). Default: |
Details
miData
can either be a crwData
or crwHierData
object (as returned by crawlWrap
), a crwSim
or crwHierSim
object (as returned by MIfitHMM
when fit=FALSE
),
or a list of momentuHMMData
or momentuHierHMMData
objects (e.g., each element of the list as returned by prepData
).
If miData
is a crwData
(or crwHierData
) object, MIfitHMM
uses a combination of
crwSimulator
, crwPostIS
, prepData
, and fitHMM
to draw nSims
realizations of the position process
and fit the specified HMM to each imputation of the data. The vast majority of MIfitHMM
arguments are identical to the corresponding arguments from these functions.
If miData
is a crwData
or crwHierData
object, nSims
determines both the number of realizations of the position process to draw
(using crwSimulator
and crwPostIS
) as well as the number of HMM fits.
If miData
is a crwSim
(or crwHierSim
) object or a list of momentuHMMData
(or momentuHierHMMData
) object(s), the specified HMM will simply be fitted to each of the momentuHMMData
(or momentuHierHMMData
) objects
and all arguments related to crwSimulator
, crwPostIS
, or prepData
are ignored.
Value
If nSims>1
, poolEstimates=TRUE
, and fit=TRUE
, a miHMM
object, i.e., a list consisting of:
miSum |
|
HMMfits |
List of length |
If poolEstimates=FALSE
and fit=TRUE
, a list of length nSims
consisting of momentuHMM
objects is returned.
However, if fit=FALSE
and miData
is a crwData
object, then MIfitHMM
returns a crwSim
object, i.e., a list containing miData
(a list of
momentuHMMData
objects) and crwSimulator
(a list of crwSimulator
objects),and most other arguments related to fitHMM
are ignored.
References
Hooten M.B., Johnson D.S., McClintock B.T., Morales J.M. 2017. Animal Movement: Statistical Models for Telemetry Data. CRC Press, Boca Raton.
McClintock B.T. 2017. Incorporating telemetry error into hidden Markov movement models using multiple imputation. Journal of Agricultural, Biological, and Environmental Statistics.
See Also
crawlWrap
, crwPostIS
, crwSimulator
, fitHMM
, getParDM
, MIpool
, prepData
Examples
# Don't run because it takes too long on a single core
## Not run:
# extract simulated obsData from example data
obsData <- miExample$obsData
# error ellipse model
err.model <- list(x= ~ ln.sd.x - 1, y = ~ ln.sd.y - 1, rho = ~ error.corr)
# create crwData object by fitting crwMLE models to obsData and predict locations
# at default intervals for both individuals
crwOut <- crawlWrap(obsData=obsData,
theta=c(4,0),fixPar=c(1,1,NA,NA),
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,
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)
## End(Not run)