Skip to contents

Aggregates incident counts by year, restricts to the 1990-2030 window, fits an OLS line, and reports slope, intercept, and R-squared.

Usage

morie_tps_year_over_year_trend(df, year_col = "OCC_YEAR", ds_name = "?")

Arguments

df

A data.frame with one row per incident.

year_col

Character. Name of the year column (default "OCC_YEAR").

ds_name

Character label for the dataset shown in titles.

Value

A morie_rich_result list with slope, intercept, r2, direction, years, counts, fitted.

Examples

set.seed(1)
df <- data.frame(OCC_YEAR = rep(2014:2023, each = 30),
                 OCC_MONTH = sample(month.name, 300, TRUE),
                 HOOD_158 = sample(sprintf("%03d", 1:20), 300, TRUE),
                 LAT_WGS84 = runif(300, 43.6, 43.8),
                 LONG_WGS84 = runif(300, -79.5, -79.2))
res <- try(morie_tps_year_over_year_trend(df, ds_name = "synthetic"))
if (!inherits(res, "try-error")) str(res, max.level = 1)
#> List of 13
#>  $ title         : chr "Year-over-year trend -- synthetic"
#>  $ call          : chr "morie_tps_year_over_year_trend(df=<300r>, year_col=OCC_YEAR)"
#>  $ summary_lines :List of 9
#>  $ warnings      : chr(0) 
#>  $ interpretation: chr "Linear fit: count = 0.0 * year + 30, R^2 = NaN. Flat trend over the 2014-2023 window."
#>  $ n             : int 10
#>  $ years         : int [1:10] 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023
#>  $ counts        : int [1:10] 30 30 30 30 30 30 30 30 30 30
#>  $ fitted        : num [1:10] 30 30 30 30 30 30 30 30 30 30
#>  $ slope         : num 0
#>  $ intercept     : num 30
#>  $ r2            : num NA
#>  $ direction     : chr "FLAT"
#>  - attr(*, "class")= chr [1:3] "morie_tps_temporal_result" "morie_rich_result" "list"