-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
68 lines (49 loc) · 1.39 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
---
output: github_document
---
```{r, echo = FALSE}
knitr::opts_chunk$set(
fig.path = "man/figures/README-"
)
```
Overview
---
`badlm` is a small R package for inferring the temporally delayed dependence between a predictor and a response variable.
Installation
---
To install the development version of the package, use
```{r, eval = FALSE, warning=FALSE, message=F}
devtools::install_github("alastairrushworth/badlm")
# load the package
library(badlm)
```
```{r, echo = FALSE, warning=FALSE, message=F}
library(badlm)
```
`badlm` example
---
Generate a distributed lag function
```{r, cache = TRUE}
# a nice distributed lag function - hump
x <- 0:50
dlfunction <- -0.1 + (0.01*exp(-0.2*x) + exp(dnorm(x, sd = 4, mean = 10))) / 10
plot(x, dlfunction, type = "l")
```
Generate predictor and response under the distributed lag function
```{r, cache = TRUE}
# response is an AR(1) process
expose <- arima.sim(model = list(ar = 0.5), n = 500, sd = 0.1)
expose <- (expose - mean(expose)) / sd(expose)
lag_mat <- lag_matrix(expose, p = 50)
deaths.sig <- lag_mat %*% dlfunction
deaths <- deaths.sig + rnorm(450, sd = 0.01)
```
Try to recover the distribution lag function
```{r, cache = TRUE, results='hide'}
dlm_est <- badlm(x = expose, y = deaths,
nlag = 50, k = 30, samples = 10000)
```
Plot the resulting lag curve
```{r}
plot_lagcurve(dlm_est)
```