calculation of the likelihood L(Y | K)
prod_1_km <- matrix(0, (dias - K), 1)
prod_2_km <- matrix(0, (dias - K), 1)
prod_km <- matrix(0, (dias-K), 1)
for(i in 1:(dias-K)){
for(n in 1:2^K){
prod_1_km[i] = (gamma(n_m0[i,m]+alpha_m0[i,m])*gamma(n_m1[i,m]+alpha_m1[i,m]))/
(gamma(alpha_m0[i,m])*gamma(alpha_m1[i,m]))
prod_2_km[i] = gamma(alpha_m0[i,m] + alpha_m1[i,m])/gamma(alpha_m0[i,m] +
n_m0[i,m] + alpha_m1[i,m] + n_m1[i,m])
} #closed the m loop
prod_km[i] = prod_1_km[i]*prod_2_km[i]
} # closes the i loop
for(i in 1:(dias-K)){
term_general_like[i,K+1] = prod_km[i]}
} #close the K loop
write.csv(term_general_like, file = "results-file-1.csv")
write.csv(term_init_like, file = "results-file-2.txt")
#