simulate            package:HiddenMarkov            R Documentation

_S_i_m_u_l_a_t_e _V_a_r_i_o_u_s _H_M_M _P_r_o_c_e_s_s_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     These functions provide methods for the generic function
     'simulate'.

_U_s_a_g_e:

     ## S3 method for class 'dthmm':
     simulate(object, nsim = 1, seed = NULL, ...)
     ## S3 method for class 'mchain':
     simulate(object, nsim = 1, seed = NULL, ...)
     ## S3 method for class 'mmglm':
     simulate(object, nsim = 1, seed = NULL, ...)
     ## S3 method for class 'mmpp':
     simulate(object, nsim = 1, seed = NULL, ...)

_A_r_g_u_m_e_n_t_s:

  object: an object with class '"dthmm"', '"mchain"', '"mmglm"' or
          '"mmpp"'

    nsim: number of points to simulate.

    seed: seed for the random number generator.

     ...: other arguments.

_D_e_t_a_i_l_s:

     Below details about particular methods are given where necessary.

     '_s_i_m_u_l_a_t_e._m_m_g_l_m' If the covariate 'x1' is 'NULL', then uniform
          (0,1) variables are generated as the values for 'x1'. When
          the 'family' is '"binomial"' and 'size' is 'NULL' (i.e. the
          number of Bernoulli trials are not specified), then they are
          simulated as '100+rpois(nsim, lambda=5)'.

     The code for the methods '"dthmm"', '"mmglm"' and '"mmpp"' can be
     viewed by typing 'simulate.dthmm', 'simulate.mmglm' or
     'simulate.mmpp', respectively, on the R command line.

_V_a_l_u_e:

     The returned object has the same class as the input object and
     contains the components that were in the input object. Where
     'object' is of class '"dthmm"' it will also have a vector 'x'
     containing the simulated values; and when the class is '"mmglm"'
     'x' will be a dataframe. When the class is '"mmpp"' the times of
     the simulated Poisson events are contained in 'tau'. Other
     variables are also added like the sequence of Markov states, and
     the time spent in each state ('"mmpp"').

_E_x_a_m_p_l_e_s:

     #    The hidden Markov chain has 5 states with transition matrix:

     Pi <- matrix(c(1/2, 1/2,   0,   0,   0,
                    1/3, 1/3, 1/3,   0,   0,
                      0, 1/3, 1/3, 1/3,   0,
                      0,   0, 1/3, 1/3, 1/3,
                      0,   0,   0, 1/2, 1/2),
                  byrow=TRUE, nrow=5)

     #--------------------------------------------
     #   simulate a Poisson HMM

     x <- dthmm(NULL, Pi, c(0, 1, 0, 0, 0), "pois",
                list(lambda=c(1, 4, 2, 5, 3)), discrete = TRUE)

     x <- simulate(x, nsim=2000)

     #    check Poisson means
     for (i in 1:5) print(mean(x$x[x$y==i]))

     #--------------------------------------------
     #   simulate a Gaussian HMM

     x <- dthmm(NULL, Pi, c(0, 1, 0, 0, 0), "norm",
                list(mean=c(1, 4, 2, 5, 3), sd=c(0.5, 1, 1, 0.5, 0.1)))

     x <- simulate(x, nsim=2000)

     #    check means and standard deviations
     for (i in 1:5) print(mean(x$x[x$y==i]))
     for (i in 1:5) print(sd(x$x[x$y==i]))

