
Impute missing camera counts using GLM or GLMM
Source:R/impute-camera-counts.R
impute_camera_counts.RdFills outage rows in a camera count data frame using a per-stratum model.
The GLM method (default, Hartill 2016) fits a Poisson GLM with strata_col
(typically day_type) as the sole predictor. The GLMM method
(Afrifa-Yamoah 2020) fits a negative binomial GLMM and
requires the glmmTMB package (in Suggests).
Outage rows are identified as any row where status_col != "operational"
AND count_col is NA. All rows are returned; imputed rows have
.imputed = TRUE. The original status_col values (e.g.,
"battery_failure") are preserved in imputed rows for traceability.
Usage
impute_camera_counts(
data,
count_col,
strata_col,
status_col = "camera_status",
method = "glm",
site_col = NULL
)Arguments
- data
A data frame of camera count records. Must have at least one row and must contain the columns named by
count_col,strata_col, andstatus_col.- count_col
Character scalar. Name of the integer count column (e.g.,
"ingress_count"). Outage rows haveNAin this column.- strata_col
Character scalar. Name of the day-type stratum column (e.g.,
"day_type"). Used as the predictor in the per-stratum GLM/GLMM.- status_col
Character scalar. Name of the camera status column. Default
"camera_status". Rows where this column is not"operational"andcount_colisNAare treated as outages.- method
Character scalar. Imputation model:
"glm"(default, Poisson GLM, no extra dependencies) or"glmm"(negative binomial GLMM viaglmmTMB, requiresglmmTMBinSuggests).- site_col
Character scalar or
NULL. Whenmethod = "glmm"andsite_colis notNULL, a random intercept(1 | site_col)is included in the GLMM formula. DefaultNULL.
Value
A data frame with the same rows and columns as data, plus a new
logical column .imputed appended as the last column. Outage rows are
filled in count_col with model-predicted counts (rounded to integer).
The count_col storage mode is set to "integer" for schema
compatibility with add_counts(). Row count equals nrow(data).
References
Hartill, B.W., Cryer, M., and Morrison, M.A. 2020. Camera-based creel surveys: estimating fishing effort and catch rates from ingress-egress camera counts. Fisheries Research 231:105706. doi:10.1016/j.fishres.2020.105706
Afrifa-Yamoah, E., Mueller, U.A., Taylor, S.M., and Fisher, A. 2020. Missing data imputation of high-resolution temporal climate data series using an integrated framework of expectation maximisation and long short-term memory neural networks.
See also
est_effort_camera(), add_counts()
Other "Survey Design":
add_catch(),
add_counts(),
add_interviews(),
add_lengths(),
add_sections(),
as_hybrid_svydesign(),
as_survey_design(),
compute_angler_effort(),
compute_effort(),
creel_design(),
creel_schema(),
est_effort_camera(),
prep_counts_boat_party(),
prep_counts_daily_effort(),
prep_interview_catch(),
prep_interviews_trips(),
validate_creel_schema()
Examples
if (FALSE) { # \dontrun{
library(tidycreel)
data(example_camera_counts)
# Impute missing counts using the default Poisson GLM
imputed <- impute_camera_counts(
example_camera_counts,
count_col = "ingress_count",
strata_col = "day_type"
)
# Inspect imputed rows
imputed[imputed$.imputed, ]
# Pass imputed data directly into a camera design
cal <- data.frame(
date = unique(example_camera_counts$date),
day_type = unique(example_camera_counts[, c("date", "day_type")])[["day_type"]]
)
design <- creel_design(cal,
date = date, strata = day_type,
survey_type = "camera", camera_mode = "counter"
)
design <- add_counts(design, imputed)
} # }