do                  package:UsingR                  R Documentation

~~_f_u_n_c_t_i_o_n _t_o _d_o ... ~~

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

     A function to facilitate performing of simulations

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

     do(.n)

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

      .n: A positive integer

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

     This function facilitates simulations. It is called in two steps.
     The first sets up a function which will to '.n' simulations. This
     function is then called with a block of commands and returns the
     simulation.

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

     Returns a function which will repeat a block of commands for
     purposes of simulation.

_N_o_t_e:

     'do' is due to Daniel Kaplan.

_A_u_t_h_o_r(_s):

     Daniel Kaplan

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

     'replicate'

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

      aFew <- do(5)
      aLot <- do(100)
     ## simple call
      aFew(mean(rnorm(100)))
     ## t-statistic simulation
      aFew({x <- rexp(10); t.test(x)$stat})
     ## view correlation of regression coefficients. Returns a data.frame
      x <- 1:10
      res <- aLot({y <- rnorm(1+2*x); coef(lm(y~x))})
      plot(res)

