我正在尝试使用栖息地协变量为丰度和发生数据准备物种观察数据框。
使用此代码时:
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"))
我收到此错误:
format_unmarked_occu (occu, site_id = "site", response = "species_observed", 错误:站点级协变量在站点间必须保持不变
这是什么意思,我该如何克服这个错误?
可在此处找到可重现的代码: https ://github.com/lime-n/ebird_data/blob/master/occ.csv
我找到了一种通过使用绕过它的方法
library( data.table )
setDT(mydata)[ !duplicated( site, fromlast = TRUE ), ]
但是,当我运行occu模型时,它主要显示负值:
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)
这意味着我无法运行此代码,因为它需要正值:
occ_gof <- mb.gof.test(occ_model, nsim = 10, plot.hist = FALSE)
这意味着我没有正确处理它,因为大多数有价值的网站都被删除了。
编辑:问题在纵坐标内