# 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)
if (FALSE) {
newModel <- fitHMM(model$data,dist=dist,nbStates=nbStates,
Par0=Par0$Par,beta0=Par0$beta,
formula=newformula,
estAngleMean=estAngleMean)
}
newDM1 <- list(step=list(mean=~cov1,sd=~cov1))
Par0 <- getPar0(model,DM=newDM1)
if (FALSE) {
newModel1 <- fitHMM(model$data,dist=dist,nbStates=nbStates,
Par0=Par0$Par,beta0=Par0$beta,
formula=model$conditions$formula,
estAngleMean=estAngleMean,
DM=newDM1)
}
# 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)
if (FALSE) {
newModel2 <- fitHMM(model$data,dist=dist,nbStates=nbStates,
Par0=Par0$Par,beta0=Par0$beta,
formula=model$conditions$formula,
estAngleMean=estAngleMean,
DM=newDM2)
}
Run the code above in your browser using DataLab