i have created bayesian model estimates 6 parameters using rjags r. want predictions based on new data in r. can me 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 (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) } }
generally, in bayesian model predictions on new data same way non-bayesian models. example complicated provide simplified 1 make things easier illustrate. want estimate linear regression model
$$ y_i = \beta_0 + \beta_1 x_i + \varepsilon_i $$
and based on model want predict $y_\text{new}$ values given $x_\text{new}$ data. in case plug in $x_\text{new}$ estimated model , jags samples $y_\text{new}$ values based on model. code similar this:
beta0 ~ dnorm(0, 10) beta1 ~ dnorm(0, 10) sigma ~ dunif(0, 50) (i in 1:n) { y[i] ~ dnorm(beta0 + beta1 * x[i], sigma) } (j in 1:nnew) { ynew[j] ~ dnorm(beta0 + beta1 * xnew[j], sigma) } where y, x , xnew data vectors , ynew variable storing predictions. distribution of values plausible given estimated model. since model probabilistic, prediction probabilistic, i.e. whole distribution of possible ynew values. point-values take average of ynew, can make prediction intervals taking highest density intervals ynew values.
Comments
Post a Comment