model{
for(i in 1:N){
#measurement equation model
for(j in 1:P){
y[i,j]~dnorm(mu[i,j],psi[j])I(thd[j,z[i,j]],thd[j,z[i,j]+1])
ephat[i,j]<-y[i,j]-mu[i,j]
}
mu[i,1]<-xi[i,1]
mu[i,2]<-lam[2]*xi[i,1]
mu[i,3]<-lam[3]*xi[i,1]
mu[i,4]<-lam[4]*xi[i,1]
mu[i,5]<-lam[5]*xi[i,1]
mu[i,6]<-lam[6]*xi[i,1]
mu[i,7]<-xi[i,2]
mu[i,8]<-lam[7]*xi[i,2]
mu[i,9]<-lam[8]*xi[i,2]
mu[i,10]<-lam[9]*xi[i,2]
mu[i,11]<-lam[10]*xi[i,2]
mu[i,12]<-lam[11]*xi[i,2]
mu[i,13]<-xi[i,3]
mu[i,14]<-lam[12]*xi[i,3]
mu[i,15]<-lam[13]*xi[i,3]
mu[i,16]<-lam[14]*xi[i,3]
mu[i,17]<-lam[15]*xi[i,3]
mu[i,18]<-lam[16]*xi[i,3]
#structural equation model
xi[i,1:3]~dmnorm(u[1:3],phi[1:3,1:3])
eta[i]~dnorm(nu[i],psd)
nu[i]<-gam[1]*xi[i,1]+gam[2]*xi[i,2]+gam[3]*xi[i,3]
dthat[i]<-eta[i]-nu[i]
}# end of i
for(i in 1:3){u[i]<-0.0}
#priors on loadings and coefficients
var.lam[1]<-4.0*psi[2] var.lam[2]<-4.0*psi[4] var.lam[3]<-4.0*psi[5] var.lam[4]<-4.0*psi[6]
var.lam[5]<-4.0*psi[7] var.lam[6]<-4.0*psi[8] var.lam[7]<-4.0*psi[9] var.lam[8]<-4.0*psi[11]
var.lam[9]<-4.0*psi[12] var.lam[10]<-4.0*psi[13] var.lam[11]<-4.0*psi[14] var.lam[12]<-4.0*psi[15]
var.lam[13]<-4.0*psi[17] var.lam[14]<-4.0*psi[18] var.lam[15]<-4.0*psi[20] var.lam[16]<-4.0*psi[21]
for(i in 1:16){lam[i]~dnorm(0.8,var.lam[i])}
var.gam<-4.0*psd
gam[1]~dnorm(0.6,var.gam) gam[2]~dnorm(0.6,var.gam) gam[3]~dnorm(0.4,var.gam)
#priors on precisions
for(j in 1:P){
psi[j]~dgamma(10,8)
sgm[j]<-1/psi[j]
}
psd~dgamma(10,8)
sgd<-1/psd
phi[1:3,1:3]~dwish(R[1:3,1:3], 30)
phx[1:3,1:3]<-inverse(phi[1:3,1:3])
} #end of model
Data Set
list(N=124, P=18,
R=structure(
.Data=c(8.0, 0.0, 0.0,
0.0, 8.0, 0.0,
0.0, 0.0, 8.0 ),
.Dim=c(3,3)),
thd=structure(
Data=c(-200.000,-2.517,-1.245,-0.444, 0.848,200.000,
-200.000,-1.447,-0.420, 0.119, 1.245,200.000,
-200.000,-1.671,-0.869,-0.194, 0.679,200.000,
-200.000,-1.642,-0.869,-0.293, 0.332,200.000,
-200.000,-1.671,-0.827, 0.052, 0.756,200.000,
-200.000,-1.769,-1.098,-0.469, 0.255,200.000,
-200.000,-1.490,-0.670,-0.082, 0.880,200.000,
-200.000,-1.933,-0.880,-0.317, 1.008,200.000,
-200.000,-1.587,-0.624, 0.000, 1.008,200.000,
-200.000,-1.983,-1.348,-0.348, 1.045,200.000,
-200.000,-1.983,-1.229,-0.247, 0.869,200.000,
-200.000,-2.262,-1.426, 0.037, 1.330,200.000,
-200.000,-2.371,-1.295,-0.224, 0.651,200.000,
-200.000,-2.039,-1.112,-0.149, 1.169,200.000,
-200.000,-2.262,-1.198,-0.309, 1.198,200.000,
-200.000,-2.176,-1.537,-0.717, 0.597,200.000,
-200.000,-1.447,-0.786, 0.119, 1.008,200.000,
-200.000,-2.039,-1.769,-0.661, 0.642,200.000,
.Dim=c(18,6))
z=structure(
.Data=c(4 4 5 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5
3 4 3 5 3 3 3 4 4 4 3 3 3 4 3 4 4 4
4 4 4 3 3 3 5 5 4 3 4 4 4 4 3 4 3 4
5 5 5 5 4 5 3 5 5 5 5 5 5 5 5 5 4 5
4 4 4 4 5 3 5 5 4 4 5 4 5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