Fitting a Spatial Factor Multi-Species Occupancy Model

Data from Tamshiyacu-Tahuayo, Yasuni, Madidi

model
code
analysis
453 sites, 24 mammal species
Authors

German Forero

Robert Wallace

Galo Zapara-Rios

Emiliana Isasi-Catalá

Diego J. Lizcano

Published

May 16, 2025

Single-species occupancy models

Single-species occupancy models (MacKenzie et al., 2002) are widely used in ecology to estimate and predict the spatial distribution of a species from data collected in presence–absence repeated surveys. The popularity of these models stems from their ability to estimate the effects of environmental or management covariates on species occurrences, while accounting for false-negative errors in detection, which are common in surveys of natural populations.

Multi-species occupancy models

Multi-species occupancy models for estimating the effects of environmental covariates on several species occurrences while accounting for imperfect detection were build on the principle of the Single-species occupancy model, and developed more than 20 years ago.

Multi-species occupancy models are a powerful tool for combining information from multiple species to estimate both individual and community-level responses to management and environmental variables.

Objective

We want to asses the effect of protected areas on the occupancy of the species. We hypothesize that several mammal species have benefited of the conservation actions provided by protected areas, so we expect a decreases in occupancy from the interior of the protected area to the exterior as a function of the distance to the protected area border.

To account for several ecological factors we also tested and included elevation and forest integrity index as occupancy covariates.

We used the newly developed R package spOccupancy as approach to modelling the probability of occurrence of each species as a function of fixed effects of measured environmental covariates and random effects designed to account for unobserved sources of spatial dependence (spatial autocorrelation).

Code
library(grateful) # Facilitate Citation of R Packages
library(readxl) # Read Excel Files
library(DT) # A Wrapper of the JavaScript Library 'DataTables'
library(sf) # Simple Features for R
library(mapview) # Interactive Viewing of Spatial Data in R
library(maps) # Draw Geographical Maps
library(tmap) # Thematic Maps
library(terra) # Spatial Data Analysis
library(elevatr) # Access Elevation Data from Various APIs

# library(rjags) # Bayesian Graphical Models using MCMC 
library(bayesplot) # Plotting for Bayesian Models # Plotting for Bayesian Models
library(tictoc) # Functions for Timing R Scripts, as Well as Implementations of "Stack" and "StackList" Structures 
library(MCMCvis) # Tools to Visualize, Manipulate, and Summarize MCMC Output
library(coda) # Output Analysis and Diagnostics for MCMC
library(beepr) # Easily Play Notification Sounds on any Platform 
library(snowfall) # Easier Cluster Computing (Based on 'snow')

#library(ggmcmc)
library(camtrapR) # Camera Trap Data Management and Preparation 
library(spOccupancy) # Single-Species, Multi-Species, and Integrated Spatial Occupancy
library(tidyverse) # Easily Install and Load the 'Tidyverse'

Fitting a Multi-Species Spatial Occupancy Model

We use a more computationally efficient approach for fitting spatial multi-species occupancy models. This alternative approach is called a “spatial factor multi-species occupancy model”, and is described in depth in Doser, Finley, and Banerjee (2023). This newer approach also accounts for residual species correlations (i.e., it is a joint species distribution model with imperfect detection). The simulation results from Doser, Finley, and Banerjee (2023) show that this new alternative approach outperforms, or performs equally to spMsPGOcc(), while being substantially faster.

The Latent factor multi-species occupancy model is described in detail here

Data fom Bajo Madidi and Heath

Here we use the tables BOL-008a - BOL-008b and BOL14a - BOL14b

Code
source("C:/CodigoR/WCS-CameraTrap/R/organiza_datos_v3.R")

Area_Madidi <- read_sf("C:/CodigoR/Occu_APs/shp/Area_Madidi/WDPA_WDOECM_Jul2025_Public_303894_shp-polygons.shp")

Madidi_NP <- read_sf("C:/CodigoR/Occu_APs/shp/Madidi_NP/WDPA_WDOECM_Jul2025_Public_98183_shp-polygons.shp")
#AP_Tahuayo <- read_sf("C:/CodigoR/Occu_APs/shp/Tahuayo/WDPA_WDOECM_Jun2025_Public_555555621_shp-polygons.shp")

# load data and make array_locID column
#Bol_Pacaya <- read_excel("F:/WCS-CameraTrap/data/BDcorregidas/Peru/PER-003_BD_ACRCTT_T0.xlsx", sheet = "Image")


Bol_Madidi_1 <- loadproject("F:/WCS-CameraTrap/data/BDcorregidas/Bolivia/Guido/BOL-008a.xlsx") |> mutate(Point.x=as.character(paste("M1",Point.x, sep = "-"))) |> mutate(Point.y=as.character(paste("M1",Point.y, sep = "-")))
65 cameras in Cameras. 
 61 cameras in Deployment. 
 61 deployments in Deployment. 
 31 points in Deployment. 
 61 cameras in Images. 
 31 points in Images. 
Joining with `by = join_by(Camera_Id)`
[1] "dates ok"
year: 2005 
 Jaguar_Design: yes 
Code
Bol_Madidi_2 <- loadproject("F:/WCS-CameraTrap/data/BDcorregidas/Bolivia/Guido/BOL-008b.xlsx") |> mutate(Point.x=as.character(paste("M2",Point.x, sep = "-"))) |> mutate(Point.y=as.character(paste("M2",Point.y, sep = "-")))
60 cameras in Cameras. 
 52 cameras in Deployment. 
 52 deployments in Deployment. 
 30 points in Deployment. 
 51 cameras in Images. 
 30 points in Images. 
Joining with `by = join_by(Camera_Id)`
[1] "dates ok"
year: 2005 
 Jaguar_Design: yes 
Code
Bol_Madidi_3 <- loadproject("F:/WCS-CameraTrap/data/BDcorregidas/Bolivia/Guido/BOL-014a.xlsx")|> mutate(Point.x=as.character(paste("M3",Point.x, sep = "-"))) |> mutate(Point.y=as.character(paste("M3",Point.y, sep = "-")))
47 cameras in Cameras. 
 44 cameras in Deployment. 
 44 deployments in Deployment. 
 26 points in Deployment. 
 44 cameras in Images. 
 26 points in Images. 
Joining with `by = join_by(Camera_Id)`
[1] "dates ok"
year: 2009 
 Jaguar_Design: yes 
Code
Bol_Madidi_4 <- loadproject("F:/WCS-CameraTrap/data/BDcorregidas/Bolivia/Guido/BOL-014b.xlsx")|> mutate(Point.x=as.character(paste("M4",Point.x, sep = "-"))) |> mutate(Point.y=as.character(paste("M1",Point.y, sep = "-")))
29 cameras in Cameras. 
 22 cameras in Deployment. 
 22 deployments in Deployment. 
 15 points in Deployment. 
 22 cameras in Images. 
 15 points in Images. 
Joining with `by = join_by(Camera_Id)`
[1] "dates ok"
year: 2009 
 Jaguar_Design: yes 
Code
# get sites
Bol_Madidi_sites1 <-  Bol_Madidi_1 |> 
   dplyr::bind_rows(Bol_Madidi_2) |> 
   dplyr::bind_rows(Bol_Madidi_3) |> 
   dplyr::bind_rows(Bol_Madidi_4) |> 
  select("Latitude", "Longitude", "Point.x" 
) |> dplyr::distinct( )  

Bol_Madidi_sites <- sf::st_as_sf(Bol_Madidi_sites1, coords = c("Longitude","Latitude"))
st_crs(Bol_Madidi_sites) <- 4326


# get elevation map
elevation_17 <- rast(get_elev_raster(Bol_Madidi_sites, z = 9)) #z =1-14
Mosaicing & Projecting
Note: Elevation units are in meters.
Code
# bb <-  st_as_sfc(st_bbox(elevation_17)) # make bounding box 



# extract covs using points and add to _sites
covs_Bol_Madidi_sites <- cbind(Bol_Madidi_sites, terra::extract(elevation_17, Bol_Madidi_sites))
# covs_Ecu_17_sites <- cbind(Ecu_17_sites, terra::extract(elevation_17, Ecu_17_sites))


# get which are in and out
covs_Bol_Madidi_sites$in_AP = st_intersects(covs_Bol_Madidi_sites, Madidi_NP, sparse = FALSE)
# covs_Ecu_17_sites$in_AP = st_intersects(covs_Ecu_17_sites, AP_Machalilla, sparse = FALSE)


# make a map
mapview (elevation_17, alpha=0.7) + 
  mapview (Madidi_NP, color = "green", col.regions = "green", alpha = 0.5) +
  mapview (Area_Madidi, color = "yellow", col.regions = "yellow", alpha = 0.5) +
  #mapview (AP_Tahuayo, color = "green", col.regions = "green", alpha = 0.5) +
  mapview (covs_Bol_Madidi_sites, zcol = "in_AP", col.regions =c("red","blue"), burst = TRUE) 
Number of pixels is above 5e+05.Only about 5e+05 pixels will be shown.
You can increase the value of `maxpixels` to 516558 to avoid this.

Tamshiyacu Tahuayo data

Here we use the tables: - PER-003_BD_ACRCTT_T0.xlsx - PER-002_BD_ACRTT-PILOTO.xlsx

Code
source("C:/CodigoR/WCS-CameraTrap/R/organiza_datos_v3.R")

AP_Pacaya <- read_sf("C:/CodigoR/Occu_APs/shp/PacayaSamiria/WDPA_WDOECM_Jun2025_Public_249_shp-polygons.shp")

AP_Tahuayo <- read_sf("C:/CodigoR/Occu_APs/shp/Tahuayo/WDPA_WDOECM_Jun2025_Public_555555621_shp-polygons.shp")

# load data and make array_locID column
Per_Tahuayo_piloto <- loadproject("F:/WCS-CameraTrap/data/BDcorregidas/Peru/PER-002_BD_ACRTT-PILOTO.xlsx")
50 cameras in Cameras. 
 50 cameras in Deployment. 
 50 deployments in Deployment. 
 50 points in Deployment. 
 50 cameras in Images. 
 50 points in Images. 
Joining with `by = join_by(Camera_Id)`
[1] "dates ok"
year: 2015 
 Jaguar_Design: no 
Code
Per_Tahuayo <- loadproject("F:/WCS-CameraTrap/data/BDcorregidas/Peru/PER-003_BD_ACRCTT_T0.xlsx")
85 cameras in Cameras. 
 84 cameras in Deployment. 
 84 deployments in Deployment. 
 84 points in Deployment. 
 84 cameras in Images. 
 84 points in Images. 
Joining with `by = join_by(Camera_Id)`
[1] "dates ok"
year: 2016 
 Jaguar_Design: no 
Code
FLII2016 <- rast("C:/CodigoR/WCS_2024/FLI/raster/FLII_final/FLII_2016.tif")

# get sites
# Per_Pacaya_sites <- get.sites("F:/WCS-CameraTrap/data/BDcorregidas/Peru/PER-003_BD_ACRCTT_T0.xlsx")

# get sites
Per_Tahuayo_sites1 <- Per_Tahuayo |> select("Latitude",
                                    "Longitude",
                                    "Camera_Id" 
                                    ) |> dplyr::distinct( )  

Per_Tahuayo_sites <- sf::st_as_sf(Per_Tahuayo_sites1, coords = c("Longitude","Latitude"))
st_crs(Per_Tahuayo_sites) <- 4326



# get Pacaya sites
Per_Tahuayo_piloto_sites1 <- Per_Tahuayo_piloto |> select("Latitude",
                                    "Longitude",
                                    "Camera_Id" 
                                    ) |> dplyr::distinct( )  

Per_Tahuayo_piloto_sites <- sf::st_as_sf(Per_Tahuayo_piloto_sites1, coords = c("Longitude","Latitude"))
st_crs(Per_Tahuayo_piloto_sites) <- 4326




# get elevation map
elevation_PE <- rast(get_elev_raster(Per_Tahuayo_sites, z = 10)) #z =1-14
Mosaicing & Projecting
Note: Elevation units are in meters.
Code
# bb <-  st_as_sfc(st_bbox(elevation_17)) # make bounding box 





# extract covs using points and add to _sites
covs_Per_Tahuayo_sites <- cbind(Per_Tahuayo_sites,
                                terra::extract(elevation_PE,
                                               Per_Tahuayo_sites)
                                )

# extract covs using points and add to _sites
covs_Per_Tahuayo_piloto_sites <- cbind(Per_Tahuayo_piloto_sites, terra::extract(elevation_PE, Per_Tahuayo_piloto_sites))



# get which are in and out
covs_Per_Tahuayo_sites$in_AP = st_intersects(covs_Per_Tahuayo_sites, AP_Tahuayo, sparse = FALSE)

covs_Per_Tahuayo_piloto_sites$in_AP = st_intersects(covs_Per_Tahuayo_piloto_sites, AP_Tahuayo, sparse = FALSE)




# make a map
mapview (elevation_PE, alpha=0.5) + 
  mapview (AP_Pacaya, color = "green", col.regions = "green", alpha = 0.5) +
  mapview (AP_Tahuayo, color = "green", col.regions = "green", alpha = 0.5) +
  mapview (covs_Per_Tahuayo_sites, zcol = "in_AP", col.regions =c("red","blue"), burst = TRUE) +   
  mapview (covs_Per_Tahuayo_piloto_sites, 
           zcol = "in_AP", 
           col.regions =c("blue"), 
           burst = TRUE) 
Number of pixels is above 5e+05.Only about 5e+05 pixels will be shown.
You can increase the value of `maxpixels` to 523775 to avoid this.

Yasuni data

Here we use the tables Ecu-13, Ecu-17, Ecu-18 y Ecu-20

Code
source("C:/CodigoR/WCS-CameraTrap/R/organiza_datos_v3.R")

AP_Yasuni <- read_sf("C:/CodigoR/Occu_APs/shp/Yasuni/WDPA_WDOECM_May2025_Public_186_shp-polygons.shp")

### Ecu 17, Ecu 18, ECU 20, Ecu 22  

# load data and make array_locID column
Ecu_13 <- loadproject("F:/WCS-CameraTrap/data/BDcorregidas/Ecuador/ECU-013.xlsx") |> mutate(array_locID=paste("Ecu_13", locationID, sep="_"))
28 cameras in Cameras. 
 28 cameras in Deployment. 
 28 deployments in Deployment. 
 28 points in Deployment. 
 28 cameras in Images. 
 28 points in Images. 
Joining with `by = join_by(Camera_Id)`
[1] "dates ok"
year: 2015 
 Jaguar_Design: no 
Code
Ecu_17 <- loadproject("F:/WCS-CameraTrap/data/BDcorregidas/Ecuador/ECU-017.xlsx") |> mutate(array_locID=paste("Ecu_17", locationID, sep="_"))
30 cameras in Cameras. 
 30 cameras in Deployment. 
 30 deployments in Deployment. 
 30 points in Deployment. 
 30 cameras in Images. 
 30 points in Images. 
Joining with `by = join_by(Camera_Id)`
[1] "dates ok"
year: 2015 
 Jaguar_Design: no 
Code
Ecu_18 <- loadproject("F:/WCS-CameraTrap/data/BDcorregidas/Ecuador/ECU-018.xlsx")|> mutate(array_locID=paste("Ecu_18", locationID, sep="_"))
30 cameras in Cameras. 
 30 cameras in Deployment. 
 30 deployments in Deployment. 
 30 points in Deployment. 
 30 cameras in Images. 
 30 points in Images. 
Joining with `by = join_by(Camera_Id)`
[1] "dates ok"
year: 2016 
 Jaguar_Design: no 
Code
Ecu_20 <- loadproject("F:/WCS-CameraTrap/data/BDcorregidas/Ecuador/ECU-020_Fix.xlsx")|> mutate(array_locID=paste("Ecu_20", locationID, sep="_"))
30 cameras in Cameras. 
 25 cameras in Deployment. 
 25 deployments in Deployment. 
 25 points in Deployment. 
 25 cameras in Images. 
 25 points in Images. 
Joining with `by = join_by(Camera_Id)`
[1] "dates ok"
year: 2018 
 Jaguar_Design: no 
Code
# Ecu_21 <- loadproject("F:/WCS-CameraTrap/data/BDcorregidas/Ecuador/ECU-021.xlsx") |> mutate(array_locID=paste("Ecu_14", locationID, sep="_"))
Ecu_22 <- loadproject("F:/WCS-CameraTrap/data/BDcorregidas/Ecuador/ECU-022.xlsx")|> mutate(array_locID=paste("Ecu_22", locationID, sep="_"))
Warning: Expecting numeric in O5508 / R5508C15: got 'NA'
Warning: Expecting numeric in O5509 / R5509C15: got 'NA'
Warning: Expecting numeric in O5510 / R5510C15: got 'NA'
Warning: Expecting numeric in O5511 / R5511C15: got 'NA'
Warning: Expecting numeric in O5512 / R5512C15: got 'NA'
30 cameras in Cameras. 
 30 cameras in Deployment. 
 30 deployments in Deployment. 
 30 points in Deployment. 
 30 cameras in Images. 
 30 points in Images. 
Joining with `by = join_by(Camera_Id)`
[1] "dates ok"
year: 2018 
 Jaguar_Design: no 
