Skip to content
Prev 68502 / 398506 Next

Proba( Ut+2=1 / ((Ut+1==1) && (Ut==1))) ?

table() can return all the n-gram statistics, e.g.:

 > v <- sample(c(-1,1), 1000, rep=TRUE)
 > table("v_{t-2}"=v[-seq(to=length(v), len=2)], 
"v_{t-1}"=v[-c(1,length(v))], "v_t"=v[-(1:2)])
, , v_t = -1

        v_{t-1}
v_{t-2}  -1   1
      -1 136 134
      1  131 112

, , v_t = 1

        v_{t-1}
v_{t-2}  -1   1
      -1 131 113
      1  115 126

 >

This says that there were 136 cases in which a -1 followed two -1's (and 
126 cases in which a 1 followed to 1's).

If you're really only interested in particular contexts, you can do 
something like:

 > table(v[-seq(to=length(v), len=2)]==1 & v[-c(1,length(v))]==1 & 
v[-(1:2)]==1)

FALSE  TRUE
   872   126
 > table(v[-seq(to=length(v), len=2)]==-1 & v[-c(1,length(v))]==-1 & 
v[-(1:2)]==-1)

FALSE  TRUE
   862   136

or

 > sum(v[-seq(to=length(v), len=2)]==-1 & v[-c(1,length(v))]==-1 & 
v[-(1:2)]==-1)
[1] 136
 >
vincent wrote: