PTBdiscrete {accuracy} | R Documentation

## Function to perturb vectors of discrete numeric values or factors, logicals, characters

### Description

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

### Usage

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

### Arguments

`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

### Details

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.

### Value

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

### Author(s)

Micah Altman Micah_Altman@harvard.edu http://www.hmdc.harvard.edu/micah_altman/

### References

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/

### See Also

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

### Examples

            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

[Package accuracy version 1.35 Index]