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

experiencing problems with format_marked_occu #45

Closed lime-n closed 4 years ago

lime-n commented 4 years ago

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(pract, 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:

structure(list(site = c("L10018668_obs439702_2020", "L10018668_obs439702_2020", 
"L10018668_obs439702_2020", "L10018668_obs439702_2020", "L10024459_obs1462591_2020", 
"L10024459_obs1462591_2020"), closure_id = c("2020", "2020", 
"2020", "2020", "2020", "2020"), n_observations = c(4L, 4L, 4L, 
4L, 6L, 6L), checklist_id = c("S62823384", "S62823384", "S62823384", 
"S62823384", "S62830871", "S62830871"), observer_id = c("obs439702", 
"obs439702", "obs439702", "obs439702", "obs1462591", "obs1462591"
), sampling_event_identifier = c("S62823384", "S62823384", "S62823384", 
"S62823384", "S62830871", "S62830871"), scientific_name = c("Calidris canutus", 
"Calidris canutus", "Calidris canutus", "Calidris canutus", "Calidris canutus", 
"Calidris canutus"), observation_count = c(0, 0, 0, 0, 0, 0), 
    species_observed = c(0L, 0L, 0L, 0L, 0L, 0L), state_code = c("AU-VIC", 
    "AU-VIC", "AU-VIC", "AU-VIC", "AU-NSW", "AU-NSW"), locality_id = c("L10018668", 
    "L10018668", "L10018668", "L10018668", "L10024459", "L10024459"
    ), latitude = c(-37.0209359, -37.0209359, -37.0209359, -37.0209359, 
    -34.785917, -34.785917), longitude = c(145.1458832, 145.1458832, 
    145.1458832, 145.1458832, 150.750221, 150.750221), protocol_type = c("Stationary", 
    "Stationary", "Stationary", "Stationary", "Traveling", "Traveling"
    ), all_species_reported = c(TRUE, TRUE, TRUE, TRUE, TRUE, 
    TRUE), observation_date = structure(c(18262, 18262, 18262, 
    18262, 18262, 18262), class = "Date"), year = c(2020, 2020, 
    2020, 2020, 2020, 2020), day_of_year = c(1, 1, 1, 1, 1, 1
    ), time_observations_started = c(8.71666666666667, 8.71666666666667, 
    8.71666666666667, 8.71666666666667, 14.8166666666667, 14.8166666666667
    ), duration_minutes = c(30, 30, 30, 30, 59, 59), effort_distance_km = c(0, 
    0, 0, 0, 0.805, 0.805), number_observers = c(1, 1, 1, 1, 
    1, 1), pland_00_water = c(NA, NA, NA, NA, 0.032258064516129, 
    NA), pland_01_evergreen_needleleaf = c(NA, NA, NA, NA, NA, 
    NA), pland_02_evergreen_broadleaf = c(NA, NA, NA, NA, NA, 
    0.129032258064516), pland_03_deciduous_needleleaf = c(NA, 
    NA, NA, NA, NA, NA), pland_04_deciduous_broadleaf = c(NA, 
    NA, NA, NA, NA, NA), pland_05_mixed_forest = c(NA, NA, NA, 
    NA, NA, NA), pland_06_closed_shrubland = c(NA, NA, NA, NA, 
    NA, NA), pland_07_open_shrubland = c(NA_real_, NA_real_, 
    NA_real_, NA_real_, NA_real_, NA_real_), pland_08_woody_savanna = c(NA, 
    NA, NA, NA, NA, NA), pland_09_savanna = c(NA, NA, NA, NA, 
    NA, NA), pland_10_grassland = c(NA, NA, NA, NA, NA, NA), 
    pland_11_wetland = c(NA, NA, NA, NA, NA, NA), pland_12_cropland = c(NA, 
    NA, NA, NA, NA, NA), pland_13_urban = c(NA, NA, NA, 0.125, 
    NA, NA), pland_14_mosiac = c(NA, NA, NA, NA, NA, NA), pland_15_barren = c(NA_real_, 
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), id = c(57262, 
    57262, 57262, 57262, 85293, 85293), elevation_median = c(150.127420697893, 
    150.127420697893, 150.127420697893, 150.127420697893, 17.1925210271563, 
    17.1925210271563), elevation_sd = c(5.25428441050561, 5.25428441050561, 
    5.25428441050561, 5.25428441050561, 7.86367063800502, 7.86367063800502
    )), row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame"
))
mstrimas commented 4 years ago

closing because addressed here: https://github.com/CornellLabofOrnithology/ebird-best-practices/issues/8#issuecomment-674951896