Skip to content

Commit

Permalink
add vignette
Browse files Browse the repository at this point in the history
only use log scale in plot if data is not already logged
  • Loading branch information
hillalex committed Nov 19, 2024
1 parent b552ba2 commit 63821f9
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 3 deletions.
2 changes: 1 addition & 1 deletion R/inspect-model.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ inspect_model <- function(mod, private) {
if (is.null(selected) || selected == "None") {
selected <- character(0)
}
plot_data(data(), ncol = cols(), covariates = selected) +
plot_sero_data(data(), ncol = cols(), covariates = selected) +
theme(plot.margin = unit(c(1, 0, 0, 0), "cm"))
})

Expand Down
4 changes: 2 additions & 2 deletions R/shiny-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ raw_numeric_input <- function(inputId, value, min = NA, max = NA, step = NA) {

raw_text_input <- function(inputId, value = "", placeholder = NULL) {
value <- shiny::restoreInput(id = inputId, default = value)
tags$input(id = inputId, type = "text", class = "shiny-input-text form-control", value = value, placeholder = placeholder)
shiny::tags$input(id = inputId, type = "text", class = "shiny-input-text form-control", value = value, placeholder = placeholder)
}

raw_select_input <- function(inputId, choices, selected = NULL, multiple = FALSE) {
Expand All @@ -18,7 +18,7 @@ raw_select_input <- function(inputId, choices, selected = NULL, multiple = FALSE
if (is.null(selected)) {
if (!multiple) selected <- shiny:::firstChoice(choices)
} else selected <- as.character(selected)
tags$select(id = inputId, class = "shiny-input-select", class = "form-control", shiny:::selectOptions(choices, selected, inputId))
shiny::tags$select(id = inputId, class = "shiny-input-select", class = "form-control", shiny:::selectOptions(choices, selected, inputId))
}


Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ To run all tests locally:
devtools::test()
```

To run tests in a single file:

```{r}
devtools::test(filter="filename")
```

Some tests are skipped on CI to avoid exorbitantly long build times, but this means
it is important to run all tests locally at least once before merging a pull request.

Expand Down
64 changes: 64 additions & 0 deletions vignettes/diagnostics.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: "Model diagnostics and plotting"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Model diagnostics and plotting}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

## Plotting model inputs

### Priors
Calling `plot` on an object of type [biokinetics_priors](../reference/biokinetics_priors.html) will generate
a plot of the kinetics predicted by the given priors.

```{r}
priors <- epikinetics::biokinetics_priors()
plot(priors)
```

You can optionally pass a dataset to compare against the predicted kinetics. Required columns are
`time_since_last_exp` and `value` and values should be on the scale required by the model.

```{r}
data <- data.table::fread(system.file("delta_full.rds", package = "epikinetics"))
data[, time_since_last_exp := as.integer(day - last_exp_day, units = "days")]
data <- epikinetics::convert_log2_scale(data)
priors <- epikinetics::biokinetics_priors()
plot(priors, data = data)
```

If you have an instance of the [biokinetics](../reference/biokinetics.html) class, the method `plot_prior_predictive`
generates this plot for the priors and data given to the model.

```{r}
data <- data.table::fread(system.file("delta_full.rds", package = "epikinetics"))
priors <- epikinetics::biokinetics_priors()
mod <- epikinetics::biokinetics$new(priors = priors, data = data)
mod$plot_prior_predictive()
```

### Data

If you have an instance of the [biokinetics](../reference/biokinetics.html) class, the method `plot_model_inputs`
plots the input data used to fit the model, disaggregated by the covariates in the covariate formula.

```{r}
mod <- epikinetics::biokinetics$new(priors = priors, data = data, covariate_formula = ~0 + infection_history)
mod$plot_model_inputs()
```

## Interactive data exploration

To play around with different priors and visualise input data filtered and disaggregated in different ways,
the function [biokinetics$inspect](reference/biokinetics.html#method-biokinetics-inspect) runs a local RShiny app with interactive plots.

![RShiny demonstration](./shiny.webm)
Binary file added vignettes/shiny.webm
Binary file not shown.

0 comments on commit 63821f9

Please sign in to comment.