I am trying to prepare a dataframe of species observation for abundance and occurrence data using habitat covariates.
When using this code:
library(auk)
occ_wide <- format_unmarked_occu(occ,
site_id = "site",
response = "species_observed",
site_covs = c("n_observations",
"latitude", "longitude",
"pland_00_water",
"pland_11_wetland",
"pland_12_cropland",
"pland_13_urban"),
obs_covs = c("time_observations_started",
"duration_minutes",
"effort_distance_km",
"number_observers",
"protocol_type",
"pland_11_wetland"))
I get this error:
Error in format_unmarked_occu(occu, site_id = "site", response = "species_observed", : Site-level covariates must be constant across sites
What does this mean and how can I overcome this error?
a reproducible code can be found here: https://github.com/lime-n/ebird_data/blob/master/occ.csv
I have found a way of bypassing this by using
library( data.table )
setDT(mydata)[ !duplicated( site, fromlast = TRUE ), ]
However, when I run the occu model, it shows mainly negative values:
dggs <- dgconstruct(spacing = 5)
# get hexagonal cell id for each site
occ_wide_cell <- occ_wide %>%
mutate(cell = dgGEO_to_SEQNUM(dggs, longitude, latitude)$seqnum)
# sample one site per grid cell
occ_ss <- occ_wide_cell %>%
group_by(cell) %>%
sample_n(size = 1) %>%
ungroup() %>%
select(-cell)
# calculate the percent decrease in the number of sites
1 - nrow(occ_ss) / nrow(occ_wide)
occ_um <- formatWide(occ_ss, type = "unmarkedFrameOccu")
summary(occ_um)
occ_model <- occu(~ time_observations_started +
duration_minutes +
effort_distance_km +
number_observers +
protocol_type +
pland_04_deciduous_broadleaf +
pland_05_mixed_forest
~ pland_04_deciduous_broadleaf +
pland_05_mixed_forest +
pland_12_cropland +
pland_13_urban,
data = occ_um)
# look at the regression coefficients from the model
summary(occ_model)
which means I cannot run this code as it requires postive values:
occ_gof <- mb.gof.test(occ_model, nsim = 10, plot.hist = FALSE)
Meaning that I did not approach it correctly, because the majority of valuable sites are removed.
EDIT: problem is within longitudinal coordinates