vermicellion
vermicellion

Reputation: 389

define residuals in hierarchical jags model r

I have a jags model in R:

modelScript.name <- "rick.txt"
jagsscript <- cat("
model {

###priors####

    alpha.m ~ dunif(1,100);
    beta.m ~ dunif(0,1);
    #FlowEff ~ dnorm(0,3);
    
    s.a.sd ~ dunif(0,3);
    s.b.sd ~ dunif(0,3);
    #d.a.sd ~ dunif(0,3);
    #y.a.sd ~ dunif(0,3);
    
    sigmaObs ~ dunif(0,2);


    for(i in 1:Ndata){
  
    
    lRR[i] ~ dnorm(log(pRR[i]) -
    (pow(sigmaObs,2)/2),pow(sigmaObs,-2)); 
      
    pRR[i] <- alpha[i] * SS[i] * exp(-1*beta[i]*SS[i]);   
      
      lalpha[i] <- log(alpha.m) + s.a[stream[i]];# + y.a[Year[i]]; #taking into account the random effect of stream on alpha
      lbeta[i] <- log(beta.m) + s.b[stream[i]];#taking into account the random effect of stream on beta
      
      
      alpha[i] <- exp(lalpha[i]); #exp() so no longer on log scale
      beta[i] <- exp(lbeta[i]);
      
    }

    for(SS in 1:Nstream){
      #s.a[SS] ~ dnorm(d.a[drainage[SS]],pow(s.a.sd[drainage[SS]],-2));
      s.a[SS] ~ dnorm(0,pow(s.a.sd,-2));
      s.b[SS] ~ dnorm(0,pow(s.b.sd,-2));
    }

    
    for(SS in 1:Nstream){
      Smsy[SS] <- ((log(alpha.m) + s.a[stream[SS]]) * (0.5 - 0.07*(log(alpha.m) + s.a[stream[SS]]))) / exp(log(beta.m) + s.b[stream[SS]])
    }


}  
", 
file = here(modelScript.name))


##### SET NODES TO MONITOR #####
jags.params <- c('beta.m','alpha.m','s.a','s.b','sigmaObs','Smsy')




I want to examine the residuals from the model, but I don't understand how to define them in the model before running.

I've looked at this example: Can we get the residuals from JAGS output?, but it doesn't help me much because the model they use is not hierarchical.

How do I define the residuals for a hierarchical model (my model).

Upvotes: 2

Views: 45

Answers (0)

Related Questions