or maybe something like this
 
x<- sample(c(1, -1), 100, TRUE); t <- p <- 0
for (i in 1: (lenght(x)-2))
{ if (x[i]+x[i+1]+x[i+2] == 3) t<- t+1; if (x[i]+x[i+1]+x[i+2] == -3) p<-p+1}
P1<-t/length(x); P2<-p/length(x)
 
Tom

Dimitris Rizopoulos <dimitris.rizopoulos@med.kuleuven.ac.be> wrote:
maybe something like this:

x <- sample(c(1, -1), 100, TRUE)
y <- rle(x)
##
ind1 <- y$length[y$value == 1]
sum(ind1[ind1 > 2] - 2)
ind2 <- y$length[y$value == -1]
##
sum(ind1[ind1 > 2] - 2)


could be helpful.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: "vincent" 
To: 
Sent: Monday, April 25, 2005 6:03 PM
Subject: [R] Proba( Ut+2=1 / ((Ut+1==1) && (Ut==1))) ?


> Dear all,
>
> First I apologize if my question is quite simple,
> but i'm very newbie with R.
>
> I have vectors of the form v = c(1,1,-1,-1,-1,1,1,1,1,-1,1)
> (longer than this one of course).
> The elements are only +1 or -1.
>
> I would like to calculate :
> - the frequencies of -1 occurences after 2 consecutives -1
> - the frequencies of +1 occurences after 2 consecutives +1
>
> It looks probably something like :
> Proba( Ut+2=1 / ((Ut+1==1) && (Ut==1)))
>
> could someone please give me a little hint about how
> i should/could begin to proceed ?
>
> Thanks
> (Thanks also to the R creators/contributors, this soft
> seems really great !)
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
>

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

__________________________________________________



	[[alternative HTML version deleted]]


