# Is there a loss function when estimating a model using MCMC?

I am trying to understand how fitting a model using MCMC works. Is there a loss function that is optimized?

Or is it simply a case of more draws from the distribution amount to a more complete description of the posterior and therefore more accurate parameters?

In particular I am referring to how a BSTS time series model is fitted using MCMC draws as described in Scott and Varian "Predicting the Present with Bayesian Structural Time Series", 2013.

In that paper a state space model of a time series is described:

$y_t = Z_t^T \alpha_t + \epsilon_t$.

$\alpha_{t+1} = T_t \alpha_t + R_t\eta_t$

Let

$\theta = (Z, T, R, \epsilon, \eta)$

and

$\textbf{y} = y_1,....y_n$ their time series data.

They then use MCMC to simulate the posterior distribution of the parameters of the model given their data $p(\theta|\textbf{y})$ - and presumably (they don't actually states this, I am assuming) they select $\theta$ that maximizes $p(\theta|\textbf{y})$.

In R the BSTS model takes a number of MCMC draws as an input parameter - and I am trying to figure how to choose that number.

If it is the second case (more draws = better simulation of the distribution), how do we decided the number of iterations and how do we avoid overfitting?

• You are confusing inference (estimation) and simulation (MCMC), precision in the estimation and precision of the Monte Carlo approximation. Commented Jul 6, 2018 at 8:39
• Your question has reopened. @Xi'an's comment still stands. 'Train the model' is estimation (it certainly will be in this instance). Commented Jul 6, 2018 at 21:39
• Sorry, I don't see how that changes the point being made about confusing precision in the estimation and precision of the Monte Carlo approximation. Commented Jul 6, 2018 at 23:19
• This is clearer but there is no such thing as overfitting associated with an MCMC chain. The more the better. Commented Jul 7, 2018 at 14:44
• @Alex Bayesian estimation has notable links to loss functions. You should learn how $\hat{\theta}$ is taken from $p(\theta|y)$. In minimax theory, different estimators optimize different losses: the median with L1 loss, the mean with L2 loss and the mode with Linf loss: all of these are used in practice. The use of MCMC is just to numerically calculate the shape of $p(\theta|y)$: we can assume it has no bearing on the actual "loss" function that is minimized by the estimator $\hat{\theta} = f(p(\theta|y))$. Commented Jul 9, 2018 at 17:50