I have created a bayesian model that estimates 6 parameters using rjags from R. Now i want to do some predictions based on new data in R. Can anyone help me with an example.

model {
   B.m[1] <- Kb # mean B[1]
   B[1] ~ dnorm( B.m[1], tau_B)
   for(t in 2 : 10) { # Process model
      B.m[t]<- max( B[t-1] + rB[t-1](1 -B[t-1]/K) - C[t-1] , 0.0)
      B[t] ~ dnorm(B.m[t], tau_B) } # Observation mode
      for (t in 1: 10) {
         LogC_mean[t] <- log( max(qsegB[t]Eff[t], 0.000001))
         C[t] ~ dlnorm(LogC_mean[t], tau_c) } # Prior
         b~dbeta(1, 1)
         cv <- 1
         K.mean <- 500000
         K.v <- pow(cvK.mean, 2)
         K.tau <- 1/K.v
         K ~ dnorm(K.mean, K.tau)
         r ~ dlnorm(0.0, 1.4)
         qseg ~ dlnorm(-15.4, 1.44)
         tau_c ~ dgamma(0.001,0.001)
         tau_B ~ dgamma(0.01,0.01)
  • $\begingroup$ I just want to understand in general way how to predict new values based on new data from estimated parameters in bayesian framework. $\endgroup$ – Abdelouahed BEN MHAMED Apr 23 '15 at 11:35
  • $\begingroup$ Relevant post. $\endgroup$ – COOLSerdash Apr 23 '15 at 11:37

Generally, in Bayesian model you do predictions on new data the same way as you do with non-Bayesian models. As your example is complicated I will provide a simplified one to make things easier to illustrate. Say you want to estimate linear regression model

$$ y_i = \beta_0 + \beta_1 x_i + \varepsilon_i $$

and based on the model you want to predict $y_\text{new}$ values given $x_\text{new}$ data. In this case you plug in the $x_\text{new}$ into estimated model and JAGS samples $y_\text{new}$ values based on your model. The code would look similar to this:

 beta0 ~ dnorm(0, 10)
 beta1 ~ dnorm(0, 10)
 sigma ~ dunif(0, 50)
 for (i in 1:N) {
    y[i] ~ dnorm(beta0 + beta1 * x[i], sigma)
 for (j in 1:Nnew) {
    ynew[j] ~ dnorm(beta0 + beta1 * xnew[j], sigma)

where y, x and xnew are data vectors and ynew is a variable for storing predictions. What you get is a distribution of values that are plausible given your estimated model. Since the model is probabilistic, the prediction is also probabilistic, i.e. we get the whole distribution of possible ynew values. For point-values take the average of ynew, you can also make prediction intervals taking the highest density intervals from ynew values.

  • $\begingroup$ but in bugs, when you use the symbol ~ you have to provide initial values for this node. $\endgroup$ – Abdelouahed BEN MHAMED Apr 23 '15 at 11:47
  • $\begingroup$ @AbdelouahedBENMHAMED What node? If some variable (e.g. beta0 or ynew) is 'empty' then the values are just drawn from some distribution. JAGS does the same things with missing values in your data. $\endgroup$ – Tim Apr 23 '15 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.