# Predicting the next value

I've recently read a blogpost where someone tries to predict the outcome of eurovision.

Quoting from the summary of the site:

Essentially, we can look at people’s voting preferences in the Eurovision Song Contest as composed of two components: song quality, and a “friendship” score, which takes into account how much the voting country likes or dislikes1 the country being voted on. If we want to know whether a voter V will rank country A or country B higher, we add up the song quality and the friendship score in each case, and subtract the two. Then we can take this difference, feed it through a logistic curve and use the result as a probability.

I’ve taken voting results from both the Eurovision finals (going back to the introduction of televoting in 1998) and the semi-finals (going back to their introduction in 2004). I’ve then used a *Markov Chain Monte Carlo sampler*2 to calculate the song qualities and friendship scores, assuming that they’re both normally distributed.

Once I’ve got the parameters, it’s relatively straightforward to run a simulation of this year’s contest, including the semifinals and all the voting procedures. Last year I ran 10,000 simulations like this, and looked at both who the likely qualifiers from the semifinals were, and the overall winner. The model managed fifteen out of twenty of the qualifiers, as well as the eventual winner. Although this level of success, particularly predicting the winner, was probably mostly luck, this year I’d like to do the same.

I was wondering if the same kind of approach can be used in order to solve my problem. I want to be able to predict the next state based on the previous state(s). There are 7 states. I do not know what the transition matrix is. I know that the state space consists of all permutations from 1..7 .

I know I can probably do this with a HMM. Though I was wondering if this is possible with MCMC (as used in the blogpost). I have data, which are examples of these state transitions, though I'd like to see if it is possible to predict the next state based on my data with mcmc.

My data for example looks like this:

6 ==> 1 ==> 3 ==> 5 ==> 2 ==> 6 ==> ...


And I'd like to predict the next value after the 6. ( Is this possible with the same approach like in the eurovision example ?)

Additionally I can add extra data if necessary. This data would indicate which day of the week (1 to 7) and another parameter for the week of the year( 1 to 52). So then the data would look like this:

state: 6 | state: 1 | state: 3 | state: 5 | ...
day : 1  | day: 5   | day : 7  | day: 2   | ...
week : 3 | week: 3  | week : 3 | week: 4  | ...


Maybe this kind of data is better suited ?

• Rather than base your question off the content of a link, please describe the problem clearly, and the approach used there. If the link disappears your question would be left with no context, which conflicts with the aim of a permanent repository of questions and answers. Having a link for additional context is fine, but the question should stand on its own. – Glen_b May 17 '13 at 0:01
• Ok thx for the feedback, I updated the question – Olivier_s_j May 17 '13 at 6:33
• For the Fisheries Productivity Example, can we use the similar approach if the process is not a time series? For example, the first day we draw 10 numbers, the second day we draw 10 numbers, and the fourth day we draw another 10 numbers. – Eric CD Jul 13 at 11:19

It is certainly possible to use MCMC to fit these sorts of autogreressive models, where you are predicting a value at time t+1 from its value at time t. Here is an example of such a model for a fisheries productivity example in PyMC. You will see the loop that specifies the recursive relationship of the predictions.