speed_boot_LR: speed boot LR

Description Usage Format Details Examples

Description

Example of a parametric bootstrap for model selection

Usage

1
data("speed_boot_LR")

Format

A boot object

Details

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
43
require(depmixS4)
      require(hmmr)
      require(boot)
      
      data(speed1)
      set.seed(5)
      spmix2 <- mix(RT~1, data=speed1, nstates=2)
      fspmix2 <- fit(spmix2,verbose=FALSE)
      
      set.seed(5)
      fspmix3 <- fit(mix(RT~1,data=speed1,nstates=3))
      
      speed.fun.LR <- function(model) {
        ok <- FALSE
        while(!ok) {
          bootdat <- data.frame(RT = simulate(model)@response[[1]][[1]]@y)
          fboot2 <- try({
            mod <- mix(RT~1,data=bootdat,nstates=2)
            mod <- setpars(mod,getpars(fspmix2))
            fit(mod,emcontrol=em.control(random.start=FALSE),verbose=FALSE)
          },TRUE)
          fboot3 <- try({
            mod <- mix(RT~1,data=bootdat,nstates=3)
            mod <- setpars(mod,getpars(fspmix3))
            fit(mod,emcontrol=em.control(random.start=FALSE),verbose=FALSE)
          },TRUE)
          if(!inherits(fboot2,"try-error") & !inherits(fboot3,"try-error")) ok <- TRUE
        }
        if(ok & logLik(fboot3) < logLik(fboot2)) ok <- FALSE
        while(!ok) {
          cat("trying different starting-values")
          fboot3 <- try({
            mod <- mix(RT~1,data=bootdat,nstates=3)
            mod <- setpars(mod,getpars(fspmix3))
            fit(mod,verbose=FALSE)
          },TRUE)
          if(!inherits(fboot3,"try-error") & logLik(fboot3) > logLik(fboot2)) ok <- TRUE
        }
        llratio(fboot3,fboot2)@value
      }
      set.seed(5)
      speed_boot_LR <- boot(fspmix2,speed.fun.LR,R=1000,sim="parametric")
    

Examples

1

hmmr documentation built on May 27, 2021, 9:10 a.m.

Related to speed_boot_LR in hmmr...