Skip to main content
added 115 characters in body
Source Link
Glen
  • 7.5k
  • 6
  • 45
  • 66

Usually you can do the predictions in JAGS. Below is a regression example with FEV (something to do with lung capacity) as the dependent variable and age and smoking indicator as predictors.

FEV20s and FEV20ns are the predicted FEV values for a 20 year old smoker and a 20 year old non-smoker.

model
{
for(i in 1:n){
    FEV[i] ~ dnorm(mu[i],tau)
    mu[i] <- beta[1] + beta[2]*Age[i] + beta[3]*Smoke[i]  + beta[4]*Age[i]*Smoke[i]
}

#priors
beta[1] ~ dnorm(0,0.001)
beta[2] ~ dnorm(0,0.001)
beta[3] ~ dnorm(0,0.001)
beta[4] ~ dnorm(0,0.001)
tau ~ dgamma(0.001,0.001)
sigma<-1/sqrt(tau) 

## Predict the FEV for a 20 year old smoker and for a 20 year old nonsmoker
mu20s <-  beta[1] + (beta[2]+beta[4])*20 + beta[3]
mu20ns <-  beta[1] + beta[2]*20 
FEV20s ~ dnorm(mu20s,tau)
FEV20ns ~ dnorm(mu20ns,tau)
}

Example from: Bayesian Ideas and Data Analysis

Usually you can do the predictions in JAGS. Below is a regression example with FEV (something to do with lung capacity) as the dependent variable and age and smoking indicator as predictors.

FEV20s and FEV20ns are the predicted FEV values for a 20 year old smoker and a 20 year old non-smoker.

model
{
for(i in 1:n){
    FEV[i] ~ dnorm(mu[i],tau)
    mu[i] <- beta[1] + beta[2]*Age[i] + beta[3]*Smoke[i]  + beta[4]*Age[i]*Smoke[i]
}

#priors
beta[1] ~ dnorm(0,0.001)
beta[2] ~ dnorm(0,0.001)
beta[3] ~ dnorm(0,0.001)
beta[4] ~ dnorm(0,0.001)
tau ~ dgamma(0.001,0.001)
sigma<-1/sqrt(tau) 

## Predict the FEV for a 20 year old smoker and for a 20 year old nonsmoker
mu20s <-  beta[1] + (beta[2]+beta[4])*20 + beta[3]
mu20ns <-  beta[1] + beta[2]*20 
FEV20s ~ dnorm(mu20s,tau)
FEV20ns ~ dnorm(mu20ns,tau)
}

Usually you can do the predictions in JAGS. Below is a regression example with FEV (something to do with lung capacity) as the dependent variable and age and smoking indicator as predictors.

FEV20s and FEV20ns are the predicted FEV values for a 20 year old smoker and a 20 year old non-smoker.

model
{
for(i in 1:n){
    FEV[i] ~ dnorm(mu[i],tau)
    mu[i] <- beta[1] + beta[2]*Age[i] + beta[3]*Smoke[i]  + beta[4]*Age[i]*Smoke[i]
}

#priors
beta[1] ~ dnorm(0,0.001)
beta[2] ~ dnorm(0,0.001)
beta[3] ~ dnorm(0,0.001)
beta[4] ~ dnorm(0,0.001)
tau ~ dgamma(0.001,0.001)
sigma<-1/sqrt(tau) 

## Predict the FEV for a 20 year old smoker and for a 20 year old nonsmoker
mu20s <-  beta[1] + (beta[2]+beta[4])*20 + beta[3]
mu20ns <-  beta[1] + beta[2]*20 
FEV20s ~ dnorm(mu20s,tau)
FEV20ns ~ dnorm(mu20ns,tau)
}

Example from: Bayesian Ideas and Data Analysis

Source Link
Glen
  • 7.5k
  • 6
  • 45
  • 66

Usually you can do the predictions in JAGS. Below is a regression example with FEV (something to do with lung capacity) as the dependent variable and age and smoking indicator as predictors.

FEV20s and FEV20ns are the predicted FEV values for a 20 year old smoker and a 20 year old non-smoker.

model
{
for(i in 1:n){
    FEV[i] ~ dnorm(mu[i],tau)
    mu[i] <- beta[1] + beta[2]*Age[i] + beta[3]*Smoke[i]  + beta[4]*Age[i]*Smoke[i]
}

#priors
beta[1] ~ dnorm(0,0.001)
beta[2] ~ dnorm(0,0.001)
beta[3] ~ dnorm(0,0.001)
beta[4] ~ dnorm(0,0.001)
tau ~ dgamma(0.001,0.001)
sigma<-1/sqrt(tau) 

## Predict the FEV for a 20 year old smoker and for a 20 year old nonsmoker
mu20s <-  beta[1] + (beta[2]+beta[4])*20 + beta[3]
mu20ns <-  beta[1] + beta[2]*20 
FEV20s ~ dnorm(mu20s,tau)
FEV20ns ~ dnorm(mu20ns,tau)
}