Description Usage Arguments Value Examples
View source: R/compute_expected.R
Compute the expected death count for each unit of time. We assume counts are ovedsispersed Poisson distributed with a trend that accounts for changes in death rate across time and a seasonal effect. The function take data frame with dates and counts and returns the data frame with the expected counts as a new column. It also returns a logical column that is 'TRUE' if that entry was used in the estimation procedure.
1 2 3 4 5 6 7 8 9 10 |
counts |
A data frame with dates, counts, and population size |
exclude |
A list of dates to exclude when fitting the model |
trend.knots.per.year |
Number of knots per year used for the time trend |
harmonics |
Number of harmonics to include in the seasonal effect |
frequency |
Number of data points per year. If not provided, the function attempts to estimate it |
weekday.effect |
A logical that determines if a day of the week effect is included in the model |
keep.components |
A logical that if 'TRUE' forces the function to return the estimated trend, seasonal model, and weekday effect, if included in the model. |
verbose |
A logical that if 'TRUE' makes function prints out updates on the estimation procedure |
The 'counts' data.frame with two columns added: 'expected' and 'excluded'. The 'expected' column is the estimated expected value of the counts for that date. The 'excluded' column is a logical vector denoting if that date was excluded when estimating the expected value.
If the argument 'keep.components' is 'TRUE' a list is returned with 'counts' data.frame in the first component, the estimated trend in the second, the estimated seasonal effect in the third and the estimated weekday effects in the fourth.
1 2 3 4 5 | data(new_jersey_counts)
exclude_dates <- as.Date("2012-10-29") + 0:180
counts <- compute_expected(new_jersey_counts, exclude = exclude_dates, weekday.effect = TRUE)
library(ggplot2)
expected_plot(counts)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.