\HeaderA{reclass.mat.diag}{Function to produce reclassification matrices}{reclass.mat.diag}
\aliasA{reclass.mat.random}{reclass.mat.diag}{reclass.mat.random}
\keyword{misc}{reclass.mat.diag}
\keyword{optimize}{reclass.mat.diag}
\keyword{distribution}{reclass.mat.diag}
\begin{Description}\relax
This returns a cumulative probability matrix useful for reclassifying discrete variables with PTBdiscrete.
\end{Description}
\begin{Usage}
\begin{verbatim}
reclass.mat.diag(n, q)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{n}] number of levels of factor, character vector, or discrete values
\item[\code{q}] probability of reclassifying to same sate 
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
For reclass.mat.diag, the transition probability of changing from level i to level j is q if i==j, 0 if
abs(i-j)\textgreater{}1 and q, 1-q/2 if abs(i-j)\textgreater{}1 and 1\textgreater{}i\textgreater{}n and 1-q otherwise

For reclass.mat.random, the transition probability of changing from level i to level j is q if i==j, 
(1-q)/(n-1) otherwise.
\end{Details}
\begin{Value}
returns a matrix of cumulative probability distributions for reclassifying each level to
another level
\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{reclass.mat.random}{reclass.mat.random}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}  
        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(10,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
\end{ExampleCode}
\end{Examples}

