PTBdefault {accuracy}R Documentation

Returns a default perturbation function for a given vector.

Description

This function returns a function that can be used to repeatedly peturb the vector given to it.

Usage

PTBdefaultfn(vec, q = 0.99)
PTBdefault(vec, q=0.99)

Arguments

vec the vector which will be subject to perturbation
q for discrete vectors, the reclassification probability. For continuous vectors, perturbations will have 1-q relative uniform noise added.

Details

For numeric discrete values, and ordered factors, reclass.mat.diag will be used to generate the default reclassification matrix. For character vectors, unordered factors, and logicals, relass.mat.random is used.

Value

A function that can be used to perturb the vector.

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, PTBdiscrete, PTBus, reclass.mat.random

Examples


x=1:100
 # perturb using the default method
rpx=replicate(100,PTBdefault(x),simplify=FALSE)
# how many matches to original vector? mean should be close to 95
        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)                                
# This produces equivalent results, but is faster, 
# since reclass matrices are not recalculated on each replication   

fx=PTBdefaultfn(x,q=.95) 
rpx=replicate(100,fx(x),simplify=FALSE) 
        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)                        


[Package accuracy version 1.31 Index]