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

r estimates from fit() are different when same data are estimated separately or as groups #93

Open
jrcpulliam opened this issue Dec 13, 2018 · 1 comment
Labels

Comments

@jrcpulliam
Copy link
Member

jrcpulliam commented Dec 13, 2018

Example:

library("incidence")  
set.seed(20181213)
days <- 1:14
# Group 1
dat_cases_1 <- round(20*rexp(-.3*(days)))
dat_dates_1 <- rep(as.Date(Sys.Date() + days), dat_cases_1)

i1 <- incidence(dat_dates_1)
f1 <- fit(i1)

# Group 2
dat_cases_2 <- round(rexp(.3*(days)))
dat_dates_2 <- rep(as.Date(Sys.Date() + days), dat_cases_2)

i2 <- incidence(dat_dates_2)
f2 <- suppressWarnings(fit(i2))

# Combine groups
grp <- rep(c("grp1", "grp2"), c(length(dat_dates_1), length(dat_dates_2)))
i.grp <- incidence(c(dat_dates_1, dat_dates_2), groups = grp)
f3 <- fit(i.grp)
#> Warning in fit(i.grp): 8 dates with incidence of 0 ignored for fitting

abs(f3$info$r['grp1']-f1$info$r) # should be 0 or very close to it
#>       grp1 
#> 0.09000228

Created on 2019-01-07 by the reprex package (v0.2.1)

This behavior derives from the fact that i2 has dates with 0 cases but i1 does not, and these dates are removed for both groups when estimating the growth rate.

@jrcpulliam jrcpulliam added the bug label Dec 15, 2018
@zkamvar
Copy link
Member

zkamvar commented Jan 7, 2019

I think we may be able to address this by converting zeros to NA before fitting the model. That way, we can rely on the model functionality to handle the missing data in the way it sees fit. The thing about using this approach is that it will affect the confidence interval estimates. I'll get around to an example when I can get to coding it (which is after I slog through a month of emails github issues 😩)

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

No branches or pull requests

2 participants