Running examples in ‘jSDM-Ex.R’ failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: jSDM_binomial_probit_sp_constrained
> ### Title: Binomial probit regression with selected constrained species
> ### Aliases: jSDM_binomial_probit_sp_constrained
> ### Keywords: Bayesian Binomial Carlo Chains Gibbs JSDM MCMC Markov Monte
> ###   Sampling biodiversity hierarchical models probit regression
> 
> ### ** Examples
> 
> #======================================
> # jSDM_binomial_probit_sp_constrained()
> # Example with simulated data
> #====================================
> 
> #=================
> #== Load libraries
> library(jSDM)
> 
> #==================
> #== Data simulation
> 
> #= Number of sites
> nsite <- 30
> 
> #= Set seed for repeatability
> seed <- 1234
> set.seed(seed)
> 
> #= Number of species
> nsp <- 10
> 
> #= Number of latent variables
> n_latent <- 2
> 
> #= Ecological process (suitability)
> x1 <- rnorm(nsite,0,1)
> x2 <- rnorm(nsite,0,1)
> X <- cbind(rep(1,nsite),x1,x2)
> np <- ncol(X)
> #= Latent variables W
> W <- matrix(rnorm(nsite*n_latent,0,1), nsite, n_latent)
> #= Fixed species effect beta 
> beta.target <- t(matrix(runif(nsp*np,-2,2),
+                         byrow=TRUE, nrow=nsp))
> #= Factor loading lambda  
> lambda.target <- matrix(0, n_latent, nsp)
> mat <- t(matrix(runif(nsp*n_latent, -2, 2), byrow=TRUE, nrow=nsp))
> lambda.target[upper.tri(mat, diag=TRUE)] <- mat[upper.tri(mat, diag=TRUE)]
> diag(lambda.target) <- runif(n_latent, 0, 2)
> #= Variance of random site effect 
> V_alpha.target <- 0.5
> #= Random site effect alpha
> alpha.target <- rnorm(nsite,0 , sqrt(V_alpha.target))
> # Simulation of response data with probit link
> probit_theta <- X%*%beta.target + W%*%lambda.target + alpha.target
> theta <- pnorm(probit_theta)
> e <- matrix(rnorm(nsp*nsite,0,1),nsite,nsp)
> # Latent variable Z 
> Z_true <- probit_theta + e
> # Presence-absence matrix Y
> Y <- matrix (NA, nsite,nsp)
> for (i in 1:nsite){
+   for (j in 1:nsp){
+     if ( Z_true[i,j] > 0) {Y[i,j] <- 1}
+     else {Y[i,j] <- 0}
+   }
+ }
> 
> #==================================
> #== Site-occupancy model
> 
> # Increase number of iterations (burnin and mcmc) to get convergence
> mod <- jSDM_binomial_probit_sp_constrained(# Iteration
+                                            burnin=100,
+                                            mcmc=100,
+                                            thin=1,
+                                            # parallel MCMCs
+                                            nchains=2, ncores=2,
+                                            # Response variable
+                                            presence_data=Y,
+                                            # Explanatory variables
+                                            site_formula=~x1+x2,
+                                            site_data = X,
+                                            n_latent=2,
+                                            site_effect="random",
+                                            # Starting values
+                                            alpha_start=0,
+                                            beta_start=0,
+                                            lambda_start=0,
+                                            W_start=0,
+                                            V_alpha=1,
+                                            # Priors
+                                            shape_Valpha=0.5,
+                                            rate_Valpha=0.0005,
+                                            mu_beta=0, V_beta=1,
+                                            mu_lambda=0, V_lambda=1,
+                                            seed=c(123,1234), verbose=1)
> 
> # ===================================================
> # Result analysis
> # ===================================================
> 
> #==========
> #== Outputs
> oldpar <- par(no.readonly = TRUE) 
> burnin <- mod[[1]]$model_spec$burnin
> ngibbs <- burnin + mod[[1]]$model_spec$mcmc
> thin <-  mod[[1]]$model_spec$thin
> require(coda)
Loading required package: coda
> arr2mcmc <- function(x) {
+   return(mcmc(as.data.frame(x),
+               start=burnin+1 , end=ngibbs, thin=thin))
+ }
> mcmc_list_Deviance <- mcmc.list(lapply(lapply(mod,"[[","mcmc.Deviance"), arr2mcmc))
> mcmc_list_alpha <- mcmc.list(lapply(lapply(mod,"[[","mcmc.alpha"), arr2mcmc))
> mcmc_list_V_alpha <- mcmc.list(lapply(lapply(mod,"[[","mcmc.V_alpha"), arr2mcmc))
> mcmc_list_param <- mcmc.list(lapply(lapply(mod,"[[","mcmc.sp"), arr2mcmc))
> mcmc_list_lv <- mcmc.list(lapply(lapply(mod,"[[","mcmc.latent"), arr2mcmc))
> mcmc_list_beta <- mcmc_list_param[,grep("beta",colnames(mcmc_list_param[[1]]))]
> mcmc_list_beta0 <- mcmc_list_beta[,grep("Intercept", colnames(mcmc_list_beta[[1]]))]
> mcmc_list_lambda <- mcmc.list(
+   lapply(mcmc_list_param[, grep("lambda", colnames(mcmc_list_param[[1]]))],
+          arr2mcmc))
> # Compute Rhat
> psrf_alpha <- mean(gelman.diag(mcmc_list_alpha, multivariate=FALSE)$psrf[,2])
> psrf_V_alpha <- gelman.diag(mcmc_list_V_alpha)$psrf[,2]
> psrf_beta0 <- mean(gelman.diag(mcmc_list_beta0)$psrf[,2])
> psrf_beta <- mean(gelman.diag(mcmc_list_beta[,grep("Intercept",
+                                                    colnames(mcmc_list_beta[[1]]),
+                                                    invert=TRUE)])$psrf[,2])
> psrf_lambda <- mean(gelman.diag(mcmc_list_lambda,
+                                 multivariate=FALSE)$psrf[,2],
+                     na.rm=TRUE)
> psrf_lv <- mean(gelman.diag(mcmc_list_lv, multivariate=FALSE)$psrf[,2])
> Rhat <- data.frame(Rhat=c(psrf_alpha, psrf_V_alpha, psrf_beta0, psrf_beta,
+                           psrf_lambda, psrf_lv),
+                    Variable=c("alpha", "Valpha", "beta0", "beta",
+                               "lambda", "W"))
> # Barplot
> library(ggplot2)
Error in library(ggplot2) : there is no package called ‘ggplot2’
Execution halted
Examples with CPU (user + system) or elapsed time > 5s
                                  user system elapsed
jSDM_binomial_probit_long_format 5.233   0.08   7.055