simulate                package:stats                R Documentation

_S_i_m_u_l_a_t_e _R_e_s_p_o_n_s_e_s

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

     Simulate one or more response vectors from the theoretical
     distribution corresponding to a fitted model object.

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

     simulate(object, nsim, seed, ...)

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

  object: an object representing a fitted model.

    nsim: number of response vectors to simulate.  Defaults to 1.

    seed: an object specifying if and how the random number generator
          should be initialized ('seeded').
           For the "lm" method, either 'NULL' or an integer that will
          be used in a call to 'set.seed' before simulating the
          response vectors.  If set, the value is saved as the '"seed"'
          attribute of the returned value.  The default, 'NULL' will
          not change the random generator state, and return
          '.Random.seed' as '"seed"' attribute, see below. 

     ...: additional optional arguments.

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

     This is a generic function with a method for 'lm' objects. Consult
     the individual modeling functions for details on how to use this
     function.

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

     Typically, a list of length 'nsim' of simulated response vectors.
     When appropriate the result can be a data frame (which is a
     special type of list).

     For the '"lm"' method, the result is a data frame with an
     attribute '"seed"' containing the 'seed' argument and
     'as.list(RNGkind())' if 'seed' was not 'NULL', or the value of
     '.Random.seed' before the simulation was started when 'seed' was
     NULL as by default.

_S_e_e _A_l_s_o:

     'fitted.values' and 'residuals' for related methods; 'glm', 'lm'
     for model fitting.

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

     x <- 1:5
     mod1 <- lm(c(1:3,7,6) ~ x)
     S1 <- simulate(mod1, nsim = 4)
     ## repeat the simulation:
     .Random.seed <- attr(S1, "seed")
     identical(S1, simulate(mod1, nsim = 4))

     S2 <- simulate(mod1, nsim = 200, seed = 101)
     rowMeans(S2) # should be about
     fitted(mod1)

     ## repeat identically:
     (sseed <- attr(S2, "seed")) # seed; RNGkind as attribute
     stopifnot(identical(S2, simulate(mod1, nsim = 200, seed = sseed)))

     ## To be sure about the proper RNGkind, e.g., after
     RNGversion("2.7.0")
     ## first set the RNG kind, then simulate
     do.call(RNGkind, attr(sseed, "kind"))
     identical(S2, simulate(mod1, nsim = 200, seed = sseed))

