02.09.2014 Views

multivariate poisson hidden markov models for analysis of spatial ...

multivariate poisson hidden markov models for analysis of spatial ...

multivariate poisson hidden markov models for analysis of spatial ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

dens=matrix(0,nrow=T,ncol=N)<br />

alpha=matrix(0,nrow=T,ncol=N)<br />

beta=matrix(0,nrow=T,ncol=N)<br />

scale=matrix(c(1,rep(0,T-1)),nrow=1,ncol=T)<br />

ones=matrix(1,nrow=T,ncol=1)<br />

####E-step, compute density values<br />

dens=cbind(threep11,threep22,threep33)<br />

####E-step, <strong>for</strong>ward recursion and likelihood computation<br />

##Use a uni<strong>for</strong>m a priori probability <strong>for</strong> the initial state<br />

#[Refer to equation (5.25) and (5.26)]<br />

#The <strong>for</strong>ward and backward variables<br />

α ( i) = P[ y , y ,..., y , S = j]<br />

and<br />

#<br />

j 1 2 n i<br />

( i) = P[ y ,..., y | S = j]<br />

(5.25)<br />

# β<br />

j i+<br />

1 n i<br />

#which yield the quantities <strong>of</strong> interest by<br />

α<br />

j() i β<br />

j() i α<br />

j() i β<br />

j()<br />

i<br />

# uˆ j<br />

() i = =<br />

m<br />

∑αl<br />

( n)<br />

α () i β () i<br />

l<br />

∑<br />

j=<br />

1<br />

j<br />

j<br />

and<br />

# vˆ<br />

jk<br />

( i)<br />

=<br />

P<br />

jk<br />

f ( y ; λ<br />

i<br />

∑<br />

l<br />

k<br />

) α<br />

j<br />

( i −1)<br />

β<br />

k<br />

( i)<br />

. (5.26)<br />

α ( n)<br />

l<br />

alpha[1,]=dens[1,]/N<br />

<strong>for</strong> (t in 2:T){<br />

alpha[t,]=(alpha[t-1,]%*%TRANS)*dens[t,]<br />

#####Systematic scaling<br />

scale[,t]=sum(alpha[t,])<br />

alpha[t,]=alpha[t,]/scale[,t]<br />

}<br />

###compute likelihood<br />

loglike[nit]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!