[R] How to use R0 package?
Jeff Newmiller
jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Fri May 22 16:59:51 CEST 2020
This is getting off-topic here but R0 is a mathematical parameter unrelated to calendar dates. It arises when analyzing case counts (integers) as a function of the numerical measure of time since some non-trivial number of cases has occurred (conventionally this measure is in days)..
dta$days <- as.numeric( dta$date - startdate, units="days" )
On May 22, 2020 5:31:48 AM PDT, Luigi Marongiu <marongiu.luigi using gmail.com> wrote:
>In theory, it works
>```
>> R0 = estimate.R(x1, t=d1, GT=mGT, begin=1, end=117,
> methods="EG",pop.size=pop, nsim=N)
>>R0
>Reproduction number estimate using Exponential Growth method.
>R : 0.7425278[ 0.7409297 , 0.7441229 ]
>```
>but I am not happy because 1. I have to use numbers instead of
>variables and 2. numbers instead of dates (which are instead reported
>in
>the examples...).
>Even if I force to an integer, I still get an error:
>```
>> R0 = estimate.R(x1, t=d1, GT=mGT, begin=1, end=length(x1),
>+ methods="EG",pop.size=pop, nsim=N)
>Error in integrity.checks(epid, t, GT, begin, end, date.first.obs,
>time.step, :
> If both 'begin'= 1 and 'end'= 117 are provided, they must be of the
>same class (dates, character strings or integers).
>> int
>Error: object 'int' not found
>> R0 = estimate.R(x1, t=d1, GT=mGT, begin=1,
>end=as.integer(length(x1)),
>+ methods="EG",pop.size=pop, nsim=N)
>Error in integrity.checks(epid, t, GT, begin, end, date.first.obs,
>time.step, :
> If both 'begin'= 1 and 'end'= 117 are provided, they must be of the
>same class (dates, character strings or integers).
>```
>
>
>
>On Fri, May 22, 2020 at 1:51 PM Eric Berger <ericjberger using gmail.com>
>wrote:
>
>> Hi Luigi,
>> how about begin=1L (to force it to be integer).
>> Also please keep the correspondence on the help list.
>>
>> Best,
>> Eric
>>
>> On Fri, May 22, 2020 at 2:40 PM Luigi Marongiu
><marongiu.luigi using gmail.com>
>> wrote:
>> >
>> > Same error:
>> > ```
>> > > R0 = estimate.R(x1, t=d1, GT=mGT, begin=1, end=length(x1),
>> > methods="EG",pop.size=pop, nsim=N)
>> > Error in integrity.checks(epid, t, GT, begin, end, date.first.obs,
>> time.step, :
>> > If both 'begin'= 1 and 'end'= 117 are provided, they must be of
>the
>> same class (dates, character strings or integers).
>> > > str(length(x1))
>> > int 117
>> > ```
>> >
>> >
>> > On Fri, May 22, 2020 at 12:35 PM Eric Berger
><ericjberger using gmail.com>
>> wrote:
>> >>
>> >> Hi Luigi,
>> >> I am not familiar with the R0 package but I took a quick look.
>> >> The example in the documentation sets begin and end to integers.
>> >> Try setting begin = 1, end = 121 and see if that works.
>> >>
>> >> HTH,
>> >> Eric
>> >>
>> >> On Fri, May 22, 2020 at 1:17 PM Luigi Marongiu <
>> marongiu.luigi using gmail.com> wrote:
>> >> >
>> >> > Hello,
>> >> > I am trying ot get the R0 from the incidence data from China for
>the
>> >> > COVID-19. I set the following:
>> >> > ```
>> >> > library("R0")
>> >> > x1 <- c(259, 457, 688, 769, 1771, 1459, 1737, 1981,
>2099,
>> 2589,
>> >> > 2825, 3235, 3884, 3694, 3143,
>> >> > 3385, 2652, 2973, 2467, 2015, 14108, 5090, 2641,
>2008,
>> >> > 2048, 1888, 1749, 391, 889, 823,
>> >> > 648, 214, 508, 406, 433, 327, 427, 573,
>202,
>> 125,
>> >> > 119, 139, 143, 99, 44,
>> >> > 40, 19, 24, 15, 8, 11, 20, 0,
>16,
>> 13,
>> >> > 13, 34, 39, 46, 39,
>> >> > 78, 47, 67, 55, 54, 45, 0, 79,
>36,
>> 35,
>> >> > 31, 19, 30, 39, 32,
>> >> > 0, 63, 42, 46, 99, 108, 89, 46,
>46,
>> 26,
>> >> > 325, 27, 16, 12, 11,
>> >> > 30, 10, 6, 12, 11, 3, 6, 22,
>4,
>> 12,
>> >> > 1, 3, 3, 1, 2,
>> >> > 2, 1, 1, 14, 17, 1, 7, 3,
>4,
>> 8,
>> >> > 6, 7)
>> >> > d1 = c("2020-01-23", "2020-01-24", "2020-01-25", "2020-01-26",
>> >> > "2020-01-27", "2020-01-28", "2020-01-29",
>> >> > "2020-01-30", "2020-01-31", "2020-02-01", "2020-02-02",
>> >> > "2020-02-03", "2020-02-04", "2020-02-05",
>> >> > "2020-02-06", "2020-02-07", "2020-02-08", "2020-02-09",
>> >> > "2020-02-10", "2020-02-11", "2020-02-12",
>> >> > "2020-02-13", "2020-02-14", "2020-02-15", "2020-02-16",
>> >> > "2020-02-17", "2020-02-18", "2020-02-19",
>> >> > "2020-02-20", "2020-02-21", "2020-02-22", "2020-02-23",
>> >> > "2020-02-24", "2020-02-25", "2020-02-26",
>> >> > "2020-02-27", "2020-02-28", "2020-02-29", "2020-03-01",
>> >> > "2020-03-02", "2020-03-03", "2020-03-04",
>> >> > "2020-03-05", "2020-03-06", "2020-03-07", "2020-03-08",
>> >> > "2020-03-09", "2020-03-10", "2020-03-11",
>> >> > "2020-03-12", "2020-03-13", "2020-03-14", "2020-03-15",
>> >> > "2020-03-16", "2020-03-17", "2020-03-18",
>> >> > "2020-03-19", "2020-03-20", "2020-03-21", "2020-03-22",
>> >> > "2020-03-23", "2020-03-24", "2020-03-25",
>> >> > "2020-03-26", "2020-03-27", "2020-03-28", "2020-03-29",
>> >> > "2020-03-30", "2020-03-31", "2020-04-01",
>> >> > "2020-04-02", "2020-04-03", "2020-04-04", "2020-04-05",
>> >> > "2020-04-06", "2020-04-07", "2020-04-08",
>> >> > "2020-04-09", "2020-04-10", "2020-04-11", "2020-04-12",
>> >> > "2020-04-13", "2020-04-14", "2020-04-15",
>> >> > "2020-04-16", "2020-04-17", "2020-04-18", "2020-04-19",
>> >> > "2020-04-20", "2020-04-21", "2020-04-22",
>> >> > "2020-04-23", "2020-04-24", "2020-04-25", "2020-04-26",
>> "2020-04-27"
>> >> > ,"2020-04-28", "2020-04-29",
>> >> > "2020-04-30", "2020-05-01", "2020-05-02", "2020-05-03",
>> >> > "2020-05-04", "2020-05-05", "2020-05-06",
>> >> > "2020-05-07", "2020-05-08", "2020-05-09", "2020-05-10",
>> >> > "2020-05-11", "2020-05-12", "2020-05-13",
>> >> > "2020-05-14", "2020-05-15", "2020-05-16", "2020-05-17",
>> "2020-05-18")
>> >> > names(x1) <- d1
>> >> > pop = 1438443864
>> >> > Ts_mean = 5.16
>> >> > Ts_sd = 1.49
>> >> > N=10000
>> >> > TODAY = Sys.Date()
>> >> > mGT = generation.time("gamma", c(Ts_mean, Ts_sd))
>> >> > R0 = estimate.R(x1, t=d1, GT=mGT, begin=as.Date(d1[1]),
>end=TODAY,
>> >> > methods="EG",pop.size=pop, nsim=N)
>> >> > ```
>> >> > but when I run I get:
>> >> > ```
>> >> > Error in if (end.nb <= begin.nb) stop("'begin' and 'end' are not
>> >> > consistent.") :
>> >> > argument is of length zero
>> >> > > as.Date(d1[1])
>> >> > [1] "2020-01-23"
>> >> > > TODAY
>> >> > [1] "2020-05-22"
>> >> > > str(TODAY)
>> >> > Date[1:1], format: "2020-05-22"
>> >> > > str(as.Date(d1[1]))
>> >> > Date[1:1], format: "2020-01-23"
>> >> > ```
>> >> > Since I provided both start and end in the same format, I don't
>> understand
>> >> > the error.
>> >> > Any tips?
>> >> > Thank you
>> >> > --
>> >> > Best regards,
>> >> > Luigi
>> >> >
>> >> > [[alternative HTML version deleted]]
>> >> >
>> >> > ______________________________________________
>> >> > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more,
>see
>> >> > https://stat.ethz.ch/mailman/listinfo/r-help
>> >> > PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> >> > and provide commented, minimal, self-contained, reproducible
>code.
>> >
>> >
>> >
>> > --
>> > Best regards,
>> > Luigi
>>
--
Sent from my phone. Please excuse my brevity.
More information about the R-help
mailing list