#harborSealWA is a n=5 matrix of logged population counts
dat = t(harborSealWA)
dat = dat[2:4,] #remove the year row
#fit a model with 1 hidden state and 3 observation time series
kemfit = MARSS(dat, model=list(Z=factor(c(1,1,1)),
R="diagonal and equal"))
kemfit$model #This gives a description of the model
print(kemfit$model) # same as kemfit$model
summary(kemfit$model) #This shows the model structure
#add CIs to a marssMLE object
#default uses an estimated Hessian matrix
kem.with.hess.CIs = MARSSparamCIs(kemfit)
kem.with.hess.CIs #print with se's and CIs
#fit a model with 3 hidden states (default)
kemfit = MARSS(dat, silent=TRUE) #suppress printing
kemfit #print information on the marssMLE object
#fit a model with 3 correlated hidden states
# with one variance and one covariance
#maxit set low to speed up example, but more iterations are need for convergence
kemfit = MARSS(dat, model=list(Q="equalvarcov"), control=list(maxit=50))
#fit a model with 3 correlated hidden states
#maxit set low to speed up example, but more iterations are need for convergence
kemfit = MARSS(dat, model=list(Q="unconstrained"), control=list(maxit=50))
#fit a model with 3 independent hidden states
#where each observation time series is independent
#the hidden trajectories 1-3 & 4-5 share their U parameter
kemfit = MARSS(dat, model=list(U=matrix(c("N","S","S"),3,1)))
#same model, but with fixed independent observation errors
#and the 3rd x processes are forced to have a U=0
#Notice how a list matrix is used to combine fixed and estimated elements
#all parameters can be specified in this way using list matrices
kemfit = MARSS(dat, model=list(U=matrix(list("N","N",0),3,1), R=diag(0.01,3)))
#fit a model with 2 hidden states (north and south)
#where observation time series 1-2 are north and 3 is south
#Make the hidden state process independent with same process var
#Make the observation errors different but independent
#Make the growth parameters (U) the same
kemfit = MARSS(dat, model=list(Z=factor(c("N","N","S")),
Q="diagonal and equal",R="diagonal and unequal",U="equal"))
#print the model followed by the marssMLE object
kemfit$model
kemfit
#simulate some new data from our fitted model
sim.data=MARSSsimulate(kemfit, nsim=10, tSteps=100)
#Compute bootstrap AIC for the model; this takes a long, long time
kemfit.with.AICb = MARSSaic(kemfit, output = "AICbp")
kemfit.with.AICb
Run the code above in your browser using DataLab