reconhub / incidence

☣:chart_with_upwards_trend::chart_with_downwards_trend:☣ Compute and visualise incidence
https://reconhub.github.io/incidence
Other
58 stars 13 forks source link

Fitting log-linear model to incidence curve gives different results for Date and POSIXct inputs to incidence() #91

Closed jrcpulliam closed 5 years ago

jrcpulliam commented 5 years ago

In Ebola simulation part 1, noticed that if the as.Date() line is skipped, the coefficients for the log-linear model fit don't make sense, and don't match the output in the tutorial. Issue seems to be that default time difference for POSIXct is in seconds. Here is an example:

library("incidence")
days <- 1:14
dat_cases <- round(exp(.2*(days)))
dat_dates_Date <- rep(as.Date(Sys.Date()+days), days)
dat_dates_POSIXct <- as.POSIXct(dat_dates_Date)

iD <- incidence(dat_dates_Date)
iP <- incidence(dat_dates_POSIXct)

testthat::expect_equal(fit(iP), fit(iD))
#> Error: fit(iP) not equal to fit(iD).
#> Component "model": Component "coefficients": Mean relative difference: 0.3918407
#> Component "model": Component "qr": Component "qr": Mean relative difference: 0.9999875
#> Component "model": Component "model": Component "dates.x": Mean relative difference: 0.9999876
#> Component "info": Component "r": Mean relative difference: 86399
#> Component "info": Component "r.conf": Mean relative difference: 86399
#> Component "info": Component "pred": Component "dates": Mean absolute difference: 43199.5
#> Component "info": Component "pred": Component "dates.x": Mean relative difference: 0.9999876
#> Component "info": Component "doubling": Mean relative difference: 0.9999884
#> Component "info": Component "doubling.conf": Mean relative difference: 0.9999884

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