Hello,
I am running into an issue when trying to predict using the sfMs model output. I have 17 species and I am trying to predict on 30772 sites. I am using the code from the Doser_et_el_2022 github repository. The problem comes from this loop :
for (j in 1:length(vals)) {
print(paste("Currently on set ", j, " out of ", length(vals), sep = ''))
curr.indx <- vals[[j]]
out.pred <- predict(out, X.0[curr.indx, ], coords.0[curr.indx, ],
n.omp.threads = 5, verbose = TRUE)
rich.samples[, , curr.indx] <- apply(out.pred$z.0.samples[, indices.elasmo,], c(1,3), sum)
w.samples[, , curr.indx] <- out.pred$w.0.samples
}
It works fine until "rich.samples", the out.pred object is normal. The message error is about my dimensions :
" Error in rich.samples[, curr.indx] <- apply(out.pred$z.0.samples[, indices.elasmo, :
number of items to replace is not a multiple of replacement length"
And the same goes for w.samples.
rich.samples <- array(NA, dim = c(out$n.post, J.str))
w.samples <- array(NA, dim = c(out$n.post, out$q, J.str))
where dim(rich.samples) is 500 and 30772; and dim(w.samples) is 500 5 30772.
I understand this is simply a problem of dimensions but I can't figure out the right way. In your example code there wasn't the model output "bbs-sfMsPGOcc-2-chain-2022-03-28.R" so I couldn't exactly check how it was for you.
Could you maybe help ?
Thank you very much in advance,
Pauline
Hello, I am running into an issue when trying to predict using the sfMs model output. I have 17 species and I am trying to predict on 30772 sites. I am using the code from the Doser_et_el_2022 github repository. The problem comes from this loop :
for (j in 1:length(vals)) { print(paste("Currently on set ", j, " out of ", length(vals), sep = '')) curr.indx <- vals[[j]] out.pred <- predict(out, X.0[curr.indx, ], coords.0[curr.indx, ], n.omp.threads = 5, verbose = TRUE) rich.samples[, , curr.indx] <- apply(out.pred$z.0.samples[, indices.elasmo,], c(1,3), sum) w.samples[, , curr.indx] <- out.pred$w.0.samples }
It works fine until "rich.samples", the out.pred object is normal. The message error is about my dimensions : " Error in rich.samples[, curr.indx] <- apply(out.pred$z.0.samples[, indices.elasmo, : number of items to replace is not a multiple of replacement length" And the same goes for w.samples.
The set-up for the loop is the following :
species
elasmo <- data.list$y[,1,] %>% as.data.frame() %>% rownames_to_column("spp") %>% select(spp) %>% pull() indices.elasmo <- 1:nrow(data.list$y)
Predict piece by piece across study area
J.str <- nrow(X.0) #30772 sites
Split up the data set.
vals <- split(1:J.str, ceiling(seq_along(1:J.str) / 600))
prepare empty arrrays
rich.samples <- array(NA, dim = c(out$n.post, J.str)) w.samples <- array(NA, dim = c(out$n.post, out$q, J.str))
where dim(rich.samples) is 500 and 30772; and dim(w.samples) is 500 5 30772.
I understand this is simply a problem of dimensions but I can't figure out the right way. In your example code there wasn't the model output "bbs-sfMsPGOcc-2-chain-2022-03-28.R" so I couldn't exactly check how it was for you.
Could you maybe help ? Thank you very much in advance, Pauline