-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
124 lines (94 loc) · 3.38 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
---
output:
github_document:
fig_width: 5
fig_height: 3
---
<!-- 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-"
)
```
# designit <a href="https://bedapub.github.io/designit/"><img src="man/figures/logo.svg" align="right" height="139" /></a>
<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![Documentation](https://img.shields.io/badge/docs-pkgdown-blue.svg)](https://bedapub.github.io/designit/)
<!-- badges: end -->
The goal of designit is to generate optimal sample allocations for experimental designs.
## Installation
Install the released version of rlang from CRAN:
```{r echo=TRUE, eval=FALSE}
install.packages("designit")
```
You can install the development version from GitHub with:
```{r echo=TRUE, eval=FALSE}
# install.packages("devtools")
devtools::install_github("BEDApub/designit")
```
## Usage
### R in Pharma presentation
[![Designit: a flexible engine to generate experiment layouts, R in Pharma presentation](https://img.youtube.com/vi/mvPmSQJVy8o/0.jpg)](https://www.youtube.com/watch?v=mvPmSQJVy8o "Designit: a flexible engine to generate experiment layouts")
### Batch container
The main class used is `BatchContainer`, which holds the dimensions for sample allocation.
After creating such a container, a list of samples can be allocated in it using a given assignment function.
### Creating a table with sample information
```{r samples_table, message=FALSE}
library(tidyverse)
library(designit)
data("longitudinal_subject_samples")
# we use a subset of longitudinal_subject_samples data
subject_data <- longitudinal_subject_samples %>%
filter(Group %in% 1:5, Week %in% c(1,4)) %>%
select(SampleID, SubjectID, Group, Sex, Week) %>%
# with two observations per patient
group_by(SubjectID) %>%
filter(n() == 2) %>%
ungroup() %>%
select(SubjectID, Group, Sex) %>%
distinct()
head(subject_data)
```
### Creating a `BatchContainer` and assigning samples
```{r random_assignment}
# a batch container with 3 batches and 11 locations per batch
bc <- BatchContainer$new(
dimensions = list("batch" = 3, "location" = 11),
)
# assign samples randomly
set.seed(17)
bc <- assign_random(bc, subject_data)
bc$get_samples() %>%
ggplot() +
aes(x = batch, fill = Group) +
geom_bar()
```
Random assignmet of samples to batches produced an uneven distribution.
### Optimizing the assignemnt
```{r optimized_assignment, warning=FALSE}
# set scoring functions
scoring_f <- list(
# first priority, groups are evenly distributed
group = osat_score_generator(batch_vars = "batch",
feature_vars = "Group"),
# second priority, sexes are evenly distributed
sex = osat_score_generator(batch_vars = "batch",
feature_vars = "Sex")
)
bc <- optimize_design(
bc, scoring = scoring_f, max_iter = 150, quiet = TRUE
)
bc$get_samples() %>%
ggplot() +
aes(x = batch, fill = Group) +
geom_bar()
# show optimization trace
bc$plot_trace()
```
## Examples
See vignettes `vignette("basic_examples")`.
## Acknowledgement
The logo is inspired by [DALL-E 2](https://openai.com/dall-e-2/) and
[pipette icon by gsagri04](https://openclipart.org/detail/140941/micropipette).