R-users,
This may be a simple problem, but I don't have an intuition of
how simple it could be. Suppose I have a sequence of numbers
corresponding to a series of diagnoses on the same patient
over a sequence of time. The diagnoses are coded 1,2,3,4,5, but
could come in a sequence like 1,3,2,5,3,5,...etc. Is there a simple
way to count the number of times a 1 diagnosis is followed by a 2, or
a 3, ... A 2 by a 1, or 3,....etc. It's almost like a mover-stayer problem.
I think.
I know this seems simple but any help would be appreciated.
Cheers,
Calvin
--
==================== Calvin L. Williams, Ph.D. ===================
Department of Mathematical Sciences, Clemson University
Box 340975 , 0-323 Martin Hall
Clemson, South Carolina 29634-0975
VOICE: (864) 656-5241 or leave message (864) 654-7187
EMAIL: calvinw at ces.clemson.edu
FAX: 1-(864) 656-5230
WWW: http://www.ces.clemson.edu/~calvinw/
===========================================================-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On 04/21/02 10:33, Calvin L. Williams, Ph.D. wrote:>R-users, > >This may be a simple problem, but I don't have an intuition of >how simple it could be. Suppose I have a sequence of numbers >corresponding to a series of diagnoses on the same patient >over a sequence of time. The diagnoses are coded 1,2,3,4,5, but >could come in a sequence like 1,3,2,5,3,5,...etc. Is there a simple >way to count the number of times a 1 diagnosis is followed by a 2, or >a 3, ... A 2 by a 1, or 3,....etc. It's almost like a mover-stayer problem. >I think.Suppose you have these in a vector v1. How about something like w1 <- length(v1) table(v1[-w1],v1[2:w1]) If each subject is a row in a matrix m1, then you could do this something like (where w1 is now the number of columns) apply(m1,1,function(x) table(x[-w1],x[2:w1])) I haven't tested this, and I might have it slightly wrong, or not optimal. I'm sure there are better ways, but I'm sure this general idea will work. -- Jonathan Baron, Professor of Psychology, University of Pennsylvania Home page: http://www.sas.upenn.edu/~baron -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Let x be the sequence of numbers. What about forming a table of x[-1] against x[-length(x)], e.g. table(x[-1], x[-length(x)]) That should give you the transition matrix from each state to each other state. --Mike Mike Meyer, Salter Point Associates, Seattle WA -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._