PTBdiscrete             package:accuracy             R Documentation

_F_u_n_c_t_i_o_n _t_o _p_e_r_t_u_r_b _v_e_c_t_o_r_s _o_f _d_i_s_c_r_e_t_e _n_u_m_e_r_i_c _v_a_l_u_e_s _o_r _f_a_c_t_o_r_s, _l_o_g_i_c_a_l_s, _c_h_a_r_a_c_t_e_r_s

_D_e_s_c_r_i_p_t_i_o_n:

     This uses a reclassification matrix to perturb a vector discrete
     values.

_U_s_a_g_e:

     PTBdiscrete(x, r=NULL, q=0.99) # for factors, discrete numeric

_A_r_g_u_m_e_n_t_s:

       x: the vector to be perturbed 

       r: a reclassification matrix produced by  'reclass.mat.diag' or
          'reclass.mat.random'  or 'reclassify' (from the separate
          perturb library) 

       q: q-value for reclassification, if r is NULL

_D_e_t_a_i_l_s:

     This perturbs discrete vectors by reclassifying them at random
     based on a cumulative probability reclassification matrix. 

     By default, if 'r' is not supplied a default matrix will be
     supplied that has probability='q'  of keeping the same values,
     using the same rules as 'PTBdefault'. 

     As an alternative to classification for numeric vectors, see
     'PTBu' and related functions for methods that add random noise to
     a vector.

_V_a_l_u_e:

     Returns a new vector x' with elements randomly reclassified
     according to r.

_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:

     Altman, M., J. Gill and M. P. McDonald.  2003.  _Numerical Issues
     in Statistical Computing for the Social Scientist_.  John Wiley &
     Sons. <URL: http://www.hmdc.harvard.edu/numerical_issues/>

_S_e_e _A_l_s_o:

     'perturb', 'PTBn', 'PTBdefault' , 'reclass.mat.random',
     'reclass.mat.diag'

_E_x_a_m_p_l_e_s:

             x=ceiling(runif(1:100)*3)               # vector taking on 3 discrete levels
             rx = reclass.mat.random(3,.95)  # reclassification matrix, prob of change  = .05
             rpx=replicate(100,PTBdiscrete(x,rx),simplify=FALSE) # 100 perturbations
             if (is.R()) {
          matches <-sapply(rpx,function(y)(sum(y==x)))       # how many matches to original vector
       } else {
          # Splus variation
          matches <-sapply(rpx,substitute(function(y)(sum(y==x))))
       }
             summary(matches)                                # mean should be close to .95

