Description Usage Format Details Examples
Example of a parametric bootstrap for model selection with the dccs data
1 | data("dccs_boot_LR")
|
A boot
object
The bootstrap sample was generated by the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | require(depmixS4)
require(hmmr)
require(boot)
data(dccs)
m2 <- mix(response=cbind(nCorPost,6-nCorPost)~1,nstates=2,
data=dccs,family=binomial())
set.seed(1234)
fm2 <- fit(m2)
set.seed(1234)
fm3 <- fit(mix(response=cbind(nCorPost,6-nCorPost)~1,
nstates=3, data=dccs,family=binomial()))
boot.fun <- function(model) {
ok <- FALSE
while(!ok) {
bootdat <- data.frame(
simulate(model)@response[[1]][[1]]@y)
fboot2 <- try({
mod <- mix(cbind(X1,X2)~1, nstates=2,
family=binomial(), data=bootdat)
mod <- setpars(mod,getpars(fm2))
fit(mod,emcontrol=em.control(random.start=FALSE),
verbose=FALSE)
})
fboot3 <- try({
mod <- mix(cbind(X1,X2)~1, nstates=3,
family=binomial(), data=bootdat)
mod <- setpars(mod,getpars(fm3))
fit(mod,emcontrol=em.control(random.start=FALSE),
verbose=FALSE)
})
if(!inherits(fboot2,"try-error") &&
!inherits(fboot3,"try-error") &&
logLik(fboot3) >= logLik(fboot2)) ok <- TRUE
# if(ok) if(logLik(fboot3) < logLik(fboot2)) ok <- FALSE
}
llratio(fboot3,fboot2)@value
}
set.seed(1234)
dccs_boot_LR <- boot(fm2, boot.fun, R=10000, sim="parametric")
|
1 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.