BBS data is essentially aggregated point count data, that in its raw form has a row for each species observed at each route in each year. This means that if a species is not recorded in a given year, it just doesn’t have a record. I need to add those zeros back in, such that if a species is missing from a route, it needs a row with a zero. For my purposes, it makes the most sense to consider routes only where a given species has been recorded at some point in the history of the route (because I’m supposing its presence/absence depends on some annual variation in a predictor variable).
Leading up to this post, we’ve been shaping and reshaping BBS data and predictor variables, and the last post left off with matching up some remote sensing data to BBS data. The variable “bird” is to be set to an AOU number corresponding to the species list we imported prior.
dataperspecies <- subset(BBS[which(BBS$Aou == bird),]) vars$abundance <- dataperspecies$count[match(vars$rteno, dataperspecies$rteno)] vars[is.na(vars)] <- 0
This is to determine total counts of the species on routes, and to toss routes where the species has never occurred.
assess <- data.table(vars) whattodrop <- assess[,list(abundance=sum(abundance)),by='rteno'] droprtes <- whattodrop$rteno[whattodrop$abundance==0] vars <- vars[!(vars$rteno %in% droprtes),] vars <- vars[vars$RunType > 0,] vars <- vars[vars$RPID < 102]
Last but not least, keep only the columns that will be used in your analysis to minimize space used in the R work space. For my models, in addition to the response and predictor variables, I keep the route number, observer, and whether or not it’s the observer’s first year for consideration as nuisance effects.
Here’s the full script: bbs_species