dice              package:TeachingDemos              R Documentation

_S_i_m_u_l_a_t_e _r_o_l_l_i_n_g _d_i_c_e

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

     Simulate and optionally plot rolls of dice.

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

     dice(rolls = 1, ndice = 2, sides = 6, plot.it = FALSE, load = rep(1, sides))
     plot.dice(x, ...)

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

   rolls: Scalar, the number of times to roll the dice. 

   ndice: Scalar, the number of dice to roll each time. 

   sides: Scalar, the number of sides per die. 

 plot.it: Logical, Should the results be plotted. 

    load: Vector of length 'sides', how the dice should be loaded.

       x: Data frame, return value from 'dice'. 

     ...: Additional arguments passed to lattice plotting function. 

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

     Simulates the rolling of dice.  By default it will roll 2 dice 1
     time and the dice will be fair.  Internally the 'sample' function
     is used and the load option is passed to sample.  'load' is not
     required to sum to 1, but the elements will be divided by the sum
     of all the values.

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

     A data frame with 'rolls' rows and 'ndice' columns representing
     the results from rolling the dice.

     If only 1 die is rolled, then the return value will be a vector.

     If 'plot.it' is TRUE, then the return value will be invisible.

_N_o_t_e:

     If the plot function is used or if 'plot.it' is TRUE, then a plot
     will be created on the current graphics device.

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

     Greg Snow greg.snow@intermountainmail.org 

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

     'sample'

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

     # 10 rolls of 4 fair dice
     dice(10,4, plot.it=TRUE)

     # or

     plot(dice(10,4))

     # or 

     tmp <- dice(10,4)
     plot(tmp)

     # a loaded die
     table(tmp <- dice(100,1,plot.it=TRUE, load=6:1 ) )
     mean(tmp)

     ## redo De Mere's question

     demere1 <- dice(10000,4)
     demere2 <- dice(10000,24,sides=36)

     mean(apply( demere1, 1, function(x) 6 %in% x ))

     mean(apply( demere2, 1, function(x) 36 %in% x))

     plot(demere1[1:10,])

     ## plot all possible combinations of 2 dice

     plot.dice( expand.grid(1:6,1:6), layout=c(6,6) )

