Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new Learn article: using offsets #59

Open
topepo opened this issue Jan 23, 2024 · 0 comments
Open

new Learn article: using offsets #59

topepo opened this issue Jan 23, 2024 · 0 comments

Comments

@topepo
Copy link
Member

topepo commented Jan 23, 2024

With the new tidymodels offsets package (offsetreg), I realize that we have not documented that this can already be done:

library(tidymodels)
library(offsetreg)
library(poissonreg)

us_deaths$offset <- log(us_deaths$population)

fit <- 
  poisson_reg() %>% 
  fit(deaths ~ gender + age_group + year + offset(offset), data = us_deaths)

tidy(fit)
#> # A tibble: 9 × 5
#>   term            estimate std.error statistic p.value
#>   <chr>              <dbl>     <dbl>     <dbl>   <dbl>
#> 1 (Intercept)    -18.3     0.136        -135.        0
#> 2 genderMale       0.328   0.000388      845.        0
#> 3 age_group35-44   0.443   0.00177       250.        0
#> 4 age_group45-54   1.21    0.00155       780.        0
#> 5 age_group55-64   1.99    0.00146      1367.        0
#> 6 age_group65-74   2.71    0.00143      1899.        0
#> 7 age_group75-84   3.65    0.00141      2579.        0
#> 8 age_group85+     4.77    0.00140      3402.        0
#> 9 year             0.00568 0.0000672      84.5       0```

<sup>Created on 2024-01-23 with [reprex v2.0.2](https://reprex.tidyverse.org)</sup>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant