PTBdiscrete {accuracy} | R Documentation |
This uses a reclassification matrix to perturb a vector discrete values.
PTBdiscrete(x, r=NULL, q=0.99) # for factors, discrete numeric
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 |
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.
Returns a new vector x' with elements randomly reclassified according to r.
Micah Altman Micah_Altman@harvard.edu http://www.hmdc.harvard.edu/micah_altman/
Altman, M., J. Gill and M. P. McDonald. 2003. Numerical Issues in Statistical Computing for the Social Scientist. John Wiley & Sons. http://www.hmdc.harvard.edu/numerical_issues/
perturb
, PTBn
, PTBdefault
,
reclass.mat.random
, reclass.mat.diag
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