Title: | Encapsulating Elements of Experimental Design |
---|---|
Description: | A system to facilitate designing comparative (and non-comparative) experiments using the grammar of experimental designs <https://emitanaka.org/edibble-book/>. An experimental design is treated as an intermediate, mutable object that is built progressively by fundamental experimental components like units, treatments, and their relation. The system aids in experimental planning, management and workflow. |
Authors: | Emi Tanaka [aut, cre, cph] |
Maintainer: | Emi Tanaka <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.1.1 |
Built: | 2024-11-20 03:24:45 UTC |
Source: | https://github.com/emitanaka/edibble |
A system to facilitate designing comparative (and non-comparative) experiments using the grammar of experimental designs https://emitanaka.org/edibble-book/. An experimental design is treated as an intermediate, mutable object that is built progressively by fundamental experimental components like units, treatments, and their relation. The system aids in experimental planning, management and workflow.
(WIP)
The website for the package is at https://edibble.emitanaka.org
Discussion is at https://github.com/emitanaka/edibble/discussions
The following options are used for changing the default view for the print out of edibble design or edibble graph.
edibble.tree.decorate.trts
edibble.tree.decorate.units
edibble.tree.decorate.rcrd
edibble.tree.decorate.levels
edibble.tree.decorate.main
TODO
Maintainer: Emi Tanaka [email protected] (ORCID) [copyright holder]
Useful links:
Report bugs at https://github.com/emitanaka/edibble/issues
This is a developer function to create a new Kitchen class with the existing design.
activate_provenance( .edibble, overwrite = c("graph", "anatomy", "recipe", "validation", "simulate", "simulate_result") )
activate_provenance( .edibble, overwrite = c("graph", "anatomy", "recipe", "validation", "simulate", "simulate_result") )
.edibble |
An edibble object. |
overwrite |
What object to overwrite in the provenance object. |
A Provenance object.
activate_provenance(takeout())
activate_provenance(takeout())
This function is a short hand that combines allot_trts()
, assign_trts()
and serve_table()
.
allot_table( .edibble = NULL, ..., order = "random", seed = NULL, constrain = nesting_structure(.edibble), label_nested = NULL, fail = "error", .record = TRUE )
allot_table( .edibble = NULL, ..., order = "random", seed = NULL, constrain = nesting_structure(.edibble), label_nested = NULL, fail = "error", .record = TRUE )
.edibble |
An edibble design which should have units, treatments and allotment defined. |
... |
One-sided or two-sided formula. If the input is a one-sided formula then the whole treatment is applied to the specified unit. |
order |
A character vector signifying the apportion of treatments to units. The value should be either "random", "systematic-fastest", "systematic-slowest", "systematic-random-fastest", "systematic-random-slowest" or a class name corresponding to the algorithm for order_trts(). "random" allocates the treatment randomly to units based on specified allotment with restrictions implied by unit structure. "systematic-slowest" allocates the treatment in a systematic order to units such that the treatment level is slow in varying. In contrast, "systematic-fastest" is fast in varying for treatment levels. "systematic-random-fastest" and "systematic-random-slowest" allocates the treatment in a systematic order to units but where it is not possible to divide treatments equally (as the number of units are not divisible by the number of levels of the treatment factor), then the extras are chosen randomly. |
seed |
A scalar value used to set the seed so that the result is reproducible. |
constrain |
The nesting structure for units. |
label_nested |
The columns to show nested labels (if available). Tidyselect compatible. |
fail |
What to do when failing to convert graph to table. |
.record |
Whether to record the step. |
This function adds the edges between factor nodes to describe the high-level relationship between factors. This function does not actually assign edges between level nodes.
allot_trts(.edibble = NULL, ..., .record = TRUE)
allot_trts(.edibble = NULL, ..., .record = TRUE)
.edibble |
An edibble design which should have units, treatments and allotment defined. |
... |
One-sided or two-sided formula. If the input is a one-sided formula then the whole treatment is applied to the specified unit. |
.record |
Whether to record the step. |
Return an edibble design.
assign_fcts
Other user-facing functions:
allot_units()
,
design()
,
expect_rcrds()
,
export_design()
,
serve_table()
,
set_rcrds()
,
set_trts()
,
set_units()
design() %>% set_units(block = 10, plot = nested_in(block, 3)) %>% set_trts(treat = c("A", "B", "C"), pest = c("a", "b")) %>% allot_trts(treat ~ plot, pest ~ block)
design() %>% set_units(block = 10, plot = nested_in(block, 3)) %>% set_trts(treat = c("A", "B", "C"), pest = c("a", "b")) %>% allot_trts(treat ~ plot, pest ~ block)
This function adds the edges between factor nodes to describe the high-level relationship between factors. This function does not actually assign edges between level nodes.
allot_units(.edibble, ..., .record = TRUE)
allot_units(.edibble, ..., .record = TRUE)
.edibble |
An edibble design which should have units, treatments and allotment defined. |
... |
A two-sided formula. |
.record |
Whether to record the step. |
Return an edibble design.
assign_fcts
Other user-facing functions:
allot_trts()
,
design()
,
expect_rcrds()
,
export_design()
,
serve_table()
,
set_rcrds()
,
set_trts()
,
set_units()
design() %>% set_units(block = 10, plot = 20) %>% allot_units(block ~ plot)
design() %>% set_units(block = 10, plot = 20) %>% allot_units(block ~ plot)
A patch function where there is an issue with edbl factors
## S3 method for class 'edbl_table' as_tibble(x, ...)
## S3 method for class 'edbl_table' as_tibble(x, ...)
x |
can be a list or data frame |
... |
Not currently used. |
A data.frame.
Convert edibble table to normal data frame
## S3 method for class 'edbl_table' as.data.frame(x, ..., levels_as = "factor", ignore_numeric = TRUE)
## S3 method for class 'edbl_table' as.data.frame(x, ..., levels_as = "factor", ignore_numeric = TRUE)
x |
An edibble table |
... |
Unused. i.e. don't coerce numeric factors. |
levels_as |
Coerce the edibble factors to either "factor" or "character". |
ignore_numeric |
Whether to coerce numeric factors or not. Default is TRUE, |
This function assigns specific treatment or unit levels to actual units.
assign_trts( .edibble = NULL, order = "random", seed = NULL, constrain = nesting_structure(.edibble), ..., .record = TRUE ) assign_units( .edibble = NULL, order = "random", seed = NULL, constrain = nesting_structure(.edibble), ..., .record = TRUE )
assign_trts( .edibble = NULL, order = "random", seed = NULL, constrain = nesting_structure(.edibble), ..., .record = TRUE ) assign_units( .edibble = NULL, order = "random", seed = NULL, constrain = nesting_structure(.edibble), ..., .record = TRUE )
.edibble |
An edibble design which should have units, treatments and allotment defined. |
order |
A character vector signifying the apportion of treatments to units. The value should be either "random", "systematic-fastest", "systematic-slowest", "systematic-random-fastest", "systematic-random-slowest" or a class name corresponding to the algorithm for order_trts(). "random" allocates the treatment randomly to units based on specified allotment with restrictions implied by unit structure. "systematic-slowest" allocates the treatment in a systematic order to units such that the treatment level is slow in varying. In contrast, "systematic-fastest" is fast in varying for treatment levels. "systematic-random-fastest" and "systematic-random-slowest" allocates the treatment in a systematic order to units but where it is not possible to divide treatments equally (as the number of units are not divisible by the number of levels of the treatment factor), then the extras are chosen randomly. |
seed |
A scalar value used to set the seed so that the result is reproducible. |
constrain |
The nesting structure for units. |
... |
Arguments parsed into |
.record |
Whether to record the step. |
An edibble design.
# 10 subject, 2 vaccine treatments design() %>% set_units(subject = 10) %>% set_trts(vaccine = 2) %>% allot_trts(vaccine ~ subject) %>% assign_trts() %>% serve_table() # 20 subjects, 2 blocks, assign subjects to blocks design() %>% set_units(subject = 20, block = 2) %>% allot_units(block ~ subject) %>% assign_units() %>% serve_table()
# 10 subject, 2 vaccine treatments design() %>% set_units(subject = 10) %>% set_trts(vaccine = 2) %>% allot_trts(vaccine ~ subject) %>% assign_trts() %>% serve_table() # 20 subjects, 2 blocks, assign subjects to blocks design() %>% set_units(subject = 20, block = 2) %>% allot_units(block ~ subject) %>% assign_units() %>% serve_table()
This function fills the values of the record factors by automatically choosing a simulation process. It tries to be smart by ensuring to use values that is within expectation.
autofill_rcrds(.data, ..., .seed = NULL, .nsim = 1L)
autofill_rcrds(.data, ..., .seed = NULL, .nsim = 1L)
.data |
An edibble data. |
... |
If supplied, it is a name-value pair where the name should
correspond to the record factor name and value is the dependent factors
selected with |
.seed |
The seed number. |
.nsim |
The number of simulations to run. |
spd <- design("Split-Plot Design | Split-Unit Design") %>% set_units(mainplot = 30, subplot = nested_in(mainplot, 4)) %>% set_trts(trt1 = LETTERS[1:3], trt2 = 4) %>% allot_trts(trt1 ~ mainplot, trt2 ~ subplot) %>% assign_trts("random", seed = 719) %>% serve_table() %>% set_rcrds(mass = mainplot, yield = subplot, type = subplot) %>% expect_rcrds(mass > 0, yield > 0, yield < 100, factor(type, levels = c("a", "b", "c"))) spd %>% autofill_rcrds()
spd <- design("Split-Plot Design | Split-Unit Design") %>% set_units(mainplot = 30, subplot = nested_in(mainplot, 4)) %>% set_trts(trt1 = LETTERS[1:3], trt2 = 4) %>% allot_trts(trt1 ~ mainplot, trt2 ~ subplot) %>% assign_trts("random", seed = 719) %>% serve_table() %>% set_rcrds(mass = mainplot, yield = subplot, type = subplot) %>% expect_rcrds(mass > 0, yield > 0, yield < 100, factor(type, levels = c("a", "b", "c"))) spd %>% autofill_rcrds()
This is a helper function to select a column when data is supplied
for lvls
.
column(x)
column(x)
x |
The column to select. Can be unquoted name or the column index. |
crossed_by(A, B)
is the same as ~A:B
but crossed_by
offers more control over the names of the new units
as well as adding new attributes.
crossed_by(..., attrs = NULL)
crossed_by(..., attrs = NULL)
... |
a sequence of units |
attrs |
Currently not implemented. |
An object of class "cross_lvls".
design("Strip-Plot Design | Strip-Unit Design") %>% set_units(block = 3, row = nested_in(block, 7), col = nested_in(block, 6), unit = nested_in(block, crossed_by(row, col)))
design("Strip-Plot Design | Strip-Unit Design") %>% set_units(block = 3, row = nested_in(block, 7), col = nested_in(block, 6), unit = nested_in(block, crossed_by(row, col)))
This function doesn't really do much besides create a new edibble design object.
design( .title = NULL, ..., .name = "edibble", .record = TRUE, .seed = NULL, .provenance = Provenance$new() ) redesign( .data, .title, ..., .name = NULL, .record = TRUE, .seed = NULL, .provenance = Provenance$new() )
design( .title = NULL, ..., .name = "edibble", .record = TRUE, .seed = NULL, .provenance = Provenance$new() ) redesign( .data, .title, ..., .name = NULL, .record = TRUE, .seed = NULL, .provenance = Provenance$new() )
.title |
Optional title of the experiment. |
... |
A series of name-value pairs where the name corresponds to the name of the metadata nad the value corresponds to the actual metadata value. If the name is omitted, then no name to the metadata is assigned for the corresponding value. |
.name |
Optional name of the experiment. |
.record |
A logical value. This indicates whether to record this code step. The default is TRUE. It should remain TRUE unless this function is used as a wrapper in other code. |
.seed |
A seed number for reproducibility. |
.provenance |
An environment setup in a manner to store methods and information to trace the origin of the design |
.data |
An edibble table. |
An empty edbl_design
object.
Add variables to this design with set_units()
, set_trts()
, and
set_rcrds()
.
Other user-facing functions:
allot_trts()
,
allot_units()
,
expect_rcrds()
,
export_design()
,
serve_table()
,
set_rcrds()
,
set_trts()
,
set_units()
design("My design")
design("My design")
This is a convenient wrapper for dae::designAnatomy
where the formulae
structure is
automatically determined by the unit and treatment structure specified in edibble
system.
Note: the computation may be long if the design is quite complicated or there are many units.
design_anatomy(.edibble, ...)
design_anatomy(.edibble, ...)
.edibble |
A complete edibble design object or edibble table. |
... |
Any other arguments parsed to |
An object of class "des_anatomy".
split <- takeout(menu_split(t1 = 3, t2 = 2, r = 2)) design_anatomy(split)
split <- takeout(menu_split(t1 = 3, t2 = 2, r = 2)) design_anatomy(split)
Get the node or edge data from an edibble design
fct_nodes(x) fct_edges(x) lvl_nodes(x) lvl_edges(x)
fct_nodes(x) fct_edges(x) lvl_nodes(x) lvl_edges(x)
x |
An edibble object. |
This
design_model(data, type = c("anova", "lmer"))
design_model(data, type = c("anova", "lmer"))
data |
An edibble data. |
type |
The type of model expression to return. |
The is
functions tests if an object (or an object in its attribute)
inherits particular class and returns TRUE
if it does, otherwise FALSE
.
is_edibble_design
checks if it inherits edbl_design
.
is_edibble_graph
checks if it inherits edbl_graph
.
is_edibble_table
checks if it inherits edbl_table
is_edibble
checks if the object inherits edbl
.
The search is quite simple, it checks if
the object is edbl_design
, failing that it looks to see if the
attribute "design" of the object is edbl_design
.
is_named_design
check if it inherits NamedDesign
.
The get
functions extracts the requested edibble component (table, graph,
or design) from the object if possible.
edbl_design
tries to get edbl_design
.
edbl_table
tries to get edbl_table
with no design attribute.
edbl_graph
tries to get edbl_graph
.
is_edibble_design(x) is_named_design(x) is_edibble_table(x) is_edibble_graph(x) is_edibble(x) is_edibble_levels(x) is_nest_levels(x) is_cross_levels(x) edbl_design(x) edbl_table(x)
is_edibble_design(x) is_named_design(x) is_edibble_table(x) is_edibble_graph(x) is_edibble(x) is_edibble_levels(x) is_nest_levels(x) is_cross_levels(x) edbl_design(x) edbl_table(x)
x |
An object. |
A logical value.
is_edibble_design(takeout())
is_edibble_design(takeout())
Examine the simulation process
examine_process(data, process = NULL) examine_process_values(data, process = NULL, sim = 1L)
examine_process(data, process = NULL) examine_process_values(data, process = NULL, sim = 1L)
data |
An edibble data frame. |
process |
The process name. Typically the name of the process. If unknown, leave this empty. |
sim |
The simulation number. Default is 1. |
Check the recipe code
examine_recipe(x, ...)
examine_recipe(x, ...)
x |
An edibble design, edibble, or takeout object. |
... |
Not used. |
The recipe code.
examine_recipe(takeout())
examine_recipe(takeout())
Set the expected values for recording variables
expect_rcrds(.edibble = NULL, ..., .record = TRUE)
expect_rcrds(.edibble = NULL, ..., .record = TRUE)
.edibble |
An edibble design ( |
... |
Name-value pairs with the name belonging to the variable
that are plan to be recorded from |
.record |
A logical value. This indicates whether to record this code step. The default is TRUE. It should remain TRUE unless this function is used as a wrapper in other code. |
An edibble design.
Other user-facing functions:
allot_trts()
,
allot_units()
,
design()
,
export_design()
,
serve_table()
,
set_rcrds()
,
set_trts()
,
set_units()
takeout(menu_crd(t = 4, n = 10)) %>% set_rcrds(y = unit) %>% expect_rcrds(y > 0)
takeout(menu_crd(t = 4, n = 10)) %>% set_rcrds(y = unit) %>% expect_rcrds(y > 0)
These functions should be used within expect_vars
where variables that
are to be recorded are constraint to the expected values when exported
as an xlsx file by export_design().
The functions to set a particular
value type (numeric, integer, date, time and character) are preceded by
"to_be_" where the corresponding restriction set by with_value()
.
to_be_numeric(range) to_be_integer(range) to_be_date(range) to_be_time(range) to_be_character(length) to_be_factor(levels)
to_be_numeric(range) to_be_integer(range) to_be_date(range) to_be_time(range) to_be_character(length) to_be_factor(levels)
range , length
|
A named list with two elements: "operator" and "value" as
provided by helper |
levels |
A character vector with the factor levels. |
A record type.
This function is designed to export the design made using edibble to an external xlsx file.
export_design( .data, file, author = NULL, date = Sys.Date(), overwrite = FALSE, hide_treatments = FALSE, theme = NULL, subject = NULL, category = NULL, table_style = "TableStyleMedium9" )
export_design( .data, file, author = NULL, date = Sys.Date(), overwrite = FALSE, hide_treatments = FALSE, theme = NULL, subject = NULL, category = NULL, table_style = "TableStyleMedium9" )
.data |
An edibble table to export. |
file |
File, including the path, to export the data to. |
author |
(Optional) name of the author in character. A vector of character is supported for where there are multiple authors. |
date |
The date to be inserted in header (defaults to today). |
overwrite |
A logical value indicating whether to overwrite existing file or not. |
hide_treatments |
A logical value indicating whether treatments should be included in the data entry sheet. Default is true. |
theme |
The Excel theme to use (optional). One of "Atlas", "Badge", "Berlin", "Celestial", "Crop", "Depth", "Droplet", "Facet", "Feathered", "Gallery", "Headlines", "Integral", "Ion", "Ion Boardroom", "Madison", "Main Event", "Mesh", "Office Theme", "Old Office Theme", "Organic", "Parallax", "Parcel", "Retrospect", "Savon", "Slice", "Vapor Trail", "View", "Wisp", "Wood Type". |
subject |
The subject of the workbook (optional). |
category |
The category of the workbook (optional). |
table_style |
The table style to apply to the exported data (default: "TableStyleMedium9"). |
The input data object.
Other user-facing functions:
allot_trts()
,
allot_units()
,
design()
,
expect_rcrds()
,
serve_table()
,
set_rcrds()
,
set_trts()
,
set_units()
This function is used to set characteristics of the factors.
fct(.levels = character(), ...) fct_attrs(.levels = character(), ...)
fct(.levels = character(), ...) fct_attrs(.levels = character(), ...)
.levels |
Either a short hand given as either as a single integer (number of levels),
a vector or levels created from |
... |
A name-value pair of attributes. The value must be a scalar and attributed to the whole factor (not individual levels). The values are added as attributes to the output object. |
lvls
fct(c("A", "B"))
fct(c("A", "B"))
Generate a factor with custom levels and repetitions.
fct_generator(labels, nlevels)
fct_generator(labels, nlevels)
labels |
A character vector specifying the custom labels for the factor levels. |
nlevels |
An integer or a vector of integers indicating the number of repetitions for each label.
If a single integer is provided, it is recycled to match the length of |
This function creates a factor with custom labels and specified repetitions for each label.
A factor with custom levels and repetitions.
# Example usage of the function fct_generator(labels = c("A", "B", "C"), nlevels = 3)
# Example usage of the function fct_generator(labels = c("A", "B", "C"), nlevels = 3)
Get the factor graph.
fct_graph(x)
fct_graph(x)
x |
An edibble object. |
This function prints an edbl_graph
object as a tree to terminal.
The variables are color coded (or decorated) with the given options.
Any ANSI coloring or styling are only visible in the console or terminal
outputs that support it. The print output is best used interactively since
any text styling are lost in text or R Markdown output. More details can
be found in vignette("edbl-output", package = "edibble")
.
## S3 method for class 'edbl_design' print( x, decorate_units = edibble_decorate("units"), decorate_trts = edibble_decorate("trts"), decorate_rcrds = edibble_decorate("rcrds"), decorate_levels = edibble_decorate("levels"), decorate_title = edibble_decorate("title"), title = NULL, ... )
## S3 method for class 'edbl_design' print( x, decorate_units = edibble_decorate("units"), decorate_trts = edibble_decorate("trts"), decorate_rcrds = edibble_decorate("rcrds"), decorate_levels = edibble_decorate("levels"), decorate_title = edibble_decorate("title"), title = NULL, ... )
x |
An edibble graph. |
decorate_trts , decorate_units , decorate_rcrds , decorate_levels , decorate_title
|
A function applied to the name of treatment, unit, response factors or design title. The function should return a string. Most often this wraps the name with ANSI colored text. |
title |
The title of the design. |
... |
Unused. |
A function to process input as input for graph manipulation
graph_input(input, prov, ...)
graph_input(input, prov, ...)
input |
An input. |
prov |
A provenance object. |
... |
Unused. |
This function determines whether the given object is an instance of the "Provenance" class.
is_provenance(x)
is_provenance(x)
x |
An object to be checked for its class membership. |
TRUE
if the object is an instance of the "Provenance" class,
FALSE
otherwise.
The function returns TRUE
if the input is a takeout design.
is_takeout(x)
is_takeout(x)
x |
An object. |
A logical value.
is_takeout(takeout())
is_takeout(takeout())
Label with nested or distinct labels
label_nested(x) label_distinct(x) index_levels(x)
label_nested(x) label_distinct(x) index_levels(x)
x |
A unit vector. |
These can be handy for generating pseudo labels for the levels or
factor names using fct_generator
label_seq_from_to( from = 1L, to = 1L, by = 1L, prefix = "", suffix = "", sep_prefix = "", sep_suffix = "", leading_zero = edibble_labels_opt("leading_zero") ) label_seq_from_length( from = 1L, length = 1L, by = 1L, prefix = "", suffix = "", sep_prefix = "", sep_suffix = "", leading_zero = edibble_labels_opt("leading_zero") ) label_seq_to_length( to = 1L, length = 1L, by = 1L, prefix = "", suffix = "", sep_prefix = "", sep_suffix = "", leading_zero = edibble_labels_opt("leading_zero") ) label_seq_length( length = 1L, prefix = "", suffix = "", sep_prefix = "", sep_suffix = "", leading_zero = edibble_labels_opt("leading_zero") )
label_seq_from_to( from = 1L, to = 1L, by = 1L, prefix = "", suffix = "", sep_prefix = "", sep_suffix = "", leading_zero = edibble_labels_opt("leading_zero") ) label_seq_from_length( from = 1L, length = 1L, by = 1L, prefix = "", suffix = "", sep_prefix = "", sep_suffix = "", leading_zero = edibble_labels_opt("leading_zero") ) label_seq_to_length( to = 1L, length = 1L, by = 1L, prefix = "", suffix = "", sep_prefix = "", sep_suffix = "", leading_zero = edibble_labels_opt("leading_zero") ) label_seq_length( length = 1L, prefix = "", suffix = "", sep_prefix = "", sep_suffix = "", leading_zero = edibble_labels_opt("leading_zero") )
from |
An integer specifying the starting value (inclusive) of the sequence. |
to |
An integer specifying the ending value (inclusive) of the sequence. |
by |
An integer specifying the increment between values in the sequence. |
prefix |
A character string to be prepended to the labels. |
suffix |
A character string to be appended to the labels. |
sep_prefix |
A character string used to separate the prefix from the labels. |
sep_suffix |
A character string used to separate the suffix from the labels. |
leading_zero |
A logical value indicating whether to add leading zeros to the labels. If integer, then pad based on the number supplied. |
length |
An integer specifying the desired length of the sequence. |
A character vector containing the labels generated from the sequence.
label_seq_to_length(to = 10, length = 5, by = 2) label_seq_from_to(from = 8, to = 10, leading_zero = 3) label_seq_length(10, leading_zero = FALSE)
label_seq_to_length(to = 10, length = 5, by = 2) label_seq_from_to(from = 8, to = 10, leading_zero = 3) label_seq_length(10, leading_zero = FALSE)
Lady tasting tea experiment was described in Fisher (1935) to test the ability of a lady who said she tell whether the tea or milk was added first to a cup of tea.
The experiment consisted of preparing eight cups of tea, four with milk poured first and the other four with tea poured first. The lady has been told in advance that there are four of each kind of preparation.
This data consists of the same experimental structure and result but the order presented in practice is unknown.
The cup number.
The cup of tea prepared with milk or tea first.
The guess by lady which one was poured first.
Whether the lady's guess was correct.
lady_tasting_tea
lady_tasting_tea
An object of class tbl_df
(inherits from tbl
, data.frame
) with 8 rows and 4 columns.
Fisher, Ronald (1935) The Design of Experiments.
Other experimental data:
skittles
Latin square designs and its generalisations as an array
latin_square(n, randomise = TRUE) latin_rectangle(nr, nc, nt, randomise = TRUE) latin_array(dim, nt, randomise = TRUE)
latin_square(n, randomise = TRUE) latin_rectangle(nr, nc, nt, randomise = TRUE) latin_array(dim, nt, randomise = TRUE)
n , nt
|
The number of treatments |
randomise |
A logical value to indicate whether the treatment allocation should be randomised. The default value is |
nr |
The number of rows |
nc |
The number of columns |
dim |
A vector of integers to indicate the number of elements in each dimension. |
latin_square()
: Latin square design
latin_rectangle()
: Like a Latin square design but allow different number of rows and columns
latin_array()
: Returns an array where it stitches up multiple Latin square/rectangle design
latin_square(n = 3) latin_rectangle(3, 3, 3) latin_array(c(3, 3, 3), 3)
latin_square(n = 3) latin_rectangle(3, 3, 3) latin_array(c(3, 3, 3), 3)
Setting the traits of the levels
lvls(value = NULL, n = NA_integer_, data = NULL, ...)
lvls(value = NULL, n = NA_integer_, data = NULL, ...)
value |
A vector of the level values. |
n |
The number of replicate (if applicable). |
data |
A list or data frame of the same size as the |
... |
Name-value pair denoting other level attributes. The value should be the same
length as |
An edbl_lvls object.
lvls(c("A", "B"))
lvls(c("A", "B"))
Conditional treatment is different to nested units as the levels are assumed to be distinct for the latter but not for the former.
nested_in(x, ...) conditioned_on(x, ...)
nested_in(x, ...) conditioned_on(x, ...)
x |
The name of the parent unit to nest under. |
... |
a single number OR a sequence of two-sided formula where the
left-hand side corresponds to the name of the level (or the level number) of |
Currently when specifying conditional treatment, only character vectors are accepted on the RHS.
A nested level.
See set_units()
for examples of how to use this.
design("Split-Plot Design | Split-Unit Design") %>% set_units(mainplot = 60, subplot = nested_in(mainplot, 10))
design("Split-Plot Design | Split-Unit Design") %>% set_units(mainplot = 60, subplot = nested_in(mainplot, 10))
Get the nesting structure for the units
nesting_structure(design)
nesting_structure(design)
design |
An edibble design |
Return a named list. Only shows the direct parent.
nesting_structure(takeout(menu_split()))
nesting_structure(takeout(menu_split()))
This helps to construct a new edibble table which is a special type of tibble.
new_edibble(.data, ..., .design = NULL, .class = NULL) as_edibble(.data, ...)
new_edibble(.data, ..., .design = NULL, .class = NULL) as_edibble(.data, ...)
.data |
data frame or list of the same size. |
... |
Passed to |
.design |
An edibble graph object. |
.class |
Subclasses for edibble table. The default is NULL. |
An edibble table.
A custom ordering algorithm
order_trts(x, ...)
order_trts(x, ...)
x |
A string specifying the class |
... |
Other arguments. |
Interactive plot of the edibble design
## S3 method for class 'edbl_design' plot( x, which = c("factors", "levels"), width = "100%", height = NULL, seed = 1, title = NULL, subtitle = NULL, footer = NULL, background = "transparent", view = c("show-buttons", "hide-buttons", "static"), ... ) ## S3 method for class 'edbl_table' plot(x, ...) plot_fct_graph( x, width = "100%", height = NULL, seed = 1, title = NULL, subtitle = NULL, footer = NULL, background = "transparent", view = c("show-buttons", "hide-buttons", "static"), ... ) plot_lvl_graph( x, width = "100%", height = NULL, seed = 1, title = NULL, subtitle = NULL, footer = NULL, background = "transparent", view = c("show-buttons", "hide-buttons", "static"), ... )
## S3 method for class 'edbl_design' plot( x, which = c("factors", "levels"), width = "100%", height = NULL, seed = 1, title = NULL, subtitle = NULL, footer = NULL, background = "transparent", view = c("show-buttons", "hide-buttons", "static"), ... ) ## S3 method for class 'edbl_table' plot(x, ...) plot_fct_graph( x, width = "100%", height = NULL, seed = 1, title = NULL, subtitle = NULL, footer = NULL, background = "transparent", view = c("show-buttons", "hide-buttons", "static"), ... ) plot_lvl_graph( x, width = "100%", height = NULL, seed = 1, title = NULL, subtitle = NULL, footer = NULL, background = "transparent", view = c("show-buttons", "hide-buttons", "static"), ... )
x |
An edibble design. |
which |
A string of either "factors" or "levels". |
width , height
|
The width and height of the plot. |
seed |
A seed number so same plot is always generated. |
title , subtitle , footer
|
The title, subtitle or footer of the plot.
By default it uses the name from the |
background |
The background color of the plot. Default is transparent. The input can be a color name (e.g. "white"), a HEX value ("#FFFFFF"), or rgb/rgba in the format like rgba(0, 0, 0, 0). |
view |
A string of either "show-buttons" (default), "hide-buttons", "static" |
... |
Currently unused. |
A plot.
plot(takeout(menu_crd(t = 4, n = 20)))
plot(takeout(menu_crd(t = 4, n = 20)))
An object to query, record and modify an edibble graph
An object to query, record and modify an edibble graph
The Provenance contains a set of operations to manipulate the nodes and edges of the edibble graph object.
fct_nodes
Get the factor nodes
lvl_nodes
Get the level nodes
fct_edges
Get the factor edges
lvl_edges
Get the level edges
fct_n
Get the number of nodes in factor graph
lvl_n
Get the number of nodes in level graph
rcrd_ids
Get the ids for all edbl_rcrd factors.
unit_ids
Get the ids for all edbl_unit factors.
trt_ids
Get the ids for all edbl_trt factors.
is_connected
Check if nodes are connected. Get a new factor id. Get a new level id. Given a particular DAG, return a topological order Remember that there could be more than one order.
new()
Initialise function
Provenance$new(graph = NULL)
graph
An edibble graph.
set_title()
Set the title.
Provenance$set_title(title)
title
The title of the experiment
set_name()
Set the name.
Provenance$set_name(name)
name
The name of the edibble graph object.
set_validation()
Set the validation.
Provenance$set_validation(validation, type = "rcrds")
validation
The validation statement.
type
The type of validation.
set_simulate()
Set the simulation process
Provenance$set_simulate(name, process, rcrds)
name
The name of the process
process
A function to simulate the record
rcrds
The record factor name simulating for.
reactivate()
Reactivate the graph in the provenance object.
Provenance$reactivate( design, overwrite = c("graph", "anatomy", "recipe", "validation", "simulate", "simualte_result") )
design
An edibble design
overwrite
A vector of character to overwrite from the supplied design object.
deactivate()
Deactivate the provenance object.
Provenance$deactivate(delete = c("graph", "anatomy", "recipe", "validation"))
delete
A vector of character to delete.
fct_id()
Get the id based on either the name of the factor node. If none supplied then it will give all.
Provenance$fct_id(name = NULL, role = NULL)
name
The name of the node.
role
The role for the node.
fct_id_parent()
Get the factor parent ids
Provenance$fct_id_parent(id = NULL, role = NULL, type = NULL)
id
The id of the corresponding node.
role
The role for the node.
type
The type of edge link.
fct_id_child()
Get the factor child ids. If role
is
supplied then the child has to fit role
Provenance$fct_id_child(id = NULL, role = NULL)
id
The id of the corresponding node.
role
The role for the node.
fct_id_ancestor()
Get the factor ancestor ids
Provenance$fct_id_ancestor(id = NULL, role = NULL)
id
The id of the corresponding node.
role
The role for the node.
fct_id_descendant()
Get the factor descendant ids
Provenance$fct_id_descendant(id = NULL, role = NULL)
id
The id of the corresponding node.
role
The role for the node.
fct_id_leaves()
Get the leave factor ids.
Provenance$fct_id_leaves(role = NULL)
role
The role for the node.
lvl_id()
Get the id based on name of level node. Assumes that level ids obtained are all from the same fid
Provenance$lvl_id(value = NULL, role = NULL, fid = NULL)
value
The value of the node.
role
The role for the node.
fid
The factor id.
lvl_id_parent()
Get the level parent ids
Provenance$lvl_id_parent(id = NULL, role = NULL)
id
The id of the corresponding node.
role
The role for the node.
lvl_id_child()
Get the level child ids
Provenance$lvl_id_child(id = NULL, role = NULL)
id
The id of the corresponding node.
role
The role for the node.
lvl_id_ancestor()
Get the level ancestor ids
Provenance$lvl_id_ancestor(id = NULL, role = NULL)
id
The id of the corresponding node.
role
The role for the node.
fct_id_from_lvl_id()
Find the factor id from level ids.
Provenance$fct_id_from_lvl_id(id = NULL, fid_search = NULL)
id
The id of the corresponding node.
fid_search
A vector of fids to search from.
fct_id_from_lvl_values()
Find the factor id from level values.
Provenance$fct_id_from_lvl_values(value = NULL, fid_search = NULL)
value
The value of the node.
fid_search
A vector of fids to search from.
lvl_id_from_fct_id()
Find the level id from the given fid
Provenance$lvl_id_from_fct_id(fid = NULL)
fid
The factor id.
fct_names()
Get the factor names based on id or role
Provenance$fct_names(id = NULL, role = NULL)
id
The id of the corresponding node.
role
The role for the node.
unit_names()
Get the unit names
Provenance$unit_names(id = NULL)
id
The id of the corresponding node.
trt_names()
Get the treatment names
Provenance$trt_names(id = NULL)
id
The id of the corresponding node.
rcrd_names()
Get the record names.
Provenance$rcrd_names(id = NULL)
id
The id of the corresponding node.
rcrd_class()
Get the class for record with validation.
Provenance$rcrd_class(name = NULL)
name
The name of the node.
lvl_values()
Get the level values based on id or role cannot have just role only defined. id must be from the same fid
Provenance$lvl_values(id = NULL, role = NULL, fid = NULL)
id
The id of the corresponding node.
role
The role for the node.
fid
The factor id.
unit_values()
Get the unit values.
Provenance$unit_values(id = NULL, fid = NULL)
id
The id of the corresponding node.
fid
The factor id.
trt_values()
Get the treatment values.
Provenance$trt_values(id = NULL, fid = NULL)
id
The id of the corresponding node.
fid
The factor id.
rcrd_values()
Get the record values.
Provenance$rcrd_values(uid = NULL, fid = NULL)
uid
The unit level id
fid
The factor id.
fct_role()
Get the role of the vertex given the factor id
Provenance$fct_role(id = NULL)
id
The id of the corresponding node.
fct_levels()
Get the levels for each factor
Provenance$fct_levels(id = NULL, name = NULL, return = c("id", "value"))
id
The id of the corresponding node.
name
The name of the node.
return
To return in "id" or "value" format.
fct_levels_id_to_edbl_fct()
Factor levels to edble factor
Provenance$fct_levels_id_to_edbl_fct(fct_levels, role)
fct_levels
The factor levels in id.
role
The role for the node.
fct_levels_id_to_value()
Get the factor levels in value given id format
Provenance$fct_levels_id_to_value(fct_levels)
fct_levels
A list of factor levels in id format.
fct_levels_value_to_id()
Get the factor levels in id given value format.
Provenance$fct_levels_value_to_id(fct_levels)
fct_levels
A list of factor levels in id format.
fct_exists()
One of name
, id
or role
is defined to check if it exists.
If more than one of the arguments name
, id
and role
are supplied, then
the intersection of it will be checked.
Provenance$fct_exists(id = NULL, name = NULL, role = NULL, abort = TRUE)
id
The id of the corresponding node.
name
The name of the node.
role
The role for the node.
abort
Whether to abort.
trt_exists()
Check if treatment exists.
Provenance$trt_exists(id = NULL, name = NULL, abort = TRUE)
id
The id of the corresponding node.
name
The name of the node.
abort
Whether to abort.
unit_exists()
Check if unit exists.
Provenance$unit_exists(id = NULL, name = NULL, abort = TRUE)
id
The id of the corresponding node.
name
The name of the node.
abort
Whether to abort.
rcrd_exists()
Check if record exists.
Provenance$rcrd_exists(id = NULL, name = NULL, abort = TRUE)
id
The id of the corresponding node.
name
The name of the node.
abort
Whether to abort.
append_fct_nodes()
Given node data, append the factor nodes
Provenance$append_fct_nodes(name, role, attrs = NULL)
name
The name of the node.
role
The role for the node.
attrs
The attributes.
append_lvl_nodes()
Given node data, append the level nodes
Provenance$append_lvl_nodes( value, n = NULL, label = NULL, attrs = NULL, fid = NULL )
value
The value of the node.
n
The number of replications.
label
The labels for the levels.
attrs
The attributes.
fid
The factor id.
append_fct_edges()
Given edge data, append the factor edges
Provenance$append_fct_edges(from, to, type = NULL, group = FALSE, attrs = NULL)
from
The node id from.
to
The node id to.
type
The type of edges.
group
A logical value to indicate whether to create new group id or not.
attrs
The attributes.
append_lvl_edges()
Given edge data, append the level edges
Provenance$append_lvl_edges(from, to, attrs = NULL)
from
The node id from.
to
The node id to.
attrs
The attributes.
serve_units()
Serve the units.
Provenance$serve_units(id = NULL, return = c("id", "value"))
id
The id of the corresponding node.
return
To return in "id" or "value" format.
serve_trts()
Serve treatments
Provenance$serve_trts(id = NULL, return = c("id", "value"))
id
The id of the corresponding node.
return
To return in "id" or "value" format.
serve_rcrds()
Serve records
Provenance$serve_rcrds(id = NULL, return = c("id", "value"))
id
The id of the corresponding node.
return
To return in "id" or "value" format.
make_trts_table()
Make the treatments table
Provenance$make_trts_table(id = NULL, return = c("id", "value"))
id
The id of the corresponding node.
return
To return in "id" or "value" format.
A treatment table
graph_subset()
Subset graph
Provenance$graph_subset( id = NULL, include = c("self", "child", "parent", "ancestors") )
id
The id of the corresponding node.
include
"self" for only input id, "child" for child also, "parent" for parent also, nodes immediately related, and "ancestors" for all ancestors
subsetted graph
save_seed()
Save the seed
Provenance$save_seed(seed, type)
seed
A seed.
type
Type.
get_title()
Get the title
Provenance$get_title()
get_validation()
Get the validation
Provenance$get_validation(type = NULL)
type
A type.
get_trail()
Get the trail.
Provenance$get_trail()
get_graph()
Get the graph
Provenance$get_graph()
get_seed()
Get the seed
Provenance$get_seed()
get_session_info()
Get the session information
Provenance$get_session_info()
get_edibble_version()
Get the edibble version.
Provenance$get_edibble_version()
get_simulate()
Get the simulation information
Provenance$get_simulate(name = NULL)
name
The process name. Only one name allowed.
get_simulate_result_env()
Get the simulation results
Provenance$get_simulate_result_env(name = NULL)
name
The process name. Only one name allowed.
mapping()
Mapping of a role to role
Provenance$mapping(role_from, role_to)
role_from
The role from.
role_to
The role to.
mapping_to_unit()
Mapping of an id to a unit
Provenance$mapping_to_unit(id = NULL)
id
The id of the corresponding node.
record_step()
Record step.
Provenance$record_step()
lvl_mapping()
Get the level edges by factor
Provenance$lvl_mapping(from, to, return = c("vector", "table"))
from, to
The factor id.
return
To return in "id" or "value" format.
record_track_external()
Record track external.
Provenance$record_track_external(code)
code
The code to record.
fct_id_links()
Find all id that is linked.
Provenance$fct_id_links(id = NULL, role = NULL, link = c("direct", "indirect"))
id
The id of the corresponding node.
role
The role for the node.
link
Whether the link should be direct or indirect
id of linked factors, excluding itself.
fct_graph_components()
Get the nodes with components (subgraph number)
Provenance$fct_graph_components(id = NULL)
id
The id of the corresponding node.
lvl_graph_components()
Get the nodes with components (subgraph number)
Provenance$lvl_graph_components()
clone()
The objects of this class are cloneable with this method.
Provenance$clone(deep = FALSE)
deep
Whether to make a deep clone.
Similar to scales::rescale()
but it has a different
behaviour when only upper or lower bound is given.
rescale_values(x, lower = NA, upper = NA)
rescale_values(x, lower = NA, upper = NA)
x |
A numerical vector. |
lower |
The lower bound. |
upper |
The upper bound. |
This converts an edibble graph object to a data frame called edibble. This function should be used when the design is in the final form (or close to the final form). The table can only be formed when the variables can be reconciled, otherwise it will be a data frame with zero rows.
serve_table( .edibble = NULL, label_nested = NULL, fail = c("error", "warn", "ignore"), .record = TRUE )
serve_table( .edibble = NULL, label_nested = NULL, fail = c("error", "warn", "ignore"), .record = TRUE )
.edibble |
An edibble design ( |
label_nested |
The columns to show nested labels (if available). Tidyselect compatible. |
fail |
What to do when failing to convert graph to table. |
.record |
A logical value. This indicates whether to record this code step. The default is TRUE. It should remain TRUE unless this function is used as a wrapper in other code. |
An edbl
data frame with columns defined by vertices and
rows displayed only if the vertices are connected and reconcile for output.
Other user-facing functions:
allot_trts()
,
allot_units()
,
design()
,
expect_rcrds()
,
export_design()
,
set_rcrds()
,
set_trts()
,
set_units()
design("Completely Randomised Design") %>% set_units(unit = 28) %>% set_trts(trt = 6) %>% allot_trts(trt ~ unit) %>% assign_trts("random", seed = 521) %>% serve_table()
design("Completely Randomised Design") %>% set_units(unit = 28) %>% set_trts(trt = 6) %>% allot_trts(trt ~ unit) %>% assign_trts("random", seed = 521) %>% serve_table()
These are structured information that can be encoded in into the design
object. By encoding this information, you can make it interoperable.
If you use export_design()
, the information is exported to the title sheet
of the excel output.
set_attrs(.edibble = design(), ...)
set_attrs(.edibble = design(), ...)
.edibble |
An edibble table or design. |
... |
A series of name-value pairs where the name corresponds to the name of the metadata nad the value corresponds to the actual metadata value. If the name is omitted, then no name to the metadata is assigned for the corresponding value. |
des <- set_attrs(design(aim = "Testing for new flu vaccine.", contact = "emi.tanaka (at) anu.edu", "Funded by Better Experiments Institute.") ) des$context
des <- set_attrs(design(aim = "Testing for new flu vaccine.", contact = "emi.tanaka (at) anu.edu", "Funded by Better Experiments Institute.") ) des$context
This function creates new nodes to edibble graph with the name corresponding to either the intended response that will be measured or a variable to be recorded. Avoid record names staring with a "." as these are reserved for other purposes downstream.
set_rcrds( .edibble = NULL, ..., .name_repair = c("check_unique", "unique", "universal", "minimal"), .record = TRUE ) set_rcrds_of(.edibble = NULL, ...)
set_rcrds( .edibble = NULL, ..., .name_repair = c("check_unique", "unique", "universal", "minimal"), .record = TRUE ) set_rcrds_of(.edibble = NULL, ...)
.edibble |
An edibble design ( |
... |
Name-value pair. The value should correspond to a single name of the
unit defined in |
.name_repair |
Same as the argument in |
.record |
A logical value. This indicates whether to record this code step. The default is TRUE. It should remain TRUE unless this function is used as a wrapper in other code. |
An edibble design.
Other user-facing functions:
allot_trts()
,
allot_units()
,
design()
,
expect_rcrds()
,
export_design()
,
serve_table()
,
set_trts()
,
set_units()
takeout(menu_crd(t = 4, n = 10)) %>% set_rcrds(y = unit) takeout(menu_crd(t = 4, n = 10)) %>% set_rcrds_of(unit = "y")
takeout(menu_crd(t = 4, n = 10)) %>% set_rcrds(y = unit) takeout(menu_crd(t = 4, n = 10)) %>% set_rcrds_of(unit = "y")
This function add a special class, called edbl_trt
, of edibble variables.
set_trts( .edibble = design(), ..., .name_repair = c("check_unique", "unique", "universal", "minimal"), .record = TRUE )
set_trts( .edibble = design(), ..., .name_repair = c("check_unique", "unique", "universal", "minimal"), .record = TRUE )
.edibble |
An edibble design ( |
... |
Either a name-value pair or a series of the names. |
.name_repair |
Same as the argument in |
.record |
A logical value. This indicates whether to record this code step. The default is TRUE. It should remain TRUE unless this function is used as a wrapper in other code. |
An edibble design.
The word treatment is sometimes used to refer to one of these variables. When there are more than one treatment variables then this unfortunately confuses whether treatment refers to the variable or the combination of all treatment variables.
Treatment is the whole description of what is applied in an experiment.
Other user-facing functions:
allot_trts()
,
allot_units()
,
design()
,
expect_rcrds()
,
export_design()
,
serve_table()
,
set_rcrds()
,
set_units()
design() %>% set_trts(pesticide = c("A", "B", "C"), dosage = c(0, 10, 20, 30, 40))
design() %>% set_trts(pesticide = c("A", "B", "C"), dosage = c(0, 10, 20, 30, 40))
This function sets new edibble variables of class edbl_unit
. More
specifically, this means that new nodes are added to the edbl_graph
.
set_units( .edibble = design(), ..., .name_repair = c("check_unique", "unique", "universal", "minimal"), .record = TRUE )
set_units( .edibble = design(), ..., .name_repair = c("check_unique", "unique", "universal", "minimal"), .record = TRUE )
.edibble |
An edibble design ( |
... |
Either a name-value pair or a series of the names. |
.name_repair |
Same as the argument in |
.record |
A logical value. This indicates whether to record this code step. The default is TRUE. It should remain TRUE unless this function is used as a wrapper in other code. |
An edibble design.
A unit, much like factor, is an over-used word but due to lack of a better word, edibble uses the word "unit" to refer to any entity, physical or otherwise, that pertain to the experiment. This function doen't explicitly distinguish between experimental or observational units, nor is a unit limited to these type of units. A unit in edibble can be a blocking factor or even a discrete time unit.
Currently a unit should only have a discrete set of levels and you need to know the number of levels prior to setting the units.
Other user-facing functions:
allot_trts()
,
allot_units()
,
design()
,
expect_rcrds()
,
export_design()
,
serve_table()
,
set_rcrds()
,
set_trts()
# 30 rats design() %>% set_units(rat = 30) %>% serve_table() # 4 girls named "Anna", "Betty", "Carol", "Diana" design() %>% set_units(girl = c("Anna", "Betty", "Carol", "Diana")) %>% serve_table() # 3 companies, with 10 boxes each design() %>% set_units(company = c("A", "B", "C"), box = nested_in(company, 10)) # 2 classes, one with 10 students, the other with 20 students design() %>% set_units(class = 2, student = nested_in(class, 1 ~ 10, 2 ~ 20)) # 4 countries with 10 people from Australia & New Zealand and 20 from the rest design() %>% set_units(country = c("AU", "NZ", "USA", "JPN"), person = nested_in(country, c("AU", "NZ") ~ 10, . ~ 20)) %>% serve_table()
# 30 rats design() %>% set_units(rat = 30) %>% serve_table() # 4 girls named "Anna", "Betty", "Carol", "Diana" design() %>% set_units(girl = c("Anna", "Betty", "Carol", "Diana")) %>% serve_table() # 3 companies, with 10 boxes each design() %>% set_units(company = c("A", "B", "C"), box = nested_in(company, 10)) # 2 classes, one with 10 students, the other with 20 students design() %>% set_units(class = 2, student = nested_in(class, 1 ~ 10, 2 ~ 20)) # 4 countries with 10 people from Australia & New Zealand and 20 from the rest design() %>% set_units(country = c("AU", "NZ", "USA", "JPN"), person = nested_in(country, c("AU", "NZ") ~ 10, . ~ 20)) %>% serve_table()
This function to create and store functions to simulate the records.
simulate_process(.data, ...)
simulate_process(.data, ...)
.data |
An edibble table. |
... |
A name-value pair where the name should correspond to either the record name that you are simulating or a process name if the return object is a data frame with columns corresponding to the name of the records. The value must be a function with set default arguments. The return object of this function should be either a vector or a data frame with the column names corresponding to the record names. The size should correspond to the number of columns. |
When creating a function, internally you can refer to any of the factors without referring
to the actual data. The data referred to is expected to be from the full data.
Like in tidyverse, syntax .data
is reserved for the full data and .env
can be
used to refer to environment variables.
You can use the syntax n()
to refer to nrow(.data)
or n(fct)
where fct
corresponds to
unquoted factor name. The return value will be the number of the observed number of levels of factor fct
in the data. For n(fct1, fct2)
it will return the observed number of distinct interaction levels for fct1
and fct2
.
Note that you can actually put as many process as you like if you use a process name (starting with a dot), even if this is for the same record factor.
Simulate records
simulate_rcrds(.data, ..., .seed = NULL, .nsim = 1L)
simulate_rcrds(.data, ..., .seed = NULL, .nsim = 1L)
.data |
An edibble data |
... |
A name-value pair where the name should correspond to the names
used in the |
.seed |
An optional seed value. |
.nsim |
The number of times to simulate data. |
design() %>% set_units(unit = 4) %>% set_trts(trt = 2) %>% allot_table(trt ~ unit) %>% set_rcrds(y = unit) %>% simulate_process(y = function() { res <- rnorm(n()) res }) %>% simulate_rcrds(y = with_params(), .nsim = 3)
design() %>% set_units(unit = 4) %>% set_trts(trt = 2) %>% allot_table(trt ~ unit) %>% set_rcrds(y = unit) %>% simulate_process(y = function() { res <- rnorm(n()) res }) %>% simulate_rcrds(y = with_params(), .nsim = 3)
This contains the data from the skittle experiment conducted by Nick Tierney. The goal of the experiment was to assess if people can discern the flavour of the skittle (indicated by color of the skittle) based on taste alone. The participants are blindfolded.
The experiment had 3 participants with each participant tasting 10 skittles, 2 of each 5 color, in a random order.
The type of skittle. Coincides with real_skittle
.
The participant.
The order the skittle was tasted.
The participant's choice.
The actual skittle color.
skittles
skittles
An object of class spec_tbl_df
(inherits from tbl_df
, tbl
, data.frame
) with 30 rows and 6 columns.
https://github.com/njtierney/skittles
Other experimental data:
lady_tasting_tea
This function has a similar result with split()
where
it returns a named list with names corresponding to the
levels of the separating factor (or concatenated strings
if multiple separating factors). The key differences to split()
,
are that the splitting factor does not appear in the elements of the
list and only linked factors and their ancestors appear in the output, e.g.
if treatment is applied to wholeplot and subplots are nested within
subplots, then the subplot will not be shown in the output if split by
treatment.
split_by(.data, ..., .sep = ":", .remove_empty = TRUE) count_by(.data, ..., .remove_empty = TRUE)
split_by(.data, ..., .sep = ":", .remove_empty = TRUE) count_by(.data, ..., .remove_empty = TRUE)
.data |
An edibble table. |
... |
The factors to split or count by. You cannot split by a record factor or a factor that uniquely indexes the smallest unit in the design. You cannot also combine treatment and unit factors together. |
.sep |
The separator to use if more than one factor to split by. |
.remove_empty |
Remove empty combinations. Default is TRUE. |
A named list.
spd <- takeout(menu_split()) split(spd, spd$trt1) spd %>% split_by(trt1) spd %>% split_by(trt2) spd %>% split_by(mainplot) spd %>% count_by(trt1) fac <- takeout(menu_factorial(trt = c(2, 2, 2))) fac %>% count_by(where(~is_trt(.x)))
spd <- takeout(menu_split()) split(spd, spd$trt1) spd %>% split_by(trt1) spd %>% split_by(trt2) spd %>% split_by(mainplot) spd %>% count_by(trt1) fac <- takeout(menu_factorial(trt = c(2, 2, 2))) fac %>% count_by(where(~is_trt(.x)))
This function generates a named experimental design by supplying the selected menu named design and prints out by default
You can find the available recipes with scan_menu()
.
takeout(recipe = NULL, show = TRUE)
takeout(recipe = NULL, show = TRUE)
recipe |
A named design object. This should be typically generated from a
function with prefix |
show |
A logical value to indicate whether the code should be shown or not. Default is TRUE. |
A recipe design.
See scan_menu()
for finding the short names of the
named experimental designs.
takeout(menu_crd(n = 50, t = 5)) # if you omit the design parameters then it will use the default # (which may be random) takeout(menu_crd()) # if you don't give any short names then it will generate a random one takeout()
takeout(menu_crd(n = 50, t = 5)) # if you omit the design parameters then it will use the default # (which may be random) takeout(menu_crd()) # if you don't give any short names then it will generate a random one takeout()
Treatments table
trts_table(.edibble)
trts_table(.edibble)
.edibble |
An edibble table |
The S3 methods for edbl_fct
objects have
the same expected output that of a factor.
Other functions are utility functions related to edbl_fct
object.
## S3 method for class 'edbl_fct' as.character(x, ...) ## S3 method for class 'edbl_fct' as.integer(x, ...) is_fct(x) is_unit(x) is_trt(x) is_rcrd(x)
## S3 method for class 'edbl_fct' as.character(x, ...) ## S3 method for class 'edbl_fct' as.integer(x, ...) is_fct(x) is_unit(x) is_trt(x) is_rcrd(x)
x |
An |
... |
Ignored. |
A character vector.
This is a helper function to set the parameter values
with_params(..., .censor = NA, .aggregate = NULL)
with_params(..., .censor = NA, .aggregate = NULL)
... |
A series of name-value pair that are inputs used for the simulation process. |
.censor |
The value to censor if it outside the valid values. If the
value has a lower and upper bound then it should be a vector of size 2. Use
-Inf or Inf if you don't want to censor either value. You can use a list if
you want a different censoring for different records where the name corresponds to
the name of the record. If you want to apply a default value/function for censoring
then use the name ".default". You can use a function instead of a value. The function
may be specified by as a lambda function. The object |
.aggregate |
The function for aggregation if the response values differ
within the same unit level for the record. Use |
This creates a list that is used later for creating data validation rules when the data is exported.
with_value( operator = c("=", "==", ">=", "<=", "<", ">", "!="), value = NULL, between = NULL, not_between = NULL )
with_value( operator = c("=", "==", ">=", "<=", "<", ">", "!="), value = NULL, between = NULL, not_between = NULL )
operator |
Operator to apply. |
value |
An optional value related to operator |
between , not_between
|
An optional numerical vector of size two where the
first entry is the minimum value and the second entry is the maximum value.
For |
A list with two elements operator
and value
.
The other options give are characteristics of the record (not the independent variables). Warning: none of the other options work at the moment!
with_variables( ..., .missing = FALSE, .interaction = random_true_false(), .discrete = FALSE, .linear = random_true_false(), .error_dist = NULL )
with_variables( ..., .missing = FALSE, .interaction = random_true_false(), .discrete = FALSE, .linear = random_true_false(), .error_dist = NULL )
... |
A series of factors in which the record is explicitly dependent upon (tidyselect campatible). |
.missing |
A logical value indicating whether there should be some missing values. Default is FALSE. The missing values are introduced at random. It can also be numeric of between 0 and 1 giving the proportion of missing values. |
.interaction |
Whether there should be treatment interaction effects. |
.discrete |
Whether to make the response value discrete or not. |
.linear |
Whether to include non-linear term or not. The value is always additive. |
.error_dist |
The random distribution to use for numerical values (either "normal", "uniform", "exponential", "gamma", "beta", "cauchy", "chisq", "f", "t", "poisson", "weibull"). The default choice is random out of these with higher chances of "normal". |