/
model-summary.Rmd
163 lines (123 loc) · 3.38 KB
/
model-summary.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
---
title: "Model Summary"
output: html_document
---
```{r libraries, include = FALSE}
library(bbr)
library(tidyverse)
source("functions-model.R")
knitr::opts_chunk$set(
out.width = 500,
out.height = 750
)
```
```{r directories, include=F}
### Directories ----------------------------
scriptDir <- getwd()
projectDir <- file.path("..")
figDir <- file.path(projectDir, "deliv", "figure")
tabDir <- file.path(projectDir, "deliv", "table")
```
```{r echo = FALSE, results = "asis"}
cat("## Run log")
```
```{r }
# create the raw run log
MODEL_DIR <- "../model/pk"
log_df <- run_log(MODEL_DIR) %>%
add_config() %>%
add_summary()
```
```{r echo = FALSE, results = "asis"}
# These two are helpers for doing some
# automatic QC on all the models in log_df
# check if model or data files have changed (from bbr)
check_up_to_date(log_df)
# check if any rogue tags that aren't in tags.yaml (from functions-model.R)
tags_ok <- audit_tags(log_df, yaml::read_yaml(here::here("script", "tags.yaml")))
if (all(tags_ok)) cat("All tags are valid.\n")
```
```{r}
# format log_df for display
log_df %>%
collapse_to_string(based_on, tags, notes) %>%
select(run, based_on, description, tags, ofv, param_count, notes) %>%
knitr::kable()
```
### Tags diff
_Optionally view the tags that were added or removed for each model._
```{r}
# format log_df for display
log_df %>%
add_tags_diff() %>%
format_tags_diff() %>%
select(run, based_on, description, tags, tags_diff) %>%
knitr::kable()
```
# Modeling notes
## Model 100-101
Compare Model 100 (one-cmpt) and 101 (two-cmpt)
```{r obj_100_101}
# this is a helper from functions-model.R which filters
# the summary log tibble to only the specified columns
compare_ofv(100:101, log_df)
```
\newpage
Compare CWRES between model 100 & 101
```{r 100_101_cwres_time_tad}
knitr::include_graphics(file.path(figDir, "100/100-cwres-pred-time-tad.pdf"))
knitr::include_graphics(file.path(figDir, "101/101-cwres-pred-time-tad.pdf"))
```
Second compartment reduces the objective function and residual issues.
\newpage
# Model 101-102
Look at ETA's vs. covariates to decide how to begin incorporating covariates.
```{r}
mod101 <- read_model(file.path(MODEL_DIR, 101))
print(mod101$notes)
```
```{r, out.extra='page=2'}
knitr::include_graphics(file.path(figDir, "101/101-eta-all-cont-cov.pdf"))
```
```{r, out.extra='page=2'}
knitr::include_graphics(file.path(figDir, "102/102-eta-all-cont-cov.pdf"))
```
## Models 102-104
Proportional, additive or combined RUV
```{r}
compare_ofv(102:104, log_df, notes)
```
\newpage
## Models 105-106
105 adds pre-specified covariates. For 106, client was interested in adding Albumin to CL.
```{r}
# filter the run log to only models with this covariate tag
TAGS <- yaml::read_yaml("tags.yaml")
run_log(MODEL_DIR, .include = TAGS$cov_cl_egfr) %>%
add_summary() %>%
select(run, ofv, param_count, condition_number) %>%
knitr::kable()
```
# Comparing final model to base model
```{r}
log_df %>%
filter(star) %>%
select(run, description, ofv, param_count) %>%
knitr::kable()
```
```{r}
mod102 <- read_model(file.path(MODEL_DIR, 102))
mod106 <- read_model(file.path(MODEL_DIR, 106))
tags_diff(mod102, mod106)
```
```{r, results = "asis"}
model_diff(mod102, mod106)
```
# Final model - 106
```{r}
mod106 %>%
model_summary() %>%
param_estimates() %>%
mutate(across(where(is.numeric), pmtables::sig)) %>%
knitr::kable()
```