forked from NMautoverse/NMdata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
179 lines (150 loc) · 8.18 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
---
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/README-",
out.width = "100%"
)
library(NMdata)
library(data.table)
library(tibble)
NMdataConf(check.time=FALSE)
NMscanData <- function(x,...)NMdata::NMscanData(file.path(system.file(paste0("examples/nonmem/",x), package="NMdata")),...)
```
# NMdata<a href='https://nmautoverse.github.io/NMdata/'><img src='man/figures/logo.png' align="right" height="120" /></a>
<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html)
[![R-CMD-check](https://github.com/nmautoverse/NMdata/workflows/R-CMD-check/badge.svg)](https://github.com/nmautoverse/NMdata/actions)
[![Codecov test coverage](https://codecov.io/gh/NMautoverse/NMdata/branch/master/graph/badge.svg)](https://app.codecov.io/gh/nmautoverse/NMdata?branch=master)
[![CRAN status](https://www.r-pkg.org/badges/version/NMdata)](https://CRAN.R-project.org/package=NMdata)
[![CRAN downloads](https://cranlogs.r-pkg.org/badges/NMdata)](https://cran.r-project.org/package=NMdata)
<!-- badges: end -->
## A fast R package for efficient data preparation, consistency-checking and post-processing in PK/PD modeling
Pharmacometrics and PK/PD modeling offers unique information for
decision-making in several steps of drug development. However, it
often takes a lot of work to get there, and there are many pitfalls
along the way. NMdata helps simplifying this work and steering around
the pitfalls or at least making sure we didn't fall into them.
### Automate book keeping and focus on modeling
Preparing data sets - and if you use NONMEM, reading the results
data - can be tedious, and mistakes can lead to hours of
frustration. NMdata provides useful tools (including automated checks)
for these trivial tasks.
### NMdata is not a silo
Any functionality in the NMdata can be used independently of the rest
of the package, and NMdata is not intended to force you to change any
habits or preferences. Instead, NMdata tries to fit in with how you
(or your colleague who worked on the project before you) do things. It
likely provides helpful additions no matter what other tools you
already use.
### More information
The best place to browse information about the package is
[here](https://nmautoverse.github.io/NMdata/). The quickest way in is
the
[Cheatsheet](https://htmlpreview.github.io/?https://github.com/nmautoverse/NMdata/blob/master/vignettes/NMdata-cheat.html).
<!-- ![Cheatsheet](man/figures/cheatsheet_icon_0010.png){width="15%"} -->
<!-- [Cheatsheet](https://htmlpreview.github.io/?https://github.com/nmautoverse/NMdata/blob/master/devel/NMdata-cheat.html) -->
<a href="https://htmlpreview.github.io/?https://github.com/nmautoverse/NMdata/blob/master/vignettes/NMdata-cheat.html"><img src="man/figures/cheatsheet_icon_0010.png" alt="CheatSheet" width="200"/></a>
### How to install
`NMdata` is on [CRAN](https://cran.r-project.org/package=NMdata) and [MPN](https://mpn.metworx.com/docs/packages/NMdata). To install from the package archive you are already using, do:
```{r,eval=FALSE}
install.packages("NMdata")
library(NMdata)
```
See further below for instructions on how to install from other sources than your default archive, if need be.
## Prepare, check, and export PK/PD data
On the data-generation side, functionality is provided for
documentation of the datasets while generating them. Check out [this
vignette](https://nmautoverse.github.io/NMdata/articles/DataPrepare.html)
on the topic. There are functions for automatic checks of (some) data
merges, handling and counting of exclusions flags, final preparations
for ensuring readability in NONMEM, and ensuring traceability of
datasets back to data generation scripts.
## Check data as read by NONMEM
The `NMcheckData`
function will do an extensive and fully automated set of checks of the
data before you run NONMEM. And did NONMEM not behave? `NMcheckData`
can debug the data _as seen by NONMEM_. That's right - it has never
been easier to find data bugs.
## Automated and general reader of NONMEM results data
Reading the resulting data from NONMEM can require a few
manual steps. Especially because all modelers seem to do things a
little differently. `NMscanData` can return all data output (`$TABLE`) from NONMEM combined, and if wanted with additional columns and rows in
input data. It's as simple as
```{r,NMscanData-example1}
res <- NMscanData("xgxr014.lst",recover.rows=TRUE)
```
And we are ready to plot (a subset of) the result:
```{r,NMscanData-example1-plot}
res.plot <- subset(res,ID%in%c(113,135)&EVID==0)
library(ggplot2)
ggplot(res.plot,aes(TIME))+
geom_point(aes(y=DV,colour=flag))+
geom_line(aes(y=PRED))+
facet_wrap(~trtact)+
labs(y="Concentration (unit)",colour="Observations",
subtitle="NOTICE:\nObservations are coloured by a character column fetched from input data.\nSamples below LLOQ are rows added from input data.\nPlots are correctly sorted because factor levels of dose are preserved from input data.")+
theme_bw()+theme(legend.position="bottom")
```
Want a tibble instead? Easy:
```{r,NMscanData-example2}
res.tibble <- NMscanData("xgxr001.lst",as.fun=tibble::as_tibble,quiet=TRUE)
```
Or a data.table? This time, we'll configure NMdata to return data.tables by default:
```{r,NMscanData-example3}
NMdataConf(as.fun="data.table")
res.dt <- NMscanData("xgxr001.lst",quiet=TRUE)
```
`NMscanData` is very general, and should work with all kinds of models,
and all kinds of other software and configurations. Take a look at
[this
vignette](https://nmautoverse.github.io/NMdata/articles/NMscanData.html)
for more info on the NONMEM data reader. Then you will learn how to
access the meta data that will allow you to trace every step that was
taken combining the data and the many checks that were done along the
way too.
## Meta analysis made really easy
Since `NMscanData` is so general and will figure out where to find
input and output data on its own, let's use the `NMscanMultiple`
wrapper to read multiple models and compare their predictions.
```{r,NMscanMultiple-plot}
res <- NMscanMultiple(dir=system.file("examples/nonmem", package="NMdata"),
file.pattern="xgxr.*\\.lst",as.fun="data.table",quiet=TRUE)
gmean <- function(x)exp(mean(log(x)))
res.mean <- res[,.(gmeanPRED=gmean(PRED)),by=.(model,NOMTIME)]
obs.all <- unique(res[,.(ID,NOMTIME,TIME,DV)])
ggplot(res.mean,aes(NOMTIME,gmeanPRED,colour=model))+geom_line()+
geom_point(aes(TIME,DV),data=obs.all[!is.na(DV)],inherit.aes=FALSE)+
scale_y_log10()+
labs(x="Time",y="Concentration",subtitle="Comparison of population predictions")+
theme_bw()+
theme(legend.position="bottom")
```
## Get the most recent version
If your archive has not been updated since July 2021, you may not find
`NMdata` if you try to install with `install.packages` (option 1). In that case you have two other options. You can
explicitly select CRAN for the installation. Or if you should want a
version that has not yet reached CRAN, installing from Github is easy
too.
```{r,eval=FALSE}
## Option 1: Install from your default repository
install.packages("NMdata")
## Option 2: Install explicitly from CRAN
install.packages("NMdata",repos="https://cloud.r-project.org")
## Option 3: Install from github
library(remotes)
install_github("nmautoverse/NMdata")
```
If you use the Github version, you may want to see the
[FAQ](https://nmautoverse.github.io/NMdata/articles/NMdata-FAQ.html)
for how to install specific releases from Github (ensuring reproducibility).
## Questions?
Check the [FAQ](https://nmautoverse.github.io/NMdata/articles/NMdata-FAQ.html), or ask on [github](https://github.com/nmautoverse/NMdata/)
## Issues?
The best way to report a bug or to request features is on [github](https://github.com/nmautoverse/NMdata/).
## Code of Conduct
Please note that the patchwork project is released with a [Contributor Code of Conduct](https://nmautoverse.github.io/NMdata/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.