Skip to contents

Turns a creel_estimates result into a plain table that dplyr, tidyr and ggplot2 accept, so a result can be filtered, joined, bound to other results or written out like any other data.

Usage

# S3 method for class 'creel_estimates'
as_tibble(x, ..., metadata = TRUE)

# S3 method for class 'creel_estimates'
as.data.frame(x, ..., metadata = TRUE)

Arguments

x

A creel_estimates object, as returned by the estimate_*() functions.

...

Unused by as_tibble(); passed to as.data.frame() by as.data.frame().

metadata

If TRUE (the default), add the metadata columns described below. If FALSE, return the estimates table alone.

Value

A tibble (as_tibble()) or data frame (as.data.frame()) with one row per estimate: the grouping columns, estimate, se, ci_lower, ci_upper, n (NA where the estimator reports no sample size) and any further columns the estimator reports. With metadata = TRUE these columns follow:

method

The estimation method, e.g. "total".

estimator

The rate estimator asked for, e.g. "ratio-of-means". Present only on results whose function takes an estimator choice.

variance_method

"taylor", "bootstrap" or "jackknife".

conf_level

Confidence level of ci_lower and ci_upper.

effort_target

What an effort or total estimate totals over, e.g. "sampled_days". Present only on results that have one.

unit

The unit of estimate, e.g. "angler-hours". NA means the unit could not be derived from the data, not that there is none.

Standard-error components (x$se_components) are not returned as columns, for the reason given in tidy.creel_estimates(): read them from the object or from print().

A grouping column with the same name as a metadata column (a by column called unit, say) is an error rather than being overwritten; use metadata = FALSE and read the metadata from the object.

Details

A creel_estimates object keeps what the numbers mean (the method, the unit, the confidence level) beside its table rather than in attributes on it, because an ordinary select() or filter() drops attributes without a word. The conversion copies that metadata into columns, so it travels with every row and is visible if it is dropped.

Examples

design <- creel_design(example_calendar, date = date, strata = day_type)
counts <- prep_counts_daily_effort(example_counts,
  date = date, strata = day_type, daily_effort = effort_hours
)
design <- add_counts(design, counts)
est <- estimate_effort(design, by = day_type)

tibble::as_tibble(est)
#> # A tibble: 2 × 13
#>   day_type estimate    se se_between se_within ci_lower ci_upper     n method
#>   <chr>       <dbl> <dbl>      <dbl>     <dbl>    <dbl>    <dbl> <int> <chr> 
#> 1 weekday      171.  9.67       9.67         0     150.     192.    10 total 
#> 2 weekend      202.  8.95       8.95         0     182.     221.     4 total 
#> # ℹ 4 more variables: variance_method <chr>, conf_level <dbl>,
#> #   effort_target <chr>, unit <chr>
as.data.frame(est, metadata = FALSE)
#>   day_type estimate       se se_between se_within ci_lower ci_upper  n
#> 1  weekday    170.6 9.673790   9.673790         0 149.5226 191.6774 10
#> 2  weekend    201.9 8.946321   8.946321         0 182.4076 221.3924  4