CornellLabofOrnithology / auk

Working with eBird data in R
https://CornellLabofOrnithology.github.io/auk/
GNU General Public License v3.0
136 stars 20 forks source link

Error in format_unmarked_occu(occ, site_id = "site", response = "pres_abs", : Site-level covariates must be constant across sites #56

Closed vjjan91 closed 2 years ago

vjjan91 commented 3 years ago

I keep running into this error that says: Site-level covariates must be constant across sites. I have been following the code outlined in 'Best practices...', but each time I run this code chunk, I run into the above error:

occ_wide <- format_unmarked_occu(occ, site_id = "site", response = "pres_abs", site_covs = c( "locality_id", "lc_02.y", "lc_09.y", "lc_01.y", "lc_05.y", "lc_04.y", "lc_07.y", "lc_03.y", "bio_15a.y", "bio_4a.y" ), obs_covs = obs_covs )

For some reason, if I got rid of bio_15 - I don't run into this error anymore, which is weird.

mstrimas commented 3 years ago

I suggest you start by identifying which rows in your data frame have different values of bio_15a.y for the same value of site, e.g.:

occ <- data.frame(site = c(1, 1, 2, 2),
                  bio_15a.y = c(1.1, 1.1, 12.2, 9.1))
occ %>% 
  select(site, bio_15a.y) %>% 
  group_by(site) %>% 
  filter(n_distinct(bio_15a.y) > 1)