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

Error with monthly data #1

Open
jshannon75 opened this issue Aug 29, 2020 · 2 comments
Open

Error with monthly data #1

jshannon75 opened this issue Aug 29, 2020 · 2 comments

Comments

@jshannon75
Copy link

I'm trying this package out on monthly mortality data in Georgia. I've got the following variables:

  • Date (year, month, day--but just the first date of each month)
  • Outcome (count of deaths)
  • Population

There's 147 observations going back to 2000, and I exclude dates from 2020. When I run expected_count, I get the following error:

Error: Column expected must be length 7 (the group size) or one, not 147

Here's the function:
expect_test<-compute_expected(data_test,
frequency=7,
exclude=excludedates)

It looks like it's trying to created 1 expected count for each month but there's 20 years of data. Am I somehow setting this up wrong?

@RJNunez
Copy link
Collaborator

RJNunez commented Aug 29, 2020

Hi, this seems to be an error coming from a processing pipeline where you group by some variable but forgot to ungroup. Are you using group_by? If so, make sure to use ungroup. Also, if you are using monthly data then the frequency argument should be set to 12, not 7. If you don't specify this argument, the function automatically calculates it. Here is an example of using compute_expected with monthly data. You should be able to run this snippet:

library(tidyverse)
library(lubridate)
library(excessmort)

counts <- puerto_rico_counts %>%
group_by(date) %>%
summarize(outcome = sum(outcome),
population = sum(population)) %>%
mutate(date = make_date(year(date), month(date), 01)) %>%
group_by(date) %>%
summarize(outcome = sum(outcome),
population = mean(population))

exclude <- seq(make_date(2020, 01, 01), today(), by = "1 months")
compute_expected(counts = counts,
exclude = exclude)

Repository owner deleted a comment from rafalab Aug 29, 2020
@jshannon75
Copy link
Author

jshannon75 commented Aug 29, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants