diff options
author | Naeem Model <me@nmode.ca> | 2023-06-21 15:56:12 +0000 |
---|---|---|
committer | Naeem Model <me@nmode.ca> | 2023-06-21 15:56:12 +0000 |
commit | c85280a9cfe1f46eb4bc260d7f479a33d86dceff (patch) | |
tree | e14928565b80793d177607ce321a06e9993c41c2 | |
parent | e0988851b26668ec69131e22a0815ce6f85b94c4 (diff) |
Re-generate docs
-rw-r--r-- | DESCRIPTION | 1 | ||||
-rw-r--r-- | NAMESPACE | 10 | ||||
-rw-r--r-- | man/ID.Rd | 31 | ||||
-rw-r--r-- | man/IDEA.Rd | 32 | ||||
-rw-r--r-- | man/WP.Rd | 72 | ||||
-rw-r--r-- | man/WP_known.Rd | 9 | ||||
-rw-r--r-- | man/WP_unknown.Rd | 24 | ||||
-rw-r--r-- | man/computeLL.Rd | 8 | ||||
-rw-r--r-- | man/seqB.Rd | 54 |
9 files changed, 154 insertions, 87 deletions
diff --git a/DESCRIPTION b/DESCRIPTION index f983020..4558fa8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -9,3 +9,4 @@ Description: More about what it does (maybe more than one line) License: What license is it under? Encoding: UTF-8 LazyData: true +RoxygenNote: 7.2.3 @@ -1 +1,9 @@ -exportPattern("^[[:alpha:]]+") +# Generated by roxygen2: do not edit by hand + +export(ID) +export(IDEA) +export(WP) +export(WP_known) +export(WP_unknown) +export(computeLL) +export(seqB) @@ -7,40 +7,43 @@ ID(NT, mu) } \arguments{ -\item{NT}{Vector of case counts} +\item{NT}{Vector of case counts.} -\item{mu}{Mean of the serial distribution (needs to match case counts in time units; for example, if case counts are weekly and the serial distribution has a mean of seven days, then \code{mu} should be set to one, if case counts are daily and the serial distribution has a mean of seven days, then \code{mu} should be set to seven).} +\item{mu}{Mean of the serial distribution. This needs to match case counts in time units. For example, if case counts +are weekly and the serial distribution has a mean of seven days, then \code{mu} should be set to one If case +counts are daily and the serial distribution has a mean of seven days, then \code{mu} should be set to seven.} } \value{ -\code{ID} returns a list containing the following components: \code{Rhat} is the estimate of R0 and \code{inputs} is a list of the original input variables \code{NT, mu}. +\code{ID} returns a single value, the estimate of R0. } \description{ -This function implements a least squares estimation method of R0 due to Fisman et al. (PloS One, 2013). See details for implementation notes. +This function implements a least squares estimation method of R0 due to Fisman et al. (PloS One, 2013). +See details for implementation notes. } \details{ -The method is based on a straightforward incidence decay model. The estimate of R0 is the value which minimizes the sum of squares between observed case counts and cases counts 'expected' under the model. +The method is based on a straightforward incidence decay model. The estimate of R0 is the value which +minimizes the sum of squares between observed case counts and cases counts 'expected' under the model. -This method is based on an approximation of the SIR model, which is most valid at the beginning of an epidemic. The method assumes that the mean of the serial distribution (sometimes called the serial interval) is known. The final estimate can be quite sensitive to this value, so sensitivity testing is strongly recommended. Users should be careful about units of time (e.g. are counts observed daily or weekly?) when implementing. +This method is based on an approximation of the SIR model, which is most valid at the beginning of an epidemic. +The method assumes that the mean of the serial distribution (sometimes called the serial interval) is known. +The final estimate can be quite sensitive to this value, so sensitivity testing is strongly recommended. +Users should be careful about units of time (e.g., are counts observed daily or weekly?) when implementing. } \examples{ - ## ===================================================== ## ## Illustrate on weekly data ## ## ===================================================== ## -NT <- c(1, 4, 10, 5, 3, 4, 19, 3, 3, 14, 4) +NT <- c(1, 4, 10, 5, 3, 4, 19, 3, 3, 14, 4) ## obtain Rhat when serial distribution has mean of five days -res1 <- ID(NT=NT, mu=5/7) -res1$Rhat +ID(NT=NT, mu=5/7) ## obtain Rhat when serial distribution has mean of three days -res2 <- ID(NT=NT, mu=3/7) -res2$Rhat +ID(NT=NT, mu=3/7) ## ========================================================= ## ## Compute Rhat using only the first five weeks of data ## ## ========================================================= ## +ID(NT=NT[1:5], mu=5/7) # serial distribution has mean of five days -res3 <- ID(NT=NT[1:5], mu=5/7) # serial distribution has mean of five days -res3$Rhat } diff --git a/man/IDEA.Rd b/man/IDEA.Rd index 4a55853..2dc8240 100644 --- a/man/IDEA.Rd +++ b/man/IDEA.Rd @@ -7,40 +7,44 @@ IDEA(NT, mu) } \arguments{ -\item{NT}{Vector of case counts} +\item{NT}{Vector of case counts.} -\item{mu}{Mean of the serial distribution (needs to match case counts in time units; for example, if case counts are weekly and the serial distribution has a mean of seven days, then \code{mu} should be set to one, if case counts are daily and the serial distribution has a mean of seven days, then \code{mu} should be set to seven)} +\item{mu}{Mean of the serial distribution. This needs to match case counts in time units. For example, if case counts +are weekly and the serial distribution has a mean of seven days, then \code{mu} should be set to one. If case +counts are daily and the serial distribution has a mean of seven days, then \code{mu} should be set to seven.} } \value{ -\code{IDEA} returns a list containing the following components: \code{Rhat} is the estimate of R0 and \code{inputs} is a list of the original input variables \code{NT, mu}. +\code{IDEA} returns a single value, the estimate of R0. } \description{ -This function implements a least squares estimation method of R0 due to Fisman et al. (PloS One, 2013). See details for implementation notes. +This function implements a least squares estimation method of R0 due to Fisman et al. (PloS One, 2013). +See details for implementation notes. } \details{ -This method is closely related to that implemented in \code{ID}. The method is based on an incidence decay model. The estimate of R0 is the value which minimizes the sum of squares between observed case counts and cases counts 'expected' under the model. +This method is closely related to that implemented in \code{ID}. The method is based on an incidence decay model. +The estimate of R0 is the value which minimizes the sum of squares between observed case counts and cases counts +expected under the model. -This method is based on an approximation of the SIR model, which is most valid at the beginning of an epidemic. The method assumes that the mean of the serial distribution (sometimes called the serial interval) is known. The final estimate can be quite sensitive to this value, so sensitivity testing is strongly recommended. Users should be careful about units of time (e.g. are counts observed daily or weekly?) when implementing. +This method is based on an approximation of the SIR model, which is most valid at the beginning of an epidemic. +The method assumes that the mean of the serial distribution (sometimes called the serial interval) is known. +The final estimate can be quite sensitive to this value, so sensitivity testing is strongly recommended. +Users should be careful about units of time (e.g., are counts observed daily or weekly?) when implementing. } \examples{ - ## ===================================================== ## ## Illustrate on weekly data ## ## ===================================================== ## -NT <- c(1, 4, 10, 5, 3, 4, 19, 3, 3, 14, 4) +NT <- c(1, 4, 10, 5, 3, 4, 19, 3, 3, 14, 4) ## obtain Rhat when serial distribution has mean of five days -res1 <- IDEA(NT=NT, mu=5/7) -res1$Rhat +IDEA(NT=NT, mu=5/7) ## obtain Rhat when serial distribution has mean of three days -res2 <- IDEA(NT=NT, mu=3/7) -res2$Rhat +IDEA(NT=NT, mu=3/7) ## ========================================================= ## ## Compute Rhat using only the first five weeks of data ## ## ========================================================= ## +IDEA(NT=NT[1:5], mu=5/7) # serial distribution has mean of five days -res3 <- IDEA(NT=NT[1:5], mu=5/7) # serial distribution has mean of five days -res3$Rhat } @@ -6,65 +6,89 @@ \usage{ WP( NT, - mu = "NA", - method = "unknown", + mu = NA, search = list(B = 100, shape.max = 10, scale.max = 10), tol = 0.999 ) } \arguments{ -\item{NT}{Vector of case counts} +\item{NT}{Vector of case counts.} -\item{mu}{Mean of the serial distribution (needs to match case counts in time units; for example, if case counts are weekly and the serial distribution has a mean of seven days, then \code{mu} should be set to one). The default value of \code{mu} is set to \code{NA}.} +\item{mu}{Mean of the serial distribution (needs to match case counts in time units; for example, if case +counts are weekly and the serial distribution has a mean of seven days, then \code{mu} should be +set to one). The default value of \code{mu} is set to \code{NA}.} -\item{method}{Variable taking one of two possible values: \code{known} or \code{unknown}. If "known", the serial distribution is assumed to be gamma with rate 1/\code{mu} and shape equal to one, if "unknown" then the serial distribution is gamma with unknown parameters. Defaults to "unknown"} +\item{search}{List of default values for the grid search algorithm. The list includes three elements: the +first is \code{B}, which is the length of the grid in one dimension; the second is +\code{scale.max}, which is the largest possible value of the scale parameter; and the third +is \code{shape.max}, which is the largest possible value of the shape parameter. Defaults to +\code{B=100, scale.max=10, shape.max=10}. For both shape and scale, the smallest possible +value is 1/\code{B}.} -\item{search}{List of default values for the grid search algorithm; the list includes three elements: the first is \code{B} which is the length of the grid in one dimension, the second is \code{scale.max} which is the largest possible value of the scale parameter, and the third is \code{shape.max} which is the largest possible value of the shape parameter; defaults to \code{B=100, scale.max=10, shape.max=10}. For both shape and scale, the smallest possible value is 1/\code{B}.} - -\item{tol}{Cutoff value for cumulative distribution function of the pre-discretization gamma serial distribution, defaults to 0.999 (i.e. in the discretization, the maximum is chosen such that the original gamma distribution has cumulative probability of no more than 0.999 at this maximum).} +\item{tol}{Cutoff value for cumulative distribution function of the pre-discretization gamma serial +distribution. Defaults to 0.999 (i.e. in the discretization, the maximum is chosen such that the +original gamma distribution has cumulative probability of no more than 0.999 at this maximum).} } \value{ -WP returns a list containing the following components: \code{Rhat} is the estimate of R0, \code{SD} is either the discretized serial distribution (if \code{method="known"}) or the estimated discretized serial distribution (if \code{method="unknown"}), and \code{inputs} is a list of the original input variables \code{NT, mu, method, search, tol}. The list also returns the variable \code{check}, which is equal to the number of non-unique maximum likelihood estimators. The serial distribution \code{SD} is returned as a list made up of \code{supp} the support of the distribution and \code{pmf} the probability mass function. +\code{WP} returns a list containing the following components: \code{Rhat} is the estimate of R0, + and \code{SD} is either the discretized serial distribution (if \code{mu} is not \code{NA}), or the + estimated discretized serial distribution (if \code{mu} is \code{NA}). The list also returns the + variable \code{check}, which is equal to the number of non-unique maximum likelihood estimators. + The serial distribution \code{SD} is returned as a list made up of \code{supp} (the support of + the distribution) and \code{pmf} (the probability mass function). } \description{ -This function implements an R0 estimation due to White and Pagano (Statistics in Medicine, 2008). The method is based on maximum likelihood estimation in a Poisson transmission model. See details for important implementation notes. +This function implements an R0 estimation due to White and Pagano (Statistics in Medicine, 2008). +The method is based on maximum likelihood estimation in a Poisson transmission model. +See details for important implementation notes. } \details{ -This method is based on a Poisson transmission model, and hence may be most most valid at the beginning of an epidemic. In their model, the serial distribution is assumed to be discrete with a finite number of posible values. In this implementation, if the serial distribution is assumed known, it is taken to be a discretized version of a gamma distribution with mean \code{mu}, shape parameter one, and largest possible value based on parameter \code{tol}. When the serial distribution is unknown, the function implements a grid search algorithm to find the maximum likelihood estimator over all possible gamma distributions with unknown mean and variance, restricting these to a prespecified grid (see \code{search} parameter). +This method is based on a Poisson transmission model, and hence may be most most valid at the beginning +of an epidemic. In their model, the serial distribution is assumed to be discrete with a finite number +of posible values. In this implementation, if \code{mu} is not {NA}, the serial distribution is taken to +be a discretized version of a gamma distribution with mean \code{mu}, shape parameter one, and largest +possible value based on parameter \code{tol}. When \code{mu} is \code{NA}, the function implements a +grid search algorithm to find the maximum likelihood estimator over all possible gamma distributions +with unknown mean and variance, restricting these to a prespecified grid (see \code{search} parameter). -When the serial distribution is taken to be \code{known}, sensitivity testing of the parameter \code{mu} is strongly recommended. If the serial distribution is \code{unknown}, the likelihood function can be flat near the maximum, resulting in numerical instability of the optimizer. When the serial distribution is \code{unkown} the implementation takes considerably longer to run. Users should be careful about units of time (e.g. are counts observed daily or weekly?) when implementing. +When the serial distribution is known (i.e., \code{mu} is not \code{NA}), sensitivity testing of \code{mu} +is strongly recommended. If the serial distribution is unknown (i.e., \code{mu} is \code{NA}), the +likelihood function can be flat near the maximum, resulting in numerical instability of the optimizer. +When \code{mu} is \code{NA}, the implementation takes considerably longer to run. Users should be careful +about units of time (e.g., are counts observed daily or weekly?) when implementing. -The model developed in White and Pagano (2008) is discrete, and hence the serial distribution is finite discrete. In our implementation, the input value \code{mu} is that of a continuous distribution. The algorithm when \code{method="known"} disretizes this input, and hence the mean of the serial distribution returned in the list \code{SD} will differ from \code{mu} somewhat. That is to say, if the user notices that the input \code{mu} and out put mean of \code{SD} are different, this is to be expected, and is caused by the discretization. +The model developed in White and Pagano (2008) is discrete, and hence the serial distribution is finite +discrete. In our implementation, the input value \code{mu} is that of a continuous distribution. The +algorithm discretizes this input when \code{mu} is not \code{NA}, and hence the mean of the serial +distribution returned in the list \code{SD} will differ from \code{mu} somewhat. That is to say, if the +user notices that the input \code{mu} and output mean of \code{SD} are different, this is to be expected, +and is caused by the discretization. } \examples{ - ## ===================================================== ## ## Illustrate on weekly data ## ## ===================================================== ## -NT <- c(1, 4, 10, 5, 3, 4, 19, 3, 3, 14, 4) +NT <- c(1, 4, 10, 5, 3, 4, 19, 3, 3, 14, 4) ## obtain Rhat when serial distribution has mean of five days -res1 <- WP(NT=NT, mu=5/7, method="known") +res1 <- WP(NT=NT, mu=5/7) res1$Rhat ## obtain Rhat when serial distribution has mean of three days -res2 <- WP(NT=NT, mu=3/7, method="known") +res2 <- WP(NT=NT, mu=3/7) res2$Rhat ## obtain Rhat when serial distribution is unknown ## NOTE: this implementation will take longer to run -res3 <- WP(NT=NT) +res3 <- WP(NT=NT) res3$Rhat ## find mean of estimated serial distribution -serial <- res3$SD -sum(serial$supp*serial$pmf) -TODO - talk to Jane about this example - should we have tested SD in our simulations as well in the paper? +serial <- res3$SD +sum(serial$supp * serial$pmf) ## ========================================================= ## ## Compute Rhat using only the first five weeks of data ## ## ========================================================= ## - -res4 <- WP(NT=NT[1:5], mu=5/7, method="known") # serial distribution has mean of five days +res4 <- WP(NT=NT[1:5], mu=5/7) # serial distribution has mean of five days res4$Rhat - } diff --git a/man/WP_known.Rd b/man/WP_known.Rd index 92f3859..dd113ac 100644 --- a/man/WP_known.Rd +++ b/man/WP_known.Rd @@ -7,13 +7,14 @@ WP_known(NT, p) } \arguments{ -\item{NT}{vector of case counts} +\item{NT}{Vector of case counts.} -\item{p}{discretized version of the serial distribution} +\item{p}{Discretized version of the serial distribution.} } \value{ -The function returns \code{Rhat}, the maximum likelihood estimator of R0. +The function returns the maximum likelihood estimator of R0. } \description{ -This is a background/internal function called by \code{WP}. It computes the maximum likelihood estimator of R0 assuming that the serial distribution is known and finite discrete. +This is a background/internal function called by \code{WP}. It computes the maximum +likelihood estimator of R0 assuming that the serial distribution is known and finite discrete. } diff --git a/man/WP_unknown.Rd b/man/WP_unknown.Rd index c3872d6..f625019 100644 --- a/man/WP_unknown.Rd +++ b/man/WP_unknown.Rd @@ -7,19 +7,29 @@ WP_unknown(NT, B = 100, shape.max = 10, scale.max = 10, tol = 0.999) } \arguments{ -\item{NT}{vector of case counts} +\item{NT}{Vector of case counts.} -\item{B}{length of grid for shape and scale (grid search parameter)} +\item{B}{Length of grid for shape and scale (grid search parameter).} -\item{shape.max}{maximum shape value (grid search parameter)} +\item{shape.max}{Maximum shape value (grid \code{search} parameter).} -\item{scale.max}{maximum scale value (grid search parameter)} +\item{scale.max}{Maximum scale value (grid \code{search} parameter).} -\item{tol}{cutoff value for cumulative distribution function of the serial distribution, defaults to 0.999} +\item{tol}{cutoff value for cumulative distribution function of the serial distribution (defaults to 0.999).} } \value{ -The function returns \code{Rhat}, the maximum likelihood estimator of R0, as well as the maximum likelihood estimator of the discretized serial distribution given by \code{p} (the probability mass function) and \code{range.max} (the distribution has support on the integers one to \code{range.max}). The function also returns \code{resLL} (all values of the log-likelihood) at \code{shape} (grid for shape parameter) and at \code{scale} (grid for scale parameter), as well as \code{resR0} (the full vector of maximum likelihood estimators), \code{JJ} (the locations for the likelihood for these), and \code{J0} (the location for the maximum likelihood estimator \code{Rhat}). If \code{JJ} and \code{J0} are not the same, this means that the maximum likelihood estimator is not unique. +The function returns \code{Rhat}, the maximum likelihood estimator of R0, as well as the maximum + likelihood estimator of the discretized serial distribution given by \code{p} (the probability mass + function) and \code{range.max} (the distribution has support on the integers one to \code{range.max}). + The function also returns \code{resLL} (all values of the log-likelihood) at \code{shape} (grid for + shape parameter) and at \code{scale} (grid for scale parameter), as well as \code{resR0} (the full + vector of maximum likelihood estimators), \code{JJ} (the locations for the likelihood for these), and + \code{J0} (the location for the maximum likelihood estimator \code{Rhat}). If \code{JJ} and \code{J0} + are not the same, this means that the maximum likelihood estimator is not unique. } \description{ -This is a background/internal function called by \code{WP}. It computes the maximum likelihood estimator of R0 assuming that the serial distribution is unknown but comes from a discretized gamma distribution. The function then implements a simple grid search algorithm to obtain the maximum likelihood estimator of R0 as well as the gamma parameters. +This is a background/internal function called by \code{WP}. It computes the maximum likelihood estimator +of R0 assuming that the serial distribution is unknown but comes from a discretized gamma distribution. +The function then implements a simple grid search algorithm to obtain the maximum likelihood estimator +of R0 as well as the gamma parameters. } diff --git a/man/computeLL.Rd b/man/computeLL.Rd index 15a186e..241d1ad 100644 --- a/man/computeLL.Rd +++ b/man/computeLL.Rd @@ -7,14 +7,14 @@ computeLL(p, NT, R0) } \arguments{ -\item{p}{discretized version of the serial distribution} +\item{p}{Discretized version of the serial distribution.} -\item{NT}{vector of case counts} +\item{NT}{Vector of case counts.} -\item{R0}{basic reproductive ratio} +\item{R0}{Basic reproductive ratio.} } \value{ -The function returns the variable \code{LL} which is the log-likelihood at the input variables and parameters. +This function returns the log-likelihood at the input variables and parameters. } \description{ This is a background/internal function called by \code{WP}. It computes the log-likelihood. diff --git a/man/seqB.Rd b/man/seqB.Rd index b691014..0628a89 100644 --- a/man/seqB.Rd +++ b/man/seqB.Rd @@ -7,38 +7,54 @@ seqB(NT, mu, kappa = 20) } \arguments{ -\item{NT}{Vector of case counts} +\item{NT}{Vector of case counts.} -\item{mu}{Mean of the serial distribution (needs to match case counts in time units; for example, if case counts are weekly and the serial distribution has a mean of seven days, then mu should be set to 1=7/7, if case counts are dailty and the serial distribution has a mean of seven days, then mu should be set to seven).} +\item{mu}{Mean of the serial distribution. This needs to match case counts in time units. For example, if case counts +are weekly and the serial distribution has a mean of seven days, then \code{mu} should be set to one. If case +counts are daily and the serial distribution has a mean of seven days, then \code{mu} should be set to seven.} -\item{kappa}{Largest possible value of uniform prior, defaults to 20. This describes the prior belief on ranges of R0, so should be set to a higher value if R0 is believed to be larger.} +\item{kappa}{Largest possible value of uniform prior (defaults to 20). This describes the prior belief on ranges of R0, +and should be set to a higher value if R0 is believed to be larger.} } \value{ -secB returns a list containing the following components: \code{Rhat} is the estimate of R0 (the posterior mean), \code{posterior} is the posterior distribution of R0 from which alternate estimates can be obtained (see examples), \code{group} is an indicator variable (if \code{group=TRUE}, zero values of NT were input and grouping was done to obtain \code{Rhat}), and \code{inputs} is a list of the original input variables \code{NT, gamma, kappa}. The variable \code{posterior} is returned as a list made up of \code{supp} the support of the distribution and \code{pmf} the probability mass function. +\code{secB} returns a list containing the following components: \code{Rhat} is the estimate of R0 (the posterior mean), + \code{posterior} is the posterior distribution of R0 from which alternate estimates can be obtained (see examples), + and \code{group} is an indicator variable (if \code{group=TRUE}, zero values of NT were input and grouping was done + to obtain \code{Rhat}). The variable \code{posterior} is returned as a list made up of \code{supp} (the support of + the distribution) and \code{pmf} (the probability mass function). } \description{ -This function implements a sequential Bayesian estimation method of R0 due to Bettencourt and Riberio (PloS One, 2008). See details for important implementation notes. +This function implements a sequential Bayesian estimation method of R0 due to Bettencourt and Riberio (PloS One, 2008). +See details for important implementation notes. } \details{ -The method sets a uniform prior distribution on R0 with possible values between zero and \code{kappa}, discretized to a fine grid. The distribution of R0 is then updated sequentially, with one update for each new case count observation. The final estimate of R0 is \code{Rhat}, the mean of the (last) posterior distribution. -The prior distribution is the initial belief of the distribution of R0; which in this implementation is the uninformative uniform distribution with values between zero and kappa. Users can change the value of kappa only (ie. the prior distribution cannot be changed from the uniform). As more case counts are observed, the influence of the prior distribution should lessen on the final estimate \code{Rhat}. +The method sets a uniform prior distribution on R0 with possible values between zero and \code{kappa}, discretized to a fine grid. +The distribution of R0 is then updated sequentially, with one update for each new case count observation. +The final estimate of R0 is \code{Rhat}, the mean of the (last) posterior distribution. +The prior distribution is the initial belief of the distribution of R0; which in this implementation is the uninformative uniform +distribution with values between zero and \code{kappa}. Users can change the value of /code{kappa} only (i.e., the prior distribution +cannot be changed from the uniform). As more case counts are observed, the influence of the prior distribution should lessen on +the final estimate \code{Rhat}. -This method is based on an approximation of the SIR model, which is most valid at the beginning of an epidemic. The method assumes that the mean of the serial distribution (sometimes called the serial interval) is known. The final estimate can be quite sensitive to this value, so sensitivity testing is strongly recommended. Users should be careful about units of time (e.g. are counts observed daily or weekly?) when implementing. +This method is based on an approximation of the SIR model, which is most valid at the beginning of an epidemic. The method assumes +that the mean of the serial distribution (sometimes called the serial interval) is known. The final estimate can be quite sensitive +to this value, so sensitivity testing is strongly recommended. Users should be careful about units of time (e.g., are counts observed +daily or weekly?) when implementing. -Our code has been modified to provide an estimate even if case counts equal to zero are present in some time intervals. This is done by grouping the counts over such periods of time. Without grouping, and in the presence of zero counts, no estimate can be provided. +Our code has been modified to provide an estimate even if case counts equal to zero are present in some time intervals. This is done +by grouping the counts over such periods of time. Without grouping, and in the presence of zero counts, no estimate can be provided. } \examples{ - ## ===================================================== ## ## Illustrate on weekly data ## ## ===================================================== ## -NT <- c(1, 4, 10, 5, 3, 4, 19, 3, 3, 14, 4) +NT <- c(1, 4, 10, 5, 3, 4, 19, 3, 3, 14, 4) ## obtain Rhat when serial distribution has mean of five days -res1 <- seqB(NT=NT, mu=5/7) +res1 <- seqB(NT=NT, mu=5/7) res1$Rhat ## obtain Rhat when serial distribution has mean of three days -res2 <- seqB(NT=NT, mu=3/7) +res2 <- seqB(NT=NT, mu=3/7) res2$Rhat ## ============================================================= ## @@ -46,17 +62,17 @@ res2$Rhat ## ============================================================= ## Rpost <- res1$posterior -loc <- which(Rpost$pmf==max(Rpost$pmf)) -Rpost$supp[loc] # posterior mode -res1$Rhat # compare with posterior mean +loc <- which(Rpost$pmf == max(Rpost$pmf)) +Rpost$supp[loc] # posterior mode +res1$Rhat # compare with posterior mean -par(mfrow=c(2,1), mar=c(2,2,1,1)) +par(mfrow=c(2, 1), mar=c(2, 2, 1, 1)) plot(Rpost$supp, Rpost$pmf, col="black", type="l", xlab="", ylab="") abline(h=1/(20/0.01+1), col="red") abline(v=res1$Rhat, col="blue") abline(v=Rpost$supp[loc], col="purple") legend("topright", legend=c("prior", "posterior", "posterior mean (Rhat)", "posterior mode"), col=c("red", "black", "blue", "purple"), lty=1) -plot(Rpost$supp, Rpost$pmf, col="black", type="l", xlim=c(0.5,1.5), xlab="", ylab="") +plot(Rpost$supp, Rpost$pmf, col="black", type="l", xlim=c(0.5, 1.5), xlab="", ylab="") abline(h=1/(20/0.01+1), col="red") abline(v=res1$Rhat, col="blue") abline(v=Rpost$supp[loc], col="purple") @@ -66,7 +82,7 @@ legend("topright", legend=c("prior", "posterior", "posterior mean (Rhat)", "post ## Compute Rhat using only the first five weeks of data ## ## ========================================================= ## - res3 <- seqB(NT=NT[1:5], mu=5/7) # serial distribution has mean of five days res3$Rhat + } |