\HeaderA{PTBdefault}{Returns a default perturbation function for a given vector.}{PTBdefault}
\aliasA{PTBdefaultfn}{PTBdefault}{PTBdefaultfn}
\keyword{misc}{PTBdefault}
\keyword{optimize}{PTBdefault}
\keyword{distribution}{PTBdefault}
\begin{Description}\relax
This function returns a function that can be used to  repeatedly peturb the vector given to it.
\end{Description}
\begin{Usage}
\begin{verbatim}
PTBdefaultfn(vec, q = 0.99)
PTBdefault(vec, q=0.99)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{vec}] the vector which will be subject to perturbation
\item[\code{q}] for discrete vectors, the reclassification probability. For continuous vectors, perturbations will have 
1-q relative uniform noise added. 
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
For numeric discrete values, and ordered factors, \code{reclass.mat.diag} will
be used to generate the default reclassification matrix. For character vectors, unordered factors, and logicals,
\code{relass.mat.random} is used.
\end{Details}
\begin{Value}
A function that can be used to perturb the vector.
\end{Value}
\begin{Author}\relax
Micah Altman
\email{Micah\_Altman@harvard.edu}
\url{http://www.hmdc.harvard.edu/micah_altman/}
\end{Author}
\begin{References}\relax
Altman, M., J. Gill and M. P. McDonald.  2003.  \emph{Numerical Issues in Statistical
Computing for the Social Scientist}.  John Wiley \& Sons.
\url{http://www.hmdc.harvard.edu/numerical_issues/}
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{perturb}{perturb}},
\code{\LinkA{PTBdiscrete}{PTBdiscrete}}, 
\code{\LinkA{PTBus}{PTBus}}, 
\code{\LinkA{reclass.mat.random}{reclass.mat.random}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}

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)                        

\end{ExampleCode}
\end{Examples}

