Extracting Residuals Bayesian Model with 2 random errors

21 views
Skip to first unread message

Stefano Anile

unread,
Apr 22, 2024, 4:05:37 AMApr 22
to hmecology: Hierarchical Modeling in Ecology
Hi everyone, 

I would greatly appreciate any help with extracting the residuals from a Bayesian Model with 2 random error. 

Model structure is reported below:

# File name "DMA with 3 random errors.jags"

model {
  # Likelihood
    for (i in 1:n_PD){
    #introducing BM in the equation
      y[i] ~ dnorm(mu[i]+bBM*BM[i], tau_level0)
      mu[i] <- b0 + U[SP[i]]# + V[SSF[i]]
    }
  ##########################
  # Random effect of level1#Species#
  ##########################
  # Loop through the species to create a vector of random deviations.
  for (j in 1:n_SP){
    U[j] ~ dnorm(0, tau_SP)
  }
  #################################
  # Random effect of level2#Study Site Factor#
  #################################
  # Loop through the ssf to create a vector of random deviations.
  for (k in 1:n_SSF){
  V[k] ~ dnorm(0, tau_SSF)
  }
 
  #################
  # priors on fixed parts#
  #################
 
  # the intercept (overall mean in this case)
  b0 ~ dnorm(0, 10^-6)
  bBM~ dnorm(0,10^-6)

  # priors on random parts (deviances from the overall mean)
  # these are specified on the standard deviations, and then
  # variance and precision are calculated for each for the
  # likelihood above.
 
  # level 0 (the residual error)
  sigma ~ dunif(0,10)
  v_level0 <- sigma * sigma
  tau_level0 <- 1 / v_level0
 
  # level 1
  sigma_SP ~ dunif(0,10)
  v_SP <- sigma_SP * sigma_SP
  tau_SP <- 1 / v_SP
 
  # level 2
  sigma_SSF ~ dunif(0,10)
  v_SSF <- sigma_SSF * sigma_SSF
  tau_SSF <- 1 / v_SSF
 
  } # end of model

Thank you very much, 

Stef

Reply all
Reply to author
Forward
0 new messages