class: middle center hide-slide-number monash-bg-gray80 .info-box.w-50.bg-white[ These slides are viewed best by Chrome or Firefox and occasionally need to be refreshed if elements did not load properly. Please note this web version takes a while to load. See <a href="deggust.pdf">here for the PDF <i class="fas fa-file-pdf"></i></a>. ] <br> .white[Press the **right arrow** to progress to the next slide!] --- background-size: cover class: title-slide count: false # .f1.monash-blue[Visualising experimental designs with the `edibble` and `deggust` R-packages] <br> <h2 style="font-weight:900!important;"></h2> .bottom_abs.width100[ Presenter: *Emi Tanaka* <i class="fas fa-university"></i> Department of Econometrics and Business Statistics, <Br> Monash University, Melbourne, Australia <i class="fas fa-envelope"></i> emi.tanaka@monash.edu <a href="https://twitter.com/statsgen" style="color:black"><i class="fab fa-twitter"></i> @statsgen</a> <i class="fas fa-calendar-alt"></i> 11 Nov 2021 @ Applications of Statistical Procedures in Biological Data <br> ] --- name: toc class: transition .f1.tl[ <i class="fas fa-utensils"></i> .menu-font[today's menu]] .f2.pa3.tl[ .plate[1] Experimental design in *reality* .f3.grey[<i class="fas fa-lightbulb"></i>] [.f4[<i class="fas fa-caret-right"></i>]](#reality) .plate[2] Overview of .yellow[`edibble`] .f3.grey[<i class="fas fa-laptop-code"></i>] [.f4[<i class="fas fa-caret-right"></i>]](#edibble) .plate[3] Grammar of graphics with .yellow[`ggplot2`] .f3.grey[<i class="fas fa-laptop-code"></i>] [.f4[<i class="fas fa-caret-right"></i>]](#ggplot) .plate[4] Visualising experimental designs with .yellow[`deggust`] .f3.grey[<i class="fas fa-laptop-code"></i>] [.f4[<i class="fas fa-caret-right"></i>]](#deggust) ] <br> .border-box.monash-bg-blue2.center.w-70[ <i class="fas fa-link"></i> These slides made using R powered by HTML/CSS/JS can be found at<br><a class="f2" style="color:yellow!important" href="https://emitanaka.org/slides/stats4bio2021/deggust">emitanaka.org/slides/stats4bio2021/deggust</a> ] --- name: reality class: transition animate__animated animate__slideInRight .plate-big[1] <br> # Experimental design in *reality* --- class: inform-slide middle center # .f-headline[An experiment generally involves *more than one person*] --- class: inform-slide center .f-subheadline[Meet the cast starring today] .flex[ .w-33[ <br> <img src="images/stickman/domain1.svg" width="100px" class=""> The **"domain expert"** ] .w-33[ <img src="images/stickman/statistician1.svg" width="120px" class=""> The **"statistician"** <img src="images/stickman/statistician2.svg" width="100px" class=""> The **"analyst"** ] .w-33[ <br> <img src="images/stickman/technician2.svg" width="100px" class="img-hor"> The **"technician"** ] ] .absolute.bottom-0.f5[ Stick person images by <a href="https://pixabay.com/users/openclipart-vectors-30363/?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=151793">OpenClipart-Vectors</a> from <a href="https://pixabay.com/?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=151793">Pixabay</a> ] --- class: inform-slide center .f-subheadline.hidden[Meet the cast starring today] .flex[ .w-33[ <br> <img src="images/stickman/domain1.svg" width="100px" class=""> The **"domain expert"** ] .w-60.tl[ <br><br> The .monash-blue2[**"domain expert"**] drives the experimental objective and has the intricate knowledge about the subject area ] ] --- class: inform-slide center .f-subheadline.hidden[Meet the cast starring today] .flex[ .w-33.tl[ <br><br><br><br><br> The .monash-red2[**"analyst"**] analyses the data after the data is collected. ] .w-33[ <img src="images/stickman/statistician1.svg" width="120px" class=""> The **"statistician"** <img src="images/stickman/statistician2.svg" width="100px" class=""> The **"analyst"** ] .w-33.tl[ The .monash-ruby2[**"statistican"**] creates the experimental design layout after taking into account the statistical and practical constraints. ] ] --- class: inform-slide center .f-subheadline.hidden[Meet the cast starring today] .flex[ .w-33[ ] .w-33[ The .monash-green2[**"technician"**] carries out the experiment and collects the data. ] .w-33[ <br> <img src="images/stickman/technician2.svg" width="100px" class="img-hor"> The **"technician"** ] ] --- class: inform-slide center .f-subheadline[See the props] <br> .flex[ .w-33.pr3.pl3[ <span class="fa-stack fa-2x "><i class="fas fa-laptop-code fa-stack-2x"></i></span> The statistical software to design experiments ] .w-33.pr3.pl3[ <br><br><br><br> <span class="fa-stack fa-2x "><i class="fas fa-book-open fa-stack-2x"></i></span> Good old pen and paper ] .w-33.pr3.pl3[ <span class="fa-stack fa-2x"><i class="fas fa-desktop fa-stack-2x"></i><i class="fas fa-database fa-stack-1x"></i></span> The software to enter and store data ]] <br> .gray[Missing prop: the statistical software to analyse experimental data] --- class: inform-slide middle .center.b[ .f1[The actors are purely illustrative.] ] -- <br> .flex[ .w-20[ ] .w-70[ .f2[ In practice: * multiple people can take on each role, * one person can take on multiple roles, and/or * a person in the role may not specialise in that role (e.g. the statistician role can be acted out by a non-statistician). ] ] .w-10[ ]] .center[ <img src="images/stickman/technician1.svg" width="100px" class=""> <img src="images/stickman/actor1.svg" width="75px" class=""> <img src="images/stickman/actor2.svg" width="100px" class=""> ] --- layout: true class: inform-slide .f1[ How we expect experiments are run ] --- <br> .flex[ .w-20[ <img src="images/stickman/domain1.svg" width="200px" class=""> ] .w-60[ .sm-quote.pr5.monash-blue2[ Hey, I need to run an experiment. <br> Can you test irrigation and fertilizer effect on plant growth? Bla bla bla... ] <br> .sm-quote.pl5.monash-ruby2[ {{content}} ] ] .w-20[ <img src="images/stickman/statistician1.svg" width="200px" class="img-hor"> .center[ <span class="fa-stack fa-2x f2"><i class="fas fa-book-open fa-stack-2x"></i><i class="fas fa-pen fa-stack-1x fa-inverse"></i></span> ] ]] -- Okay. **I got the experimental structure *perfectly*.** I'll go generate the experimental design layout. --- <br> .flex[ .w-20[ <img src="images/stickman/statistician1.svg" width="200px" class=""> .center[ <span class="fa-stack fa-2x f2"><i class="fas fa-book-open fa-stack-2x"></i><i class="fas fa-pen fa-stack-1x fa-inverse"></i></span> ] ] .w-60[ .sm-quote.pr5.monash-ruby2[ I have a **_complete_ understanding of the experimental structure** so I shall enter it in the software to generate the experimental design ] ] .w-20[ <br> <span class="fa-stack fa-2x "><i class="fas fa-laptop-code fa-stack-2x"></i></span> ]] --- <br> .flex[ .w-20[ <img src="images/stickman/statistician1.svg" width="200px" class=""> .center[ <span class="fa-stack fa-2x f2"><i class="fas fa-book-open fa-stack-2x"></i></span> ] ] .w-60[ .sm-quote.pr5.monash-ruby2[ Here is the design layout ] <br> .sm-quote.pl5.monash-green2[ I'll execute this experiment **exactly as planned** and enter the data with **absolutely no mistake** ] <br> .center[ <span class="fa-stack fa-2x"><i class="fas fa-desktop fa-stack-2x"></i><i class="fas fa-database fa-stack-1x"></i></span> ] ] .w-20[ <img src="images/stickman/technician2.svg" width="150px" class="img-hor"> ]] --- layout: false class: inform-slide middle .f1[But] .blockquote[ communication is complex, fraught with tensions, misunderstandings, and problems — rather than a simple process of creating shared meaning .pull-right[— Littlejohn et al. (2017)] ] .footnote.tl.f4[ Littlejohn, Stephen W., Karen A. Foss, and John G. Oetzel. 2017. Theories of Human Communication. Waveland Press, Inc. ] --- layout: true class: inform-slide .f1[ What happens in reality ] --- .f2.pl3[ * Misunderstandings or incomplete understandings ] .flex[ .w-20[ <img src="images/stickman/domain1.svg" width="200px" class=""> ] .w-60[ .sm-quote.pr5.monash-blue2[ Hey, I need to run an experiment. <br> Can you test irrigation and fertilizer effect on plant growth? Bla bla bla... ] <br> .sm-quote.pl5.monash-ruby2[ {{content}} ] ] .w-20[ <img src="images/stickman/statistician1.svg" width="200px" class="img-hor"> .center[ <span class="fa-stack fa-2x f2"><i class="fas fa-book-open fa-stack-2x"></i><i class="fas fa-pen fa-stack-1x fa-inverse"></i></span> ] ]] -- Okay. I think I got it. I'll go see what we can do for the experimental design. --- .f2.pl3[ * A lot of back-and-forth to be on the same page <br> .f3[(which is completely natural and okay) ]] .flex[ .w-20[ <img src="images/stickman/statistician1.svg" width="200px" class=""> .center[ <span class="fa-stack fa-2x f2"><i class="fas fa-book-open fa-stack-2x"></i><i class="fas fa-pen fa-stack-1x fa-inverse"></i></span> ] ] .w-60[ .sm-quote.pr5.monash-ruby2[ Okay how about this plan. ] .center[ <span class="fa-stack fa-2x f2"><i class="fas fa-laptop-code fa-stack-2x"></i></span> ] {{content}} ] .w-20[ <img src="images/stickman/domain1.svg" width="200px" class="img-hor"> ]] -- <br> <div class="sm-quote pl5 monash-blue2"> Actually, we can't apply different irrigation methods to these set of plots so we have to change this part. Bla bla. </div> {{content}} -- <br> <div class="sm-quote pr5 monash-ruby2"> Okay, I'll write this in my notebook. </div> --- .f2.pl3[ * OR limited communication and decisions made in silo ] .flex[ .w-33.br.pa3[ .pull-left[ <img src="images/stickman/domain1.svg" width="120px" class=""> ] .sm-quote.monash-blue2[ Oh actually, we didn't have enough seedlings for the test line. Oh well, we'll just leave that empty when we get the plan. ] ] .w-33.br.pa3[ .pull-left[ <img src="images/stickman/statistician1.svg" width="150px" class=""> ] .sm-quote.monash-ruby2[ Hmm, I'm not sure about this but I guess this will do for the experimental design. ] .center[ <span class="fa-stack fa-2x f2"><i class="fas fa-laptop-code fa-stack-2x"></i></span> ] ] .w-33.pa3[ .pull-left[ <img src="images/stickman/technician1.svg" width="120px" class=""> ] .sm-quote.monash-green2[ Oh no! One side of the green house gets more sunlight than the other! Let's move the pots around so that they get the same amount of sunlight. ] ]] --- .f2.pl3[ * Implicit decisions never explicitly transcribed ] .flex[ .w-20[ <img src="images/stickman/statistician2.svg" width="100px" class=""> ] .w-60[ .sm-quote.monash-red2.pr5[ Why is the experimental design like this? ] <br> .sm-quote.monash-ruby2.pl5[ I think I had a good reason at the time but I can't remember! ] <br> .sm-quote.monash-red2.pr5.f5[ Why are we always on a handstand anyway? ] <br> .sm-quote.monash-ruby2.pl5.f5[ There's no good reason for that! ] ] .w-20[ <img src="images/stickman/statistician1.svg" width="120px" class="img-hor"> ]] --- .f2.pl3[ * Knowledge lost ] .flex[ .w-20[ <img src="images/stickman/statistician2.svg" width="100px" class=""> ] .w-60[ .sm-quote.monash-red2.pr5[ How was the experimental design constructed? ] <br> .sm-quote.monash-blue2.pl5[ The statistician left a bunch of notes before leaving us for another position but I don't know what's what, so I don't know. ] .center[ <span class="fa-stack fa-2x "><i class="fas fa-book-open fa-stack-2x"></i></span> ] ] .w-20[ <img src="images/stickman/domain1.svg" width="100px" class="img-hor"> ]] --- .f2.pl3[ * Thinking analysis will save you ] .flex[ .w-20[ <img src="images/stickman/statistician2.svg" width="100px" class=""> ] .w-60[ .sm-quote.monash-blue2.pl5[ I think we may have data quality issues in this experimental data. ] .sm-quote.monash-red2.pr5[ Oh cool data! I can try this fancy statistical model! Hmm, what did you say? ] .sm-quote.monash-blue2.pl5[ I'm saying that the data may be rubbish. ] .sm-quote.monash-red2.pr5[ But I got some numbers from fitting this model. ] <br> ] .w-20[ <img src="images/stickman/domain1.svg" width="100px" class="img-hor"> ]] --- class: transition layout: false # Garbage in, garbage out .w-80.mauto.f1[ No statistical model, however complex it is, can make any sense of the data if the collected data is rubbish ] --- class: transition # Redoing an experiment is *expensive* -- .f1[ There's a higher stake in getting the experiment design wrong compared to getting the analysis wrong. ] In some cases, redoing an experiment is not every possible! --- # What most statistics (and data science) research is about <img src="images/tidyverse.png" width="100%"> .center[ (with disproportionate amount in Model) ] .footnote.f5[ Grolemund, G., & Wickham, H. (2017). R for Data Science. O'Reilly Media. ] --- # World of data collection But there is a whole world of data collection before importing data! <img src="images/workflow.png" width="100%"> -- * There is probably more gain in extracting information in ensuring the quality of the data than analysis. -- * Experimental design research is generally concerned about generating the experimental design layout -- * `edibble` aims to complement many great experimental design research to design the whole experiment --- name: edibble class: transition animate__animated animate__slideInRight .plate-big[2] <br> # Overview of `edibble` --- # The grammar of experimental designs <img src="images/edibble.png" style="width:200px" class="pull-right"> .info-box.w-60[ An abstract computational framework that maps fundamental experimental components to an object oriented system to build and modify experimental designs.<br> Currently implemented as the `edibble` R-package. ] .f2[ <i class="fab fa-r-project"></i></i></span> **Package documentation**: .center[ <a href='https://edibble.emitanaka.org'>edibble.emitanaka.org</a> ] <i class="fab fa-github"></i></span> **Source code**: .center[ <a href='https://github.com/emitanaka/edibble'>github.com/emitanaka/edibble</a> ] <i class="fas fa-signature"></i> **Name origin**: <i class="fas fa-crosshairs"></i> produce **e**xperimental **d**esign table (or `t**ibble**`) ] .footnote.f5[ Kirill Müller and Hadley Wickham (2021). tibble: Simple Data Frames. R package version 3.1.5. https://CRAN.R-project.org/package=tibble ] --- # Lifecycle .f1[ <i class="fas fa-book"></i> https://lifecycle.r-lib.org/articles/stages.html ] <center> <img src="images/lifecycle.svg"> </center> <br> .f2[ * Currently `edibble` is <a href="https://lifecycle.r-lib.org/articles/stages.html#experimental"><img src="images/lifecycle-experimental.svg" style = "height:1em"></a> * Some functions like `allocation_trts` and `randomise_trts` have become <a href="https://lifecycle.r-lib.org/articles/stages.html#deprecated"><img src="images/lifecycle-deprecated.svg" style = "height:1em"></a> in favour of `allot_trts` and `assign_trts` ] .footnote.f5[ Lionel Henry and Hadley Wickham (2021). lifecycle: Manage the Life Cycle of your Package Functions. R package version 1.0.1. https://CRAN.R-project.org/package=lifecycle ] --- # Reframing how you think about experimental designs .blockquote.w-100[ .pl3[ Good design considers units and treatments first, and then allocates treatments to units. It does not choose from a menu of named designs. .right[—Rosemary Bailey (2008)] ]] .footnote.f5[ Bailey, R. (2008). Design of Comparative Experiments (Cambridge Series in Statistical and Probabilistic Mathematics). Cambridge: Cambridge University Press. doi:10.1017/CBO9780511611483 ] -- .f2[ * `edibble` encourages users to think about designs exactly as Bailey (2008) suggests ] -- .f2[ * Nevertheless named experimental designs are very prevelant and can be useful to describe particular designs succintly!] -- .f2[ * So let's have the best of both worlds ] --- # Example .circle[1] Completely randomised design .flex[ .w-30[ <br> <img src="images/eg0.png" width="300px"> ] .w-70[ ```r library(edibble) *code_classical("crd", t = 3, n = 6) ``` ``` set.seed(648) start_design("crd") %>% set_units(unit = 6) %>% set_trts(treat = 3) %>% allot_trts(treat ~ unit) %>% assign_trts("random") %>% serve_table() ``` * Note: currently only limited named experimental designs are supported * <i class="fas fa-exclamation-triangle"></i> this function name and arguments will likely change in near future ] ] --- # Example .circle[2] Randomised complete block design .flex[ .w-30[ <br> <img src="images/eg1.png" width="300px"> ] .w-70[ ```r library(edibble) *code_classical("rcbd", t = 3, b = 2) ``` ``` set.seed(231) start_design("rcbd") %>% set_units(block = 2, unit = nested_in(block, 3)) %>% set_trts(treat = 3) %>% allot_trts(treat ~ unit) %>% assign_trts("random") %>% serve_table() ``` * <i class="fas fa-exclamation-triangle"></i> this function name and arguments will likely change in near future ] ] --- # Example .circle[3] Factorial design .flex[ .w-30[ <br> <img src="images/factorial-eg1.png" width="300px"> ] .w-70[ ```r library(edibble) *code_classical("factorial", trt = c(2, 4), n = 16) ``` ``` set.seed(289) start_design("factorial") %>% set_units(unit = 16) %>% set_trts(treat1 = 2, treat2 = 4) %>% allot_trts( ~ unit) %>% assign_trts("random") %>% serve_table() ``` * <i class="fas fa-exclamation-triangle"></i> this function name and arguments will likely change in near future ] ] --- # Example .circle[4] Split-plot design .flex[ .w-30[ <br> <img src="images/split-plot-eg1.png" width="300px"> ] .w-70[ ```r library(edibble) *code_classical("split", t1 = 2, t2 = 4, r = 2) ``` ``` set.seed(566) start_design("split") %>% set_units(mainplot = 4, subplot = nested_in(mainplot, 4)) %>% set_trts(treat1 = 2, treat2 = 4) %>% allot_trts(treat1 ~ mainplot, treat2 ~ subplot) %>% assign_trts("random") %>% serve_table() ``` * <i class="fas fa-exclamation-triangle"></i> this function name and arguments will likely change in near future ] ] --- # Example .circle[5] Strip-plot design .flex[ .w-30[ <br> <img src="images/strip-plot.png" width="300px"> ] .w-70[ {{content}} ] ] -- ```r library(edibble) start_design("Strip-plot") %>% set_trts(diet = 4, breed = 5) %>% set_units(hen = 5, order = 4, chick = ~hen:order) %>% allot_trts(breed ~ hen, diet ~ order) %>% assign_trts("random") %>% serve_table() ``` ``` ## # An edibble: 20 x 5 ## diet breed hen order chick ## <trt(4)> <trt(5)> <unit(5)> <unit(4)> <unit(20)> ## 1 diet1 breed1 hen1 order1 chick1 ## 2 diet1 breed4 hen2 order1 chick2 ## 3 diet1 breed2 hen3 order1 chick3 ## 4 diet1 breed3 hen4 order1 chick4 ## 5 diet1 breed5 hen5 order1 chick5 ## 6 diet3 breed1 hen1 order2 chick6 ## 7 diet3 breed4 hen2 order2 chick7 ## 8 diet3 breed2 hen3 order2 chick8 ## 9 diet3 breed3 hen4 order2 chick9 ## 10 diet3 breed5 hen5 order2 chick10 ## 11 diet2 breed1 hen1 order3 chick11 ## 12 diet2 breed4 hen2 order3 chick12 ## 13 diet2 breed2 hen3 order3 chick13 ## 14 diet2 breed3 hen4 order3 chick14 ## 15 diet2 breed5 hen5 order3 chick15 ## 16 diet4 breed1 hen1 order4 chick16 ## 17 diet4 breed4 hen2 order4 chick17 ## 18 diet4 breed2 hen3 order4 chick18 ## 19 diet4 breed3 hen4 order4 chick19 ## 20 diet4 breed5 hen5 order4 chick20 ``` --- # Experimental context is important * Name the variables so it always reminds you of the context .flex.f4[ .w-50.br[ ```r start_design("My plant experiment") %>% set_units(mainplot = 4, subplot = nested_in(mainplot, 4)) %>% set_trts(water = c("irrigated", "rain-fed"), variety = 4) %>% allot_trts(water ~ mainplot, variety ~ subplot) %>% assign_trts("random", seed = 1) %>% serve_table() ``` ``` ## # An edibble: 16 x 4 ## mainplot subplot water variety ## <unit(4)> <unit(16)> <trt(2)> <trt(4)> ## 1 mainplot1 subplot1 irrigated variety3 ## 2 mainplot1 subplot2 irrigated variety1 ## 3 mainplot1 subplot3 irrigated variety4 ## 4 mainplot1 subplot4 irrigated variety2 ## 5 mainplot2 subplot5 irrigated variety2 ## 6 mainplot2 subplot6 irrigated variety4 ## 7 mainplot2 subplot7 irrigated variety3 ## 8 mainplot2 subplot8 irrigated variety1 ## 9 mainplot3 subplot9 rain-fed variety3 ## 10 mainplot3 subplot10 rain-fed variety1 ## 11 mainplot3 subplot11 rain-fed variety4 ## 12 mainplot3 subplot12 rain-fed variety2 ## 13 mainplot4 subplot13 rain-fed variety1 ## 14 mainplot4 subplot14 rain-fed variety4 ## 15 mainplot4 subplot15 rain-fed variety3 ## 16 mainplot4 subplot16 rain-fed variety2 ``` ] .w-50[ ```r start_design("My animal experiment") %>% set_units(pen = 4, cow = nested_in(pen, 4)) %>% set_trts(diet = c("low-card", "high-fat"), breed = 4) %>% allot_trts(diet ~ pen, breed ~ cow) %>% assign_trts("random", seed = 1) %>% serve_table() ``` ``` ## # An edibble: 16 x 4 ## pen cow diet breed ## <unit(4)> <unit(16)> <trt(2)> <trt(4)> ## 1 pen1 cow1 low-card breed3 ## 2 pen1 cow2 low-card breed1 ## 3 pen1 cow3 low-card breed4 ## 4 pen1 cow4 low-card breed2 ## 5 pen2 cow5 low-card breed2 ## 6 pen2 cow6 low-card breed4 ## 7 pen2 cow7 low-card breed3 ## 8 pen2 cow8 low-card breed1 ## 9 pen3 cow9 high-fat breed3 ## 10 pen3 cow10 high-fat breed1 ## 11 pen3 cow11 high-fat breed4 ## 12 pen3 cow12 high-fat breed2 ## 13 pen4 cow13 high-fat breed1 ## 14 pen4 cow14 high-fat breed4 ## 15 pen4 cow15 high-fat breed3 ## 16 pen4 cow16 high-fat breed2 ``` ]] --- # Example .circle[6] Calf feeding experiment .flex[ .w-30[ <br> <img src="images/eg2-calf-feeding.png" width="300px"> ] .w-70.f4[ {{content}} ] ] -- ```r start_design("Calf feeding") %>% * set_context(location = "Wagga Wagga") %>% set_trts(feed = 3) %>% set_units(pen = 6, calf = nested_in(pen, 4)) %>% allot_trts(feed ~ pen) %>% assign_trts("random") %>% * set_rcrds_of(calf = c("milk", "weight")) %>% * expect_rcrds(milk = to_be_numeric(with_value(">=", 0)), * yield = to_be_numeric(with_value(">=", 0))) %>% serve_table() %>% export_design("calf-design.xlsx", overwrite = TRUE) ``` ``` ## Loading required package: openxlsx ``` ``` ## Wagga Wagga ``` ``` ## ✓ Calf feeding has been written to 'calf-design.xlsx' ``` --- # Example .circle[7] Chick weight .flex.f5[ .w-50[ * An experiment was conducted on a prairie in Western Canada to find out if insecticides used to control grasshoppers affected the weight of young chicks of ring-necked pheasants, either by affecting the grass around the chicks or by affecting the grasshoppers eaten by the chicks. {{content}} ] .w-50[ ]] .footnote.f5[ Experiment based from Martin et al. (1996) Effects of grasshopper-control insecticides on survival and brain acetylcholinesterase of pheasant (Phasianus colchicus) chicks. Environmental Toxicology and Chemistry **15**(4) 518-524. ] -- * Three insecticides were used, at low and high doses. {{content}} -- * The low dose was the highest dose recommended by the department of agriculture; the high dose was four times as much as the recommended dose, to assess the effects of mistakes. {{content}} -- * The experimental procedure took place in each of three consecutive weeks. {{content}} -- * On the first day of each week a number of newly-hatched female pheasant chicks were placed in a brooder pen. {{content}} -- * On the third day, the chicks were randomly divided into twelve groups of six chicks each. {{content}} -- * Each chick was given an identification tape and weighed. {{content}} -- * On the fourth day, a portion of the field was divided into three strips, each of which was divided into two swathes. {{content}} -- * The two swathes within each strip were sprayed with the two doses of the same insecticide. --- count: false # Example .circle[7] Chick weight .flex.f5[ .w-50[ * An experiment was conducted on a prairie in Western Canada to find out if insecticides used to control grasshoppers affected the weight of young chicks of ring-necked pheasants, either by affecting the grass around the chicks or by affecting the grasshoppers eaten by the chicks. * Three insecticides were used, at low and high doses. * The low dose was the highest dose recommended by the department of agriculture; the high dose was four times as much as the recommended dose, to assess the effects of mistakes. * The experimental procedure took place in each of three consecutive weeks. * On the first day of each week a number of newly-hatched female pheasant chicks were placed in a brooder pen. * On the third day, the chicks were randomly divided into twelve groups of six chicks each. * Each chick was given an identification tape and weighed. * On the fourth day, a portion of the field was divided into three strips, each of which was divided into two swathes. * The two swathes within each strip were sprayed with the two doses of the same insecticide. ] .w-50[ * Two pens were erected on each swathe, and one group of pheasant chicks was put into each pen. {{content}} ]] .footnote.f5[ Experiment based from Martin et al. (1996) Effects of grasshopper-control insecticides on survival and brain acetylcholinesterase of pheasant (Phasianus colchicus) chicks. Environmental Toxicology and Chemistry **15**(4) 518-524. ] -- * For the next 48 hours, the chicks were fed with grasshoppers which had been collected locally. {{content}} -- * Half the grasshoppers were anaesthetized and sprayed with insecticide; the other half were also anaesthetized and handled in every way like the first half except that they were not sprayed. {{content}} -- * All grasshoppers were frozen. {{content}} -- * The experimenters maintained a supply of frozen grasshoppers to each pen, putting them on small platforms so that they would not absorb further insecticide from the grass. {{content}} -- * In each swathe, one pen had unsprayed grasshoppers while the other had grasshoppers sprayed by the insecticide which had been applied to that swathe. {{content}} -- * At the end of the 48 hours, the chicks were weighed again individually. {{content}} -- <center class="f1"> 😵 😵 😵 </center> --- # Example .circle[7] Chick weight: the `edibble` code .f3[ ```r start_design("Chick weight") %>% set_trts(insecticide = 3, dose = c("low", "high")) %>% set_units(week = 3, strip = nested_in(week, 4), swathes = nested_in(strip, 2), pen = nested_in(swathes, 2), chick = nested_in(pen, 6)) %>% set_trts(food = c("spray", "no-spray")) %>% allot_trts(insecticide ~ strip, dose ~ swathes, food ~ pen) %>% assign_trts("random") %>% set_rcrds(weight = chick) %>% serve_table() ``` ``` ## # An edibble: 288 x 9 ## insecticide dose week strip swathes pen ## <trt(3)> <trt(2)> <unit(3)> <unit(12)> <unit(24)> <unit(48)> ## 1 insecticide2 high week1 strip1 swathes1 pen1 ## 2 insecticide2 high week1 strip1 swathes1 pen1 ## 3 insecticide2 high week1 strip1 swathes1 pen1 ## 4 insecticide2 high week1 strip1 swathes1 pen1 ## 5 insecticide2 high week1 strip1 swathes1 pen1 ## 6 insecticide2 high week1 strip1 swathes1 pen1 ## 7 insecticide2 high week1 strip1 swathes1 pen2 ## 8 insecticide2 high week1 strip1 swathes1 pen2 ## 9 insecticide2 high week1 strip1 swathes1 pen2 ## 10 insecticide2 high week1 strip1 swathes1 pen2 ## # … with 278 more rows, and 3 more variables: chick <unit(288)>, food <trt(2)>, ## # weight <rcrd> ``` ] --- # Example .circle[7] Chick weight: closer look .flex[ .w-50[ .overflow-scroll.vh-100[ <img src="images/eg4-chicks.png" width="100%"> ] .center[ scroll down to see the rest of image ] ] .w-50.pl3[ <img src="images/eg4-chicks-anova.png" width="100%"> ]] --- # Example .circle[8] Unbalanced designs .f2[ All designs thus far have been **balanced** (i.e. equal replicate) and **complete** (each treatment appears the same number of times in each block)... ] -- .f1[What about unbalanced and/or incomplete designs?] -- .flex[ .w-50.f4[ Reference level by its name: ```r start_design("unbalanced & incomplete") %>% set_units(site = c("Horsham", "Narrabri", "Wagga", "Roseworthy"), * plot = nested_in(site, * "Horsham" ~ 6, * "Narrabri" ~ 3, * . ~ 4)) %>% set_trts(breed = 4) %>% allot_trts(breed ~ plot) %>% assign_trts("random") %>% serve_table() ``` ``` ## # An edibble: 17 x 3 ## site plot breed ## <unit(4)> <unit(17)> <trt(4)> ## 1 Horsham plot1 breed1 ## 2 Horsham plot2 breed1 ## 3 Horsham plot3 breed4 ## 4 Horsham plot4 breed2 ## 5 Horsham plot5 breed3 ## 6 Horsham plot6 breed4 ## 7 Narrabri plot7 breed1 ## 8 Narrabri plot8 breed3 ## 9 Narrabri plot9 breed2 ## 10 Wagga plot10 breed4 ## 11 Wagga plot11 breed1 ## 12 Wagga plot12 breed3 ## 13 Wagga plot13 breed2 ## 14 Roseworthy plot14 breed2 ## 15 Roseworthy plot15 breed3 ## 16 Roseworthy plot16 breed4 ## 17 Roseworthy plot17 breed1 ``` ] .w-50.bl.pl3.f4[ Reference level by number: ```r start_design("unbalanced & incomplete") %>% set_units(site = c("Horsham", "Narrabri", "Wagga", "Roseworthy"), * plot = nested_in(site, * 1 ~ 6, * 2 ~ 3, * . ~ 4)) %>% set_trts(breed = 4) %>% allot_trts(breed ~ plot) %>% assign_trts("random") %>% serve_table() ``` ``` ## # An edibble: 17 x 3 ## site plot breed ## <unit(4)> <unit(17)> <trt(4)> ## 1 Horsham plot1 breed4 ## 2 Horsham plot2 breed4 ## 3 Horsham plot3 breed2 ## 4 Horsham plot4 breed1 ## 5 Horsham plot5 breed3 ## 6 Horsham plot6 breed2 ## 7 Narrabri plot7 breed2 ## 8 Narrabri plot8 breed3 ## 9 Narrabri plot9 breed1 ## 10 Wagga plot10 breed3 ## 11 Wagga plot11 breed1 ## 12 Wagga plot12 breed4 ## 13 Wagga plot13 breed2 ## 14 Roseworthy plot14 breed2 ## 15 Roseworthy plot15 breed1 ## 16 Roseworthy plot16 breed4 ## 17 Roseworthy plot17 breed3 ``` ]] --- background-image: url("images/workflow.png") background-size: 80% .absolute.f5.right-0[ .blockquote.w-60[ communication is complex, fraught with tensions, misunderstandings, and problems — rather than a simple process of creating shared meaning .pull-right[— Littlejohn et al. (2017)] ]] .absolute[ <img src="images/stickman/domain1.svg" width="100px" class=""> <img src="images/stickman/statistician1.svg" width="120px" class=""> <img src="images/stickman/technician2.svg" width="100px" class=""> ] .absolute.right-3[ <img src="images/stickman/statistician2.svg" width="100px" class="img-hor"> ] .absolute.bottom-0.right-1[ .f1[What can help to communicate more effectively?] ] --- name: ggplot class: transition animate__animated animate__slideInRight .plate-big[3] <br> # Grammar of graphics with `ggplot2` --- # Grammar of graphics: origin and implementations * Initial instances of the grammar of graphics was mentioned by William C. Brinton * A full computational framework was developed by Leland Wilkinson with implementation in **SYSTAT**. .footnote.f4[ Brinton (1914) Graphic methods for presenting facts<br> Wilkinson (1999) The Grammar of Graphics. *Statistics and Computing. Springer, 1st edition.* ] -- * An interpretation of the grammar of graphics by Hadley Wickham (as part of his PhD, 2008) was implemented in **R** as the `ggplot2` package. -- * Emulation of `ggplot2` in **python** started to be developed: * `ggpy` (defunct) * `plotnine` by Hassan Kibirige, * `seaborn` by Michael Waskom .f7[(this one is not quite trying to emulate ggplot)] -- * In **Julia**, `Gadfly` by Daniel C. Jones implements the grammar of graphics. -- * In **Matlab**, `gramm` by Pierre Morel implements the grammar as a toolbox. -- * In **Javascript**, `G2` by AntV team, adding also interactivity, with this version emulated in R as `g2r` package. -- * `ggplot2` is arguably the most popular interpretation of grammar of graphics with over 35,000 citations --- # .square[Data .circle[1]] Crop production in Australia .measure.f3.pa3[ In Australia, total production of each crop nationally are <br> <table class=" lightable-classic" style='font-family: "Arial Narrow", "Source Sans Pro", sans-serif; width: auto !important; margin-left: auto; margin-right: auto;'> <thead> <tr> <th style="text-align:left;"> Crop </th> <th style="text-align:right;"> Production ('000t) </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> barley </td> <td style="text-align:right;"> 13,414 </td> </tr> <tr> <td style="text-align:left;"> sorghum </td> <td style="text-align:right;"> 1,208 </td> </tr> <tr> <td style="text-align:left;"> maize </td> <td style="text-align:right;"> 467 </td> </tr> <tr> <td style="text-align:left;"> oats </td> <td style="text-align:right;"> 1,879 </td> </tr> <tr> <td style="text-align:left;"> triticale </td> <td style="text-align:right;"> 247 </td> </tr> <tr> <td style="text-align:left;"> wheat </td> <td style="text-align:right;"> 35,134 </td> </tr> </tbody> </table> ] <br> .footnote.f4[ Data source: ABARES Australian Crop Report, 2017, No. 181 ] --- name: base-plot # Plotting with "base R" .flex.h-80[ .w33.br[ ```r df ``` ``` ## crop prod ## 1 barley 13414 ## 2 sorghum 1208 ## 3 maize 467 ## 4 oats 1879 ## 5 triticale 247 ## 6 wheat 35134 ``` ] .w33.br[ ```r barplot(as.matrix(df$prod), legend = df$crop) ``` <img src="images/barplot-1.png" width="288" style="display: block; margin: auto;" /> ] .w33[ ```r pie(df$prod, labels = df$crop) ``` <img src="images/pie-1.png" width="432" style="display: block; margin: auto;" /> ] ] .footnote.f4[ <i class="fas fa-book"></i> R Core Team (2020) R: A Language and Environment for Statistical Computing https://www.R-project.org/ ] -- .absolute.bottom-3.left-1[ .note-box.w-80[ Single purpose functions to generate "named plots" ]] --- # Plotting with the `ggplot2` R-package .flex.h-80[ .w-33.br[ ```r df ``` ``` ## crop prod ## 1 barley 13414 ## 2 sorghum 1208 ## 3 maize 467 ## 4 oats 1879 ## 5 triticale 247 ## 6 wheat 35134 ``` ] .w-33.br.f4[ ```r ggplot(df, aes(x = "", # dummy y = prod, fill = crop)) + geom_col(color = "black") ``` <img src="images/ggbarplot-1.png" width="360" style="display: block; margin: auto;" /> ] .w-33.f4[ {{content}} ] ] -- ```r ggplot(df, aes(x = "", # dummy y = prod, fill = crop)) + geom_col(color = "black") + * coord_polar(theta = "y") ``` <img src="images/ggpie-1.png" width="360" style="display: block; margin: auto;" /> -- .absolute.bottom-2.left-1[ .info-box.w-60[ The difference between a **stacked barplot** and a **pie chart** is that the coordinate system is transformed from the **Cartesian coordinate** to **polar coordinate**. ]] --- # .square[Data .circle[2]] Potato scab infection with sulfur treatments Let's look at another data... .flex.f4[ .w-33[ .overflow-scroll.h---400[ ```r data(cochran.crd, package = "agridat") cochran.crd ``` ``` ## inf trt row col ## 1 9 F3 4 1 ## 2 12 O 4 2 ## 3 18 S6 4 3 ## 4 10 F12 4 4 ## 5 24 S6 4 5 ## 6 17 S12 4 6 ## 7 30 S3 4 7 ## 8 16 F6 4 8 ## 9 10 O 3 1 ## 10 7 S3 3 2 ## 11 4 F12 3 3 ## 12 10 F6 3 4 ## 13 21 S3 3 5 ## 14 24 O 3 6 ## 15 29 O 3 7 ## 16 12 S6 3 8 ## 17 9 F3 2 1 ## 18 7 S12 2 2 ## 19 18 F6 2 3 ## 20 30 O 2 4 ## 21 18 F6 2 5 ## 22 16 S12 2 6 ## 23 16 F3 2 7 ## 24 4 F12 2 8 ## 25 9 S3 1 1 ## 26 18 O 1 2 ## 27 17 S12 1 3 ## 28 19 S6 1 4 ## 29 32 O 1 5 ## 30 5 F12 1 6 ## 31 26 O 1 7 ## 32 4 F3 1 8 ``` ] ] .w-33[ ```r ggplot(cochran.crd, aes(col, row, fill = trt)) + geom_tile(color = "black", size = 1.3) ``` <img src="images/unnamed-chunk-22-1.png" width="432" style="display: block; margin: auto;" /> ] .w-33[ ```r ggplot(cochran.crd, aes(col, row, fill = inf)) + geom_tile(color = "black", size = 1.3) ``` <img src="images/unnamed-chunk-23-1.png" width="432" style="display: block; margin: auto;" /> ] ] --- name: ggplot2-demo count: false # Making publication ready plots with `ggplot2` .flex[ .w-60.f4[ ```r ggplot(cochran.crd, aes(col, row, fill = inf)) + geom_tile(color = "black", size = 1.3) ``` ] .w-40[ <img src="images/cochran-1-1.png" width="432" style="display: block; margin: auto;" /> ] ] --- count: false # Making publication ready plots with `ggplot2` .flex[ .w-60.f4[ ```r ggplot(cochran.crd, aes(col, row, fill = inf)) + geom_tile(color = "black", size = 1.3) + scale_fill_gradient(low = "white", high = "firebrick") ``` ] .w-40[ <img src="images/cochran-2-1.png" width="432" style="display: block; margin: auto;" /> ] ] --- count: false # Making publication ready plots with `ggplot2` .flex[ .w-60.f4[ ```r ggplot(cochran.crd, aes(col, row, fill = inf)) + geom_tile(color = "black", size = 1.3) + scale_fill_gradient(low = "white", high = "firebrick") + labs(title = "Potato scab infection with sulfur\ntreatments") ``` ] .w-40[ <img src="images/cochran-3-1.png" width="432" style="display: block; margin: auto;" /> ] ] --- count: false # Making publication ready plots with `ggplot2` .flex[ .w-60.f4[ ```r ggplot(cochran.crd, aes(col, row, fill = inf)) + geom_tile(color = "black", size = 1.3) + scale_fill_gradient(low = "white", high = "firebrick") + labs(title = "Potato scab infection with sulfur\ntreatments", x = "Column", y = "Row") ``` ] .w-40[ <img src="images/cochran-4-1.png" width="432" style="display: block; margin: auto;" /> ] ] --- count: false # Making publication ready plots with `ggplot2` .flex[ .w-60.f4[ ```r ggplot(cochran.crd, aes(col, row, fill = inf)) + geom_tile(color = "black", size = 1.3) + scale_fill_gradient(low = "white", high = "firebrick") + labs(title = "Potato scab infection with sulfur\ntreatments", x = "Column", y = "Row", caption = "Data source: Tamura, R.N. and Nelson, L.A. and Naderman, G.C., (1988).\nAn investigation of the validity and usefulness of trend analysis for field plot data.\nAgronomy Journal, 80, 712-718.") ``` ] .w-40[ <img src="images/cochran-5-1.png" width="432" style="display: block; margin: auto;" /> ] ] --- count: false # Making publication ready plots with `ggplot2` .flex[ .w-60.f4[ ```r ggplot(cochran.crd, aes(col, row, fill = inf)) + geom_tile(color = "black", size = 1.3) + scale_fill_gradient(low = "white", high = "firebrick") + labs(title = "Potato scab infection with sulfur\ntreatments", x = "Column", y = "Row", caption = "Data source: Tamura, R.N. and Nelson, L.A. and Naderman, G.C., (1988).\nAn investigation of the validity and usefulness of trend analysis for field plot data.\nAgronomy Journal, 80, 712-718.") + theme(text = element_text(size = 20)) ``` ] .w-40[ <img src="images/cochran-6-1.png" width="432" style="display: block; margin: auto;" /> ] ] --- count: false # Making publication ready plots with `ggplot2` .flex[ .w-60.f4[ ```r ggplot(cochran.crd, aes(col, row, fill = inf)) + geom_tile(color = "black", size = 1.3) + scale_fill_gradient(low = "white", high = "firebrick") + labs(title = "Potato scab infection with sulfur\ntreatments", x = "Column", y = "Row", caption = "Data source: Tamura, R.N. and Nelson, L.A. and Naderman, G.C., (1988).\nAn investigation of the validity and usefulness of trend analysis for field plot data.\nAgronomy Journal, 80, 712-718.") + theme(text = element_text(size = 20), plot.caption = element_text(size = 12)) ``` ] .w-40[ <img src="images/cochran-7-1.png" width="432" style="display: block; margin: auto;" /> ] ] --- count: false # Making publication ready plots with `ggplot2` .flex[ .w-60.f4[ ```r ggplot(cochran.crd, aes(col, row, fill = inf)) + geom_tile(color = "black", size = 1.3) + scale_fill_gradient(low = "white", high = "firebrick") + labs(title = "Potato scab infection with sulfur\ntreatments", x = "Column", y = "Row", caption = "Data source: Tamura, R.N. and Nelson, L.A. and Naderman, G.C., (1988).\nAn investigation of the validity and usefulness of trend analysis for field plot data.\nAgronomy Journal, 80, 712-718.") + theme(text = element_text(size = 20), plot.caption = element_text(size = 12), plot.title.position = "plot", plot.caption.position = "plot",) ``` ] .w-40[ <img src="images/cochran-8-1.png" width="432" style="display: block; margin: auto;" /> ] ] --- # Making publication ready plots with `ggplot2` .flex[ .w-60.f4[ ```r ggplot(cochran.crd, aes(col, row, fill = inf)) + geom_tile(color = "black", size = 1.3) + scale_fill_gradient(low = "white", high = "firebrick") + labs(title = "Potato scab infection with sulfur\ntreatments", x = "Column", y = "Row", caption = "Data source: Tamura, R.N. and Nelson, L.A. and Naderman, G.C., (1988).\nAn investigation of the validity and usefulness of trend analysis for field plot data.\nAgronomy Journal, 80, 712-718.") + theme(text = element_text(size = 20), plot.caption = element_text(size = 12), plot.title.position = "plot", plot.caption.position = "plot", panel.background = element_blank()) ``` ] .w-40[ <img src="images/cochran-final-1.png" width="432" style="display: block; margin: auto;" /> ] ] --- # Many extension packages exists for `ggplot2` .f1[https://exts.ggplot2.tidyverse.org/gallery/] ```r ggplot(cochran.crd, aes(trt, inf, color = trt)) + geom_boxplot() + theme_bw(base_size = 18) ``` <img src="images/ext-1-1.png" width="360" style="display: block; margin: auto;" /> --- count: false # Many extension packages exists for `ggplot2` .f1[https://exts.ggplot2.tidyverse.org/gallery/] ```r ggplot(cochran.crd, aes(trt, inf, color = trt)) + * ggbeeswarm::geom_quasirandom() + theme_bw(base_size = 18) ``` <img src="images/ext-2-1.png" width="360" style="display: block; margin: auto;" /> --- name: deggust class: transition animate__animated animate__slideInRight .plate-big[4] <br> # Visualising experimental designs with the `deggust` R-package --- # Visualising experimental designs <img src="images/deggust.png" style="width:200px" class="pull-right"> .info-box.w-60[ The `deggust` R-package aims to convert `edibble` designs to `ggplot` objects *seamlessly*. ] <i class="fas fa-exclamation-triangle"></i> Currently under developed! .f2[ <i class="fab fa-r-project"></i></i></span> **Package documentation**: .center[ <a href='https://deggust.emitanaka.org'>deggust.emitanaka.org</a> ] <i class="fab fa-github"></i></span> **Source code**: .center[ <a href='https://github.com/emitanaka/deggust'>github.com/emitanaka/deggust</a> ] <i class="fas fa-signature"></i> **Name origin**: deggust as in *degust*, and <br>  <i class="fas fa-crosshairs"></i> make **d**esign of **e**xperiments into `**gg**plot` objects ] .footnote.f5[ H. Wickham. ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York, 2016. ] --- # Example: Pig diet experiment ```r library(edibble) plan <- start_design("Pig diet experiment") %>% set_trts(diet = c("carb", "protein", "fat")) %>% set_units(pig = 50) %>% allot_trts(diet ~ pig) %>% assign_trts("random", seed = 1) %>% serve_table() plan ``` ``` ## # An edibble: 50 x 2 ## diet pig ## <trt(3)> <unit(50)> ## 1 carb pig1 ## 2 carb pig2 ## 3 protein pig3 ## 4 carb pig4 ## 5 protein pig5 ## 6 fat pig6 ## 7 fat pig7 ## 8 fat pig8 ## 9 protein pig9 ## 10 carb pig10 ## # … with 40 more rows ``` --- # Visualising designs with `ggplot2` ```r library(ggplot2) plan %>% edibble::as_data_frame() %>% # in the future this step will not be needed ggplot(aes(pig, "1", fill = diet)) + geom_tile(color = "black") ``` <img src="images/des1-1.png" width="1080" style="display: block; margin: auto;" /> -- * Slightly painful if you want to *quickly* visualise your design. -- * Also not a great visualisation --- # `deggust::autoplot()` .f3[Part 1] Just `autoplot` it! ```r library(deggust) ``` -- ```r autoplot(plan) ``` <img src="images/deggust-part1-1.png" width="432" style="display: block; margin: auto;" /> --- # `deggust::autoplot()` .f4[Part 2] * It makes some decision for you of how to plot which can be customised in two ways: 1. modify scale and theme like any ggplot objects! 2. as arguments in the `autoplot` function .flex[ .w-50[ ] .w-50[ ] ] --- # `deggust::autoplot()` .f4[Part 3] * It makes some decision for you of how to plot which can be customised in two ways: 1. .red[**modify scale and theme like any ggplot objects!**] 2. as arguments in the `autoplot` function .flex[ .w-50[ ```r autoplot(plan) + # ggplot2 functions below * theme_void() + * scale_fill_viridis_d(option = "A") ``` ] .w-50[ <img src="images/vis-autoplot-modify-1.png" width="432" style="display: block; margin: auto;" /> ] ] --- # `deggust::autoplot()` .f4[Part 4] * It makes some decision for you of how to plot which can be customised in two ways: 1. modify scale and theme like any ggplot objects! 2. .red[**as arguments in the `autoplot` function**] .flex[ .w-50[ ```r autoplot(plan, * shape = "hexagon", * text = TRUE, * aspect_ratio = 0.5) ``` ] .w-50[ <img src="images/vis-autoplot-args-1.png" width="432" style="display: block; margin: auto;" /> ] ] --- # `deggust::autoplot()` .f4[Part 5] <img src="images/pig.png" width = "200px"> -- .flex[ .w-50[ ```r autoplot(plan, * image = "images/pig.png") + theme_void() ``` ] .w-50[ <img src="images/vis-autoplot-pigimage-1.png" width="432" style="display: block; margin: auto;" /> ] ] --- # `deggust::autoplot()` .f4[Part 6] * Nested design .flex[ .w-60[ ```r start_design() %>% set_units(pen = 10, pig = nested_in(pen, 5)) %>% set_trts(breed = c("A", "B", "C")) %>% allot_trts(breed ~ pig) %>% assign_trts("random", seed = 2021) %>% serve_table() %>% autoplot() ``` ] .w-50[ <img src="images/vis-nested-1.png" width="432" style="display: block; margin: auto;" /> ] ] --- # `deggust::autoplot()` .f4[Part 7] * What changed here? .flex[ .w-60[ ```r start_design() %>% set_units(pen = 10, pig = nested_in(pen, 5)) %>% set_trts(breed = c("A", "B", "C")) %>% allot_trts(breed ~ pen) %>% assign_trts("random", seed = 2021) %>% serve_table() %>% autoplot() ``` ] .w-50[ <img src="images/vis-nested-pen-1.png" width="432" style="display: block; margin: auto;" /> ] ] --- # `deggust::autoplot()` .f4[Part 8] * Factorial experiment .flex[ .w-60[ ```r start_design() %>% set_units(pig = 40) %>% set_trts(breed = c("A", "B", "C"), feed = c("X", "Y", "Z")) %>% allot_trts(breed:feed ~ pig) %>% assign_trts("random", seed = 2021) %>% serve_table() %>% autoplot() ``` * Note: scale will be fixed so it's easier to distinguish between different treatment factors ] .w-50[ <img src="images/vis-nested-fac-1.png" width="432" style="display: block; margin: auto;" /> ] ] --- # `deggust::autoplot()` .f4[Part 9] * Focus on the treatment you want: .flex[ .w-60[ ```r start_design() %>% set_units(pig = 40) %>% set_trts(breed = c("A", "B", "C"), feed = c("X", "Y", "Z")) %>% allot_trts(breed:feed ~ pig) %>% assign_trts("random", seed = 2021) %>% serve_table() %>% * autoplot(trts = "breed") ``` ] .w-50[ <img src="images/vis-nested-fac1-1.png" width="432" style="display: block; margin: auto;" /> ] ] --- count: false # `deggust::autoplot()` .f4[Part 10] * Is your design too big to fit in the plot? .flex[ .w-60[ ```r start_design() %>% set_units(pen = 100, pig = nested_in(pen, 10)) %>% set_trts(breed = c("A", "B", "C")) %>% allot_trts(breed ~ pig) %>% assign_trts("random", seed = 2021) %>% serve_table() %>% autoplot() ``` ] .w-50[ <img src="images/vis-nested-big-1.png" width="432" style="display: block; margin: auto;" /> ] ] --- # `deggust::autoplot()` .f4[Part 10] * Is your design too big to fit in the plot? * Subset it! .flex[ .w-70[ ```r start_design() %>% set_units(pen = 100, pig = nested_in(pen, 10)) %>% set_trts(breed = c("A", "B", "C")) %>% allot_trts(breed ~ pig) %>% assign_trts("random", seed = 2021) %>% serve_table() %>% * dplyr::filter(pen %in% c("pen1", "pen2", "pen3", "pen4")) %>% autoplot() + annotate("text", x = 10, y = 4.7, label = "x 25 more") ``` ] .w-50[ <img src="images/vis-nested-filter-1.png" width="432" style="display: block; margin: auto;" /> ] ] --- # Summary .flex[ .w-60[ * The .monash-blue[grammar of experimental designs] is an abstract computational framework that .monash-blue[encourages a higher-order thinking] by enforcing the experimental structure and context {{content}} ] .w-40.center[ <img src="images/edibble.png" height="120px"> <img src="images/deggust.png" height="120px"> <img src="images/data-collection.png" width="100%"> ]] -- * `edibble` is designed to be <span class="monash-blue">user friendly</span> and accommodate <span class="monash-blue">natural order of thinking</span> for specifying experimental structure {{content}} -- * The grammar makes each step <span class="monash-blue">modular</span>... you can <span class="monash-blue">easily extend</span> it (like `deggust`) or <span class="monash-blue">mix-and-match methods</span> {{content}} -- * This makes it easier to leverage existing functionalities in `edibble` so other developers can focus on what they want to do the most {{content}} -- * And hopefully this framework becomes a common base that <span class="monash-blue">promotes collaboration and knowledge sharing</span> --- class: inform-slide # Thanks for listening! <ul class="fa-ul f2"> <li><span class="fa-li"><i class="fas fa-link fa-spin"></i></span>Slides: <a href='https://emitanaka.org/slides/stats4bio2021/deggust'>emitanaka.org/slides/stats4bio2021/deggust</a> </li> <li><span class="fa-li"><i class="fab fa-r-project"></i></i></span> <code>edibble</code> package documentation: <a href='https://edibble.emitanaka.org'>edibble.emitanaka.org</a></li> <li><span class="fa-li"><i class="fab fa-github"></i></span><code>edibble</code> source code: <a href='https://github.com/emitanaka/edibble'>github.com/emitanaka/edibble</a></li> <li><span class="fa-li"><i class="fab fa-r-project"></i></i></span> <code>deggust</code> package documentation: <a href='https://deggust.emitanaka.org'>deggust.emitanaka.org</a></li> <li><span class="fa-li"><i class="fab fa-github"></i></span><code>deggust</code> source code: <a href='https://github.com/emitanaka/deggust'>github.com/emitanaka/deggust</a></li> <li><span class="fa-li"><i class="fas fa-envelope"></i></span><a href="mailto:emi.tanaka@monash.edu">emi.tanaka@monash.edu</a> <i class="fab fa-twitter "></i> <a href="https://twitter.com/statsgen">@statsgen</a></li> </ul> .f2[ * Feature requests or issues with `edibble` or `deggust`? Submit or upvote here: <a href='https://github.com/emitanaka/edibble/issues'>github.com/emitanaka/edibble/issues</a>, <a href='https://github.com/emitanaka/deggust/issues'>github.com/emitanaka/deggust/issues</a>, send me an email or tell me now! ]