-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathREADME.Rmd
118 lines (90 loc) · 3.77 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
---
output:
md_document:
variant: markdown_github
---
```{r, echo = FALSE, results='hide', message = FALSE, warning=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
library(popEpi)
```
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/popEpi)](https://cran.r-project.org/package=popEpi)
[![Codecov test coverage](https://codecov.io/gh/FinnishCancerRegistry/popEpi/branch/master/graph/badge.svg)](https://app.codecov.io/gh/FinnishCancerRegistry/popEpi?branch=master)
[![CRAN_DLs_via_RStudio](https://cranlogs.r-pkg.org/badges/popEpi)](https://cran.r-project.org/package=popEpi)
[![R-CMD-check](https://github.com/FinnishCancerRegistry/popEpi/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/FinnishCancerRegistry/popEpi/actions/workflows/R-CMD-check.yaml)
# popEpi: Epidemiology with population data
The purpose of popEpi is to facilitate computing certain epidemiological
statistics where population data is used. Current main attractions:
## Splitting, merging population hazards, and aggregating
the `lexpand` function allows users to split their subject-level follow-up data into sub-intervals along age, follow-up time and calendar time,
merge corresponding population hazard information to those intervals,
and to aggregate the resulting data if needed.
```{r lexpand}
data(sire)
sr <- sire[1,]
print(sr)
```
```{r lexpand2}
x <- lexpand(sr, birth = bi_date, entry = dg_date, exit = ex_date,
status = status %in% 1:2,
fot = 0:5, per = 1994:2000)
print(x)
```
```{r lexpand3}
data(popmort)
x <- lexpand(sr, birth = bi_date, entry = dg_date, exit = ex_date,
status = status %in% 1:2,
fot = 0:5, per = 1994:2000, pophaz = popmort)
print(x)
```
```{r aggre}
a <- lexpand(sr, birth = bi_date, entry = dg_date, exit = ex_date,
status = status %in% 1:2,
fot = 0:5, per = 1994:2000, aggre = list(fot, per))
print(a)
```
## SIRs / SMRs
One can make use of the `sir` function to estimate indirectly standardised incidence or
mortality ratios (SIRs/SMRs). The data can be aggregated by `lexpand` or by other means.
While `sir` is simple and flexible in itself, one may also use `sirspline` to fit
spline functions for the effect of e.g. age as a continuous variable on SIRs.
```{r sir}
data(popmort)
data(sire)
c <- lexpand( sire, status = status %in% 1:2, birth = bi_date, exit = ex_date, entry = dg_date,
breaks = list(per = 1950:2013, age = 1:100, fot = c(0,10,20,Inf)),
aggre = list(fot, agegroup = age, year = per, sex) )
se <- sir( coh.data = c, coh.obs = 'from0to1', coh.pyrs = 'pyrs',
ref.data = popmort, ref.rate = 'haz',
adjust = c('agegroup', 'year', 'sex'), print = 'fot')
se
```
## (Relative) survival
The `survtab` function computes observed, net/relative and cause-specific
survivals as well as cumulative incidence functions for `Lexis` data.
Any of the supported survival time functions can be
easily adjusted by any number of categorical variables if needed.
One can also use `survtab_ag` for aggregated data. This means the data does
not have to be on the subject-level to compute survival time function estimates.
```{r survtab}
library(Epi)
data(sibr)
sire$cancer <- "rectal"
sibr$cancer <- "breast"
sr <- rbind(sire, sibr)
sr$cancer <- factor(sr$cancer)
sr <- sr[sr$dg_date < sr$ex_date, ]
sr$status <- factor(sr$status, levels = 0:2,
labels = c("alive", "canD", "othD"))
x <- Lexis(entry = list(FUT = 0, AGE = dg_age, CAL = get.yrs(dg_date)),
exit = list(CAL = get.yrs(ex_date)),
data = sr,
exit.status = status)
st <- survtab(FUT ~ cancer, data = x,
breaks = list(FUT = seq(0, 5, 1/12)),
surv.type = "cif.obs")
st
```