-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
128 lines (97 loc) · 4 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
117
118
119
120
121
122
123
124
125
126
127
128
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures",
out.width = "100%"
)
```
# chartplotter
<!-- badges: start -->
[![R-CMD-check](https://github.com/growthcharts/chartplotter/workflows/R-CMD-check/badge.svg)](https://github.com/growthcharts/chartplotter/actions)
[![R-CMD-check](https://github.com/growthcharts/chartplotter/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/growthcharts/chartplotter/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
The goal of `chartplotter` is to
- plot the child's growth curves on pre-defined charts;
- plot two (visit) lines indicating a present and a future visit;
- find matches from donor data similar to the target child;
- predict the most likely future visit value;
- represent the inherent uncertainty of the prediction.
## Installation
You need access to `growthcharts/donorloader` in order to install `chartplotter`.
The following statements will install the `chartplotter` package, as
well as any of its dependencies:
```{r eval = FALSE}
install.packages("remotes")
remotes::install_github("growthcharts/chartplotter")
remotes::install_github("growthcharts/jamesdemodata")
```
```{r setup, include=FALSE}
if (!dir.exists("man/figures")) dir.create("man/figures", recursive = TRUE)
## Example
```
The main function in `chartplotter` is `process_chart()`.
### Example 1: Plot child's data onto a growth chart
```{r example}
library(chartplotter)
library(bdsreader)
library(svglite)
fn <- system.file("extdata", "bds_v2.0", "smocc", "Laura_S.json", package = "jamesdemodata")
tgt <- bdsreader::read_bds(fn)
# No need to manually set file path
svglite::svglite(file = "man/figures/chart1.svg", height = 29.7/2.54, width = 21/2.54)
g <- process_chart(tgt, chartcode = "NMBA")
grid::grid.draw(g)
dev.off()
```
```{r displaysvg, echo=FALSE, fig.align="center", fig.cap="Dutch girls, 0-4 years"}
knitr::include_graphics("man/figures/chart1.svg")
```
### Example 2: Predict height at 3y9m when child is 3 months
Suppose the baby is 3 months old, and that we want to predict
the future child's height at the age of 3y9m.
The following examples finds 25 matches to the child, and plots
the observed curves of those matches as grey curves.
The blue line indicates the predicted height at age 3y9m. The variation
between the grey curves at age 3y9m indicates the amount of
uncertainty of the prediction.
```{r example2}
set.seed(61771)
svglite(file = "man/figures/chart2.svg", height = 29.7/2.54, width = 21/2.54)
g <- process_chart(tgt, chartcode = "NMBA", dnr = "2-4", period = c(0.25, 3.75),
nmatch = 25, show_future = TRUE)
grid::grid.draw(g)
dev.off()
```
```{r display2, echo=FALSE, fig.align = "center", fig.cap="Dutch girls, 0-4 years"}
knitr::include_graphics("man/figures/chart2.svg")
```
### Example 3: Predict height at 3y9m when child is 2 years
Same as before, but now using all data up to (but not beyond)
the age of 2 years. The variation between the grey curves at age 3y9m is now much smaller.
```{r example3}
svglite(file = "man/figures/chart3.svg", height = 29.7/2.54, width = 21/2.54)
g <- process_chart(tgt, chartcode = "NMBA", dnr = "2-4", period = c(2.0, 3.75),
nmatch = 25, show_future = TRUE)
grid::grid.draw(g)
dev.off()
```
```{r display3, echo=FALSE, fig.align = "center", fig.cap="Dutch girls, 0-4 years"}
knitr::include_graphics("man/figures/chart3.svg")
```
### Example 4: Square plot of height, chart `NMBH`
```{r example4}
svglite(file = "man/figures/chart4.svg", height = 18/2.54, width = 18/2.54)
g <- process_chart(tgt, chartcode = "NMBH", quiet = FALSE, dnr = "2-4",
period = c(2.0, 3.75), nmatch = 25,
show_future = TRUE, show_realized = TRUE)
grid::grid.draw(g)
dev.off()
```
```{r display4, echo=FALSE, fig.align = "center", fig.cap="Dutch girls, 0-4 years"}
knitr::include_graphics("man/figures/chart4.svg")
```