##load a model object
data(mesa.data.model)
##examine the model
printMesaDataNbrObs(mesa.data.model)
##covariates
mesa.data.model$LUR.list
mesa.data.model$ST.Ind
##Important dimensions of the model
dim <- loglike.dim(mesa.data.model)
print(dim)
##Set up initial parameter values for optimization
x.init <- cbind(rep(2,dim$nparam.cov),
c(rep(c(1,-3),dim$m+1),-3))
##and add names to the initial values
rownames(x.init) <- loglike.var.names(mesa.data.model,
all=FALSE)
print(x.init)
##estimate parameters
##This may take a while...
par.est <- fit.mesa.model(x.init, mesa.data.model, type="p",
hessian.all=TRUE, control=list(trace=3,maxit=1000))
##Let's load precomputed results instead.
data(mesa.data.res)
par.est <- mesa.data.res$par.est
##Optimisation status message
par.est$message
##compare the estimated parameters for the two starting points
cbind(par.est$res.all[[1]]$par.all,
par.est$res.all[[2]]$par.all)
##and values of the likelihood
cbind(par.est$res.all[[1]]$value,
par.est$res.all[[2]]$value)
##extract the estimated parameters
x <- par.est$res.best$par.all
##and approximate uncertainties from the hessian
x.sd <- sqrt(diag(-solve(par.est$res.best$hessian.all)))
names(x.sd) <- names(x)
##plot the estimated parameters with uncertainties
par(mfrow=c(1,1),mar=c(13.5,2.5,.5,.5))
plot(x, ylim=range(c(x-1.96*x.sd,x+1.96*x.sd)),
xlab="", xaxt="n")
points(x-1.96*x.sd, pch=3)
points(x+1.96*x.sd, pch=3)
axis(1,1:length(x),names(x),las=2)
Run the code above in your browser using DataLab