================================================================================ Design Library - Experimental Design ================================================================================ This library contains functions for experimental design, including Latin squares, counterbalancing, and design matrices. .. contents:: Function Index :local: :depth: 0 .. index:: ChooseN ChooseN() --------- **Description:** Samples ```` items from list, returning a list in the original order. Items are sampled without replacement, so once an item is chosen it will not be chosen again. If ```` is larger than the length of the list, the entire list is returned in order. It differs from ``SampleN`` in that ``ChooseN`` returns items in the order they appeared in the originial list, but ``SampleN`` is shuffled. **Usage:** .. code-block:: pebl define ChooseN(...) **Example:** .. code-block:: pebl # Returns 5 numbers ChooseN([1,1,1,2,2], 5) # Returns 3 numbers from 1 and 7: ChooseN([1,2,3,4,5,6,7], 3) **See Also:** :func:`SampleN()`, :func:`SampleNWithReplacement()`, :func:`Subset()` .. index:: DesignBalancedSampling DesignBalancedSampling() ------------------------ **Description:** Samples elements ``roughly'' equally. This function returns a list of repeated samples from ````, such that each element in ```` appears approximately equally. Each element from ```` is sampled once without replacement before all elements are returned to the mix and sampling is repeated. If there are no repeated items in ````, there will be no consecutive repeats in the output. The last repeat-sampling will be truncated so that a ````-size list is returned. If you don't want the repeated epochs this function provides, Shuffle() the results. **Usage:** .. code-block:: pebl define DesignBalancedSampling(...) **Example:** .. code-block:: pebl DesignBalancedSampling([1,2,3,4,5],12) ## e.g., produces something like: ## [5,3,1,4,2, 3,1,5,2,4, 3,1 ] **See Also:** :func:`CrossFactorWithoutDuplicates()`, :func:`Shuffle()`, :func:`DesignFullCounterBalance()`, :func:`DesignGrecoLatinSquare()`, :func:`DesignLatinSquare()`, :func:`Repeat()`, :func:`RepeatList()`, :func:`LatinSquare()` .. index:: DesignGrecoLatinSquare DesignGrecoLatinSquare() ------------------------ **Description:** This will return a list of lists formed by rotating through each element of the ```` s, making a list containing all element of the list, according to a greco-latin square. All lists must be of the same length. **Usage:** .. code-block:: pebl define DesignGrecoLatinSquare(...) **Example:** .. code-block:: pebl x <- ["a","b","c"] y <- ["p","q","r"] z <- ["x","y","z"] Print(DesignGrecoLatinSquare(x,y,z)) # produces: [[[a, p, x], [b, q, y], [c, r, z]], # [[a, q, z], [b, r, x], [c, p, y]], # [[a, r, y], [b, p, z], [c, q, x]]] **See Also:** :func:`CrossFactorWithoutDuplicates()`, :func:`LatinSquare()`, :func:`DesignFullCounterBalance()`, :func:`DesignBalancedSampling()`, :func:`DesignLatinSquare()`, :func:`Repeat()`, :func:`RepeatList()`, :func:`Shuffle()` .. index:: DesignLatinSquare DesignLatinSquare() ------------------- *Simple latin square* **Description:** This returns return a list of lists formed by rotating through each element of ````, making a list containing all element of the list. Has no side effect on input lists. **Usage:** .. code-block:: pebl define DesignLatinSquare(...) **Example:** .. code-block:: pebl order <- [1,2,3] treatment <- ["A","B","C"] design <- DesignLatinSquare(order,treatment) # produces: [[[1, A], [2, B], [3, C]], # [[1, B], [2, C], [3, A]], # [[1, C], [2, A], [3, B]]] **See Also:** :func:`CrossFactorWithoutDuplicates()`, :func:`DesignFullCounterBalance()`, :func:`DesignBalancedSampling()`, :func:`DesignGrecoLatinSquare()`, :func:`Repeat()`, :func:`LatinSquare()` :func:`RepeatList()`, :func:`Shuffle()`, :func:`Rotate()` .. index:: ExtractListItems ExtractListItems() ------------------ *Gets a subset of items from a list* **Description:** Extracts items from a list, forming a new list. The list ```` are the integers representing the indices that should be extracted. **Usage:** .. code-block:: pebl define ExtractListItems(...) **Example:** .. code-block:: pebl myList <- Sequence(101, 110, 1) ExtractListItems(myList, [2,4,5,1,4]) # produces [102, 104, 105, 101, 104] **See Also:** :func:`Subset()`, :func:`SubList()`, :func:`SampleN()`, :func:`Filter()` .. index:: Flatten Flatten() --------- *Flattens a nested list completely* **Description:** Flattens nested list ```` to a single flat list. **Usage:** .. code-block:: pebl define Flatten(...) **Example:** .. code-block:: pebl Flatten([1,2,[3,4],[5,[6,7],8],[9]]) # == [1,2,3,4,5,6,7,8,9] Flatten([1,2,[3,4],[5,[6,7],8],[9]]) # == [1,2,3,4,5,6,7,8,9] **See Also:** :func:`FlattenN()`, :func:`FoldList()` .. index:: FlattenN FlattenN() ---------- *Flattens n levels of a nested list* **Description:** Flattens ```` levels of nested list ````. **Usage:** .. code-block:: pebl define FlattenN(...) **Example:** .. code-block:: pebl Flatten([1,2,[3,4],[5,[6,7],8],[9]],1) # == [1,2,3,4,5,[6,7],8,9] **See Also:** :func:`Flatten()`, :func:`FoldList()` .. index:: FoldList FoldList() ---------- *Folds list into length-n sublists.* **Description:** Folds a list into equal-length sublists. **Usage:** .. code-block:: pebl define FoldList(...) **Example:** .. code-block:: pebl FoldList([1,2,3,4,5,6,7,8],2) # == [[1,2],[3,4],[5,6],[7,8]] **See Also:** :func:`FlattenN()`, :func:`Flatten()` .. index:: Insert Insert() -------- **Description:** Inserts an element into a list at a specified position, returning the new list. The original list in unchanged. **Usage:** .. code-block:: pebl define Insert(...) **Example:** .. code-block:: pebl x <- [1,2,3,5] y <- Insert(x,1,4) ##y== [1,2,3,1,5] **See Also:** :func:`List()`, ``Merge``, ``Append`` .. index:: LatinSquare LatinSquare() ------------- *A simple latin square constructor* **Description:** Quick and dirty latin square, taking on just one list argument. **Usage:** .. code-block:: pebl define LatinSquare(...) **Example:** .. code-block:: pebl Print(LatinSquare([11,12,13,14,15,16])) # Output: #[[11, 12, 13, 14, 15, 16] #, [12, 13, 14, 15, 16, 11] #, [13, 14, 15, 16, 11, 12] #, [14, 15, 16, 11, 12, 13] #, [15, 16, 11, 12, 13, 14] #, [16, 11, 12, 13, 14, 15] #] **See Also:** :func:`DesignFullCounterBalance()`, :func:`DesignBalancedSampling()`, :func:`DesignGrecoLatinSquare()`, :func:`DesignLatinSquare()`, :func:`Repeat()`, :func:`RepeatList()`, :func:`Shuffle()` .. index:: Levels Levels() -------- *Returns a sorted list of unique elements in list.* **Description:** Returns sorted list of unique elements of a list. **Usage:** .. code-block:: pebl define Levels(...) **Example:** .. code-block:: pebl Levels([1,3,55,1,5,1,5]) # == [1,3,5,55] **See Also:** :func:`Match()`, :func:`Filter()`, :func:`Sort()` .. index:: ListBy ListBy() -------- *Segments a list into sublist by the values of a second list* **Description:** organizes a list into sublists, based on the elements of a second list. It returns a list of two entities: (1) a condition list, describing what values were aggregated across; (2) the nested list elements. The length of each element should be the same. Together with Match and Filter, ListBy is useful for aggregating data across blocks and conditions for immediate feedback. **Usage:** .. code-block:: pebl define ListBy(...) **Example:** .. code-block:: pebl a <- Sequence(1,10,1) b <- RepeatList([1,2],5) x <- ListBy(a,b) Print(x) #[[1, 2], # [[1, 3, 5, 7, 9], # [2, 4, 6, 8, 10]] #] Print(ListBy(b,a)) #[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], # [[1], [2], [1], [2], [1], [2], [1], [2], [1], [2]]] **See Also:** :func:`List()`, ``[ ]``, :func:`Merge()`, :func:`Append()` .. index:: RemoveSubset RemoveSubset() -------------- **Description:** Removes a subset of elements from a list. Creates a new list, and does not affect the original **Usage:** .. code-block:: pebl define RemoveSubset(...) **Example:** .. code-block:: pebl list1 <- [1,2,2,4,5] list2 <- RemoveSubset(list1,[2,3]) Print(list1) #[1,2,2,4,5] Print(list2) #[1,4,5] **See Also:** :func:`Merge()`, :func:`Insert()`, :func:`Rest()` .. index:: Replace Replace() --------- *Replaces items in a data structure* **Description:** Creates a copy of a (possibly nested) list in which items matching some list are replaced for other items. ``