Code
# get sites
Ecu_13_sites <- get.sites("F:/WCS-CameraTrap/data/BDcorregidas/Ecuador/ECU-013.xlsx")
Joining with `by = join_by(Camera_Id)`
Joining with `by = join_by(Point)`
Joining with `by = join_by(Point, Longitude, Latitude, bait, season, rio_playa,
arroyo, camino, senda_animal, senda_gente, salitral, pozo_agua, bosque, sabana,
intermedio, intervalo_trigger, CamType)`
Joining with `by = join_by(Point, Longitude, Latitude, bait, season, rio_playa,
arroyo, camino, senda_animal, senda_gente, salitral, pozo_agua, bosque, sabana,
intermedio, intervalo_trigger, CamType, Deployment_ID, start_date, end_date,
`Bait Type`, `Feature Type`, `Feature Type methodology`, Camera_Id, `Quiet
Period Setting`, `Restriction on Access`, `Camera Failure Details`, `Project
Id`, Make, Model, `Serial Number`, Year_Purchased)`
Code
Ecu_17_sites <- get.sites("F:/WCS-CameraTrap/data/BDcorregidas/Ecuador/ECU-017.xlsx")
Joining with `by = join_by(Camera_Id)`
Joining with `by = join_by(Point)`
Joining with `by = join_by(Point, Longitude, Latitude, bait, season, rio_playa,
arroyo, camino, senda_animal, senda_gente, salitral, pozo_agua, bosque, sabana,
intermedio, intervalo_trigger, CamType)`
Joining with `by = join_by(Point, Longitude, Latitude, bait, season, rio_playa,
arroyo, camino, senda_animal, senda_gente, salitral, pozo_agua, bosque, sabana,
intermedio, intervalo_trigger, CamType, Deployment_ID, start_date, end_date,
`Bait Type`, `Feature Type`, `Feature Type methodology`, Camera_Id, `Quiet
Period Setting`, `Restriction on Access`, `Camera Failure Details`, `Project
Id`, Make, Model, `Serial Number`, Year_Purchased)`
Code
Ecu_18_sites <- get.sites("F:/WCS-CameraTrap/data/BDcorregidas/Ecuador/ECU-018.xlsx")
Joining with `by = join_by(Camera_Id)`
Joining with `by = join_by(Point)`
Joining with `by = join_by(Point, Longitude, Latitude, bait, season, rio_playa,
arroyo, camino, senda_animal, senda_gente, salitral, pozo_agua, bosque, sabana,
intermedio, intervalo_trigger, CamType)`
Joining with `by = join_by(Point, Longitude, Latitude, bait, season, rio_playa,
arroyo, camino, senda_animal, senda_gente, salitral, pozo_agua, bosque, sabana,
intermedio, intervalo_trigger, CamType, Deployment_ID, start_date, end_date,
`Bait Type`, `Feature Type`, `Feature Type methodology`, Camera_Id, `Quiet
Period Setting`, `Restriction on Access`, `Camera Failure Details`, `Project
Id`, Make, Model, `Serial Number`, Year_Purchased)`
Code
Ecu_20_sites <- get.sites("F:/WCS-CameraTrap/data/BDcorregidas/Ecuador/ECU-020_Fix.xlsx")
Joining with `by = join_by(Camera_Id)`
Joining with `by = join_by(Point)`
Joining with `by = join_by(Point, Longitude, Latitude, bait, season, rio_playa,
arroyo, camino, senda_animal, senda_gente, salitral, pozo_agua, bosque, sabana,
intermedio, intervalo_trigger, CamType)`
Joining with `by = join_by(Point, Longitude, Latitude, bait, season, rio_playa,
arroyo, camino, senda_animal, senda_gente, salitral, pozo_agua, bosque, sabana,
intermedio, intervalo_trigger, CamType, Deployment_ID, start_date, end_date,
`Bait Type`, `Feature Type`, `Feature Type methodology`, Camera_Id, `Quiet
Period Setting`, `Restriction on Access`, `Camera Failure Details`, `Project
Id`, Make, Model, `Serial Number`, Year_Purchased)`
Code
# Ecu_21_sites <- get.sites("F:/WCS-CameraTrap/data/BDcorregidas/Ecuador/ECU-021.xlsx")
Ecu_22_sites <- get.sites("F:/WCS-CameraTrap/data/BDcorregidas/Ecuador/ECU-022.xlsx")
Joining with `by = join_by(Camera_Id)`
Joining with `by = join_by(Point)`
Joining with `by = join_by(Point, Longitude, Latitude, bait, season, rio_playa,
arroyo, camino, senda_animal, senda_gente, salitral, pozo_agua, bosque, sabana,
intermedio, intervalo_trigger, CamType)`
Joining with `by = join_by(Point, Longitude, Latitude, bait, season, rio_playa,
arroyo, camino, senda_animal, senda_gente, salitral, pozo_agua, bosque, sabana,
intermedio, intervalo_trigger, CamType, Deployment_ID, start_date, end_date,
`Bait Type`, `Feature Type`, `Feature Type methodology`, Camera_Id, `Quiet
Period Setting`, `Restriction on Access`, `Camera Failure Details`, `Project
Id`, Make, Model, `Serial Number`, Year_Purchased)`
Code
# get elevation map
elevation_EC <- rast(get_elev_raster(Ecu_17_sites, z = 7)) #z =1-14
Mosaicing & Projecting
Note: Elevation units are in meters.
Code
bb <-  st_as_sfc(st_bbox(elevation_EC)) # make bounding box 




# extract covs using points and add to _sites
covs_Ecu_13_sites <- cbind(Ecu_13_sites, terra::extract(elevation_EC, Ecu_13_sites))
covs_Ecu_17_sites <- cbind(Ecu_17_sites, terra::extract(elevation_EC, Ecu_17_sites))
covs_Ecu_18_sites <- cbind(Ecu_18_sites, terra::extract(elevation_EC, Ecu_18_sites))
covs_Ecu_20_sites <- cbind(Ecu_20_sites, terra::extract(elevation_EC, Ecu_20_sites))
#covs_Ecu_21_sites <- cbind(Ecu_21_sites, terra::extract(elevation_17, Ecu_21_sites))
covs_Ecu_22_sites <- cbind(Ecu_22_sites, terra::extract(elevation_EC, Ecu_22_sites))

# get which are in and out
covs_Ecu_13_sites$in_AP = st_intersects(covs_Ecu_13_sites, AP_Yasuni, sparse = FALSE)
covs_Ecu_17_sites$in_AP = st_intersects(covs_Ecu_17_sites, AP_Yasuni, sparse = FALSE)
covs_Ecu_18_sites$in_AP = st_intersects(covs_Ecu_18_sites, AP_Yasuni, sparse = FALSE)
covs_Ecu_20_sites$in_AP = st_intersects(covs_Ecu_20_sites, AP_Yasuni, sparse = FALSE)
#covs_Ecu_21_sites$in_AP = st_intersects(covs_Ecu_21_sites, AP_Yasuni, sparse = FALSE)
covs_Ecu_22_sites$in_AP = st_intersects(covs_Ecu_22_sites, AP_Yasuni, sparse = FALSE)

# covs_Ecu_16_sites$in_AP = st_intersects(covs_Ecu_16_sites, AP_Llanganates, sparse = FALSE)



# make a map
mapview (elevation_EC, alpha=0.5) + 
  mapview (AP_Yasuni, color = "green", col.regions = "green", alpha = 0.5) +
  mapview (covs_Ecu_13_sites, zcol = "in_AP", col.regions =c("red"), burst = TRUE) +
  mapview (covs_Ecu_17_sites, zcol = "in_AP", col.regions =c("red","blue"), burst = TRUE) +
  mapview (covs_Ecu_18_sites, zcol = "in_AP", col.regions =c("red"), burst = TRUE) +
  mapview (covs_Ecu_20_sites, zcol = "in_AP", col.regions =c("red","blue"), burst = TRUE) +
#  mapview (covs_Ecu_21_sites, zcol = "in_AP", col.regions =c("red"), burst = TRUE) +
  mapview (covs_Ecu_22_sites, zcol = "in_AP", burst = TRUE, col.regions = c("red") ) #+
Code
  # mapview (covs_Ecu_16_sites, zcol = "in_AP", burst = TRUE, col.regions =c("red","blue")) 

Camera trap operation data and detection history

Code
# Join 3 tables
# fix count in ECU 13, 17, 22,
Ecu_13$Count <- as.character(Ecu_13$Count)
Ecu_17$Count <- as.character(Ecu_17$Count)
Ecu_22$Count <- as.character(Ecu_22$Count)

Ecu_full <- Ecu_13 |> full_join(Ecu_17) |> 
                      full_join(Ecu_18) |> 
                      full_join(Ecu_20) |> 
#                      full_join(Ecu_21) |> 
                      full_join(Ecu_22)

###### Bolivia

Bol_full <- Bol_Madidi_1  |> 
   full_join(Bol_Madidi_2) |> 
   full_join(Bol_Madidi_3) |> 
   full_join(Bol_Madidi_4) 
# change camera Id by point. two cameras in one
Bol_full <- Bol_full |> mutate(Camera_Id=Point.x)


# Ecu_18$Count <- as.numeric(Ecu_18$Count)
Per_Tahuayo_piloto$Longitude <- as.numeric(Per_Tahuayo_piloto$Longitude)
Per_Tahuayo_piloto$Latitude <- as.numeric(Per_Tahuayo_piloto$Latitude)


Per_full <- Per_Tahuayo|> 
  full_join(Per_Tahuayo_piloto) #|> 
                      # full_join(Ecu_18) |> 
                      # full_join(Ecu_20) |> 
                      # full_join(Ecu_21) |> 
                      # full_join(Ecu_22)

# rename camera id
# Per_full$camid <- Per_full$`Camera_Id`

Ecu_full$Count <- as.numeric(Ecu_full$Count)
Per_full$Count <- as.numeric(Per_full$Count)

Ecu_full <- Ecu_full[,-47]

##################################
data_full <- rbind(Ecu_full, 
                   Per_full,
                   Bol_full)


# fix date format
# 
# Formatting a Date object
data_full$start_date <- as.Date(data_full$"start_date", "%Y/%m/%d")
data_full$start_date <- format(data_full$start_date, "%Y-%m-%d")

data_full$end_date <- as.Date(data_full$"end_date", "%Y/%m/%d")
data_full$end_date <- format(data_full$end_date, "%Y-%m-%d")

data_full$eventDate <- as.Date(data_full$"Date_Time_Captured", "%Y/%m/%d")
data_full$eventDate <- format(data_full$eventDate, "%Y-%m-%d")

# Per_full$eventDateTime <- ymd_hms(paste(Per_full$"photo_date", Per_full$"photo_time", sep=" "))
data_full$eventDateTime <- ymd_hms(data_full$"Date_Time_Captured")

###############################
# remove duplicated cameras
################################
ind1 <- which(data_full$Camera_Id=="ECU-020-C0027")
ind2 <- which(data_full$Camera_Id=="ECU-020-C0006")
data_full <- data_full[-ind1,]
data_full <- data_full[-ind2,]


# filter 2021 and make uniques
CToperation  <- data_full |> dplyr::group_by(Camera_Id) |> #(array_locID) |> 
                           mutate(minStart=start_date, maxEnd=end_date) |> distinct(Longitude, Latitude, minStart, maxEnd) |> dplyr::ungroup()
# remove one duplicated
# View(CToperation)
# CToperation <- CToperation[-15,]

# M3-19: M3-21: M4-10: M4-12: M4-18:  From Madidi
CToperation <- CToperation[-c(379, 373, 365, 362, 357),]


CToperation[231,3] <- -4.482831 #Latitude
CToperation[93,3] <- -0.5548211 #Latitude
CToperation[93,2] <- -76.48333

### remove duplicated
# View(as.data.frame(table(CToperation$Latitude)))
# View(as.data.frame(table(CToperation$Longitude)))
# CToperation <- CToperation[-c(90,94),]
# Latitude -4.48283
# Latitude -0.554820969700813
# Longitude -76.4833290316164

# Generamos la matríz de operación de las cámaras

camop <- cameraOperation(CTtable= CToperation, # Tabla de operación
                         stationCol= "Camera_Id", # Columna que define la estación
                         setupCol= "minStart", #Columna fecha de colocación
                         retrievalCol= "maxEnd", #Columna fecha de retiro
                         #hasProblems= T, # Hubo fallos de cámaras
                         dateFormat= "%Y-%m-%d")#, #, # Formato de las fechas
                         #cameraCol="Camera_Id")
                         # sessionCol= "Year")

# Generar las historias de detección ---------------------------------------
## remove plroblem species

# Per_full$scientificName <- paste(Per_full$genus, Per_full$species, sep=" ")

#### remove stups
# ind <- which(Per_full$scientificName=="NA NA")
# Per_full <- Per_full[-ind,]

# ind <- which(Per_full$scientificName=="Set up")
# Per_full <- Per_full[-ind,]
# 
# ind <- which(Per_full$scientificName=="Blank")
# Per_full <- Per_full[-ind,]
# 
# ind <- which(Per_full$scientificName=="Unidentifiable")
# Per_full <- Per_full[-ind,]


DetHist_list <- lapply(unique(data_full$scientificName), FUN = function(x) {
  detectionHistory(
    recordTable         = data_full, # abla de registros
    camOp                = camop, # Matriz de operación de cámaras
    stationCol           = "Camera_Id",
    speciesCol           = "scientificName",
    recordDateTimeCol    = "eventDateTime",
    recordDateTimeFormat  = "%Y-%m-%d %H:%M:%S",
    species              = x,     # la función reemplaza x por cada una de las especies
    occasionLength       = 7, # Colapso de las historias a 10 ías
    day1                 = "station", # "survey" a specific date, "station", #inicie en la fecha de cada survey
    datesAsOccasionNames = FALSE,
    includeEffort        = TRUE,
    scaleEffort          = FALSE,
    #unmarkedMultFrameInput=TRUE
    timeZone             = "America/Bogota" 
    )
  }
)

# names
names(DetHist_list) <- unique(data_full$scientificName)

# Finalmente creamos una lista nueva donde estén solo las historias de detección
ylist <- lapply(DetHist_list, FUN = function(x) x$detection_history)
# otra lista con effort scaled
efort <- lapply(DetHist_list, FUN = function(x) x$effort)

# number of observetions per sp, collapsed to 7 days
# lapply(ylist, sum, na.rm = TRUE)

Arrange spatial covariates

The standard EPSG code for a Lambert Azimuthal Equal-Area projection for South America is EPSG:10603 (WGS 84 / GLANCE South America). This projection is specifically designed for the continent and has its center located around the central meridian for the region. The units are meters.

FLII scores range from 0 (lowest integrity) to 10 (highest). Grantham discretized this range to define three broad illustrative categories: low (≤6.0); medium (>6.0 and <9.6); and high integrity (≥9.6).

Code
#transform coord data to Lambert Azimuthal Equal-Area
AP_Tahuayo_UTM <- st_transform(AP_Tahuayo, "EPSG:10603")
# Convert to LINESTRING
AP_Tahuayo_UTM_line <- st_cast(AP_Tahuayo_UTM,"MULTILINESTRING")# "LINESTRING")
#transform Yasuni to Lambert Azimuthal Equal-Area
AP_Yasuni_UTM <- st_transform(AP_Yasuni, "EPSG:10603")
# Convert to LINESTRING
AP_Yasuni_UTM_line <- st_cast(AP_Yasuni_UTM, "MULTILINESTRING")

#transform Yasuni to Lambert Azimuthal Equal-Area
AP_Madidi_UTM <- st_transform(Madidi_NP, "EPSG:10603")
# Convert to LINESTRING
AP_Madidi_UTM_line <- st_cast(AP_Madidi_UTM, "MULTILINESTRING")




############## sf AP Union 
AP_merged_sf_UTM <- st_union(AP_Tahuayo_UTM, 
                             AP_Yasuni_UTM,
                             AP_Madidi_UTM)
Warning: attribute variables are assumed to be spatially constant throughout
all geometries
Code
AP_merged_line <- st_cast(AP_merged_sf_UTM, to="MULTILINESTRING")


# make sf() from data table
data_full_sf <- CToperation |> 
    st_as_sf(coords = c("Longitude", "Latitude"), 
              crs = 4326)

# gete elevation proint from AWS
elev_data <- elevatr::get_elev_point(locations = data_full_sf, src = "aws")
Mosaicing & Projecting
Note: Elevation units are in meters
Code
# extract elev and paste to table
data_full_sf$elev <- elev_data$elevation
str(data_full_sf$elev)
 num [1:377] 449 396 622 478 468 401 537 549 456 498 ...
Code
# extract in AP
data_full_sf$in_AP = as.factor(st_intersects(data_full_sf, AP_Tahuayo, sparse = FALSE))

in_AP <- as.numeric((st_drop_geometry(data_full_sf$in_AP)))

# extract FLII
data_full_sf$FLII <- terra::extract(FLII2016, data_full_sf)[,2]
str(data_full_sf$FLII)
 num [1:377] 9.57 9.65 9.69 9.66 9.92 ...
Code
# Replace all NAs with min flii in a numeric column
data_full_sf$FLII[is.na(data_full_sf$FLII)] <- min(data_full_sf$FLII, na.rm = TRUE)

# mapview(full_sites_14_15_16_sf, zcol = "in_AP", burst = TRUE)

# Transform coord to Lambert Azimuthal Equal-Area
data_full_sf_UTM <- st_transform(data_full_sf, "EPSG:10603")


coords <- st_coordinates(data_full_sf_UTM)
#str(coords)

#### fix duplicated coord
# -1840583.53296873  en x
# -1842515.36969736  en x
# 1547741.44311964  en y
# 1541202.24796904 en y

# which(coords[,1]=="-1840583.53296873")
# which(coords[,1]=="-1842515.36969736")
# which(coords[,2]=="1547741.44311964")
# which(coords[,2]=="1541202.24796904")

# make Ecu_14_15_16 an sf object
#    cam_sf <- st_as_sf(Ecu_14_15_16, coords = c("lon","lat"))   #crs="EPSG:4326")
    #--- set CRS ---#
#    st_crs(cam_sf) <- 4326




# Calculate the distance
#multiplic <- full_sites_14_15_16_sf_UTM |> mutate(multiplic= as.numeric(in_AP)) 
multiplic=ifelse(data_full_sf_UTM$in_AP=="TRUE",-1,1)
data_full_sf_UTM$border_dist <- as.numeric(st_distance(data_full_sf_UTM, AP_Tahuayo_UTM_line) * multiplic )
# print(border_dist)

# convert true false to inside 1, outside 0
data_full_sf_UTM <- data_full_sf_UTM |>
  mutate(in_AP = case_when(
    str_detect(in_AP, "TRUE") ~ 1, # "inside_AP",
    str_detect(in_AP, "FALSE") ~ 0 #"outside_AP"
  )) |> mutate(in_AP=as.factor(in_AP))


hist(data_full_sf_UTM$border_dist)

Prepare the model

TipData in a 3D array

The data must be placed in a three-dimensional array with dimensions corresponding to species, sites, and replicates in that order.

The function sfMsPGOcc

Fits multi-species spatial occupancy models with species correlations (i.e., a spatially-explicit joint species distribution model with imperfect detection). We use Polya-Gamma latent variables and a spatial factor modeling approach. Currently, models are implemented using a Nearest Neighbor Gaussian Process.

Code
# Detection-nondetection data ---------
# Species of interest, can select individually
# curr.sp <- sort(unique(Ecu_14_15_16$.id))# c('BAWW', 'BLJA', 'GCFL')
# sort(names(DetHist_list))
selected.sp <-  c(
"Atelocynus microtis" ,
"Coendou prehensilis" ,
"Cuniculus paca",           
"Dasyprocta fuliginosa",      
"Dasypus sp." ,    
"Didelphis marsupialis",    
"Eira barbara",  
"Herpailurus yagouaroundi",
"Leopardus pardalis",    
"Leopardus tigrinus" ,
"Leopardus wiedii",         
"Mazama americana",
"Mazama nemorivaga",
#"Mitu tuberosum" ,
"Myoprocta pratti",
"Myrmecophaga tridactyla",
"Nasua nasua" ,
# "Mazama americana",         
# "Myotis myotis",           
# "Nasua narica",             
# "Odocoileus virginianus",   
"Panthera onca" ,
# "Procyon cancrivorus" ,
"Pecari tajacu",    
#"Penelope jacquacu" ,
"Priodontes maximus" ,
"Procyon cancrivorous",      
# "Psophia leucoptera",
"Puma concolor" ,
"Puma yagouaroundi",        
# "Rattus rattus" ,
# "Roedor sp.",
# "Sciurus sp.",       
# "Sus scrofa",               
# "Sylvilagus brasiliensis",  
"Tamandua tetradactyla",   
"Tapirus terrestris",
"Tayassu pecari"
#"Tinamus major"            
              )

# y.msom <- y[which(sp.codes %in% selected.sp), , ]
# str(y.msom)

# Use selection
y.selected <- ylist[selected.sp]   

#### three-dimensional array with dimensions corresponding to species, sites, and replicates

# 1. Load the abind library to make arrays easily 
library(abind)
my_array_abind <- abind(y.selected, # start from list
                        along = 3, # 3D array
                        use.first.dimnames=TRUE) # keep names

# Transpose the array to have:
# species, sites, and sampling occasions in that order
# The new order is (3rd dim, 1st dim, 2nd dim)
transposed_array <- aperm(my_array_abind, c(3, 1, 2))

