knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

experDesign

CRAN status CRAN checks R-CMD-check Coverage status Lifecycle: stable Project Status: Active - The project has reached a stable, usable state and is being actively developed. JOSS DOI

The goal of experDesign is to help you distribute your samples before an experiment but after they are collected. For example, checking for common problems in the data, and reducing or even preventing batch bias before performing an experiment, or measuring it once the experiment is performed. It provides four main functions:

There are other helpers.

Installation

To install the latest version on CRAN use:

install.packages("experDesign")

::: {.pkgdown-devel} You can install the development version of pkgdown from GitHub with:

# install.packages("devtools")
devtools::install_github("llrs/experDesign")

:::

Example

We can use the survey dataset for the examples:

library("experDesign")
data(survey, package = "MASS") 
head(survey)

The dataset has numeric, categorical values and NA values.

Checking initial data

We can check some issues from an experimental point of view via check_data():

check_data(survey)

As you can see with the warnings we get a collections of problems. In general, try to have at least 3 replicates for each condition and try to have all the data of each variable.

Picking samples for each batch

Imagine that we can only work in groups of 70, and we want to randomize by Sex, Smoke, Age, and by hand.
There are r choose(237, 70) combinations of samples per batch in a this experiment. However, in some of those combinations all the right handed students are in the same batch making it impossible to compare the right handed students with the others and draw conclusions from it.

We could check all the combinations to select those that allow us to do this comparison. But as this would be too long with experDesign we can try to find the combination with the best design by comparing each combination with the original according to multiple statistics.

# To reduce the variables used:
omit <- c("Wr.Hnd", "NW.Hnd", "Fold", "Pulse", "Clap", "Exer", "Height", "M.I")
(keep <- colnames(survey)[!colnames(survey) %in% omit])
head(survey[, keep])

# Set a seed for reproducibility
set.seed(87732135)
# Looking for groups at most of 70 samples.
index <- design(pheno = survey, size_subset = 70, omit = omit, iterations = 100)
index

We can transform then into a vector to append to the file or to pass to a colleague with:

head(batch_names(index))
# Or via inspect() to keep it in a matrix format:
head(inspect(index, survey[, keep]))

Previous work

The CRAN task View of Experimental Design includes many packages relevant for designing an experiment before collecting data, but none of them provides how to manage them once the samples are already collected.

Two packages allow to distribute the samples on batches:

If you are still designing the experiment and do not have collected any data DeclareDesign might be relevant for you. But specially the randomizr packages which makes common forms of random assignment and sampling.

Question in Bioinformatics.SE I made before developing the package.

Other

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.



llrs/experDesign documentation built on Dec. 24, 2024, 8:22 a.m.