-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
78 lines (61 loc) · 2.24 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = FALSE,
comment = "#>",
fig.path = "man/figures/README-",
fig.align = "center",
fig.height = 3,
fig.width = 6,
dpi = 300,
out.width = "80%"
)
```
# rtestim <a href="https://dajmcdon.github.io/rtestim/"><img src="man/figures/logo.png" align="right" height="139" alt="rtestim website" /></a>
<!-- badges: start -->
[![R-CMD-check](https://github.com/dajmcdon/rtestim/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/dajmcdon/rtestim/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
This package uses Poisson likelihood with a trend filtering penalty (a type of
regularized nonparametric regression)
to estimate the effective reproductive number, Rt.
This value roughly says "how many new infections will result from
each new infection today". Values larger than 1 indicate that an
epidemic is growing while those less than 1 indicate decline.
## Installation
You can install the development version of rtestim from [GitHub](https://github.com/) with:
``` r
# install.packages("remotes")
remotes::install_github("dajmcdon/rtestim")
```
## Quick example
Here we create some data that "looks" like a typical wave in an epidemic.
Because the model uses regularized regression, we estimate the model
at a range of tuning parameters simultaneously.
```{r plot-data, message=FALSE, fig.align='center'}
set.seed(12345)
library(rtestim)
library(ggplot2)
dat <- data.frame(
Time = 1:101,
incident_cases = c(1, rpois(100, dnorm(1:100, 50, 15) * 500 + 1))
)
ggplot(dat, aes(Time, incident_cases)) +
geom_point(colour = "cornflowerblue") +
theme_bw()
```
We fit the model and visualize the resulting estimated sequences of $R_t$:
```{r full-fit, fig.align='center'}
mod <- estimate_rt(observed_counts = dat$incident_cases, nsol = 20)
plot(mod)
```
The additional parameter `nsol = 20` specifies the number of
$\lambda$s for which $R_t$ is estimated.
A built in function for cross-validation can be used to select the
tuning parameter.
```{r cv-estimate, fig.align='center'}
mod_cv <- cv_estimate_rt(dat$incident_cases, nsol = 20)
plot(mod_cv, which_lambda = "lambda.1se")
```