Closed spedygiorgio closed 9 years ago
Added the logLikelihood slot and the hidden function.
great job thanks. Remember:
Sorry I am not sure the loglikelihood is correct....
for(int i = 0; i < seq.size() - 1; i ++) {
for(int r = 0; r < rnames.size(); r ++) {
if(rnames[r] == seq[i]) from = r;
if(rnames[r] == seq[i + 1]) to = r;
}
out += log(transMatr(from, to));
you are only taking into account the names but you also might need to take into account the actual transition. You migh need to run createSequenceMatrix on the seqw I suppose. Have a look to Fitting.R of clickstream package: logLikelihood=sum(x$frequency*log(x$probability))
It's the same as I basically iterate over all the transitions. Also, it is cheaper than creating the frequency matrix from the computation perspective.
I can change it to the clickstream way if you want.
If your approach is more efficient, we will keep your! Thansk again!
It would be useful to add a logLikelihood slot to the markovchainFit output list. The likelihood should be calculated by a hidden function receiving the original data and the estimated transition matrix, then retuned to the calling function. See http://stats.stackexchange.com/questions/47685/calculating-log-likelihood-for-given-mle-markov-chains for a formula