Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
sethharju authored Sep 12, 2023
1 parent 1ff9368 commit b0fd521
Show file tree
Hide file tree
Showing 15 changed files with 302 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## on intercept parameters and other correlated coefficients for each site
## within each stratum. Slopes vary by stratum.
for(k in 1:y.n.strata) {

mu.B0.raw[k] ~ dnorm(0, VAGUE_COEF_PRIOR_INTERCEPT)
mu.B0[k] <- xi[1, k] * mu.B0.raw[k]
#sigma.B0[k] ~ SIGMA_B0_PRIOR
B1[k] ~ dnorm(0, VAGUE_COEF_PRIOR_SLOPE)

Tau.Beta.raw[1:n.rand.slopes, 1:n.rand.slopes, k] ~ dwish(R.wish[, ], k.wish) # dmvnorm with a Wishart (dwish) prior
mu.Beta.raw[1, k] <- mu.B0.raw[k]
for (b in 2:n.rand.slopes) {
mu.Beta.raw[b, k] ~ dnorm(0, VAGUE_COEF_PRIOR_SLOPE)
}
Sigma.Beta.raw[1:n.rand.slopes, 1:n.rand.slopes, k] <-
inverse(Tau.Beta.raw[1:n.rand.slopes, 1:n.rand.slopes, k])
for (b in 1:n.rand.slopes) {
mu.Beta[b, k] <- xi[b, k] * mu.Beta.raw[b, k]
sigma.Beta[b, k] <- abs(xi[b, k]) * sqrt(Sigma.Beta.raw[b, b, k])
xi[b, k] ~ dunif(0, 100)
for (b.prime in 1:n.rand.slopes) {
rho.Beta[b, b.prime, k] <- Sigma.Beta.raw[b, b.prime, k] /
sqrt(Sigma.Beta.raw[b, b, k] * Sigma.Beta.raw[b.prime, b.prime, k])
}
}

for(j in 1:y.n.site[k]) {
Beta.grp.raw[j, 1:n.rand.slopes, k] ~ dmnorm(mu.Beta.raw[, k], Tau.Beta.raw[, , k])
for (b in 1:n.rand.slopes) {
Beta.grp[j, b, k] <- xi[b, k] * Beta.grp.raw[j, b, k]
}
### Intercepts vary by site and stratum.
B0[j, k] <- Beta.grp[j, 1, k]
### Put coefficients into matrix form to make them compatible with
### the multiple slopes model.
B[j, 1, k] <- B0[j, k]
B[j, 2, k] <- B1[k]
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## on intercept parameters and other correlated coefficients for each site
## within each stratum. Slopes vary by stratum.
for(k in 1:y.n.strata) {

mu.B0[k] ~ dnorm(0, VAGUE_COEF_PRIOR_INTERCEPT)
#sigma.B0[k] ~ SIGMA_B0_PRIOR
B1[k] ~ dnorm(0, VAGUE_COEF_PRIOR_SLOPE)

Tau.Beta.raw[1:n.rand.slopes, 1:n.rand.slopes, k] ~ dwish(R.wish[, ], k.wish) # dmvnorm with a Wishart (dwish) prior
mu.Beta[1, k] <- mu.B0[k]
for (b in 2:n.rand.slopes) {
mu.Beta[b, k] ~ dnorm(0, VAGUE_COEF_PRIOR_SLOPE)
}
Sigma.Beta[1:n.rand.slopes, 1:n.rand.slopes, k] <-
inverse(Tau.Beta.raw[1:n.rand.slopes, 1:n.rand.slopes, k])
for (b in 1:n.rand.slopes) {
sigma.Beta[b, k] <- sqrt(Sigma.Beta[b, b, k])
mu.Beta.raw[b, k] <- mu.Beta[b, k] # a hack
xi[b, k] <- 1 # a hack
for (b.prime in 1:n.rand.slopes) {
rho.Beta[b, b.prime, k] <- Sigma.Beta[b, b.prime, k] /
sqrt(Sigma.Beta[b, b, k] * Sigma.Beta[b.prime, b.prime, k])
}
}

for(j in 1:y.n.site[k]) {
Beta.grp[j, 1:n.rand.slopes, k] ~ dmnorm(mu.Beta[, k], Tau.Beta.raw[, , k])
### Intercepts vary by site and stratum.
B0[j, k] <- Beta.grp[j, 1, k]
### Put coefficients into matrix form to make them compatible with
### the multiple slopes model.
B[j, 1, k] <- B0[j, k]
B[j, 2, k] <- B1[k]
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## on intercept parameters and other correlated coefficients for each site
## within each stratum. Slopes vary by stratum.
for(k in 1:y.n.strata) {

mu.B0.raw[k] ~ dnorm(0, 1 / 100^2) # VAGUE_COEF_PRIOR_INTERCEPT
mu.B0[k] <- xi[1, k] * mu.B0.raw[k]
#sigma.B0[k] ~ SIGMA_B0_PRIOR
B1[k] ~ dnorm(0, 1 / 100^2) # VAGUE_COEF_PRIOR_SLOPE

Tau.Beta.raw[1:n.rand.slopes, 1:n.rand.slopes, k] ~ dwish(R.wish[, ], k.wish) # dmvnorm with a Wishart (dwish) prior
mu.Beta.raw[1, k] <- mu.B0.raw[k]
for (b in 2:n.rand.slopes) {
mu.Beta.raw[b, k] ~ dnorm(0, 1 / 100^2) # VAGUE_COEF_PRIOR_SLOPE
}
Sigma.Beta.raw[1:n.rand.slopes, 1:n.rand.slopes, k] <-
inverse(Tau.Beta.raw[1:n.rand.slopes, 1:n.rand.slopes, k])
for (b in 1:n.rand.slopes) {
mu.Beta[b, k] <- xi[b, k] * mu.Beta.raw[b, k]
sigma.Beta[b, k] <- abs(xi[b, k]) * sqrt(Sigma.Beta.raw[b, b, k])
xi[b, k] ~ dunif(0, 100)
for (b.prime in 1:n.rand.slopes) {
rho.Beta[b, b.prime, k] <- Sigma.Beta.raw[b, b.prime, k] /
sqrt(Sigma.Beta.raw[b, b, k] * Sigma.Beta.raw[b.prime, b.prime, k])
}
}

for(j in 1:y.n.site[k]) {
Beta.grp.raw[j, 1:n.rand.slopes, k] ~ dmnorm(mu.Beta.raw[, k], Tau.Beta.raw[, , k])
for (b in 1:n.rand.slopes) {
Beta.grp[j, b, k] <- xi[b, k] * Beta.grp.raw[j, b, k]
}
### Intercepts vary by site and stratum.
B0[j, k] <- Beta.grp[j, 1, k]
### Put coefficients into matrix form to make them compatible with
### the multiple slopes model.
B[j, 1, k] <- B0[j, k]
B[j, 2, k] <- B1[k]
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## on slope and intercept parameters and their covariance matrix for each
## site within each stratum.
for(k in 1:y.n.strata) {
for(j in 1:y.n.site[k]) {
B[j, 1:2, k] ~ dmnorm(B.hat[j, 1:2, k], Tau.B[, 1:2, k])
B.hat[j, 1, k] <- mu.B0[k]
B.hat[j, 2, k] <- mu.B1[k]
}
mu.B0[k] ~ dnorm(0, VAGUE_COEF_PRIOR_INTERCEPT)
mu.B1[k] ~ dnorm(0, VAGUE_COEF_PRIOR_SLOPE)
Tau.B[1:2, 1:2, k] <- inverse(Sigma.B[1:2, 1:2, k])
Sigma.B[1, 1, k] <- sigma.B0[k]^2
sigma.B0[k] ~ SIGMA_B0_PRIOR
Sigma.B[2, 2, k] <- sigma.B1[k]^2
sigma.B1[k] ~ SIGMA_B1_PRIOR
Sigma.B[1, 2, k] <- rho[k] * sigma.B0[k] * sigma.B1[k]
Sigma.B[2, 1, k] <- Sigma.B[1, 2, k]
rho[k] ~ dunif(-1, 1)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## on slope and intercept parameters and their covariance matrix for each
## site within each stratum. # TODO
for(k in 1:y.n.strata) {
for(j in 1:y.n.site[k]) {
z.unit.corr[j, 1:2, k] ~ dmnorm(B.hat[j, 1:2, k], Tau.Omega.B[, 1:2, k])
B.hat[j, 1, k] <- 0
B.hat[j, 2, k] <- 0
B0[j, k] <- mu.B0[k] + z.unit.corr[j, 1, k] * sigma.B0[k]
B1[j, k] <- mu.B1[k] + z.unit.corr[j, 2, k] * sigma.B1[k]
B[j, 1, k] <- B0[j, k]
B[j, 2, k] <- B1[j, k]
}
mu.B0[k] ~ dnorm(0, VAGUE_COEF_PRIOR_INTERCEPT)
mu.B1[k] ~ dnorm(0, VAGUE_COEF_PRIOR_SLOPE)
Tau.Omega.B[1:2, 1:2, k] <- inverse(Omega.B[1:2, 1:2, k])
Omega.B[1, 1, k] <- 1
sigma.B0[k] ~ dt(0, 1/(VAGUE_VAR_PRIOR_UL^2), 1) T(0,)
Omega.B[2, 2, k] <- 1
sigma.B1[k] ~ dt(0, 1/(VAGUE_VAR_PRIOR_UL^2), 1) T(0,)
Omega.B[1, 2, k] <- rho[k]
Omega.B[2, 1, k] <- Omega.B[1, 2, k]
rho[k] ~ dunif(-1, 1)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## on slope and intercept parameters and their covariance matrix for each
## site within each stratum.
for(k in 1:y.n.strata) {
for(j in 1:y.n.site[k]) {
B[j, 1:2, k] ~ dmnorm(B.hat[j, 1:2, k], Tau.B[, 1:2, k])
B.hat[j, 1, k] <- mu.B0[k]
B.hat[j, 2, k] <- mu.B1[k]
}
mu.B0[k] ~ dnorm(0, VAGUE_COEF_PRIOR_INTERCEPT)
mu.B1[k] ~ dnorm(0, VAGUE_COEF_PRIOR_SLOPE)
Tau.B[1:2, 1:2, k] <- inverse(Sigma.B[1:2, 1:2, k])
Sigma.B[1, 1, k] <- sigma.B0[k]^2
sigma.B0[k] ~ SIGMA_B0_PRIOR
Sigma.B[2, 2, k] <- sigma.B1[k]^2
sigma.B1[k] ~ SIGMA_B1_PRIOR
Sigma.B[1, 2, k] <- rho[k] * sigma.B0[k] * sigma.B1[k]
Sigma.B[2, 1, k] <- Sigma.B[1, 2, k]
rho[k] ~ dunif(-1, 1)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## on intercept parameters for each site within each stratum. Slopes vary by
## stratum.
for(k in 1:y.n.strata) {
mu.B0[k] ~ dnorm(0, VAGUE_COEF_PRIOR_INTERCEPT)
sigma.B0[k] ~ SIGMA_B0_PRIOR
tau.B0[k] <- 1 / sigma.B0[k]^2
for(j in 1:y.n.site[k]) {
### Intercepts vary by site and stratum.
B0[j, k] ~ dnorm(mu.B0[k], tau.B0[k])
### Put coefficients into matrix form to make them compatible with
### the multiple slopes model.
B[j, 1, k] <- B0[j, k]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## on intercept parameters for each site within each stratum. Slopes vary by
## stratum.
for(k in 1:y.n.strata) {
mu.B0[k] ~ dnorm(0, VAGUE_COEF_PRIOR_INTERCEPT)
for(j in 1:y.n.site[k]) {
### Intercepts vary by site and stratum.
B0[j, k] <- mu.B0[k]
### Put coefficients into matrix form to make them compatible with
### the multiple slopes model.
B[j, 1, k] <- B0[j, k]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## on intercept parameters for each site within each stratum. Slopes vary by
## stratum.
for(k in 1:y.n.strata) {
mu.B0[k] ~ dnorm(0, VAGUE_COEF_PRIOR_INTERCEPT)
sigma.B0[k] ~ SIGMA_B0_PRIOR
tau.B0[k] <- 1 / sigma.B0[k]^2
for(j in 1:y.n.site[k]) {
### Intercepts vary by site and stratum.
B0[j, k] ~ dnorm(mu.B0[k], tau.B0[k])
### Put coefficients into matrix form to make them compatible with
### the multiple slopes model.
B[j, 1, k] <- B0[j, k]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## on intercept parameters for each site within each stratum. Slopes vary by
## stratum.
for(k in 1:y.n.strata) {
mu.B0[k] ~ dnorm(0, VAGUE_COEF_PRIOR_INTERCEPT)
for(j in 1:y.n.site[k]) {
### Intercepts vary by site and stratum.
B0[j, k] <- mu.B0[k]
### Put coefficients into matrix form to make them compatible with
### the multiple slopes model.
B[j, 1, k] <- B0[j, k]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## on intercept parameters for each site within each stratum. Slopes vary by
## stratum.
for(k in 1:y.n.strata) {
mu.B0[k] ~ dnorm(0, VAGUE_COEF_PRIOR_INTERCEPT)
sigma.B0[k] ~ SIGMA_B0_PRIOR
tau.B0[k] <- 1 / sigma.B0[k]^2
B1[k] ~ dnorm(0, VAGUE_COEF_PRIOR_SLOPE)
for(j in 1:y.n.site[k]) {
### Intercepts vary by site and stratum.
B0[j, k] ~ dnorm(mu.B0[k], tau.B0[k])
### Put coefficients into matrix form to make them compatible with
### the multiple slopes model.
B[j, 1, k] <- B0[j, k]
B[j, 2, k] <- B1[k]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## on intercept parameters for each site within each stratum. Slopes vary by
## stratum.
for(k in 1:y.n.strata) {
mu.B0[k] ~ dnorm(0, VAGUE_COEF_PRIOR_INTERCEPT)
for(j in 1:y.n.site[k]) {
### Intercepts vary by site and stratum.
B0[j, k] <- mu.B0[k]
### Put coefficients into matrix form to make them compatible with
### the multiple slopes model.
B[j, 1, k] <- B0[j, k]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## on intercept parameters for each site within each stratum. Slopes vary by
## stratum.
for(k in 1:y.n.strata) {
mu.B0[k] ~ dnorm(0, VAGUE_COEF_PRIOR_INTERCEPT)
sigma.B0[k] ~ dt(0, 1/(VAGUE_VAR_PRIOR_UL^2), 1) T(0,) # implies half-cauchy with scale of VAGUE_VAR_PRIOR_UL
tau.B0[k] <- 1 / sigma.B0[k]^2
B1[k] ~ dnorm(0, VAGUE_COEF_PRIOR_SLOPE)
for(j in 1:y.n.site[k]) {
### Intercepts vary by site and stratum.
B0.offset[j, k] ~ dnorm(0, 1)
B0[j, k] <- mu.B0[k] + B0.offset[j, k] * sigma.B0[k]
### Put coefficients into matrix form to make them compatible with
### the multiple slopes model.
B[j, 1, k] <- B0[j, k]
B[j, 2, k] <- B1[k]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## on intercept parameters for each site within each stratum. Slopes vary by
## stratum.
for(k in 1:y.n.strata) {
mu.B0[k] ~ dnorm(0, VAGUE_COEF_PRIOR_INTERCEPT)
sigma.B0[k] ~ SIGMA_B0_PRIOR
tau.B0[k] <- 1 / sigma.B0[k]^2
B1[k] ~ dnorm(0, VAGUE_COEF_PRIOR_SLOPE)
for(j in 1:y.n.site[k]) {
### Intercepts vary by site and stratum.
B0[j, k] ~ dnorm(mu.B0[k], tau.B0[k])
### Put coefficients into matrix form to make them compatible with
### the multiple slopes model.
B[j, 1, k] <- B0[j, k]
B[j, 2, k] <- B1[k]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## on intercept parameters for each site within each stratum. Slopes vary by
## stratum.
for(k in 1:y.n.strata) {
B0[k] ~ dnorm(0, VAGUE_COEF_PRIOR_INTERCEPT)
B1[k] ~ dnorm(0, VAGUE_COEF_PRIOR_SLOPE)
for(j in 1:y.n.site[k]) {
### Put coefficients into matrix form to make them compatible with
### the multiple slopes model.
B[j, 1, k] <- B0[k]
B[j, 2, k] <- B1[k]
}
}

0 comments on commit b0fd521

Please sign in to comment.