Skip to contents

Accepts either a long-format data.frame (columns year, category, count) or a nested list keyed [[year]][[category]] = count.

Usage

morie_tps_csi_per_year(
  counts_per_year,
  variant = c("total", "violent"),
  weights = NULL,
  population = NULL,
  per_capita_unit = 100000L,
  rebase_to_year = NULL,
  rebase_to_value = 100
)

Arguments

counts_per_year

Long data.frame or nested list (see above).

variant

One of "total" or "violent".

weights

Optional override vector of weights.

population

Optional named integer vector (year -> pop); defaults to MORIE_TPS_TORONTO_POPULATION_BY_YEAR().

per_capita_unit

Rate denominator (default 100000).

rebase_to_year

Optional anchor year for the index.

rebase_to_value

Index value at the anchor year (default 100).

Value

A data.frame with one row per year.

Details

Returns a data.frame indexed by year with columns:

  • raw_weighted_sum – sum_c w_c * n_(c,year)

  • total_count – sum_c n_(c,year)

  • population – Toronto population that year

  • csi_per_capita – raw_weighted_sum / population * per_capita_unit

  • simple_count_rate – total_count / population * per_capita_unit

When rebase_to_year is supplied, an additional csi_index column is added, anchored so that that year's value equals rebase_to_value.