Learn R Programming

momentuHMM (version 1.2.0)

getPar0: Get starting values for new model from existing momentuHMM model fit

Description

For nested models, this function will extract starting parameter values (i.e., Par0 in fitHMM or MIfitHMM) from an existing momentuHMM model fit based on the provided arguments for the new model. Any parameters that are not in common between model and the new model (as specified by the arguments) are set to 0. This function is intended to help users incrementally build and fit more complicated models from simpler nested models (and vice versa).

Usage

getPar0(model, nbStates = NULL, estAngleMean = NULL,
  circularAngleMean = NULL, formula = NULL, formulaDelta = NULL,
  DM = NULL, stateNames = NULL)

Arguments

model

A momentuHMM, miHMM, or miSum object (as returned by fitHMM, MIfitHMM, or MIpool)

nbStates

Number of states in the new model. If nbStates=NULL (the default), then nbStates=length(model$stateNames)

estAngleMean

Named list indicating whether or not the angle mean for data streams with angular distributions ('vm' and 'wrpcauchy') are to be estimated in the new model. If estAngleMean=NULL (the default), then estAngleMean=model$conditions$estAngleMean

circularAngleMean

Named list indicating whether circular-linear (FALSE) or circular-circular (TRUE) regression on the mean of circular distributions ('vm' and 'wrpcauchy') for turning angles are to be used in the new model. If circularAngleMean=NULL (the default), then circularAngleMean=model$conditions$circularAngleMean

formula

Regression formula for the transition probability covariates of the new model (see fitHMM). If formula=NULL (the default), then formula=model$conditions$formula.

formulaDelta

Regression formula for the initial distribution covariates of the new model (see fitHMM). If formulaDelta=NULL (the default), then formulaDelta=model$conditions$formulaDelta.

DM

Named list indicating the design matrices to be used for the probability distribution parameters of each data stream in the new model (see fitHMM). Only parameters with design matrix column names that match those in model$conditions$fullDM are extracted, so care must be taken in naming columns if any elements of DM are specified as matrices instead of formulas. If DM=NULL (the default), then DM=model$conditions$DM.

stateNames

Character vector of length nbStates indicating the names and order of the states in the new model. If stateNames=NULL (the default), then stateNames=model$stateNames[1:nbStates].

Value

A named list containing starting values suitable for Par0 and beta0 arguments in fitHMM or MIfitHMM:

Par

A list of vectors of state-dependent probability distribution parameters for each data stream specified in model$conditions$dist

beta

Matrix of regression coefficients for the transition probabilities

delta

Initial distribution of the HMM. Only returned if stateNames has the same membership as the state names for model

.

All other fitHMM (or MIfitHMM) model specifications (e.g., dist, cons, userBounds, workcons, etc.) and data are assumed to be the same for model and the new model (as specified by estAngleMean, circularAngleMean, formula, formulaDelta, DM, and stateNames).

See Also

getPar, getParDM, fitHMM, MIfitHMM

Examples

Run this code
# NOT RUN {
# model is a momentuHMM object, automatically loaded with the package
model <- example$m
data <- model$data
dist <- model$conditions$dist
nbStates <- length(model$stateNames)
estAngleMean <- model$conditions$estAngleMean

newformula <- ~cov1+cov2
Par0 <- getPar0(model,formula=newformula)

# }
# NOT RUN {
newModel <- fitHMM(model$data,dist=dist,nbStates=nbStates,
                   Par0=Par0$Par,beta0=Par0$beta,
                   formula=newformula,
                   estAngleMean=estAngleMean)
# }
# NOT RUN {
newDM1 <- list(step=list(mean=~cov1,sd=~cov1))
Par0 <- getPar0(model,DM=newDM1)

# }
# NOT RUN {
newModel1 <- fitHMM(model$data,dist=dist,nbStates=nbStates,
                   Par0=Par0$Par,beta0=Par0$beta,
                   formula=model$conditions$formula,
                   estAngleMean=estAngleMean,
                   DM=newDM1)
# }
# NOT RUN {
# same model but specify DM for step using matrices
newDM2 <- list(step=matrix(c(1,0,0,0,
                           "cov1",0,0,0,
                           0,1,0,0,
                           0,"cov1",0,0,
                           0,0,1,0,
                           0,0,"cov1",0,
                           0,0,0,1,
                           0,0,0,"cov1"),nrow=nbStates*2))
                           
# to be extracted, new design matrix column names must match 
# column names of model$conditions$fullDM
colnames(newDM2$step)<-paste0(rep(c("mean_","sd_"),each=2*nbStates),
                      rep(1:nbStates,each=2),
                      rep(c(":(Intercept)",":cov1"),2*nbStates))
Par0 <- getPar0(model,DM=newDM2)
                      
# }
# NOT RUN {
newModel2 <- fitHMM(model$data,dist=dist,nbStates=nbStates,
                   Par0=Par0$Par,beta0=Par0$beta,
                   formula=model$conditions$formula,
                   estAngleMean=estAngleMean,
                   DM=newDM2)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab