Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in array(r, dim = d, dimnames = if (!(is.null(n1 <- names(x[[1L]])) & : negative length vectors are not allowed #112

Open
pyspider opened this issue Jul 30, 2021 · 2 comments

Comments

@pyspider
Copy link

Hi,
I was just going through the mcmc convergence diagnostics. Here is my code.

dim(m$Y)
#[1] 521 217

mpost = convertToCodaObject(m)

ess.beta<-effectiveSize(mpost$Beta)
psrf.beta<-gelman.diag(mpost$Beta, multivariate=FALSE)$psrf

ess.omega = effectiveSize(mpost$Omega[[1]])
psrf.omega = gelman.diag(mpost$Omega[[1]], multivariate=FALSE)$psrf

dev.new()
tiff("results/MCMC convergence.tiff",width=8,height=5,units="in",res=300)
par(mfrow=c(1,2))
hist(ess.beta)
hist(psrf.beta)
hist(ess.omega)
hist(psrf.omega)
dev.off()

I am getting this error when I evaluate MCMC convergence for Omega. I do not know how to fix this. Many thanks for your help!

Error in array(r, dim = d, dimnames = if (!(is.null(n1 <- names(x[[1L]])) & :
negative length vectors are not allowed
Calls: gelman.diag -> array -> sapply -> simplify2array -> array
In addition: Warning message:
In array(r, dim = d, dimnames = if (!(is.null(n1 <- names(x[[1L]])) & :
NAs introduced by coercion to integer range
Execution halted

@jarioksa
Copy link
Collaborator

The error comes from the coda package. Function coda::gelman.diag() does not get the kind of input it expects. It seems that sampleMcmc does not produce data expected. We do not have your data, but how do you your Omegas look like? How many of them you have? Do you have non-finite values among them?

@pyspider
Copy link
Author

pyspider commented Oct 15, 2021

The error comes from the coda package. Function coda::gelman.diag() does not get the kind of input it expects. It seems that sampleMcmc does not produce data expected. We do not have your data, but how do you your Omegas look like?

I obtained this hmsc model output here that has taken one and a half months (from this issue: #97), with two random effects (i.e., spatial and temporal).
hmsc_section_v0.01_20210730.pdf
I got a very low SR2. I tried to run another model using fewer species (e.g., 49 species). But I still get a similar SR2 using 30 chains, 1000 samples, and 100 thins. I am not sure whether it means I'm missing some important variables and/or it is difficult to fit the model for count data. w.r.t. the explanatory powers of models, could I only look at AUC for discriminating incidence data (O.AUC) if I can not get a moderate power for abundance data?

How many of them you have?

With 4 chains of 2000 samples and 217 species the Omega1/2 has 8000*47089 (4*2000*217*217) numbers.

> load("models/model_iCAMP_backbone_tree_chains_4_samples_2000_thin_100")
> m<-models[[1]]
> mpost = convertToCodaObject(m)
> ess.beta<-effectiveSize(mpost$Beta)
> psrf.beta<-gelman.diag(mpost$Beta, multivariate=FALSE)$psrf
> ess.omega = effectiveSize(mpost$Omega[[1]])
> Omega1<-as.data.frame(rbind(mpost$Omega[[1]][[1]],mpost$Omega[[1]][[2]],mpost$Omega[[1]][[3]],mpost$Omega[[1]][[4]]))
> dim(Omega1)
[1]  8000 47089
> Omega2<-as.data.frame(rbind(mpost$Omega[[2]][[1]],mpost$Omega[[2]][[2]],mpost$Omega[[2]][[3]],mpost$Omega[[2]][[4]]))
> dim(Omega2)
[1]  8000 47089

Do you have non-finite values among them?

No, I don't have non-finite vlaues.

> which(grepl("TRUE",lapply(Omega1,is.nan)))
integer(0)
> which(grepl("TRUE",lapply(Omega2,is.nan)))
integer(0)

Alternatively, I did check using sum() (following #45).

> sum(Omega1)
[1] 13236812
> sum(Omega2)
[1] 21921501

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants