rafalab / excessmort

R package for estimating excess deaths from daily count data
20 stars 3 forks source link

Error with monthly data #1

Open jshannon75 opened 4 years ago

jshannon75 commented 4 years ago

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

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 commented 4 years ago

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 _groupby? 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)

jshannon75 commented 4 years ago

Thanks. It looks like group_by was the culprit. I had only January-July data since I'm looking at the COVID outbreak here in Georgia. It works now. Appreciate the quick response.

On Sat, Aug 29, 2020 at 4:18 PM Rolando J. Acosta notifications@github.com wrote:

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)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/rafalab/excessmort/issues/1#issuecomment-683337618, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADJVRGC2D3YO56T6MPFRK2TSDFPA5ANCNFSM4QPE2C3Q .