#### site covs
sitecovs <- as.data.frame(st_drop_geometry(
                    data_full_sf_UTM[,5:8]))

 sitecovs[, 1] <- as.vector((sitecovs[,1]))   # scale numeric covariates
 sitecovs[, 1] <- as.numeric((sitecovs[,2]))   # scale numeric covariates
 sitecovs[, 3] <- as.vector((sitecovs[,3]))   # scale numeric covariates
 sitecovs[, 4] <- as.vector((sitecovs[,4]))   # scale numeric covariates
 # sitecovs$fact <- factor(c("A", "A", "B"))    # categorical covariate

names(sitecovs) <- c("elev", "in_AP", "FLII", "border_dist")

# check consistancy equal number of spatial covariates and rows in data
# identical(nrow(ylist[[1]]), nrow(covars)) 

# Base de datos para los análisis -----------------------------------------

# match the names to "y"  "occ.covs" "det.covs" "coords" 
data_list <- list(y = transposed_array, # Historias de detección
                  occ.covs = sitecovs, # covs de sitio
                  det.covs  = list(effort = DetHist_list[[1]]$effort),
                  coords = st_coordinates(data_full_sf_UTM)
                  )  # agregamos el esfuerzo de muestreo como covariable de observación

Running the model

We let spOccupancy set the initial values by default based on the prior distributions.

Code
# Running the model

# 3. 1 Modelo multi-especie  -----------------------------------------

# 2. Model fitting --------------------------------------------------------
# Fit a non-spatial, multi-species occupancy model. 
out <- msPGOcc(occ.formula = ~ scale(elev) +
                               scale(border_dist) + 
                               scale(FLII) , 
               det.formula = ~ scale(effort) , # Ordinal.day + I(Ordinal.day^2) + Year
                 data = data_list, 
                 n.samples = 6000, 
                 n.thin = 10, 
                 n.burn = 1000, 
                 n.chains = 3,
                 n.report = 1000);beep(sound = 4)
----------------------------------------
    Preparing to run the model
----------------------------------------
No prior specified for beta.comm.normal.
Setting prior mean to 0 and prior variance to 2.72
No prior specified for alpha.comm.normal.
Setting prior mean to 0 and prior variance to 2.72
No prior specified for tau.sq.beta.ig.
Setting prior shape to 0.1 and prior scale to 0.1
No prior specified for tau.sq.alpha.ig.
Setting prior shape to 0.1 and prior scale to 0.1
z is not specified in initial values.
Setting initial values based on observed data
beta.comm is not specified in initial values.
Setting initial values to random values from the prior distribution
alpha.comm is not specified in initial values.
Setting initial values to random values from the prior distribution
tau.sq.beta is not specified in initial values.
Setting initial values to random values between 0.5 and 10
tau.sq.alpha is not specified in initial values.
Setting to initial values to random values between 0.5 and 10
beta is not specified in initial values.
Setting initial values to random values from the community-level normal distribution
alpha is not specified in initial values.
Setting initial values to random values from the community-level normal distribution
----------------------------------------
    Model description
----------------------------------------
Multi-species Occupancy Model with Polya-Gamma latent
variable fit with 377 sites and 25 species.

Samples per Chain: 6000 
Burn-in: 1000 
Thinning Rate: 10 
Number of Chains: 3 
Total Posterior Samples: 1500 

Source compiled with OpenMP support and model fit using 1 thread(s).

----------------------------------------
    Chain 1
----------------------------------------
Sampling ... 
Sampled: 1000 of 6000, 16.67%
-------------------------------------------------
Sampled: 2000 of 6000, 33.33%
-------------------------------------------------
Sampled: 3000 of 6000, 50.00%
-------------------------------------------------
Sampled: 4000 of 6000, 66.67%
-------------------------------------------------
Sampled: 5000 of 6000, 83.33%
-------------------------------------------------
Sampled: 6000 of 6000, 100.00%
----------------------------------------
    Chain 2
----------------------------------------
Sampling ... 
Sampled: 1000 of 6000, 16.67%
-------------------------------------------------
Sampled: 2000 of 6000, 33.33%
-------------------------------------------------
Sampled: 3000 of 6000, 50.00%
-------------------------------------------------
Sampled: 4000 of 6000, 66.67%
-------------------------------------------------
Sampled: 5000 of 6000, 83.33%
-------------------------------------------------
Sampled: 6000 of 6000, 100.00%
----------------------------------------
    Chain 3
----------------------------------------
Sampling ... 
Sampled: 1000 of 6000, 16.67%
-------------------------------------------------
Sampled: 2000 of 6000, 33.33%
-------------------------------------------------
Sampled: 3000 of 6000, 50.00%
-------------------------------------------------
Sampled: 4000 of 6000, 66.67%
-------------------------------------------------
Sampled: 5000 of 6000, 83.33%
-------------------------------------------------
Sampled: 6000 of 6000, 100.00%
Code
# Fit a non-spatial, Latent Factor Multi-Species Occupancy Model. 
  out.lfMs <- msPGOcc(occ.formula = ~ scale(elev) +
                               scale(border_dist) + 
                               scale(FLII) , 
               det.formula = ~ scale(effort), # Ordinal.day + I(Ordinal.day^2) + Year
                 data = data_list, 
                 n.omp.threads = 6,
                 n.samples = 6000, 
                 n.factors = 5, # balance of rare sp. and run time
                 n.thin = 10, 
                 n.burn = 1000, 
                 n.chains = 3,
                 n.report = 1000);beep(sound = 4)
----------------------------------------
    Preparing to run the model
----------------------------------------
Warning in msPGOcc(occ.formula = ~scale(elev) + scale(border_dist) +
scale(FLII), : 'n.factors' is not an argument
No prior specified for beta.comm.normal.
Setting prior mean to 0 and prior variance to 2.72
No prior specified for alpha.comm.normal.
Setting prior mean to 0 and prior variance to 2.72
No prior specified for tau.sq.beta.ig.
Setting prior shape to 0.1 and prior scale to 0.1
No prior specified for tau.sq.alpha.ig.
Setting prior shape to 0.1 and prior scale to 0.1
z is not specified in initial values.
Setting initial values based on observed data
beta.comm is not specified in initial values.
Setting initial values to random values from the prior distribution
alpha.comm is not specified in initial values.
Setting initial values to random values from the prior distribution
tau.sq.beta is not specified in initial values.
Setting initial values to random values between 0.5 and 10
tau.sq.alpha is not specified in initial values.
Setting to initial values to random values between 0.5 and 10
beta is not specified in initial values.
Setting initial values to random values from the community-level normal distribution
alpha is not specified in initial values.
Setting initial values to random values from the community-level normal distribution
----------------------------------------
    Model description
----------------------------------------
Multi-species Occupancy Model with Polya-Gamma latent
variable fit with 377 sites and 25 species.

Samples per Chain: 6000 
Burn-in: 1000 
Thinning Rate: 10 
Number of Chains: 3 
Total Posterior Samples: 1500 

Source compiled with OpenMP support and model fit using 6 thread(s).

----------------------------------------
    Chain 1
----------------------------------------
Sampling ... 
Sampled: 1000 of 6000, 16.67%
-------------------------------------------------
Sampled: 2000 of 6000, 33.33%
-------------------------------------------------
Sampled: 3000 of 6000, 50.00%
-------------------------------------------------
Sampled: 4000 of 6000, 66.67%
-------------------------------------------------
Sampled: 5000 of 6000, 83.33%
-------------------------------------------------
Sampled: 6000 of 6000, 100.00%
----------------------------------------
    Chain 2
----------------------------------------
Sampling ... 
Sampled: 1000 of 6000, 16.67%
-------------------------------------------------
Sampled: 2000 of 6000, 33.33%
-------------------------------------------------
Sampled: 3000 of 6000, 50.00%
-------------------------------------------------
Sampled: 4000 of 6000, 66.67%
-------------------------------------------------
Sampled: 5000 of 6000, 83.33%
-------------------------------------------------
Sampled: 6000 of 6000, 100.00%
----------------------------------------
    Chain 3
----------------------------------------
Sampling ... 
Sampled: 1000 of 6000, 16.67%
-------------------------------------------------
Sampled: 2000 of 6000, 33.33%
-------------------------------------------------
Sampled: 3000 of 6000, 50.00%
-------------------------------------------------
Sampled: 4000 of 6000, 66.67%
-------------------------------------------------
Sampled: 5000 of 6000, 83.33%
-------------------------------------------------
Sampled: 6000 of 6000, 100.00%
Code
summary(out, level = 'community')

Call:
msPGOcc(occ.formula = ~scale(elev) + scale(border_dist) + scale(FLII), 
    det.formula = ~scale(effort), data = data_list, n.samples = 6000, 
    n.report = 1000, n.burn = 1000, n.thin = 10, n.chains = 3)

Samples per Chain: 6000
Burn-in: 1000
Thinning Rate: 10
Number of Chains: 3
Total Posterior Samples: 1500
Run Time (min): 6.5557

----------------------------------------
    Community Level
----------------------------------------
Occurrence Means (logit scale): 
                      Mean     SD    2.5%     50%   97.5%   Rhat  ESS
(Intercept)        -1.9029 0.3475 -2.5989 -1.9037 -1.2372 1.0173  294
scale(elev)        -0.1814 0.1342 -0.4492 -0.1844  0.0853 1.0020 1212
scale(border_dist) -0.3751 0.2422 -0.8557 -0.3734  0.0939 1.0030 1044
scale(FLII)         0.3792 0.1245  0.1601  0.3679  0.6505 1.0102  523

Occurrence Variances (logit scale): 
                     Mean     SD   2.5%    50%  97.5%   Rhat ESS
(Intercept)        2.6100 1.0362 1.2049 2.4232 5.2357 1.0048 462
scale(elev)        0.3037 0.1523 0.1146 0.2670 0.6968 1.0087 996
scale(border_dist) 1.2159 0.5216 0.5198 1.1105 2.5792 1.0076 524
scale(FLII)        0.1560 0.1134 0.0349 0.1268 0.4688 1.0217 462

Detection Means (logit scale): 
                 Mean     SD    2.5%     50%   97.5%   Rhat  ESS
(Intercept)   -2.2592 0.2722 -2.8347 -2.2436 -1.7610 1.0201  425
scale(effort)  0.3996 0.0694  0.2665  0.3981  0.5504 1.0188 1301

Detection Variances (logit scale): 
                Mean     SD   2.5%    50%  97.5%   Rhat  ESS
(Intercept)   1.4516 0.6698 0.6129 1.3052 3.2993 1.0879   90
scale(effort) 0.0457 0.0245 0.0163 0.0404 0.1074 1.0114 1136
Code
# Fit a Spatial Factor Multi-Species Occupancy Model
# latent spatial factors.
tictoc::tic()
  out.sp <- sfMsPGOcc(occ.formula = ~ scale(elev) +
                               scale(border_dist) + 
                               scale(FLII) , 
               det.formula = ~ scale(effort), # Ordinal.day + I(Ordinal.day^2) + Year,            
                      data = data_list, 
                      n.omp.threads = 6,
                      n.batch = 600, 
                      batch.length = 25, # iter=600*25
                      n.thin = 10, 
                      n.burn = 5000, 
                      n.chains = 3,
                      NNGP = TRUE,
                      n.factors = 5, # balance of rare sp. and run time
                      n.neighbors = 15,
                      cov.model = 'exponential',
                      n.report = 1000);beep(sound = 4)
----------------------------------------
    Preparing to run the model
----------------------------------------
No prior specified for beta.comm.normal.
Setting prior mean to 0 and prior variance to 2.72
No prior specified for alpha.comm.normal.
Setting prior mean to 0 and prior variance to 2.72
No prior specified for tau.sq.beta.
Using an inverse-Gamma prior with prior shape 0.1 and prior scale 0.1
No prior specified for tau.sq.alpha.
Using an inverse-Gamma prior with prior shape 0.1 and prior scale 0.1
No prior specified for phi.unif.
Setting uniform bounds based on the range of observed spatial coordinates.
z is not specified in initial values.
Setting initial values based on observed data
beta.comm is not specified in initial values.
Setting initial values to random values from the prior distribution
alpha.comm is not specified in initial values.
Setting initial values to random values from the prior distribution
tau.sq.beta is not specified in initial values.
Setting initial values to random values between 0.5 and 10
tau.sq.alpha is not specified in initial values.
Setting initial values to random values between 0.5 and 10
beta is not specified in initial values.
Setting initial values to random values from the community-level normal distribution
alpha is not specified in initial values.
Setting initial values to random values from the community-level normal distribution
phi is not specified in initial values.
Setting initial value to random values from the prior distribution
lambda is not specified in initial values.
Setting initial values of the lower triangle to 0
----------------------------------------
    Building the neighbor list
----------------------------------------
----------------------------------------
Building the neighbors of neighbors list
----------------------------------------
----------------------------------------
    Model description
----------------------------------------
Spatial Factor NNGP Multi-species Occupancy Model with Polya-Gamma latent
variable fit with 377 sites and 25 species.

Samples per chain: 15000 (600 batches of length 25)
Burn-in: 5000 
Thinning Rate: 10 
Number of Chains: 3 
Total Posterior Samples: 3000 

Using the exponential spatial correlation model.

Using 5 latent spatial factors.
Using 15 nearest neighbors.

Source compiled with OpenMP support and model fit using 6 thread(s).

Adaptive Metropolis with target acceptance rate: 43.0
----------------------------------------
    Chain 1
----------------------------------------
Sampling ... 
Batch: 600 of 600, 100.00%
----------------------------------------
    Chain 2
----------------------------------------
Sampling ... 
Batch: 600 of 600, 100.00%
----------------------------------------
    Chain 3
----------------------------------------
Sampling ... 
Batch: 600 of 600, 100.00%
Code
tictoc::toc()
1656.03 sec elapsed
Code
#########################
tictoc::tic()
  out.sp.fac <- sfMsPGOcc(occ.formula = ~ scale(elev) +
                               factor(in_AP) + 
                               scale(FLII) , 
               det.formula = ~ scale(effort), # Ordinal.day + I(Ordinal.day^2) + Year,            
                      data = data_list, 
                      n.omp.threads = 6,
                      n.batch = 600, 
                      batch.length = 25, # iter=600*25
                      n.thin = 10, 
                      n.burn = 5000, 
                      n.chains = 3,
                      NNGP = TRUE,
                      n.factors = 5, # balance of rare sp. and run time
                      n.neighbors = 15,
                      cov.model = 'exponential',
                      n.report = 1000);beep(sound = 4)
----------------------------------------
    Preparing to run the model
----------------------------------------
No prior specified for beta.comm.normal.
Setting prior mean to 0 and prior variance to 2.72
No prior specified for alpha.comm.normal.
Setting prior mean to 0 and prior variance to 2.72
No prior specified for tau.sq.beta.
Using an inverse-Gamma prior with prior shape 0.1 and prior scale 0.1
No prior specified for tau.sq.alpha.
Using an inverse-Gamma prior with prior shape 0.1 and prior scale 0.1
No prior specified for phi.unif.
Setting uniform bounds based on the range of observed spatial coordinates.
z is not specified in initial values.
Setting initial values based on observed data
beta.comm is not specified in initial values.
Setting initial values to random values from the prior distribution
alpha.comm is not specified in initial values.
Setting initial values to random values from the prior distribution
tau.sq.beta is not specified in initial values.
Setting initial values to random values between 0.5 and 10
tau.sq.alpha is not specified in initial values.
Setting initial values to random values between 0.5 and 10
beta is not specified in initial values.
Setting initial values to random values from the community-level normal distribution
alpha is not specified in initial values.
Setting initial values to random values from the community-level normal distribution
phi is not specified in initial values.
Setting initial value to random values from the prior distribution
lambda is not specified in initial values.
Setting initial values of the lower triangle to 0
----------------------------------------
    Building the neighbor list
----------------------------------------
----------------------------------------
Building the neighbors of neighbors list
----------------------------------------
----------------------------------------
    Model description
----------------------------------------
Spatial Factor NNGP Multi-species Occupancy Model with Polya-Gamma latent
variable fit with 377 sites and 25 species.

Samples per chain: 15000 (600 batches of length 25)
Burn-in: 5000 
Thinning Rate: 10 
Number of Chains: 3 
Total Posterior Samples: 3000 

Using the exponential spatial correlation model.

Using 5 latent spatial factors.
Using 15 nearest neighbors.

Source compiled with OpenMP support and model fit using 6 thread(s).

Adaptive Metropolis with target acceptance rate: 43.0
----------------------------------------
    Chain 1
----------------------------------------
Sampling ... 
Batch: 600 of 600, 100.00%
----------------------------------------
    Chain 2
----------------------------------------
Sampling ... 
Batch: 600 of 600, 100.00%
----------------------------------------
    Chain 3
----------------------------------------
Sampling ... 
Batch: 600 of 600, 100.00%
Code
tictoc::toc()
1603.01 sec elapsed
Code
# tictoc::tic()
#   out.sp.gaus <- sfMsPGOcc(occ.formula = ~ scale(border_dist) , 
#                            det.formula = ~ scale(effort), # Ordinal.day + I(Ordinal.day^2) + Year,              
#                            data = data_list, 
#                            n.batch = 400, 
#                            batch.length = 25,
#                            n.thin = 5, 
#                            n.burn = 5000, 
#                            n.chains = 1,
#                            NNGP = TRUE,
#                            n.factors = 5,
#                            n.neighbors = 15,
#                            cov.model = 'gaussian',
#                            n.report = 100);beep(sound = 4)
# tictoc::toc()

# save the results to not run again
# save(out, file="C:/CodigoR/Occu_APs_all/blog/2025-10-15-analysis/result/result_2.R") # guardamos los resultados para no correr de nuevo
# save the results to not run again
# save(out.sp, file="C:/CodigoR/Occu_APs_all/blog/2025-10-15-analysis/result/sp_result_2.R") # guardamos los resultados para no correr de nuevo

# save(out.lfMs, file="C:/CodigoR/Occu_APs_all/blog/2025-10-15-analysis/result/lfms_result_2.R") # guardamos los resultados para no correr de nuevo


# load("C:/CodigoR/Occu_APs_all/blog/2025-10-15-analysis/result/sp_result_2.R")
# summary(fit.commu)

Model validation

We next perform a posterior predictive check using the Freeman-Tukey statistic grouping the data by sites. We summarize the posterior predictive check with the summary() function, which reports a Bayesian p-value. A Bayesian p-value that hovers around 0.5 indicates adequate model fit, while values less than 0.1 or greater than 0.9 suggest our model does not fit the data well (Hobbs and Hooten 2015). As always with a simulation-based analysis using MCMC, you will get numerically slightly different values.

Code
# 3. Model validation -----------------------------------------------------
# Perform a posterior predictive check to assess model fit. 
ppc.out <- ppcOcc(out, fit.stat = 'freeman-tukey', 
                  group = 1)
ppc.out.lfMs <- ppcOcc(out.lfMs, fit.stat = 'freeman-tukey', 
                  group = 1)
ppc.out.sp <- ppcOcc(out.sp, fit.stat = 'freeman-tukey',
                     group = 1)

# Calculate a Bayesian p-value as a simple measure of Goodness of Fit.
# Bayesian p-values between 0.1 and 0.9 indicate adequate model fit. 
summary(ppc.out)

Call:
ppcOcc(object = out, fit.stat = "freeman-tukey", group = 1)

Samples per Chain: 6000
Burn-in: 1000
Thinning Rate: 10
Number of Chains: 3
Total Posterior Samples: 1500

----------------------------------------
    Community Level
----------------------------------------
Bayesian p-value:  0.3599 

----------------------------------------
    Species Level
----------------------------------------
Atelocynus microtis Bayesian p-value: 0.36
Coendou prehensilis Bayesian p-value: 0.6633
Cuniculus paca Bayesian p-value: 0.0033
Dasyprocta fuliginosa Bayesian p-value: 7e-04
Dasypus sp. Bayesian p-value: 0.1627
Didelphis marsupialis Bayesian p-value: 0.4347
Eira barbara Bayesian p-value: 0.6893
Herpailurus yagouaroundi Bayesian p-value: 0.5673
Leopardus pardalis Bayesian p-value: 0.3153
Leopardus tigrinus Bayesian p-value: 0.2173
Leopardus wiedii Bayesian p-value: 0.4387
Mazama americana Bayesian p-value: 0.0547
Mazama nemorivaga Bayesian p-value: 0.49
Myoprocta pratti Bayesian p-value: 0.2433
Myrmecophaga tridactyla Bayesian p-value: 0.3927
Nasua nasua Bayesian p-value: 0.4953
Panthera onca Bayesian p-value: 0.4613
Pecari tajacu Bayesian p-value: 0.1193
Priodontes maximus Bayesian p-value: 0.584
Procyon cancrivorous Bayesian p-value: 0.528
Puma concolor Bayesian p-value: 0.346
Puma yagouaroundi Bayesian p-value: 0.7087
Tamandua tetradactyla Bayesian p-value: 0.41
Tapirus terrestris Bayesian p-value: 0.1007
Tayassu pecari Bayesian p-value: 0.2107
Fit statistic:  freeman-tukey 
Code
summary(ppc.out.lfMs)

Call:
ppcOcc(object = out.lfMs, fit.stat = "freeman-tukey", group = 1)

Samples per Chain: 6000
Burn-in: 1000
Thinning Rate: 10
Number of Chains: 3
Total Posterior Samples: 1500

----------------------------------------
    Community Level
----------------------------------------
Bayesian p-value:  0.3617 

----------------------------------------
    Species Level
----------------------------------------
Atelocynus microtis Bayesian p-value: 0.3667
Coendou prehensilis Bayesian p-value: 0.628
Cuniculus paca Bayesian p-value: 0.0033
Dasyprocta fuliginosa Bayesian p-value: 0.0013
Dasypus sp. Bayesian p-value: 0.168
Didelphis marsupialis Bayesian p-value: 0.448
Eira barbara Bayesian p-value: 0.67
Herpailurus yagouaroundi Bayesian p-value: 0.6
Leopardus pardalis Bayesian p-value: 0.3113
Leopardus tigrinus Bayesian p-value: 0.2227
Leopardus wiedii Bayesian p-value: 0.4307
Mazama americana Bayesian p-value: 0.0573
Mazama nemorivaga Bayesian p-value: 0.488
Myoprocta pratti Bayesian p-value: 0.242
Myrmecophaga tridactyla Bayesian p-value: 0.3833
Nasua nasua Bayesian p-value: 0.498
Panthera onca Bayesian p-value: 0.4667
Pecari tajacu Bayesian p-value: 0.1347
Priodontes maximus Bayesian p-value: 0.6133
Procyon cancrivorous Bayesian p-value: 0.518
Puma concolor Bayesian p-value: 0.356
Puma yagouaroundi Bayesian p-value: 0.6827
Tamandua tetradactyla Bayesian p-value: 0.426
Tapirus terrestris Bayesian p-value: 0.1113
Tayassu pecari Bayesian p-value: 0.214
Fit statistic:  freeman-tukey 
Code
summary(ppc.out.sp)

Call:
ppcOcc(object = out.sp, fit.stat = "freeman-tukey", group = 1)

Samples per Chain: 15000
Burn-in: 5000
Thinning Rate: 10
Number of Chains: 3
Total Posterior Samples: 3000

----------------------------------------
    Community Level
----------------------------------------
Bayesian p-value:  0.3452 

----------------------------------------
    Species Level
----------------------------------------
Atelocynus microtis Bayesian p-value: 0.3423
Coendou prehensilis Bayesian p-value: 0.6207
Cuniculus paca Bayesian p-value: 0.0053
Dasyprocta fuliginosa Bayesian p-value: 0.0033
Dasypus sp. Bayesian p-value: 0.1627
Didelphis marsupialis Bayesian p-value: 0.3993
Eira barbara Bayesian p-value: 0.706
Herpailurus yagouaroundi Bayesian p-value: 0.5977
Leopardus pardalis Bayesian p-value: 0.2573
Leopardus tigrinus Bayesian p-value: 0.2633
Leopardus wiedii Bayesian p-value: 0.356
Mazama americana Bayesian p-value: 0.0467
Mazama nemorivaga Bayesian p-value: 0.644
Myoprocta pratti Bayesian p-value: 0.2513
Myrmecophaga tridactyla Bayesian p-value: 0.1947
Nasua nasua Bayesian p-value: 0.3583
Panthera onca Bayesian p-value: 0.5183
Pecari tajacu Bayesian p-value: 0.1087
Priodontes maximus Bayesian p-value: 0.5727
Procyon cancrivorous Bayesian p-value: 0.496
Puma concolor Bayesian p-value: 0.3523
Puma yagouaroundi Bayesian p-value: 0.6723
Tamandua tetradactyla Bayesian p-value: 0.4233
Tapirus terrestris Bayesian p-value: 0.0617
Tayassu pecari Bayesian p-value: 0.2153
Fit statistic:  freeman-tukey 
Important

A Bayesian p-value that around 0.5 indicates adequate model fit, while values less than 0.1 or greater than 0.9 suggest our model does not fit the data well.

Fit plot

Code
#### fit plot
ppc.df <- data.frame(fit = ppc.out.sp$fit.y, 
                     fit.rep = ppc.out.sp$fit.y.rep, 
                     color = 'lightskyblue1')

ppc.df$color[ppc.df$fit.rep.1 > ppc.df$fit.1] <- 'lightsalmon'
plot(ppc.df$fit.1, ppc.df$fit.rep.1, bg = ppc.df$color, pch = 21, 
     ylab = 'Fit', xlab = 'True')
lines(ppc.df$fit.1, ppc.df$fit.1, col = 'black')

The most symmetrical, better fit!

The most symmetrical, better fit!

Model comparison

Code
# 4. Model comparison -----------------------------------------------------
# Compute Widely Applicable Information Criterion (WAIC)
# Lower values indicate better model fit. 
waicOcc(out)
      elpd         pD       WAIC 
-7380.8846   106.2362 14974.2415 
Code
waicOcc(out.lfMs)
     elpd        pD      WAIC 
-7380.445   105.455 14971.800 
Code
waicOcc(out.sp)
      elpd         pD       WAIC 
-6584.7663   639.1395 14447.8115 
Code
waicOcc(out.sp.fac)
      elpd         pD       WAIC 
-6601.3076   633.0254 14468.6660 

Model comparison as table

Code
# Here we summarize the spatial factor loadings
# summary(out.sp$lambda.samples)

# Resultados --------------------------------------------------------------
# Extraemos lo tabla de valores estimados
modresult <- cbind(as.data.frame(waicOcc(out)),
                  as.data.frame(waicOcc(out.sp)),
                  as.data.frame(waicOcc(out.lfMs)),
                  as.data.frame(waicOcc(out.sp.fac))
                  #as.data.frame(waicOcc(out.sp.gaus))
                  )
# View(modresult)
modresult_sorted <- as.data.frame(t(modresult)) |> 
  arrange(WAIC) # sort by
  
DT::datatable(modresult_sorted)
Important

Lower values in WAIC indicate better model fit.

WAIC is the Widely Applicable Information Criterion (Watanabe 2010).

Posterior Summary

Code
# 5. Posterior summaries --------------------------------------------------
# Concise summary of main parameter estimates
summary(out.sp, level = 'community')

Call:
sfMsPGOcc(occ.formula = ~scale(elev) + scale(border_dist) + scale(FLII), 
    det.formula = ~scale(effort), data = data_list, cov.model = "exponential", 
    NNGP = TRUE, n.neighbors = 15, n.factors = 5, n.batch = 600, 
    batch.length = 25, n.omp.threads = 6, n.report = 1000, n.burn = 5000, 
    n.thin = 10, n.chains = 3)

Samples per Chain: 15000
Burn-in: 5000
Thinning Rate: 10
Number of Chains: 3
Total Posterior Samples: 3000
Run Time (min): 27.6002

----------------------------------------
    Community Level
----------------------------------------
Occurrence Means (logit scale): 
                      Mean     SD    2.5%     50%   97.5%   Rhat ESS
(Intercept)        -2.5811 0.5578 -3.6409 -2.5831 -1.4618 1.1491 294
scale(elev)        -0.0702 0.2130 -0.4974 -0.0660  0.3471 1.3555 182
scale(border_dist) -0.5060 0.3787 -1.2282 -0.5069  0.2564 1.1918 263
scale(FLII)         0.5682 0.2240  0.1770  0.5484  1.0746 1.0296 576

Occurrence Variances (logit scale): 
                     Mean     SD   2.5%    50%   97.5%   Rhat ESS
(Intercept)        6.7121 2.6922 3.1117 6.1805 13.7539 1.0980 225
scale(elev)        0.5032 0.2717 0.1596 0.4467  1.2203 1.2361 445
scale(border_dist) 2.3372 1.2231 0.7815 2.0815  5.3460 1.6710  85
scale(FLII)        0.4413 0.3797 0.0676 0.3291  1.4933 1.1006 334

Detection Means (logit scale): 
                 Mean     SD    2.5%     50%   97.5%   Rhat  ESS
(Intercept)   -2.2938 0.2732 -2.8719 -2.2873 -1.7772 1.0570  431
scale(effort)  0.3969 0.0657  0.2703  0.3959  0.5319 1.0066 2542

Detection Variances (logit scale): 
                Mean     SD   2.5%    50%  97.5%   Rhat  ESS
(Intercept)   1.5284 0.6143 0.7019 1.4172 3.0417 1.1323  236
scale(effort) 0.0466 0.0262 0.0168 0.0401 0.1169 1.0062 2465

----------------------------------------
    Spatial Covariance
----------------------------------------
         Mean     SD   2.5%     50%   97.5%   Rhat  ESS
phi-1 10.2741 9.0131 0.0000  9.1862 26.4475 2.0409   15
phi-2  8.8879 9.1384 0.0000  6.2172 26.3255 3.9448    8
phi-3 13.3497 8.0913 0.4024 13.1939 26.6927 1.0017 2827
phi-4  8.9982 9.1869 0.0000  6.5632 26.5090 4.0048   13
phi-5 13.1044 8.0811 0.3504 12.7752 26.9119 1.0093 2688
Code
summary(out.sp, level = 'species')

Call:
sfMsPGOcc(occ.formula = ~scale(elev) + scale(border_dist) + scale(FLII), 
    det.formula = ~scale(effort), data = data_list, cov.model = "exponential", 
    NNGP = TRUE, n.neighbors = 15, n.factors = 5, n.batch = 600, 
    batch.length = 25, n.omp.threads = 6, n.report = 1000, n.burn = 5000, 
    n.thin = 10, n.chains = 3)

Samples per Chain: 15000
Burn-in: 5000
Thinning Rate: 10
Number of Chains: 3
Total Posterior Samples: 3000
Run Time (min): 27.6002

----------------------------------------
    Species Level
----------------------------------------
Occurrence (logit scale): 
                                               Mean     SD    2.5%     50%
(Intercept)-Atelocynus microtis             -2.6153 0.8089 -3.9386 -2.7229
(Intercept)-Coendou prehensilis             -5.2450 1.4270 -8.0714 -5.2364
(Intercept)-Cuniculus paca                   0.1981 0.3781 -0.3381  0.1214
(Intercept)-Dasyprocta fuliginosa           -0.8368 0.9209 -2.2452 -0.9624
(Intercept)-Dasypus sp.                     -5.2605 1.0352 -7.6076 -5.1336
(Intercept)-Didelphis marsupialis           -4.6584 0.9903 -6.8930 -4.5564
(Intercept)-Eira barbara                    -3.0129 0.8550 -4.7586 -2.9941
(Intercept)-Herpailurus yagouaroundi        -4.1566 1.5690 -7.1743 -4.1608
(Intercept)-Leopardus pardalis              -1.2949 0.4583 -2.3535 -1.2543
(Intercept)-Leopardus tigrinus              -6.9134 1.3212 -9.9445 -6.7589
(Intercept)-Leopardus wiedii                -2.8619 1.5031 -5.2224 -3.0929
(Intercept)-Mazama americana                -3.6184 1.0031 -5.6170 -3.6143
(Intercept)-Mazama nemorivaga               -5.6025 1.1266 -8.1457 -5.5012
(Intercept)-Myoprocta pratti                -4.3969 0.9487 -6.4516 -4.3482
(Intercept)-Myrmecophaga tridactyla         -1.1476 1.0822 -2.8958 -1.3263
(Intercept)-Nasua nasua                     -2.1519 1.2004 -4.5390 -2.1393
(Intercept)-Panthera onca                   -0.9057 0.7866 -2.3696 -0.9471
(Intercept)-Pecari tajacu                    1.6632 0.6202  0.6276  1.6143
(Intercept)-Priodontes maximus              -0.6248 1.5891 -3.3309 -0.7481
(Intercept)-Procyon cancrivorous            -5.1325 1.6958 -8.5065 -5.0925
(Intercept)-Puma concolor                   -2.3471 0.5854 -3.5711 -2.3173
(Intercept)-Puma yagouaroundi               -4.9971 1.7958 -8.4485 -5.0558
(Intercept)-Tamandua tetradactyla           -4.2122 1.3440 -6.6060 -4.2822
(Intercept)-Tapirus terrestris               0.4987 0.3676 -0.1138  0.4646
(Intercept)-Tayassu pecari                  -0.8244 0.4445 -1.7043 -0.8422
scale(elev)-Atelocynus microtis             -0.8088 0.4670 -1.8290 -0.7828
scale(elev)-Coendou prehensilis              0.2174 0.6289 -0.9762  0.2018
scale(elev)-Cuniculus paca                  -0.3337 0.3120 -0.9253 -0.3393
scale(elev)-Dasyprocta fuliginosa            0.8564 0.6117 -0.4495  0.8676
scale(elev)-Dasypus sp.                     -0.3190 0.3107 -0.9639 -0.3043
scale(elev)-Didelphis marsupialis            0.0811 0.4866 -0.8003  0.0638
scale(elev)-Eira barbara                    -0.8970 0.4617 -1.8755 -0.8754
scale(elev)-Herpailurus yagouaroundi        -0.3839 0.6989 -1.8121 -0.3817
scale(elev)-Leopardus pardalis               0.0691 0.3566 -0.5983  0.0623
scale(elev)-Leopardus tigrinus              -0.2048 0.6492 -1.5262 -0.1947
scale(elev)-Leopardus wiedii                -0.1760 0.5291 -1.2246 -0.1678
scale(elev)-Mazama americana                 1.1180 0.5021  0.1943  1.1027
scale(elev)-Mazama nemorivaga                0.5103 0.4150 -0.2520  0.4842
scale(elev)-Myoprocta pratti                 0.1555 0.5844 -0.9579  0.1202
scale(elev)-Myrmecophaga tridactyla         -0.4802 0.4816 -1.5105 -0.4633
scale(elev)-Nasua nasua                     -0.0350 0.5775 -1.1304 -0.0450
scale(elev)-Panthera onca                    0.0381 0.4432 -0.8468  0.0439
scale(elev)-Pecari tajacu                    0.3581 0.3870 -0.5097  0.3779
scale(elev)-Priodontes maximus              -0.3174 0.5590 -1.4752 -0.2946
scale(elev)-Procyon cancrivorous            -0.2313 0.5088 -1.2866 -0.2204
scale(elev)-Puma concolor                   -0.2751 0.4712 -1.1891 -0.2825
scale(elev)-Puma yagouaroundi               -0.4262 0.5749 -1.6096 -0.4104
scale(elev)-Tamandua tetradactyla            0.1720 0.5748 -0.9236  0.1621
scale(elev)-Tapirus terrestris               0.1498 0.3277 -0.4768  0.1518
scale(elev)-Tayassu pecari                  -0.6515 0.3481 -1.3747 -0.6326
scale(border_dist)-Atelocynus microtis      -0.0541 0.5242 -1.1469 -0.0516
scale(border_dist)-Coendou prehensilis      -0.8382 1.1084 -3.1535 -0.7716
scale(border_dist)-Cuniculus paca           -1.2245 0.4481 -1.9988 -1.2691
scale(border_dist)-Dasyprocta fuliginosa    -0.8135 1.2242 -2.6210 -1.0150
scale(border_dist)-Dasypus sp.              -3.6272 1.1684 -5.9641 -3.6004
scale(border_dist)-Didelphis marsupialis     1.1618 0.7118 -0.4912  1.2047
scale(border_dist)-Eira barbara             -1.9139 0.6798 -3.3124 -1.8707
scale(border_dist)-Herpailurus yagouaroundi  0.0733 1.2443 -2.2870  0.0008
scale(border_dist)-Leopardus pardalis        1.3183 0.4831  0.4405  1.2827
scale(border_dist)-Leopardus tigrinus       -0.1020 1.0474 -2.2482 -0.0906
scale(border_dist)-Leopardus wiedii          0.5960 0.7396 -0.8069  0.5416
scale(border_dist)-Mazama americana          0.7127 0.5172 -0.4396  0.7420
scale(border_dist)-Mazama nemorivaga        -3.0387 1.1490 -5.4837 -2.9648
scale(border_dist)-Myoprocta pratti         -0.7185 0.9994 -2.6765 -0.7250
scale(border_dist)-Myrmecophaga tridactyla  -0.0639 0.6656 -1.2232 -0.1079
scale(border_dist)-Nasua nasua              -1.3143 0.8124 -3.1026 -1.2545
scale(border_dist)-Panthera onca             0.6732 0.5943 -0.3940  0.6398
scale(border_dist)-Pecari tajacu            -0.3554 0.6810 -1.4189 -0.4631
scale(border_dist)-Priodontes maximus        0.3764 0.8921 -1.1230  0.2862
scale(border_dist)-Procyon cancrivorous     -1.6297 1.0049 -3.8581 -1.5348
scale(border_dist)-Puma concolor            -0.0874 0.5740 -1.1142 -0.1281
scale(border_dist)-Puma yagouaroundi        -1.5145 1.1318 -3.9415 -1.3775
scale(border_dist)-Tamandua tetradactyla    -0.7083 0.9067 -2.5997 -0.6835
scale(border_dist)-Tapirus terrestris       -0.1681 0.4085 -0.8933 -0.1977
scale(border_dist)-Tayassu pecari            0.2989 0.4306 -0.4350  0.2563
scale(FLII)-Atelocynus microtis              0.0039 0.3959 -0.8856  0.0244
scale(FLII)-Coendou prehensilis              0.5747 0.6694 -0.6203  0.5359
scale(FLII)-Cuniculus paca                   0.0260 0.2096 -0.4024  0.0223
scale(FLII)-Dasyprocta fuliginosa           -0.0968 0.3538 -0.8178 -0.0910
scale(FLII)-Dasypus sp.                      0.5464 0.5560 -0.4760  0.5106
scale(FLII)-Didelphis marsupialis            0.9554 0.5184  0.1247  0.8867
scale(FLII)-Eira barbara                     0.5614 0.5692 -0.4884  0.5256
scale(FLII)-Herpailurus yagouaroundi         0.4829 0.6155 -0.6918  0.4655
scale(FLII)-Leopardus pardalis               0.7975 0.3288  0.2222  0.7704
scale(FLII)-Leopardus tigrinus               0.6053 0.6248 -0.4873  0.5479
scale(FLII)-Leopardus wiedii                 0.5598 0.5566 -0.5279  0.5355
scale(FLII)-Mazama americana                 0.4153 0.2846 -0.0951  0.4034
scale(FLII)-Mazama nemorivaga                0.7418 0.6694 -0.3778  0.6566
scale(FLII)-Myoprocta pratti                 0.5863 0.5225 -0.3691  0.5544
scale(FLII)-Myrmecophaga tridactyla          0.1768 0.4518 -0.7456  0.1846
scale(FLII)-Nasua nasua                      0.8707 0.6798 -0.2158  0.7807
scale(FLII)-Panthera onca                    1.2138 0.6609  0.2302  1.1032
scale(FLII)-Pecari tajacu                    0.2090 0.2580 -0.2851  0.2069
scale(FLII)-Priodontes maximus               0.1285 0.5007 -0.9131  0.1449
scale(FLII)-Procyon cancrivorous             0.7006 0.6627 -0.4530  0.6456
scale(FLII)-Puma concolor                    1.4454 0.7656  0.3267  1.3238
scale(FLII)-Puma yagouaroundi                0.6376 0.6855 -0.6583  0.5960
scale(FLII)-Tamandua tetradactyla            0.5836 0.6147 -0.5227  0.5556
scale(FLII)-Tapirus terrestris               0.5529 0.2731  0.0771  0.5292
scale(FLII)-Tayassu pecari                   1.0465 0.4320  0.3424  1.0021
                                              97.5%   Rhat  ESS
(Intercept)-Atelocynus microtis             -0.7635 1.0295  201
(Intercept)-Coendou prehensilis             -2.5356 1.0484  202
(Intercept)-Cuniculus paca                   1.1509 3.0565    7
(Intercept)-Dasyprocta fuliginosa            1.5250 2.4474    8
(Intercept)-Dasypus sp.                     -3.5548 1.2936  217
(Intercept)-Didelphis marsupialis           -2.9683 1.1490  149
(Intercept)-Eira barbara                    -1.3977 1.0035  323
(Intercept)-Herpailurus yagouaroundi        -0.9840 1.3578  110
(Intercept)-Leopardus pardalis              -0.4762 1.0643  529
(Intercept)-Leopardus tigrinus              -4.6804 1.0941  290
(Intercept)-Leopardus wiedii                 1.0111 1.2508   77
(Intercept)-Mazama americana                -1.9450 2.6103   19
(Intercept)-Mazama nemorivaga               -3.6932 1.4610  203
(Intercept)-Myoprocta pratti                -2.6218 1.2596   65
(Intercept)-Myrmecophaga tridactyla          1.4784 1.0693  141
(Intercept)-Nasua nasua                      0.1094 1.2773  167
(Intercept)-Panthera onca                    0.7904 1.0407  269
(Intercept)-Pecari tajacu                    3.0897 1.1372   41
(Intercept)-Priodontes maximus               2.9197 1.0596   73
(Intercept)-Procyon cancrivorous            -1.4863 1.1385  120
(Intercept)-Puma concolor                   -1.2064 1.1739  156
(Intercept)-Puma yagouaroundi               -1.3053 1.3033  113
(Intercept)-Tamandua tetradactyla           -1.3528 1.0245  181
(Intercept)-Tapirus terrestris               1.3287 1.0319   62
(Intercept)-Tayassu pecari                   0.0752 1.2008   82
scale(elev)-Atelocynus microtis              0.0368 1.1409 1332
scale(elev)-Coendou prehensilis              1.4874 1.1753 1127
scale(elev)-Cuniculus paca                   0.2753 2.0216   26
scale(elev)-Dasyprocta fuliginosa            2.0496 2.9744   10
scale(elev)-Dasypus sp.                      0.2504 1.0349 1466
scale(elev)-Didelphis marsupialis            1.1288 1.2596  224
scale(elev)-Eira barbara                    -0.0484 1.0035 1122
scale(elev)-Herpailurus yagouaroundi         0.9607 1.2408  288
scale(elev)-Leopardus pardalis               0.7829 1.3257  237
scale(elev)-Leopardus tigrinus               1.0218 1.1337  647
scale(elev)-Leopardus wiedii                 0.8635 1.0180 1250
scale(elev)-Mazama americana                 2.1229 2.4306   20
scale(elev)-Mazama nemorivaga                1.3729 1.2284  263
scale(elev)-Myoprocta pratti                 1.3474 1.6501   99
scale(elev)-Myrmecophaga tridactyla          0.4124 1.0423 1359
scale(elev)-Nasua nasua                      1.1907 1.0156  625
scale(elev)-Panthera onca                    0.9100 1.1330  575
scale(elev)-Pecari tajacu                    1.0645 1.6922   41
scale(elev)-Priodontes maximus               0.7242 1.1964  552
scale(elev)-Procyon cancrivorous             0.7158 1.0028 1341
scale(elev)-Puma concolor                    0.6380 2.0087   25
scale(elev)-Puma yagouaroundi                0.6494 1.0113 1057
scale(elev)-Tamandua tetradactyla            1.3146 1.0591 1440
scale(elev)-Tapirus terrestris               0.8026 1.4634   76
scale(elev)-Tayassu pecari                  -0.0070 1.1880  144
scale(border_dist)-Atelocynus microtis       0.9977 1.2051  145
scale(border_dist)-Coendou prehensilis       1.1827 1.2918  397
scale(border_dist)-Cuniculus paca           -0.0954 1.8892   16
scale(border_dist)-Dasyprocta fuliginosa     2.8943 3.1187    8
scale(border_dist)-Dasypus sp.              -1.4796 2.2481   48
scale(border_dist)-Didelphis marsupialis     2.4433 1.4870   21
scale(border_dist)-Eira barbara             -0.6951 1.2598  369
scale(border_dist)-Herpailurus yagouaroundi  2.7352 1.5528   87
scale(border_dist)-Leopardus pardalis        2.3691 1.0503  434
scale(border_dist)-Leopardus tigrinus        1.9136 1.0977  457
scale(border_dist)-Leopardus wiedii          2.2239 1.0353  320
scale(border_dist)-Mazama americana          1.6647 1.0676   48
scale(border_dist)-Mazama nemorivaga        -1.0431 1.3753  216
scale(border_dist)-Myoprocta pratti          1.3776 1.8818   33
scale(border_dist)-Myrmecophaga tridactyla   1.5272 1.0232  471
scale(border_dist)-Nasua nasua               0.0982 1.2452  251
scale(border_dist)-Panthera onca             1.9209 1.1004  529
scale(border_dist)-Pecari tajacu             1.5624 2.2652   12
scale(border_dist)-Priodontes maximus        2.4967 1.4539  133
scale(border_dist)-Procyon cancrivorous      0.1141 1.1807  367
scale(border_dist)-Puma concolor             1.2429 1.4450   23
scale(border_dist)-Puma yagouaroundi         0.4363 1.0478  323
scale(border_dist)-Tamandua tetradactyla     0.9602 1.0836  443
scale(border_dist)-Tapirus terrestris        0.7550 1.4398   36
scale(border_dist)-Tayassu pecari            1.2767 1.4242   35
scale(FLII)-Atelocynus microtis              0.7375 1.0832  648
scale(FLII)-Coendou prehensilis              2.0742 1.0384  779
scale(FLII)-Cuniculus paca                   0.4361 1.1080  774
scale(FLII)-Dasyprocta fuliginosa            0.5912 1.2150  239
scale(FLII)-Dasypus sp.                      1.7562 1.0050 1643
scale(FLII)-Didelphis marsupialis            2.0892 1.0844  556
scale(FLII)-Eira barbara                     1.7700 1.0058  855
scale(FLII)-Herpailurus yagouaroundi         1.8040 1.0097  622
scale(FLII)-Leopardus pardalis               1.4901 1.0284 1122
scale(FLII)-Leopardus tigrinus               2.0290 1.0053 1131
scale(FLII)-Leopardus wiedii                 1.6837 1.0082  788
scale(FLII)-Mazama americana                 0.9932 1.0936  902
scale(FLII)-Mazama nemorivaga                2.3389 1.0051  981
scale(FLII)-Myoprocta pratti                 1.7537 1.0467 1420
scale(FLII)-Myrmecophaga tridactyla          1.0483 1.0110  770
scale(FLII)-Nasua nasua                      2.5374 1.0348  522
scale(FLII)-Panthera onca                    2.8328 1.0788  495
scale(FLII)-Pecari tajacu                    0.7359 1.1168  387
scale(FLII)-Priodontes maximus               1.0984 1.1359  663
scale(FLII)-Procyon cancrivorous             2.1368 1.0118  748
scale(FLII)-Puma concolor                    3.3019 1.0751  398
scale(FLII)-Puma yagouaroundi                2.1709 1.0097  738
scale(FLII)-Tamandua tetradactyla            1.9349 1.0067  911
scale(FLII)-Tapirus terrestris               1.1668 1.0043 1540
scale(FLII)-Tayassu pecari                   2.0604 1.0164  821

Detection (logit scale): 
                                          Mean     SD    2.5%     50%   97.5%
(Intercept)-Atelocynus microtis        -2.9072 0.6139 -4.2090 -2.8676 -1.8285
(Intercept)-Coendou prehensilis        -3.5512 1.0884 -5.7978 -3.4789 -1.6037
(Intercept)-Cuniculus paca             -0.8278 0.0651 -0.9561 -0.8271 -0.7000
(Intercept)-Dasyprocta fuliginosa      -0.3834 0.0750 -0.5335 -0.3820 -0.2391
(Intercept)-Dasypus sp.                -1.5314 0.1247 -1.7893 -1.5299 -1.2985
(Intercept)-Didelphis marsupialis      -2.1551 0.3753 -2.9213 -2.1387 -1.4803
(Intercept)-Eira barbara               -2.9674 0.3218 -3.5983 -2.9641 -2.3575
(Intercept)-Herpailurus yagouaroundi   -3.4077 0.8330 -5.1335 -3.3814 -1.9007
(Intercept)-Leopardus pardalis         -1.8578 0.1636 -2.1829 -1.8558 -1.5507
(Intercept)-Leopardus tigrinus         -1.2614 0.9529 -3.3237 -1.2079  0.4500
(Intercept)-Leopardus wiedii           -3.3734 0.7484 -4.8681 -3.3119 -2.0872
(Intercept)-Mazama americana           -1.0921 0.1167 -1.3284 -1.0918 -0.8673
(Intercept)-Mazama nemorivaga          -2.0089 0.1830 -2.3685 -2.0064 -1.6571
(Intercept)-Myoprocta pratti           -1.5573 0.2799 -2.1324 -1.5505 -1.0325
(Intercept)-Myrmecophaga tridactyla    -3.1545 0.4611 -4.0113 -3.1523 -2.2739
(Intercept)-Nasua nasua                -3.6055 0.3932 -4.3021 -3.6386 -2.7791
(Intercept)-Panthera onca              -2.7170 0.2697 -3.2441 -2.7149 -2.1963
(Intercept)-Pecari tajacu              -1.2631 0.0720 -1.4015 -1.2628 -1.1233
(Intercept)-Priodontes maximus         -3.6352 0.5065 -4.6163 -3.6447 -2.6410
(Intercept)-Procyon cancrivorous       -3.5536 0.8292 -5.2329 -3.5137 -2.0338
(Intercept)-Puma concolor              -1.7082 0.2078 -2.1307 -1.7023 -1.3204
(Intercept)-Puma yagouaroundi          -3.9010 0.9613 -5.7081 -3.8840 -2.1131
(Intercept)-Tamandua tetradactyla      -3.3440 0.8443 -5.0243 -3.2774 -1.8322
(Intercept)-Tapirus terrestris         -1.1500 0.0793 -1.3028 -1.1477 -0.9968
(Intercept)-Tayassu pecari             -1.6976 0.1437 -1.9871 -1.6959 -1.4247
scale(effort)-Atelocynus microtis       0.3545 0.1897 -0.0223  0.3545  0.7290
scale(effort)-Coendou prehensilis       0.3914 0.2253 -0.0494  0.3912  0.8505
scale(effort)-Cuniculus paca            0.3184 0.0747  0.1715  0.3183  0.4666
scale(effort)-Dasyprocta fuliginosa     0.3789 0.0920  0.2036  0.3792  0.5639
scale(effort)-Dasypus sp.               0.4432 0.1370  0.1947  0.4353  0.7382
scale(effort)-Didelphis marsupialis     0.5425 0.1981  0.1933  0.5281  0.9873
scale(effort)-Eira barbara              0.5009 0.1960  0.1563  0.4864  0.9137
scale(effort)-Herpailurus yagouaroundi  0.2824 0.2104 -0.1506  0.2909  0.6761
scale(effort)-Leopardus pardalis        0.4324 0.1241  0.1987  0.4301  0.6845
scale(effort)-Leopardus tigrinus        0.4368 0.2229  0.0101  0.4331  0.8878
scale(effort)-Leopardus wiedii          0.4546 0.2021  0.0899  0.4489  0.8632
scale(effort)-Mazama americana          0.5169 0.1376  0.2688  0.5090  0.8084
scale(effort)-Mazama nemorivaga         0.2855 0.1506  0.0010  0.2827  0.5913
scale(effort)-Myoprocta pratti          0.3059 0.1777 -0.0532  0.3076  0.6511
scale(effort)-Myrmecophaga tridactyla   0.3910 0.1757  0.0712  0.3860  0.7668
scale(effort)-Nasua nasua               0.4372 0.1861  0.1005  0.4298  0.8265
scale(effort)-Panthera onca             0.2991 0.1406  0.0241  0.2960  0.5782
scale(effort)-Pecari tajacu             0.3683 0.0804  0.2136  0.3668  0.5311
scale(effort)-Priodontes maximus        0.2404 0.1793 -0.1086  0.2446  0.5923
scale(effort)-Procyon cancrivorous      0.4282 0.2085  0.0312  0.4215  0.8590
scale(effort)-Puma concolor             0.4126 0.1511  0.1316  0.4054  0.7313
scale(effort)-Puma yagouaroundi         0.4105 0.2148 -0.0168  0.4106  0.8453
scale(effort)-Tamandua tetradactyla     0.3281 0.2040 -0.0942  0.3277  0.7104
scale(effort)-Tapirus terrestris        0.4066 0.0870  0.2448  0.4031  0.5888
scale(effort)-Tayassu pecari            0.5569 0.1360  0.3047  0.5539  0.8364
                                         Rhat  ESS
(Intercept)-Atelocynus microtis        1.1924  166
(Intercept)-Coendou prehensilis        1.0464  357
(Intercept)-Cuniculus paca             1.0046 3000
(Intercept)-Dasyprocta fuliginosa      1.0063 3000
(Intercept)-Dasypus sp.                1.0053 2818
(Intercept)-Didelphis marsupialis      1.0184  972
(Intercept)-Eira barbara               1.0025  553
(Intercept)-Herpailurus yagouaroundi   1.1280  164
(Intercept)-Leopardus pardalis         1.0009 1226
(Intercept)-Leopardus tigrinus         1.0105 1367
(Intercept)-Leopardus wiedii           1.2879   91
(Intercept)-Mazama americana           1.0000 3000
(Intercept)-Mazama nemorivaga          1.0076 2491
(Intercept)-Myoprocta pratti           1.0024 2424
(Intercept)-Myrmecophaga tridactyla    1.0305  144
(Intercept)-Nasua nasua                1.2957  187
(Intercept)-Panthera onca              1.0274  429
(Intercept)-Pecari tajacu              1.0012 2295
(Intercept)-Priodontes maximus         1.0565  112
(Intercept)-Procyon cancrivorous       1.0254  198
(Intercept)-Puma concolor              1.0077 2209
(Intercept)-Puma yagouaroundi          1.1210  176
(Intercept)-Tamandua tetradactyla      1.0720  173
(Intercept)-Tapirus terrestris         1.0012 2844
(Intercept)-Tayassu pecari             1.0090 1808
scale(effort)-Atelocynus microtis      1.0016 2724
scale(effort)-Coendou prehensilis      1.0023 3000
scale(effort)-Cuniculus paca           1.0026 3000
scale(effort)-Dasyprocta fuliginosa    1.0093 3000
scale(effort)-Dasypus sp.              1.0034 2792
scale(effort)-Didelphis marsupialis    1.0107 2777
scale(effort)-Eira barbara             1.0028 2766
scale(effort)-Herpailurus yagouaroundi 1.0029 3000
scale(effort)-Leopardus pardalis       1.0014 3000
scale(effort)-Leopardus tigrinus       1.0000 3000
scale(effort)-Leopardus wiedii         1.0044 2590
scale(effort)-Mazama americana         1.0010 2763
scale(effort)-Mazama nemorivaga        1.0024 3000
scale(effort)-Myoprocta pratti         1.0026 3000
scale(effort)-Myrmecophaga tridactyla  1.0081 2624
scale(effort)-Nasua nasua              1.0114 2285
scale(effort)-Panthera onca            1.0004 3000
scale(effort)-Pecari tajacu            1.0039 2737
scale(effort)-Priodontes maximus       1.0032 2344
scale(effort)-Procyon cancrivorous     0.9998 2795
scale(effort)-Puma concolor            1.0087 3000
scale(effort)-Puma yagouaroundi        1.0024 3000
scale(effort)-Tamandua tetradactyla    1.0024 3000
scale(effort)-Tapirus terrestris       1.0016 3000
scale(effort)-Tayassu pecari           1.0016 2603

----------------------------------------
    Spatial Covariance
----------------------------------------
         Mean     SD   2.5%     50%   97.5%   Rhat  ESS
phi-1 10.2741 9.0131 0.0000  9.1862 26.4475 2.0409   15
phi-2  8.8879 9.1384 0.0000  6.2172 26.3255 3.9448    8
phi-3 13.3497 8.0913 0.4024 13.1939 26.6927 1.0017 2827
phi-4  8.9982 9.1869 0.0000  6.5632 26.5090 4.0048   13
phi-5 13.1044 8.0811 0.3504 12.7752 26.9119 1.0093 2688
Code
summary(out.sp, level = 'both')

Call:
sfMsPGOcc(occ.formula = ~scale(elev) + scale(border_dist) + scale(FLII), 
    det.formula = ~scale(effort), data = data_list, cov.model = "exponential", 
    NNGP = TRUE, n.neighbors = 15, n.factors = 5, n.batch = 600, 
    batch.length = 25, n.omp.threads = 6, n.report = 1000, n.burn = 5000, 
    n.thin = 10, n.chains = 3)

Samples per Chain: 15000
Burn-in: 5000
Thinning Rate: 10
Number of Chains: 3
Total Posterior Samples: 3000
Run Time (min): 27.6002

----------------------------------------
    Community Level
----------------------------------------
Occurrence Means (logit scale): 
                      Mean     SD    2.5%     50%   97.5%   Rhat ESS
(Intercept)        -2.5811 0.5578 -3.6409 -2.5831 -1.4618 1.1491 294
scale(elev)        -0.0702 0.2130 -0.4974 -0.0660  0.3471 1.3555 182
scale(border_dist) -0.5060 0.3787 -1.2282 -0.5069  0.2564 1.1918 263
scale(FLII)         0.5682 0.2240  0.1770  0.5484  1.0746 1.0296 576

Occurrence Variances (logit scale): 
                     Mean     SD   2.5%    50%   97.5%   Rhat ESS
(Intercept)        6.7121 2.6922 3.1117 6.1805 13.7539 1.0980 225
scale(elev)        0.5032 0.2717 0.1596 0.4467  1.2203 1.2361 445
scale(border_dist) 2.3372 1.2231 0.7815 2.0815  5.3460 1.6710  85
scale(FLII)        0.4413 0.3797 0.0676 0.3291  1.4933 1.1006 334

Detection Means (logit scale): 
                 Mean     SD    2.5%     50%   97.5%   Rhat  ESS
(Intercept)   -2.2938 0.2732 -2.8719 -2.2873 -1.7772 1.0570  431
scale(effort)  0.3969 0.0657  0.2703  0.3959  0.5319 1.0066 2542

Detection Variances (logit scale): 
                Mean     SD   2.5%    50%  97.5%   Rhat  ESS
(Intercept)   1.5284 0.6143 0.7019 1.4172 3.0417 1.1323  236
scale(effort) 0.0466 0.0262 0.0168 0.0401 0.1169 1.0062 2465

----------------------------------------
    Species Level
----------------------------------------
Occurrence (logit scale): 
                                               Mean     SD    2.5%     50%
(Intercept)-Atelocynus microtis             -2.6153 0.8089 -3.9386 -2.7229
(Intercept)-Coendou prehensilis             -5.2450 1.4270 -8.0714 -5.2364
(Intercept)-Cuniculus paca                   0.1981 0.3781 -0.3381  0.1214
(Intercept)-Dasyprocta fuliginosa           -0.8368 0.9209 -2.2452 -0.9624
(Intercept)-Dasypus sp.                     -5.2605 1.0352 -7.6076 -5.1336
(Intercept)-Didelphis marsupialis           -4.6584 0.9903 -6.8930 -4.5564
(Intercept)-Eira barbara                    -3.0129 0.8550 -4.7586 -2.9941
(Intercept)-Herpailurus yagouaroundi        -4.1566 1.5690 -7.1743 -4.1608
(Intercept)-Leopardus pardalis              -1.2949 0.4583 -2.3535 -1.2543
(Intercept)-Leopardus tigrinus              -6.9134 1.3212 -9.9445 -6.7589
(Intercept)-Leopardus wiedii                -2.8619 1.5031 -5.2224 -3.0929
(Intercept)-Mazama americana                -3.6184 1.0031 -5.6170 -3.6143
(Intercept)-Mazama nemorivaga               -5.6025 1.1266 -8.1457 -5.5012
(Intercept)-Myoprocta pratti                -4.3969 0.9487 -6.4516 -4.3482
(Intercept)-Myrmecophaga tridactyla         -1.1476 1.0822 -2.8958 -1.3263
(Intercept)-Nasua nasua                     -2.1519 1.2004 -4.5390 -2.1393
(Intercept)-Panthera onca                   -0.9057 0.7866 -2.3696 -0.9471
(Intercept)-Pecari tajacu                    1.6632 0.6202  0.6276  1.6143
(Intercept)-Priodontes maximus              -0.6248 1.5891 -3.3309 -0.7481
(Intercept)-Procyon cancrivorous            -5.1325 1.6958 -8.5065 -5.0925
(Intercept)-Puma concolor                   -2.3471 0.5854 -3.5711 -2.3173
(Intercept)-Puma yagouaroundi               -4.9971 1.7958 -8.4485 -5.0558
(Intercept)-Tamandua tetradactyla           -4.2122 1.3440 -6.6060 -4.2822
(Intercept)-Tapirus terrestris               0.4987 0.3676 -0.1138  0.4646
(Intercept)-Tayassu pecari                  -0.8244 0.4445 -1.7043 -0.8422
scale(elev)-Atelocynus microtis             -0.8088 0.4670 -1.8290 -0.7828
scale(elev)-Coendou prehensilis              0.2174 0.6289 -0.9762  0.2018
scale(elev)-Cuniculus paca                  -0.3337 0.3120 -0.9253 -0.3393
scale(elev)-Dasyprocta fuliginosa            0.8564 0.6117 -0.4495  0.8676
scale(elev)-Dasypus sp.                     -0.3190 0.3107 -0.9639 -0.3043
scale(elev)-Didelphis marsupialis            0.0811 0.4866 -0.8003  0.0638
scale(elev)-Eira barbara                    -0.8970 0.4617 -1.8755 -0.8754
scale(elev)-Herpailurus yagouaroundi        -0.3839 0.6989 -1.8121 -0.3817
scale(elev)-Leopardus pardalis               0.0691 0.3566 -0.5983  0.0623
scale(elev)-Leopardus tigrinus              -0.2048 0.6492 -1.5262 -0.1947
scale(elev)-Leopardus wiedii                -0.1760 0.5291 -1.2246 -0.1678
scale(elev)-Mazama americana                 1.1180 0.5021  0.1943  1.1027
scale(elev)-Mazama nemorivaga                0.5103 0.4150 -0.2520  0.4842
scale(elev)-Myoprocta pratti                 0.1555 0.5844 -0.9579  0.1202
scale(elev)-Myrmecophaga tridactyla         -0.4802 0.4816 -1.5105 -0.4633
scale(elev)-Nasua nasua                     -0.0350 0.5775 -1.1304 -0.0450
scale(elev)-Panthera onca                    0.0381 0.4432 -0.8468  0.0439
scale(elev)-Pecari tajacu                    0.3581 0.3870 -0.5097  0.3779
scale(elev)-Priodontes maximus              -0.3174 0.5590 -1.4752 -0.2946
scale(elev)-Procyon cancrivorous            -0.2313 0.5088 -1.2866 -0.2204
scale(elev)-Puma concolor                   -0.2751 0.4712 -1.1891 -0.2825
scale(elev)-Puma yagouaroundi               -0.4262 0.5749 -1.6096 -0.4104
scale(elev)-Tamandua tetradactyla            0.1720 0.5748 -0.9236  0.1621
scale(elev)-Tapirus terrestris               0.1498 0.3277 -0.4768  0.1518
scale(elev)-Tayassu pecari                  -0.6515 0.3481 -1.3747 -0.6326
scale(border_dist)-Atelocynus microtis      -0.0541 0.5242 -1.1469 -0.0516
scale(border_dist)-Coendou prehensilis      -0.8382 1.1084 -3.1535 -0.7716
scale(border_dist)-Cuniculus paca           -1.2245 0.4481 -1.9988 -1.2691
scale(border_dist)-Dasyprocta fuliginosa    -0.8135 1.2242 -2.6210 -1.0150
scale(border_dist)-Dasypus sp.              -3.6272 1.1684 -5.9641 -3.6004
scale(border_dist)-Didelphis marsupialis     1.1618 0.7118 -0.4912  1.2047
scale(border_dist)-Eira barbara             -1.9139 0.6798 -3.3124 -1.8707
scale(border_dist)-Herpailurus yagouaroundi  0.0733 1.2443 -2.2870  0.0008
scale(border_dist)-Leopardus pardalis        1.3183 0.4831  0.4405  1.2827
scale(border_dist)-Leopardus tigrinus       -0.1020 1.0474 -2.2482 -0.0906
scale(border_dist)-Leopardus wiedii          0.5960 0.7396 -0.8069  0.5416
scale(border_dist)-Mazama americana          0.7127 0.5172 -0.4396  0.7420
scale(border_dist)-Mazama nemorivaga        -3.0387 1.1490 -5.4837 -2.9648
scale(border_dist)-Myoprocta pratti         -0.7185 0.9994 -2.6765 -0.7250
scale(border_dist)-Myrmecophaga tridactyla  -0.0639 0.6656 -1.2232 -0.1079
scale(border_dist)-Nasua nasua              -1.3143 0.8124 -3.1026 -1.2545
scale(border_dist)-Panthera onca             0.6732 0.5943 -0.3940  0.6398
scale(border_dist)-Pecari tajacu            -0.3554 0.6810 -1.4189 -0.4631
scale(border_dist)-Priodontes maximus        0.3764 0.8921 -1.1230  0.2862
scale(border_dist)-Procyon cancrivorous     -1.6297 1.0049 -3.8581 -1.5348
scale(border_dist)-Puma concolor            -0.0874 0.5740 -1.1142 -0.1281
scale(border_dist)-Puma yagouaroundi        -1.5145 1.1318 -3.9415 -1.3775
scale(border_dist)-Tamandua tetradactyla    -0.7083 0.9067 -2.5997 -0.6835
scale(border_dist)-Tapirus terrestris       -0.1681 0.4085 -0.8933 -0.1977
scale(border_dist)-Tayassu pecari            0.2989 0.4306 -0.4350  0.2563
scale(FLII)-Atelocynus microtis              0.0039 0.3959 -0.8856  0.0244
scale(FLII)-Coendou prehensilis              0.5747 0.6694 -0.6203  0.5359
scale(FLII)-Cuniculus paca                   0.0260 0.2096 -0.4024  0.0223
scale(FLII)-Dasyprocta fuliginosa           -0.0968 0.3538 -0.8178 -0.0910
scale(FLII)-Dasypus sp.                      0.5464 0.5560 -0.4760  0.5106
scale(FLII)-Didelphis marsupialis            0.9554 0.5184  0.1247  0.8867
scale(FLII)-Eira barbara                     0.5614 0.5692 -0.4884  0.5256
scale(FLII)-Herpailurus yagouaroundi         0.4829 0.6155 -0.6918  0.4655
scale(FLII)-Leopardus pardalis               0.7975 0.3288  0.2222  0.7704
scale(FLII)-Leopardus tigrinus               0.6053 0.6248 -0.4873  0.5479
scale(FLII)-Leopardus wiedii                 0.5598 0.5566 -0.5279  0.5355
scale(FLII)-Mazama americana                 0.4153 0.2846 -0.0951  0.4034
scale(FLII)-Mazama nemorivaga                0.7418 0.6694 -0.3778  0.6566
scale(FLII)-Myoprocta pratti                 0.5863 0.5225 -0.3691  0.5544
scale(FLII)-Myrmecophaga tridactyla          0.1768 0.4518 -0.7456  0.1846
scale(FLII)-Nasua nasua                      0.8707 0.6798 -0.2158  0.7807
scale(FLII)-Panthera onca                    1.2138 0.6609  0.2302  1.1032
scale(FLII)-Pecari tajacu                    0.2090 0.2580 -0.2851  0.2069
scale(FLII)-Priodontes maximus               0.1285 0.5007 -0.9131  0.1449
scale(FLII)-Procyon cancrivorous             0.7006 0.6627 -0.4530  0.6456
scale(FLII)-Puma concolor                    1.4454 0.7656  0.3267  1.3238
scale(FLII)-Puma yagouaroundi                0.6376 0.6855 -0.6583  0.5960
scale(FLII)-Tamandua tetradactyla            0.5836 0.6147 -0.5227  0.5556
scale(FLII)-Tapirus terrestris               0.5529 0.2731  0.0771  0.5292
scale(FLII)-Tayassu pecari                   1.0465 0.4320  0.3424  1.0021
                                              97.5%   Rhat  ESS
(Intercept)-Atelocynus microtis             -0.7635 1.0295  201
(Intercept)-Coendou prehensilis             -2.5356 1.0484  202
(Intercept)-Cuniculus paca                   1.1509 3.0565    7
(Intercept)-Dasyprocta fuliginosa            1.5250 2.4474    8
(Intercept)-Dasypus sp.                     -3.5548 1.2936  217
(Intercept)-Didelphis marsupialis           -2.9683 1.1490  149
(Intercept)-Eira barbara                    -1.3977 1.0035  323
(Intercept)-Herpailurus yagouaroundi        -0.9840 1.3578  110
(Intercept)-Leopardus pardalis              -0.4762 1.0643  529
(Intercept)-Leopardus tigrinus              -4.6804 1.0941  290
(Intercept)-Leopardus wiedii                 1.0111 1.2508   77
(Intercept)-Mazama americana                -1.9450 2.6103   19
(Intercept)-Mazama nemorivaga               -3.6932 1.4610  203
(Intercept)-Myoprocta pratti                -2.6218 1.2596   65
(Intercept)-Myrmecophaga tridactyla          1.4784 1.0693  141
(Intercept)-Nasua nasua                      0.1094 1.2773  167
(Intercept)-Panthera onca                    0.7904 1.0407  269
(Intercept)-Pecari tajacu                    3.0897 1.1372   41
(Intercept)-Priodontes maximus               2.9197 1.0596   73
(Intercept)-Procyon cancrivorous            -1.4863 1.1385  120
(Intercept)-Puma concolor                   -1.2064 1.1739  156
(Intercept)-Puma yagouaroundi               -1.3053 1.3033  113
(Intercept)-Tamandua tetradactyla           -1.3528 1.0245  181
(Intercept)-Tapirus terrestris               1.3287 1.0319   62
(Intercept)-Tayassu pecari                   0.0752 1.2008   82
scale(elev)-Atelocynus microtis              0.0368 1.1409 1332
scale(elev)-Coendou prehensilis              1.4874 1.1753 1127
scale(elev)-Cuniculus paca                   0.2753 2.0216   26
scale(elev)-Dasyprocta fuliginosa            2.0496 2.9744   10
scale(elev)-Dasypus sp.                      0.2504 1.0349 1466
scale(elev)-Didelphis marsupialis            1.1288 1.2596  224
scale(elev)-Eira barbara                    -0.0484 1.0035 1122
scale(elev)-Herpailurus yagouaroundi         0.9607 1.2408  288
scale(elev)-Leopardus pardalis               0.7829 1.3257  237
scale(elev)-Leopardus tigrinus               1.0218 1.1337  647
scale(elev)-Leopardus wiedii                 0.8635 1.0180 1250
scale(elev)-Mazama americana                 2.1229 2.4306   20
scale(elev)-Mazama nemorivaga                1.3729 1.2284  263
scale(elev)-Myoprocta pratti                 1.3474 1.6501   99
scale(elev)-Myrmecophaga tridactyla          0.4124 1.0423 1359
scale(elev)-Nasua nasua                      1.1907 1.0156  625
scale(elev)-Panthera onca                    0.9100 1.1330  575
scale(elev)-Pecari tajacu                    1.0645 1.6922   41
scale(elev)-Priodontes maximus               0.7242 1.1964  552
scale(elev)-Procyon cancrivorous             0.7158 1.0028 1341
scale(elev)-Puma concolor                    0.6380 2.0087   25
scale(elev)-Puma yagouaroundi                0.6494 1.0113 1057
scale(elev)-Tamandua tetradactyla            1.3146 1.0591 1440
scale(elev)-Tapirus terrestris               0.8026 1.4634   76
scale(elev)-Tayassu pecari                  -0.0070 1.1880  144
scale(border_dist)-Atelocynus microtis       0.9977 1.2051  145
scale(border_dist)-Coendou prehensilis       1.1827 1.2918  397
scale(border_dist)-Cuniculus paca           -0.0954 1.8892   16
scale(border_dist)-Dasyprocta fuliginosa     2.8943 3.1187    8
scale(border_dist)-Dasypus sp.              -1.4796 2.2481   48
scale(border_dist)-Didelphis marsupialis     2.4433 1.4870   21
scale(border_dist)-Eira barbara             -0.6951 1.2598  369
scale(border_dist)-Herpailurus yagouaroundi  2.7352 1.5528   87
scale(border_dist)-Leopardus pardalis        2.3691 1.0503  434
scale(border_dist)-Leopardus tigrinus        1.9136 1.0977  457
scale(border_dist)-Leopardus wiedii          2.2239 1.0353  320
scale(border_dist)-Mazama americana          1.6647 1.0676   48
scale(border_dist)-Mazama nemorivaga        -1.0431 1.3753  216
scale(border_dist)-Myoprocta pratti          1.3776 1.8818   33
scale(border_dist)-Myrmecophaga tridactyla   1.5272 1.0232  471
scale(border_dist)-Nasua nasua               0.0982 1.2452  251
scale(border_dist)-Panthera onca             1.9209 1.1004  529
scale(border_dist)-Pecari tajacu             1.5624 2.2652   12
scale(border_dist)-Priodontes maximus        2.4967 1.4539  133
scale(border_dist)-Procyon cancrivorous      0.1141 1.1807  367
scale(border_dist)-Puma concolor             1.2429 1.4450   23
scale(border_dist)-Puma yagouaroundi         0.4363 1.0478  323
scale(border_dist)-Tamandua tetradactyla     0.9602 1.0836  443
scale(border_dist)-Tapirus terrestris        0.7550 1.4398   36
scale(border_dist)-Tayassu pecari            1.2767 1.4242   35
scale(FLII)-Atelocynus microtis              0.7375 1.0832  648
scale(FLII)-Coendou prehensilis              2.0742 1.0384  779
scale(FLII)-Cuniculus paca                   0.4361 1.1080  774
scale(FLII)-Dasyprocta fuliginosa            0.5912 1.2150  239
scale(FLII)-Dasypus sp.                      1.7562 1.0050 1643
scale(FLII)-Didelphis marsupialis            2.0892 1.0844  556
scale(FLII)-Eira barbara                     1.7700 1.0058  855
scale(FLII)-Herpailurus yagouaroundi         1.8040 1.0097  622
scale(FLII)-Leopardus pardalis               1.4901 1.0284 1122
scale(FLII)-Leopardus tigrinus               2.0290 1.0053 1131
scale(FLII)-Leopardus wiedii                 1.6837 1.0082  788
scale(FLII)-Mazama americana                 0.9932 1.0936  902
scale(FLII)-Mazama nemorivaga                2.3389 1.0051  981
scale(FLII)-Myoprocta pratti                 1.7537 1.0467 1420
scale(FLII)-Myrmecophaga tridactyla          1.0483 1.0110  770
scale(FLII)-Nasua nasua                      2.5374 1.0348  522
scale(FLII)-Panthera onca                    2.8328 1.0788  495
scale(FLII)-Pecari tajacu                    0.7359 1.1168  387
scale(FLII)-Priodontes maximus               1.0984 1.1359  663
scale(FLII)-Procyon cancrivorous             2.1368 1.0118  748
scale(FLII)-Puma concolor                    3.3019 1.0751  398
scale(FLII)-Puma yagouaroundi                2.1709 1.0097  738
scale(FLII)-Tamandua tetradactyla            1.9349 1.0067  911
scale(FLII)-Tapirus terrestris               1.1668 1.0043 1540
scale(FLII)-Tayassu pecari                   2.0604 1.0164  821

Detection (logit scale): 
                                          Mean     SD    2.5%     50%   97.5%
(Intercept)-Atelocynus microtis        -2.9072 0.6139 -4.2090 -2.8676 -1.8285
(Intercept)-Coendou prehensilis        -3.5512 1.0884 -5.7978 -3.4789 -1.6037
(Intercept)-Cuniculus paca             -0.8278 0.0651 -0.9561 -0.8271 -0.7000
(Intercept)-Dasyprocta fuliginosa      -0.3834 0.0750 -0.5335 -0.3820 -0.2391
(Intercept)-Dasypus sp.                -1.5314 0.1247 -1.7893 -1.5299 -1.2985
(Intercept)-Didelphis marsupialis      -2.1551 0.3753 -2.9213 -2.1387 -1.4803
(Intercept)-Eira barbara               -2.9674 0.3218 -3.5983 -2.9641 -2.3575
(Intercept)-Herpailurus yagouaroundi   -3.4077 0.8330 -5.1335 -3.3814 -1.9007
(Intercept)-Leopardus pardalis         -1.8578 0.1636 -2.1829 -1.8558 -1.5507
(Intercept)-Leopardus tigrinus         -1.2614 0.9529 -3.3237 -1.2079  0.4500
(Intercept)-Leopardus wiedii           -3.3734 0.7484 -4.8681 -3.3119 -2.0872
(Intercept)-Mazama americana           -1.0921 0.1167 -1.3284 -1.0918 -0.8673
(Intercept)-Mazama nemorivaga          -2.0089 0.1830 -2.3685 -2.0064 -1.6571
(Intercept)-Myoprocta pratti           -1.5573 0.2799 -2.1324 -1.5505 -1.0325
(Intercept)-Myrmecophaga tridactyla    -3.1545 0.4611 -4.0113 -3.1523 -2.2739
(Intercept)-Nasua nasua                -3.6055 0.3932 -4.3021 -3.6386 -2.7791
(Intercept)-Panthera onca              -2.7170 0.2697 -3.2441 -2.7149 -2.1963
(Intercept)-Pecari tajacu              -1.2631 0.0720 -1.4015 -1.2628 -1.1233
(Intercept)-Priodontes maximus         -3.6352 0.5065 -4.6163 -3.6447 -2.6410
(Intercept)-Procyon cancrivorous       -3.5536 0.8292 -5.2329 -3.5137 -2.0338
(Intercept)-Puma concolor              -1.7082 0.2078 -2.1307 -1.7023 -1.3204
(Intercept)-Puma yagouaroundi          -3.9010 0.9613 -5.7081 -3.8840 -2.1131
(Intercept)-Tamandua tetradactyla      -3.3440 0.8443 -5.0243 -3.2774 -1.8322
(Intercept)-Tapirus terrestris         -1.1500 0.0793 -1.3028 -1.1477 -0.9968
(Intercept)-Tayassu pecari             -1.6976 0.1437 -1.9871 -1.6959 -1.4247
scale(effort)-Atelocynus microtis       0.3545 0.1897 -0.0223  0.3545  0.7290
scale(effort)-Coendou prehensilis       0.3914 0.2253 -0.0494  0.3912  0.8505
scale(effort)-Cuniculus paca            0.3184 0.0747  0.1715  0.3183  0.4666
scale(effort)-Dasyprocta fuliginosa     0.3789 0.0920  0.2036  0.3792  0.5639
scale(effort)-Dasypus sp.               0.4432 0.1370  0.1947  0.4353  0.7382
scale(effort)-Didelphis marsupialis     0.5425 0.1981  0.1933  0.5281  0.9873
scale(effort)-Eira barbara              0.5009 0.1960  0.1563  0.4864  0.9137
scale(effort)-Herpailurus yagouaroundi  0.2824 0.2104 -0.1506  0.2909  0.6761
scale(effort)-Leopardus pardalis        0.4324 0.1241  0.1987  0.4301  0.6845
scale(effort)-Leopardus tigrinus        0.4368 0.2229  0.0101  0.4331  0.8878
scale(effort)-Leopardus wiedii          0.4546 0.2021  0.0899  0.4489  0.8632
scale(effort)-Mazama americana          0.5169 0.1376  0.2688  0.5090  0.8084
scale(effort)-Mazama nemorivaga         0.2855 0.1506  0.0010  0.2827  0.5913
scale(effort)-Myoprocta pratti          0.3059 0.1777 -0.0532  0.3076  0.6511
scale(effort)-Myrmecophaga tridactyla   0.3910 0.1757  0.0712  0.3860  0.7668
scale(effort)-Nasua nasua               0.4372 0.1861  0.1005  0.4298  0.8265
scale(effort)-Panthera onca             0.2991 0.1406  0.0241  0.2960  0.5782
scale(effort)-Pecari tajacu             0.3683 0.0804  0.2136  0.3668  0.5311
scale(effort)-Priodontes maximus        0.2404 0.1793 -0.1086  0.2446  0.5923
scale(effort)-Procyon cancrivorous      0.4282 0.2085  0.0312  0.4215  0.8590
scale(effort)-Puma concolor             0.4126 0.1511  0.1316  0.4054  0.7313
scale(effort)-Puma yagouaroundi         0.4105 0.2148 -0.0168  0.4106  0.8453
scale(effort)-Tamandua tetradactyla     0.3281 0.2040 -0.0942  0.3277  0.7104
scale(effort)-Tapirus terrestris        0.4066 0.0870  0.2448  0.4031  0.5888
scale(effort)-Tayassu pecari            0.5569 0.1360  0.3047  0.5539  0.8364
                                         Rhat  ESS
(Intercept)-Atelocynus microtis        1.1924  166
(Intercept)-Coendou prehensilis        1.0464  357
(Intercept)-Cuniculus paca             1.0046 3000
(Intercept)-Dasyprocta fuliginosa      1.0063 3000
(Intercept)-Dasypus sp.                1.0053 2818
(Intercept)-Didelphis marsupialis      1.0184  972
(Intercept)-Eira barbara               1.0025  553
(Intercept)-Herpailurus yagouaroundi   1.1280  164
(Intercept)-Leopardus pardalis         1.0009 1226
(Intercept)-Leopardus tigrinus         1.0105 1367
(Intercept)-Leopardus wiedii           1.2879   91
(Intercept)-Mazama americana           1.0000 3000
(Intercept)-Mazama nemorivaga          1.0076 2491
(Intercept)-Myoprocta pratti           1.0024 2424
(Intercept)-Myrmecophaga tridactyla    1.0305  144
(Intercept)-Nasua nasua                1.2957  187
(Intercept)-Panthera onca              1.0274  429
(Intercept)-Pecari tajacu              1.0012 2295
(Intercept)-Priodontes maximus         1.0565  112
(Intercept)-Procyon cancrivorous       1.0254  198
(Intercept)-Puma concolor              1.0077 2209
(Intercept)-Puma yagouaroundi          1.1210  176
(Intercept)-Tamandua tetradactyla      1.0720  173
(Intercept)-Tapirus terrestris         1.0012 2844
(Intercept)-Tayassu pecari             1.0090 1808
scale(effort)-Atelocynus microtis      1.0016 2724
scale(effort)-Coendou prehensilis      1.0023 3000
scale(effort)-Cuniculus paca           1.0026 3000
scale(effort)-Dasyprocta fuliginosa    1.0093 3000
scale(effort)-Dasypus sp.              1.0034 2792
scale(effort)-Didelphis marsupialis    1.0107 2777
scale(effort)-Eira barbara             1.0028 2766
scale(effort)-Herpailurus yagouaroundi 1.0029 3000
scale(effort)-Leopardus pardalis       1.0014 3000
scale(effort)-Leopardus tigrinus       1.0000 3000
scale(effort)-Leopardus wiedii         1.0044 2590
scale(effort)-Mazama americana         1.0010 2763
scale(effort)-Mazama nemorivaga        1.0024 3000
scale(effort)-Myoprocta pratti         1.0026 3000
scale(effort)-Myrmecophaga tridactyla  1.0081 2624
scale(effort)-Nasua nasua              1.0114 2285
scale(effort)-Panthera onca            1.0004 3000
scale(effort)-Pecari tajacu            1.0039 2737
scale(effort)-Priodontes maximus       1.0032 2344
scale(effort)-Procyon cancrivorous     0.9998 2795
scale(effort)-Puma concolor            1.0087 3000
scale(effort)-Puma yagouaroundi        1.0024 3000
scale(effort)-Tamandua tetradactyla    1.0024 3000
scale(effort)-Tapirus terrestris       1.0016 3000
scale(effort)-Tayassu pecari           1.0016 2603

----------------------------------------
    Spatial Covariance
----------------------------------------
         Mean     SD   2.5%     50%   97.5%   Rhat  ESS
phi-1 10.2741 9.0131 0.0000  9.1862 26.4475 2.0409   15
phi-2  8.8879 9.1384 0.0000  6.2172 26.3255 3.9448    8
phi-3 13.3497 8.0913 0.4024 13.1939 26.6927 1.0017 2827
phi-4  8.9982 9.1869 0.0000  6.5632 26.5090 4.0048   13
phi-5 13.1044 8.0811 0.3504 12.7752 26.9119 1.0093 2688

Bayesian p-values can be inspected to check for lack of fit (overall or by species). Lack of fit at significance level = 0.05 is indicated by Bayesian p-values below 0.025 or greater than 0.975. The overall Bayesian p-value (Bpvalue) indicates no problems with lack of fit. Likewise, species-level Bayesian p-values (Bpvalue_species) indicate no lack of fit for any species.

Gelman and Rubin’s convergence diagnostic: Approximate convergence is diagnosed when the upper limit is close to 1.

Convergence is diagnosed when the chains have ‘forgotten’ their initial values, and the output from all chains is indistinguishable. The gelman.diag diagnostic is applied to a single variable from the chain. It is based a comparison of within-chain and between-chain variances, and is similar to a classical analysis of variance.

Values substantially above 1 indicate lack of convergence.

Model Diagnostics

Code
#| eval: true
#| echo: true
#| code-fold: true
#| warning: false
#| message: false
# Extract posterior draws for later use
posterior1 <- as.array(out.sp)

# Trace plots to check chain mixing. Extract posterior samples and bind in a single matrix.
POSTERIOR.MATRIX <- cbind(out.sp$alpha.comm.samples, 
                          out.sp$beta.comm.samples,  
                          out.sp$alpha.samples, 
                          out.sp$beta.samples)

# Matrix output is all chains combined, split into 3 chains.
CHAIN.1 <- as.mcmc(POSTERIOR.MATRIX[1:1000,])
CHAIN.2 <- as.mcmc(POSTERIOR.MATRIX[1001:2000,])
CHAIN.3 <- as.mcmc(POSTERIOR.MATRIX[2001:3000,])
# CHAIN.4 <- as.mcmc(POSTERIOR.MATRIX[8001:10000,])

# Bind four chains as coda mcmc.list object.
POSTERIOR.CHAINS <- mcmc.list(CHAIN.1, CHAIN.2, CHAIN.3)#, CHAIN.4)

# Create an empty folder.
# dir.create ("Beetle_plots")

# Plot chain mixing of each parameter to a multi-panel plot and save to the new folder. ART 5 mins

######################################
#### SAVE Diagnostics at PDF
# MCMCtrace(POSTERIOR.CHAINS, params = "all", Rhat = TRUE, n.eff = TRUE)#, pdf = TRUE, filename = "Beetle_240909_traceplots.pdf", wd = "Beetle_plots")



#mcmc_trace(fit.commu, parms = c("beta.ranef.cont.border_dist.mean"))

#posterior2 <- extract(fit.commu, inc_warmup = TRUE, permuted = FALSE)

#color_scheme_set("mix-blue-pink")
#p <- mcmc_trace(posterior1,  pars = c("mu", "tau"), n_warmup = 300,
#                facet_args = list(nrow = 2, labeller = label_parsed))
#p + facet_text(size = 15)



#outMCMC <- fit.commu #Convert output to MCMC object
#diagnostics chains 

# all as pdf
# MCMCtrace(outMCMC)

# MCMCtrace(outMCMC, params = c("alpha0"), type = 'trace', Rhat = TRUE, n.eff = TRUE)

# MCMCtrace(outMCMC, params = c("beta0"), type = 'trace', Rhat = TRUE, n.eff = TRUE)

# MCMCtrace(outMCMC, params = c("beta.ranef.cont.border_dist"), type = 'trace', Rhat = TRUE, n.eff = TRUE)

# MCMCtrace(out.sp, params = c("beta.ranef.cont.border_dist.mean"), type = 'trace', pdf = F, Rhat = TRUE, n.eff = TRUE)

# MCMCtrace(outMCMC, params = c("beta.ranef.cont.elev"), type = 'trace', Rhat = TRUE, n.eff = TRUE)

# MCMCtrace(outMCMC, params = c("beta.ranef.cont.elev.mean"), type = 'trace', pdf = F, Rhat = TRUE, n.eff = TRUE)


### density
# MCMCtrace(outMCMC, params = c("Nspecies"), ISB = FALSE, pdf = F, exact = TRUE, post_zm = TRUE, type = 'density', Rhat = TRUE, n.eff = TRUE, ind = TRUE)

### density
# MCMCtrace(outMCMC, params = c("beta.ranef.cont.elev.mean"), ISB = FALSE, pdf = F, exact = TRUE, post_zm = TRUE, type = 'density', Rhat = TRUE, n.eff = TRUE, ind = TRUE)

### density
#MCMCtrace(outMCMC, params = c("beta.ranef.cont.border_dist.mean"), ISB = FALSE, pdf = F, exact = TRUE, post_zm = TRUE, type = 'density', Rhat = TRUE, n.eff = TRUE, ind = TRUE)

#coda::gelman.diag(outMCMC,  multivariate = FALSE, transform=FALSE)
                    
# coda::gelman.plot(outMCMC,  multivariate = FALSE)



# 
# mcmc_intervals(outMCMC, pars = c("Nspecies_in_AP[1]",
#                                  "Nspecies_in_AP[2]"),
#                point_est = "mean",
#                prob = 0.75, prob_outer = 0.95) +
#   ggtitle("Number of species") + 
#   scale_y_discrete(labels = c("Nspecies_in_AP[1]"=levels(sitecovs$in_AP)[1],
#              "Nspecies_in_AP[2]"=levels(sitecovs$in_AP)[2]))
# 
# #Continuous
# p <- mcmc_intervals(outMCMC, 
#                pars = c("beta.ranef.cont.border_dist.mean",
#                          #"beta.ranef.cont.elev.mean",
#                         "beta.ranef.categ.in_AP.mean[2]"))
# 
# # relabel parameters
# p + scale_y_discrete(
#   labels = c("beta.ranef.cont.border_dist.mean"="Dist_border",
#                          #"beta.ranef.cont.elev.mean"="Elevation",
#                         "beta.ranef.categ.in_AP.mean[2]"="in_AP")
# ) +
#   ggtitle("Treatment effect on all species")
# 

Posterior Summary (effect)

Community effects

Code
# Create simple plot summaries using MCMCvis package.
# Detection covariate effects --------- 
MCMCplot(out.sp$alpha.comm.samples, ref_ovl = TRUE, ci = c(50, 95))
# Occupancy community-level effects 
MCMCplot(out.sp$beta.comm.samples, ref_ovl = TRUE, ci = c(50, 95))
(a) Detection
(b) Occupancy
Figure 1: Community effects

Species effects

Code
# Occupancy species-level effects 
MCMCplot(out.sp$beta.samples[,26:50], ref_ovl = TRUE, ci = c(50, 95))

# Occupancy species-level effects 
MCMCplot(out.sp$beta.samples[,51:75], ref_ovl = TRUE, ci = c(50, 95))
(a) elevation
(b) distance border
Figure 2: Species effects

Species effects using bayesplot

Code
library(bayesplot)
#mcmc_areas(outMCMC, regex_pars = "Nspecies_in_AP")
# mcmc_areas(outMCMC, regex_pars = "Nspecies_in_AP")

mcmc_intervals(out.sp$beta.samples[,26:50] , point_est = "mean",
               prob = 0.75, prob_outer = 0.95) + 
  geom_vline(xintercept = 0, color = "red", linetype = "dashed", size = 0.5)
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.

Code
mcmc_intervals(out.sp$beta.samples[,51:75] , point_est = "mean",
               prob = 0.75, prob_outer = 0.95) + 
  geom_vline(xintercept = 0, color = "red", linetype = "dashed", size = 0.5)

Code
mcmc_intervals(out.sp$beta.samples[,76:100] , point_est = "mean",
               prob = 0.75, prob_outer = 0.95) + 
  geom_vline(xintercept = 0, color = "red", linetype = "dashed", size = 0.5)

Prediction as graph

This prediction uses the non spatial model

Code
# 6. Prediction -----------------------------------------------------------
# Predict occupancy along a gradient of elev   
# Create a set of values across the range of observed elev values
elev.pred.vals <- seq(min(data_list$occ.covs$elev), 
                              max(data_list$occ.covs$elev), 
                              length.out = 100)
# Scale predicted values by mean and standard deviation used to fit the model
elev.pred.vals.scale <- (elev.pred.vals - mean(data_list$occ.covs$elev)) / 
                             sd(data_list$occ.covs$elev)
# Create a set of values across the range of observed elev values
border_dist.pred.vals <- seq(min(data_list$occ.covs$border_dist), 
                              max(data_list$occ.covs$border_dist), 
                              length.out = 100)
# Scale predicted values by mean and standard deviation used to fit the model
border_dist.pred.vals.scale <- (border_dist.pred.vals -
                                  mean(data_list$occ.covs$border_dist)) /
                                  sd(data_list$occ.covs$border_dist)

# Predict occupancy across elev  values at mean values of all other variables
pred.df1 <- as.matrix(data.frame(intercept = 1, 
                                 elev = elev.pred.vals.scale, 
                                 border_dist = 0,
                                 FLII=0))#, catchment = 0, density = 0, 
                         # slope = 0))
# Predict occupancy across elev  values at mean values of all other variables
pred.df2 <- as.matrix(data.frame(intercept = 1, elev = 0, 
                         border_dist = border_dist.pred.vals.scale,
                         FLII= 0 ))#, catchment = 0, density = 0, 
                         # slope = 0))

out.pred1 <- predict(out, pred.df1) # using non spatial
str(out.pred1)
List of 3
 $ psi.0.samples: num [1:1500, 1:25, 1:100] 0.131 0.0911 0.1402 0.1496 0.0953 ...
 $ z.0.samples  : int [1:1500, 1:25, 1:100] 0 0 0 0 0 0 1 0 1 0 ...
 $ call         : language predict.msPGOcc(object = out, X.0 = pred.df1)
 - attr(*, "class")= chr "predict.msPGOcc"
Code
psi.0.quants <- apply(out.pred1$psi.0.samples, c(2, 3), quantile, 
                          prob = c(0.025, 0.5, 0.975))
sp.codes <- attr(data_list$y, "dimnames")[[1]]
psi.plot.dat <- data.frame(psi.med = c(t(psi.0.quants[2, , ])), 
                                 psi.low = c(t(psi.0.quants[1, , ])), 
                                 psi.high = c(t(psi.0.quants[3, , ])), 
                           elev = elev.pred.vals, 
                                 sp.codes = rep(sp.codes, 
                                                each = length(elev.pred.vals)))

ggplot(psi.plot.dat, aes(x = elev, y = psi.med)) + 
  geom_ribbon(aes(ymin = psi.low, ymax = psi.high), fill = 'grey70') +
  geom_line() + 
  facet_wrap(vars(sp.codes)) + 
  theme_bw() + 
  labs(x = 'elevation (m)', y = 'Occupancy Probability') 

Code
out.pred2 <- predict(out, pred.df2) # using non spatial
str(out.pred2)
List of 3
 $ psi.0.samples: num [1:1500, 1:25, 1:100] 0.1631 0.0662 0.0919 0.0636 0.1146 ...
 $ z.0.samples  : int [1:1500, 1:25, 1:100] 0 0 0 0 0 0 0 0 1 1 ...
 $ call         : language predict.msPGOcc(object = out, X.0 = pred.df2)
 - attr(*, "class")= chr "predict.msPGOcc"
Code
psi.0.quants <- apply(out.pred2$psi.0.samples, c(2, 3), quantile, 
                          prob = c(0.025, 0.5, 0.975))
sp.codes <- attr(data_list$y, "dimnames")[[1]]
psi.plot.dat <- data.frame(psi.med = c(t(psi.0.quants[2, , ])), 
                                 psi.low = c(t(psi.0.quants[1, , ])), 
                                 psi.high = c(t(psi.0.quants[3, , ])), 
                           border_dist = border_dist.pred.vals, 
                                 sp.codes = rep(sp.codes, 
                                                each = length(border_dist.pred.vals)))

ggplot(psi.plot.dat, aes(x = border_dist/1000, y = psi.med)) + 
  geom_ribbon(aes(ymin = psi.low, ymax = psi.high), fill = 'grey70') +
  geom_line() + 
  facet_wrap(vars(sp.codes)) + 
  theme_bw() + 
  labs(x = 'border_dist (Km)', y = 'Occupancy Probability') 

Spatial Prediction in elevation_EC

Code
#aggregate  resolution to (factor = 3)
#transform coord data to UTM
elevation_UTM <- project(elevation_EC, "EPSG:10603")
elevation_17.aggregate <- aggregate(elevation_UTM, fact=10)
res(elevation_17.aggregate)
[1] 5984.313 5984.313
Code
# Convert the SpatRaster to a data frame with coordinates
df_coords <- as.data.frame(elevation_17.aggregate, xy = TRUE)
names(df_coords) <-c("X","Y","elev")

elev.pred <- (df_coords$elev - mean(data_list$occ.covs$elev)) / sd(data_list$occ.covs$elev)


############### Predict new data ############### 
# we predict at one covariate varing and others at mean value = 0
# intercept = 1, elev = 0, border_dist = 0, FLII= 0
# in that order
################ ################ ################ 
predict_data <- cbind(1, elev.pred, 0, 0)
colnames(predict_data) <- c("intercept",
                            "elev",
                            "border_dist",
                            "FLII" )

# X.0 <- cbind(1, 1, elev.pred)#, elev.pred^2)

# coords.0 <- as.matrix(hbefElev[, c('Easting', 'Northing')])
out.sp.ms.pred <- predict(out.sp, 
                          X.0=predict_data, 
                          df_coords[,1:2],
                          threads=4) #Warning :'threads' is not an argument
Warning in predict.sfMsPGOcc(out.sp, X.0 = predict_data, df_coords[, 1:2], :
'threads' is not an argument
----------------------------------------
    Prediction description
----------------------------------------
Spatial Factor NNGP Multispecies Occupancy model with Polya-Gamma latent
variable fit with 377 observations.

Number of covariates 4 (including intercept if specified).

Using the exponential spatial correlation model.

Using 15 nearest neighbors.
Using 5 latent spatial factors.

Number of MCMC samples 3000.

Predicting at 2618 non-sampled locations.


Source compiled with OpenMP support and model fit using 1 threads.
-------------------------------------------------
        Predicting
-------------------------------------------------
Location: 100 of 2618, 3.82%
Location: 200 of 2618, 7.64%
Location: 300 of 2618, 11.46%
Location: 400 of 2618, 15.28%
Location: 500 of 2618, 19.10%
Location: 600 of 2618, 22.92%
Location: 700 of 2618, 26.74%
Location: 800 of 2618, 30.56%
Location: 900 of 2618, 34.38%
Location: 1000 of 2618, 38.20%
Location: 1100 of 2618, 42.02%
Location: 1200 of 2618, 45.84%
Location: 1300 of 2618, 49.66%
Location: 1400 of 2618, 53.48%
Location: 1500 of 2618, 57.30%
Location: 1600 of 2618, 61.12%
Location: 1700 of 2618, 64.94%
Location: 1800 of 2618, 68.75%
Location: 1900 of 2618, 72.57%
Location: 2000 of 2618, 76.39%
Location: 2100 of 2618, 80.21%
Location: 2200 of 2618, 84.03%
Location: 2300 of 2618, 87.85%
Location: 2400 of 2618, 91.67%
Location: 2500 of 2618, 95.49%
Location: 2600 of 2618, 99.31%
Location: 2618 of 2618, 100.00%
Generating latent occupancy state
Code
# extract the array of interest= occupancy
predicted_array <- out.sp.ms.pred$psi.0.samples



dim(predicted_array)
[1] 3000   25 2618
Code
# df_plot <- NA # empty column
predicted_raster_list <- list() # rast(nrows = 52, ncols = 103,
                         #ext(elevation_17.aggregate), 
                         # crs = "EPSG:32717")

###################################################
# simpler way to make mean in the array by species
# array order: itera=3000, sp=22, pixels=5202
# we wan to keep index 2 and 3
library(plyr)
------------------------------------------------------------------------------
You have loaded plyr after dplyr - this is likely to cause problems.
If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
library(plyr); library(dplyr)
------------------------------------------------------------------------------

Adjuntando el paquete: 'plyr'
The following objects are masked from 'package:dplyr':

    arrange, count, desc, failwith, id, mutate, rename, summarise,
    summarize
The following object is masked from 'package:purrr':

    compact
The following object is masked from 'package:maps':

    ozone
Code
aresult = (plyr::aaply(predicted_array, # mean fo all iterations
                       c(2,3), 
                       mean))

##############################################
#### Loop to make rasters and put in a list
# array order: itera=3000, sp=22, pixels=5202
for (i in 1:dim(predicted_array)[2]){
 # Convert array slice to data frame
 # df_plot[i] <- as.data.frame(predicted_array[1, i, ]) # sp_i
 # df_plot[i] <- as.vector(aresult[i,]) # Extract sp
 # Producing an SDM for all (posterior mean)
 plot.dat <- data.frame(x = df_coords$X, 
                        y = df_coords$Y, 
                        psi.sp = as.vector(aresult[i,]))
 pred_rast <- rast(plot.dat, 
                   type = "xyz", 
                   crs = "EPSG:10603") # Replace EPSG:4326 with your CRS
 predicted_raster_list[[i]] <- pred_rast
}

# Convert the list to a SpatRaster stack
predictad_raster_stack <- rast(predicted_raster_list)
# put species names
names(predictad_raster_stack) <- selected.sp

plot(predictad_raster_stack)

Code
# get the mean
predicted_mean <- mean(predictad_raster_stack)

plot(predicted_mean, main="mean occupancy")

Code
mapview(predicted_mean) + mapview(AP_Yasuni_UTM_line)
Code
# 

Package Citation

Code
pkgs <- cite_packages(output = "paragraph", pkgs="Session", out.dir = ".")
# knitr::kable(pkgs)
pkgs

We used R v. 4.4.2 (R Core Team 2024) and the following R packages: abind v. 1.4.8 (Plate and Heiberger 2024), bayesplot v. 1.14.0 (Gabry et al. 2019; Gabry and Mahr 2025), beepr v. 2.0 (Bååth 2024), camtrapR v. 3.0.0 (Niedballa et al. 2016), coda v. 0.19.4.1 (Plummer et al. 2006), DT v. 0.34.0 (Xie et al. 2025), elevatr v. 0.99.0 (Hollister et al. 2023), maps v. 3.4.3 (Becker et al. 2025), mapview v. 2.11.4 (Appelhans et al. 2025), MCMCvis v. 0.16.3 (Youngflesh 2018), plyr v. 1.8.9 (Wickham 2011), sf v. 1.0.21 (Pebesma 2018; Pebesma and Bivand 2023), snow v. 0.4.4 (Tierney et al. 2021), snowfall v. 1.84.6.3 (Knaus 2023), spOccupancy v. 0.8.0 (Doser et al. 2022, 2024; Doser, Finley, and Banerjee 2023), terra v. 1.8.70 (Hijmans 2025), tictoc v. 1.2.1 (Izrailev 2024), tidyverse v. 2.0.0 (Wickham et al. 2019), tmap v. 4.2 (Tennekes 2018).

Sesion info

Code
print(sessionInfo(), locale = FALSE)
R version 4.4.2 (2024-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 10 x64 (build 19045)

Matrix products: internal


attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] plyr_1.8.9        abind_1.4-8       lubridate_1.9.4   forcats_1.0.0    
 [5] stringr_1.5.2     dplyr_1.1.4       purrr_1.1.0       readr_2.1.5      
 [9] tidyr_1.3.1       tibble_3.2.1      ggplot2_4.0.0     tidyverse_2.0.0  
[13] spOccupancy_0.8.0 camtrapR_3.0.0    snowfall_1.84-6.3 snow_0.4-4       
[17] beepr_2.0         coda_0.19-4.1     MCMCvis_0.16.3    tictoc_1.2.1     
[21] bayesplot_1.14.0  elevatr_0.99.0    terra_1.8-70      tmap_4.2         
[25] maps_3.4.3        mapview_2.11.4    sf_1.0-21         DT_0.34.0        
[29] readxl_1.4.3      grateful_0.3.0   

loaded via a namespace (and not attached):
  [1] RColorBrewer_1.1-3      tensorA_0.36.2.1        rstudioapi_0.17.1      
  [4] audio_0.1-11            jsonlite_2.0.0          wk_0.9.4               
  [7] magrittr_2.0.3          farver_2.1.2            nloptr_2.1.1           
 [10] rmarkdown_2.30          vctrs_0.6.5             minqa_1.2.8            
 [13] base64enc_0.1-3         RcppNumerical_0.6-0     progress_1.2.3         
 [16] htmltools_0.5.8.1       leafsync_0.1.0          distributional_0.5.0   
 [19] curl_7.0.0              raster_3.6-32           cellranger_1.1.0       
 [22] s2_1.1.9                sass_0.4.10             bslib_0.9.0            
 [25] slippymath_0.3.1        KernSmooth_2.23-24      htmlwidgets_1.6.4      
 [28] cachem_1.1.0            stars_0.6-8             uuid_1.2-1             
 [31] mime_0.13               lifecycle_1.0.4         iterators_1.0.14       
 [34] pkgconfig_2.0.3         cols4all_0.8-1          Matrix_1.7-1           
 [37] R6_2.6.1                fastmap_1.2.0           shiny_1.9.1            
 [40] digest_0.6.37           colorspace_2.1-1        leafem_0.2.4           
 [43] crosstalk_1.2.1         labeling_0.4.3          lwgeom_0.2-14          
 [46] progressr_0.15.0        spacesXYZ_1.6-0         timechange_0.3.0       
 [49] httr_1.4.7              mgcv_1.9-1              compiler_4.4.2         
 [52] microbenchmark_1.5.0    proxy_0.4-27            withr_3.0.2            
 [55] doParallel_1.0.17       backports_1.5.0         brew_1.0-10            
 [58] S7_0.2.0                DBI_1.2.3               logger_0.4.0           
 [61] MASS_7.3-61             maptiles_0.10.0         tmaptools_3.3          
 [64] leaflet_2.2.3           classInt_0.4-11         tools_4.4.2            
 [67] units_0.8-7             leaflegend_1.2.1        httpuv_1.6.16          
 [70] glue_1.8.0              satellite_1.0.5         nlme_3.1-166           
 [73] promises_1.3.3          grid_4.4.2              checkmate_2.3.2        
 [76] reshape2_1.4.4          generics_0.1.3          leaflet.providers_2.0.0
 [79] gtable_0.3.6            tzdb_0.4.0              shinyBS_0.61.1         
 [82] class_7.3-22            data.table_1.17.8       hms_1.1.3              
 [85] sp_2.2-0                RANN_2.6.2              foreach_1.5.2          
 [88] pillar_1.11.1           posterior_1.6.1         later_1.4.2            
 [91] splines_4.4.2           lattice_0.22-6          tidyselect_1.2.1       
 [94] knitr_1.50              svglite_2.1.3           stats4_4.4.2           
 [97] xfun_0.52               shinydashboard_0.7.3    leafpop_0.1.0          
[100] stringi_1.8.4           rematch_2.0.0           yaml_2.3.10            
[103] boot_1.3-31             evaluate_1.0.4          codetools_0.2-20       
[106] cli_3.6.5               RcppParallel_5.1.9      systemfonts_1.1.0      
[109] xtable_1.8-4            jquerylib_0.1.4         secr_5.1.0             
[112] dichromat_2.0-0.1       Rcpp_1.1.0              spAbundance_0.2.1      
[115] png_0.1-8               XML_3.99-0.18           parallel_4.4.2         
[118] prettyunits_1.2.0       lme4_1.1-35.5           mvtnorm_1.3-2          
[121] scales_1.4.0            e1071_1.7-16            crayon_1.5.3           
[124] rlang_1.1.6            

References

Appelhans, Tim, Florian Detsch, Christoph Reudenbach, and Stefan Woellauer. 2025. mapview: Interactive Viewing of Spatial Data in r. https://CRAN.R-project.org/package=mapview.
Bååth, Rasmus. 2024. beepr: Easily Play Notification Sounds on Any Platform. https://CRAN.R-project.org/package=beepr.
Becker, Richard A., Allan R. Wilks, Ray Brownrigg, Thomas P. Minka, and Alex Deckmyn. 2025. maps: Draw Geographical Maps. https://CRAN.R-project.org/package=maps.
Doser, Jeffrey W., Andrew O. Finley, and Sudipto Banerjee. 2023. “Joint Species Distribution Models with Imperfect Detection for High-Dimensional Spatial Data.” Ecology, e4137. https://doi.org/10.1002/ecy.4137.
Doser, Jeffrey W., Andrew O. Finley, Marc Kéry, and Elise F. Zipkin. 2022. spOccupancy: An r Package for Single-Species, Multi-Species, and Integrated Spatial Occupancy Models.” Methods in Ecology and Evolution 13: 1670–78. https://doi.org/10.1111/2041-210X.13897.
Doser, Jeffrey W., Andrew O. Finley, Sarah P. Saunders, Marc Kéry, Aaron S. Weed, and Elise F. Zipkin. 2024. “Modeling Complex Species-Environment Relationships Through Spatially-Varying Coefficient Occupancy Models.” Journal of Agricultural, Biological, and Environmental Statistics. https://doi.org/10.1007/s13253-023-00595-6.
Gabry, Jonah, and Tristan Mahr. 2025. bayesplot: Plotting for Bayesian Models.” https://mc-stan.org/bayesplot/.
Gabry, Jonah, Daniel Simpson, Aki Vehtari, Michael Betancourt, and Andrew Gelman. 2019. “Visualization in Bayesian Workflow.” J. R. Stat. Soc. A 182: 389–402. https://doi.org/10.1111/rssa.12378.
Hijmans, Robert J. 2025. terra: Spatial Data Analysis. https://CRAN.R-project.org/package=terra.
Hollister, Jeffrey, Tarak Shah, Jakub Nowosad, Alec L. Robitaille, Marcus W. Beck, and Mike Johnson. 2023. elevatr: Access Elevation Data from Various APIs. https://doi.org/10.5281/zenodo.8335450.
Izrailev, Sergei. 2024. tictoc: Functions for Timing r Scripts, as Well as Implementations of Stack and StackList Structures. https://CRAN.R-project.org/package=tictoc.
Knaus, Jochen. 2023. snowfall: Easier Cluster Computing (Based on snow). https://CRAN.R-project.org/package=snowfall.
Niedballa, Jürgen, Rahel Sollmann, Alexandre Courtiol, and Andreas Wilting. 2016. camtrapR: An r Package for Efficient Camera Trap Data Management.” Methods in Ecology and Evolution 7 (12): 1457–62. https://doi.org/10.1111/2041-210X.12600.
Pebesma, Edzer. 2018. Simple Features for R: Standardized Support for Spatial Vector Data.” The R Journal 10 (1): 439–46. https://doi.org/10.32614/RJ-2018-009.
Pebesma, Edzer, and Roger Bivand. 2023. Spatial Data Science: With applications in R. Chapman and Hall/CRC. https://doi.org/10.1201/9780429459016.
Plate, Tony, and Richard Heiberger. 2024. abind: Combine Multidimensional Arrays. https://CRAN.R-project.org/package=abind.
Plummer, Martyn, Nicky Best, Kate Cowles, and Karen Vines. 2006. CODA: Convergence Diagnosis and Output Analysis for MCMC.” R News 6 (1): 7–11. https://journal.r-project.org/archive/.
R Core Team. 2024. R: A Language and Environment for Statistical Computing. Vienna, Austria: R Foundation for Statistical Computing. https://www.R-project.org/.
Tennekes, Martijn. 2018. tmap: Thematic Maps in R.” Journal of Statistical Software 84 (6): 1–39. https://doi.org/10.18637/jss.v084.i06.
Tierney, Luke, A. J. Rossini, Na Li, and H. Sevcikova. 2021. snow: Simple Network of Workstations. https://CRAN.R-project.org/package=snow.
Wickham, Hadley. 2011. “The Split-Apply-Combine Strategy for Data Analysis.” Journal of Statistical Software 40 (1): 1–29. https://www.jstatsoft.org/v40/i01/.
Wickham, Hadley, Mara Averick, Jennifer Bryan, Winston Chang, Lucy D’Agostino McGowan, Romain François, Garrett Grolemund, et al. 2019. “Welcome to the tidyverse.” Journal of Open Source Software 4 (43): 1686. https://doi.org/10.21105/joss.01686.
Xie, Yihui, Joe Cheng, Xianying Tan, and Garrick Aden-Buie. 2025. DT: A Wrapper of the JavaScript Library DataTables. https://CRAN.R-project.org/package=DT.
Youngflesh, Casey. 2018. MCMCvis: Tools to Visualize, Manipulate, and Summarize MCMC Output.” Journal of Open Source Software 3 (24): 640. https://doi.org/10.21105/joss.00640.

Reuse

Citation

BibTeX citation:
@online{forero2025,
  author = {Forero, German and Wallace, Robert and Zapara-Rios, Galo and
    Isasi-Catalá, Emiliana and J. Lizcano, Diego},
  title = {Fitting a {Spatial} {Factor} {Multi-Species} {Occupancy}
    {Model}},
  date = {2025-05-16},
  url = {https://dlizcano.github.io/Occu_APs_all/blog/2025-10-15-analysis/},
  langid = {en}
}
For attribution, please cite this work as:
Forero, German, Robert Wallace, Galo Zapara-Rios, Emiliana Isasi-Catalá, and Diego J. Lizcano. 2025. “Fitting a Spatial Factor Multi-Species Occupancy Model.” May 16, 2025. https://dlizcano.github.io/Occu_APs_all/blog/2025-10-15-analysis/.