Thanks for pointing the mistake. Now it works perfectly.
I extended the model to the AMMI model with 2 principal components described in Josse et (2014) JABES. For this purpose I used the nimbleRcall function according to Sally's suggestion but when I run the nimbleMCMC I obtain the following message
defining model...
building model...
setting data and initial values...
running calculate on model (any error reports that follow may simply reflect missing values in model variables) ... Error in model$lam[1:2] <<- sortR(model$lamb[1:2]) :
replacement has length zero
checking model sizes and dimensions... This model is not fully initialized. This is not an error. To see which variables are not initialized, use model$initializeInfo(). For more information on model initialization, see help(modelInitialization).
checking model calculations...
Error in model$lam[1:2] <<- sortR(model$lamb[1:2]) :
replacement has length zero
Error in model$lam[1:2] <<- sortR(model$lamb[1:2]) :
replacement has length zero
Note: cannot calculate logProb for node lam[1:2] .
NAs were detected in model variables: mu, logProb_mu, alpha, logProb_alpha, beta, logProb_beta, lamb, U, logProb_U, V, logProb_V, tau, logProb_tau, m, lam, lifted_d1_over_sqrt_oPtau_cP, se2, D, logProb_y.
Infinite values were detected in model variables: logProb_lamb, logProb_U.
model building finished.
compiling... this may take a minute. Use 'showCompilerOutput = TRUE' to see C++ compilation details.
Warning, in eigenizing model_D[1] the [ is still there but nDim is not 0 (not a scalar).
Error: Failed to create the shared library. Run 'printErrors()' to see the compilation errors.
In addition: Warning message:
In model$D[1] <<- diag(model$lam[1:2]) :
number of items to replace is not a multiple of replacement length
Could You help and explain me what mistake I've made? Below I enclose the modified code.
for(j in 1:ne){beta[j]~dnorm(0,tau=1/ne)}
for(q in 1:2){lamb[q]~T(dnorm(0,sd=13),0,)}#### Singular nvalues
lam[1:2]<-sortR(lamb[1:2])
for(q in 1:2){
U[1,q]~T(dnorm(0,sd=1),0,) #### Left singular vectors
for(i in 2:nv){
U[i,q]~dnorm(0,sd=1)
}
}
for(q in 1:2){ #### Right singular vectors
for(j in 1:ne){
V[j,q]~dnorm(0,sd=1)
}
}
#for(q in 1:2){
# for(i in 1:nv){
# W[i,q]<-U[i,q]*lam[q]
# }
#}
D<-diag(lam[1:2])
W<-U%*%D
inte<-W%*%t(V)
y[i,j]~dnorm(m[i,j],tau=tau)
m[i,j]<-mu+alpha[i]+beta[j]+inte[i,j]
}
}
tau~dgamma(2,0.1)
se2<-1/tau
})
mConts<-list(ne=ncol(yn),nv=nrow(yn))#,
m.mu=mean(y)
mData<-list(y=yn)#matrix(c(yn),nrow=nrow(yn)