urn                   package:urn                   R Documentation

_R_e_p_e_a_t_e_d _S_a_m_p_l_i_n_g _W_i_t_h_o_u_t _R_e_p_l_a_c_e_m_e_n_t

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

     Generate repeated samples of the same list of objects without
     replacement.

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

     u<-urn(items,prob=NULL)
     s<-sampleu(u,n)
     size<-refill.urn(u)

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

   items: Items - A set of items to be sampled. If 'items' is a list,
          calls to urn.sample are treated identically to 'sample'
          except that  $( 1 )$

          repeated calls to urn.sample sample without replacement from
          items $( 2 )$ the probability distribution is defined at urn
          creation time.

          If 'items' is a vector, however, each item in the vector is
          interpreted as the frequency of occurence of that type of
          item in the urn.   

    prob: Vector of probability weights corresponding to items. For use
          with items lists only.

       u: urn to be sampled

       n: number of items in sample

    size: number of items remaining

       s: sample drawn from urn

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

     sample() allows a single sample to be taken without replacement.
     Call urn.sample when repeated samples without replacement are
     needed. Use sum() to determine population left in urn, and
     refill.urn to restore population to originial levels.

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

     Micah Altman  Micah_Altman\@harvard.edu   <URL:
     http://www.hmdc.harvard.edu/micah_altman/>

_R_e_f_e_r_e_n_c_e_s:

     There are many references explaining sampling without replacement,
     this is one example:

     _Mathematical Statistics and Data Analysis_, John A. Rice.
     Wadsworth, 1988, 1995.

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

     'sample'

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

     library(urn)

     # Create urn with 3 items
     u<-urn(list(1,2,3))

     # custom print and summary methods
     print(u )
     summary(u)

     # draw 2 samples from the urn
     sampleu(u,2)
     # can't sample more items than in the urn, without refilling:
     # sampleu(u,2)
     sum(u)
     sampleu(u,1)
     # refill
     refill.urn(u)  
     # Create an urn with 100010 items of two types in ~51:49 proportions
     ub<-urn(c(51006,49004))
     summary(ub)

     # take ten draws each of 10001 items
     rep<-replicate(10, table(sampleu(ub,10001)), simplify=TRUE)
     print(rep)

     # should equal 51006
     sum(rep[1,])

