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. See <a href="edibble-slides.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 # .monash-blue[Grammar of Experimental Design] <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> 23 Jan 2021 @ TokyoR <br> ] --- class: footer-slide layout: true name: footer .footnote.monash-black.f4[ <i class="fas fa-link"></i> スライドは <a href="https://emitanaka.org/slides/TokyoR2021" style="color:#6F7C4D!important;">emitanaka.org/slides/TokyoR2021</a> ] --- # A little about me # 自己紹介 * オーストラリア育ちの日本語がイマイチなJapanese-Australianです🇯🇵🇦🇺 -- * 5年前に統計学の博士号を取得しました🎓 -- * Monash大学で働くため2020年1月シドニーからメルボルンへ引っ越しました📦 -- <center> <img src="images/monash-sign.jpg" alt="monash sign" width="20%"> 私のオフィスからの見晴らしです<i class="fas fa-arrow-right"></i> <img src="images/office-corridor-view.jpg" alt="office corridor view" width="20%"> </center> --- # その研究内容一つとは <br><br> .f1.center[ .animated.bounce[ .monash-blue[<b><i class="fas fa-project-diagram"></i> Grammar of Experimental Design</b>] 実験計画法の「文法」 ] {{content}} ] -- <br><br> 「文法」とはどういう意味なのでしょうか? --- # 内容 <br> .f1[ .circle.monash-bg-blue.white[1] <b><i class="fas fa-chart-bar"></i> Grammar of Graphics</b> .f3[グラフィクスの文法] <br><br> .circle.monash-bg-blue.white[2] <b><i class="fas fa-wrench"></i> Grammar of Data Manipulation</b> .f3[データ操作の文法]<Br> <br> .circle.monash-bg-blue.white[3] .monash-blue2[<b><i class="fas fa-project-diagram"></i> Grammar of Experimental Design</b>] .f3[実験計画法の文法] ] --- class: transition animated slideInLeft # .circle-big[1] # Grammar of Graphics <img src="images/ggplot2-hex.png" width="150px"> .f3.center.w-100[ Wickham (2016) ggplot2: Elegant Graphics for Data Analysis. *Springer-Verlag New York* Wilkinson (2005) The Grammar of Graphics. *Statistics and Computing. Springer, 2nd edition.*<br><br> ] --- class: middle まずはデーターから .f-headline[ 👩🏻🏫 ] .measure.f2.pa3[ 一般的なオーストラリアの大学で働いてる学者は時間を以下のように分けるよう期待されています: * 40%教育、 * 40%研究と * 20%その他。 ] --- # この二つのプロットの違いとは? .flex[ .w-50[ <img src="images/unnamed-chunk-3-1.png" width="360" style="display: block; margin: auto;" /> ] .w-50[ <img src="images/unnamed-chunk-4-1.png" width="482.4" style="display: block; margin: auto;" /> ] ] --- name: base-plot class: font_smaller # Base R .flex.h-80[ .w33.br[ ```r df ``` ``` ## duty perc ## 1 Teaching 40 ## 2 Research 40 ## 3 Other 20 ``` ```r tibble::as_tibble(df) ``` ``` ## # A tibble: 3 x 2 ## duty perc ## <chr> <dbl> ## 1 Teaching 40 ## 2 Research 40 ## 3 Other 20 ``` ] .w33.br[ ```r barplot(as.matrix(df$perc), legend = df$duty) ``` <img src="images/barplot-1.png" width="288" style="display: block; margin: auto;" /> ] .w33[ ```r pie(df$perc, labels = df$duty) ``` <img src="images/pie-1.png" width="432" style="display: block; margin: auto;" /> ] ] .footnote.monash-black.f4[ <i class="fas fa-book"></i> R Core Team (2020) R: A Language and Environment for Statistical Computing https://www.R-project.org/ <br><br> ] <div class="show-on-hover" style="padding:10px;position:absolute;bottom: 40px; right: 10px;"> <a href="#edibble" style="font-size:12pt"><i class="fas fa-caret-right"></i> edibble</a> </div> -- .absolute.bottom-3.left-1[ .info-box.w-60[ Single purpose functions to generate "named plots" ]] --- # `ggplot2` .flex.h-80[ .w-33.br[ ```r df ``` ``` ## duty perc ## 1 Teaching 40 ## 2 Research 40 ## 3 Other 20 ``` ```r tibble::as_tibble(df) ``` ``` ## # A tibble: 3 x 2 ## duty perc ## <chr> <dbl> ## 1 Teaching 40 ## 2 Research 40 ## 3 Other 20 ``` ] .w-33.br.f4[ ```r ggplot(df, aes(x = "", # dummy y = perc, fill = duty)) + geom_col() ``` <img src="images/ggbarplot-1.png" width="360" style="display: block; margin: auto;" /> ] .w-33.f4[ {{content}} ] ] -- ```r ggplot(df, aes(x = "", # dummy y = perc, fill = duty)) + geom_col() + * 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[ **stacked barplot**と**pie chart**の違いはcoordinate systemが**Cartesian coordinate**から**polar coordinate**と変わった ]] --- # <i class="fas fa-puzzle-piece"></i> ポテトフィールド研究・このプロットはどうコードする? .flex[ .overflow-scroll.h---500.w-33[ ```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.h-50[ <img src="images/field1-1.png" width="288" style="display: block; margin: auto;" /> <img src="images/field2-1.png" width="288" style="display: block; margin: auto;" /> ] .h-50.w-33.f6[ {{content}} ] ] .footnote.monash-black.f6[ <i class="fas fa-book"></i> Kevin Wright (2020). agridat: Agricultural Datasets. R package version 1.17.<br> <i class="fas fa-book"></i> W.G. Cochran and G. Cox, 1957. Experimental Designs, 2nd ed. John Wiley, New York. <br><br><br> ] -- ```r ggplot(cochran.crd, aes(x = col, y = row, * fill = inf)) + geom_tile(color = "black", size = 1.2) + * scale_fill_gradient(low = "gold", * high = "firebrick4") + theme(text = element_text(size = 20)) ``` <br> <br> <br> ```r ggplot(cochran.crd, aes(x = col, y = row, * fill = trt)) + geom_tile(color = "black", size = 1.2) + * scale_fill_viridis_d() + theme(text = element_text(size = 20)) ``` --- class: transition animated slideInLeft # .circle-big[2] # Grammar of <br>Data Manipulation <img src="images/dplyr-hex.png" width="150px"> .center.f3.w-100[ Wickham, François, Henry & Müller (2020) dplyr: A Grammar of Data Manipulation. R-package version 1.0.0. ] --- # このコードは何をしてる?アウトプットは何を期待しますか? .flex.h-80[ .w-50.h---500.overflow-scroll.br[ .f4[ ```r tapply(cochran.crd$inf, cochran.crd$trt, mean) ``` ``` ## F12 F3 F6 O S12 S3 S6 ## 5.750 9.500 15.500 22.625 14.250 16.750 18.250 ``` ```r tapply(cochran.crd$inf, cochran.crd$trt, sd) ``` ``` ## F12 F3 F6 O S12 S3 S6 ## 2.872281 4.932883 3.785939 8.365533 4.856267 10.781929 4.924429 ``` ```r tapply(cochran.crd$inf, cochran.crd$trt, function(x) c(avg = mean(x), sd = sd(x))) ``` ``` ## $F12 ## avg sd ## 5.750000 2.872281 ## ## $F3 ## avg sd ## 9.500000 4.932883 ## ## $F6 ## avg sd ## 15.500000 3.785939 ## ## $O ## avg sd ## 22.625000 8.365533 ## ## $S12 ## avg sd ## 14.250000 4.856267 ## ## $S3 ## avg sd ## 16.75000 10.78193 ## ## $S6 ## avg sd ## 18.250000 4.924429 ``` ] ] .w-50.f4[ {{content}} ] ] -- ```r library(dplyr) cochran.crd %>% group_by(trt) %>% summarise(avg = mean(inf), sd = sd(inf)) ``` ``` ## # A tibble: 7 x 3 ## trt avg sd ## * <fct> <dbl> <dbl> ## 1 F12 5.75 2.87 ## 2 F3 9.5 4.93 ## 3 F6 15.5 3.79 ## 4 O 22.6 8.37 ## 5 S12 14.2 4.86 ## 6 S3 16.8 10.8 ## 7 S6 18.2 4.92 ``` -- .absolute.bottom-3.right-1[ .info-box.w-60[ 右の方が意図が分かりやすいです ]] --- class: transition animated slideInLeft # .circle-big[3] # Grammar of <br>Experimental Design <img src="images/edibble-hex.png" width="150px"> <i class="fas fa-wrench"></i> Work-In-Progress --- # 実験計画法の一般的なコース <br>.font_small[(例えばシドニー大学2017-2019)] 教える内容: * Completely Randomised Design * Randomised Complete Block Design * Latin Square Design * Balanced Incomplete Block Design * Factorial Design * <strike> 2</strike><sup>k</sup><strike> Factorial Design</strike> .font_small[(2018年以降取り除いた)] * Split-plot Design .font_small[(私が2018年に追加した)] --- # Completely Randomised Design (CRD) .grid[ .item[ <br> <center> <img src="images/crd-eg1.png" width = "300px"/> </center> ] .item[ * `\(t\)` treatments randomised to `\(n\)` units <br> .model-box[ `$$\scriptsize \texttt{observation} = \texttt{mean} + \texttt{treatment} + \texttt{error}$$` .font_small[(with constraints and distributional assumptions)] <br> <center> <img src="images/crd-eg1-anova.png" width = "700px"/> </center> ] ] ] --- # Randomised Complete Block Design (RCBD) .grid[ .item[ <br> <center> <img src="images/rcbd-eg1.png" width = "300px"/> </center> ] .item[ * `\(b\)` blocks of size `\(t\)` * `\(t\)` treatments randomised to `\(t\)` units within each block .model-box[ `$$\scriptsize \texttt{observation} = \texttt{mean} + \texttt{treatment} + \texttt{block} + \texttt{error}$$` <center> <img src="images/rcbd-eg1-anova.png" width = "850px"/> </center> ] ] ] --- # Latin Square Design (LSD) .grid[ .item[ <br> <center> <img src="images/lsd-eg1.png" width = "300px"/> </center> ] .item[ * two orthogonal blocks of size `\(t\)` * `\(t\)` treatments randomised to units such that every treatment appears exactly once in each block .model-box[ `$$\scriptsize \texttt{observation} = \texttt{mean} + \texttt{treatment} + \texttt{row} + \texttt{column} + \texttt{error}$$` <center> <img src="images/lsd-eg1-anova.png" width = "850px"/> </center> ] ] ] --- # Balanced Incomplete Block Design (BIBD) .grid[ .item[ <br> <center> <img src="images/bibd-eg1.png" width = "300px"/> </center> ] .item[ * `\(b\)` blocks of size `\(k < t\)` * `\(t\)` treatments randomised to units within each block such that every pair of treatment appears the same number of times across blocks .model-box[ `$$\scriptsize \texttt{observation} = \texttt{mean} + \texttt{block} + \texttt{treatment} + \texttt{error}$$` <center> <img src="images/bibd-eg1-anova.png" width = "850px"/> </center> ] ] ] --- # Factorial Design .grid[ .item[ <br> <center> <img src="images/factorial-eg1.png" width = "300px"/> </center> ] .item[ * `\(ab = t\)` treatments randomised to `\(n\)` units * treatment is every combination of two factors A and B .model-box[ `$$\scriptsize \texttt{observation} = \texttt{mean} + \texttt{A} + \texttt{B} + \texttt{A:B} + \texttt{error}$$` <center> <img src="images/factorial-eg1-anova-top.png" width = "850px"/> <details style="font-size:4pt"><summary></summary> <img src="images/factorial-eg1-anova-middle.png" width = "850px"/> </details> <img src="images/factorial-eg1-anova-bottom.png" width = "850px"/> </center> ] ] ] --- # Split-plot Design .grid[ .item[ <br> <center> <img src="images/split-plot-eg1.png" width = "300px"/> </center> ] <div class="item" style="font-size: 0.85em"> <ul> <li> \(n_1\) whole plots consisting of \(b\) sub plots</li> <li>in total there are \(n\) sub plots</li> <li>treatment factor A is randomised to whole plots</li> <li>treatment factor B is randomised to sub plots within each whole plot</li> </ul> .model-box[ `$$\scriptsize \texttt{observation} = \texttt{mean} + \texttt{A} + \texttt{WP} + \texttt{B} + \texttt{A:B} + \texttt{error}$$` <center> <img src="images/split-plot-eg1-anova.png" width = "850px"/> </center> ] </div> ] --- class: transition center middle # CRAN Task View of <Br>Design of Experiments contains # 📦 .yellow[224 R-packages ] .font_small[as of 2021-01-21] .font_small[(Please note that there may be some webscrapping error)] --- # ダウンロードされたR-packagesトップ10 <img src="images/top10_2019-1.png" width="432" style="display: block; margin: auto;" /> .center[ .f2[`AlgDesign` and `agricolae` are the most downloaded] .f3[(data from `cranlogs` from 2015-01-01 to 2020-12-31)] ] --- class: font_small # `agricolae::design.crd` **Completely randomised design** for `\(t = 3\)` treatments with `\(2\)` replicates each <pre><code> trt <- c("A", "B", "C") agricolae::.bg-yellow[design.crd](trt = trt, r = 2) %>% glimpse() </code></pre> .overflow-scroll.h---340[ ``` ## List of 2 ## $ parameters:List of 7 ## ..$ design: chr "crd" ## ..$ trt : chr [1:3] "A" "B" "C" ## ..$ r : num [1:3] 2 2 2 ## ..$ serie : num 2 ## ..$ seed : int 2074805913 ## ..$ kinds : chr "Super-Duper" ## ..$ : logi TRUE ## $ book :'data.frame': 6 obs. of 3 variables: ## ..$ plots: num [1:6] 101 102 103 104 105 106 ## ..$ r : int [1:6] 1 2 1 1 2 2 ## ..$ trt : chr [1:6] "A" "A" "B" "C" ... ``` ] <div class="plot-box" style="position:absolute;top: 35%; right: 50px;"> <img src="images/ggcrd-1.png" width = "300px"> </div> --- # `agricolae::design.rcbd` **Randomised complete block design** for `\(t =3\)` treatments with `\(2\)` blocks <pre><code> trt <- c("A", "B", "C") agricolae::.bg-yellow[design.rcbd](trt = trt, r = 2) %>% glimpse() </code></pre> .overflow-scroll.h---340[ ``` ## List of 3 ## $ parameters:List of 7 ## ..$ design: chr "rcbd" ## ..$ trt : chr [1:3] "A" "B" "C" ## ..$ r : num 2 ## ..$ serie : num 2 ## ..$ seed : int 490734433 ## ..$ kinds : chr "Super-Duper" ## ..$ : logi TRUE ## $ sketch : chr [1:2, 1:3] "A" "C" "B" "A" ... ## $ book :'data.frame': 6 obs. of 3 variables: ## ..$ plots: num [1:6] 101 102 103 201 202 203 ## ..$ block: Factor w/ 2 levels "1","2": 1 1 1 2 2 2 ## ..$ trt : Factor w/ 3 levels "A","B","C": 1 2 3 3 1 2 ``` ] <div class="plot-box" style="position:absolute;bottom: 100px; right: 50px;"> <br> <img src="images/ggrcbd-1.png" width = "300px"> </div> --- # `agricolae::design.lsd()` **Latin square design** for `\(t = 3\)` treatments <pre><code> trt <- c("A", "B", "C") agricolae::.bg-yellow[design.lsd](trt = trt) %>% glimpse() </code></pre> .overflow-scroll.h---340[ ``` ## List of 3 ## $ parameters:List of 7 ## ..$ design: chr "lsd" ## ..$ trt : chr [1:3] "A" "B" "C" ## ..$ r : int 3 ## ..$ serie : num 2 ## ..$ seed : int -338489375 ## ..$ kinds : chr "Super-Duper" ## ..$ : logi TRUE ## $ sketch : chr [1:3, 1:3] "A" "C" "B" "B" ... ## $ book :'data.frame': 9 obs. of 4 variables: ## ..$ plots: num [1:9] 101 102 103 201 202 203 301 302 303 ## ..$ row : Factor w/ 3 levels "1","2","3": 1 1 1 2 2 2 3 3 3 ## ..$ col : Factor w/ 3 levels "1","2","3": 1 2 3 1 2 3 1 2 3 ## ..$ trt : Factor w/ 3 levels "A","B","C": 1 2 3 3 1 2 2 3 1 ``` ] <div class="plot-box" style="position:absolute;top: 100px; right: 50px;"> <br> <img src="images/gglsd-1.png" width = "300px"> </div> --- # `agricolae::design.bib()` **Balanced incomplete block design** for `\(t = 3\)` treatments with block size of `\(2\)` <pre><code> trt <- c("A", "B", "C") agricolae::.bg-yellow[design.bib](trt = trt, k = 2) %>% glimpse() </code></pre> .overflow-scroll.h---340[ ``` ## [1] "No improvement over initial random design." ## ## Parameters BIB ## ============== ## Lambda : 1 ## treatmeans : 3 ## Block size : 2 ## Blocks : 3 ## Replication: 2 ## ## Efficiency factor 0.75 ## ## <<< Book >>> ``` ``` ## List of 4 ## $ parameters:List of 6 ## ..$ design: chr "bib" ## ..$ trt : chr [1:3] "A" "B" "C" ## ..$ k : num 2 ## ..$ serie : num 2 ## ..$ seed : int -907106719 ## ..$ kinds : chr "Super-Duper" ## $ statistics:'data.frame': 1 obs. of 6 variables: ## ..$ lambda : num 1 ## ..$ treatmeans: int 3 ## ..$ blockSize : num 2 ## ..$ blocks : int 3 ## ..$ r : num 2 ## ..$ Efficiency: num 0.75 ## $ sketch : chr [1:3, 1:2] "C" "A" "C" "A" ... ## $ book :'data.frame': 6 obs. of 3 variables: ## ..$ plots: num [1:6] 101 102 201 202 301 302 ## ..$ block: Factor w/ 3 levels "1","2","3": 1 1 2 2 3 3 ## ..$ trt : Factor w/ 3 levels "A","B","C": 3 1 1 2 3 2 ``` ] <div class="plot-box" style="position:absolute;top: 200px; right: 50px;"> <br> <img src="images/ggbibd-1.png" width="300px"> </div> --- class: font_small # `agricolae::design.ab()` **Factorial design** for `\(t = 3 \times 2\)` treatments with `\(2\)` replication for each treatment <pre><code> agricolae::.bg-yellow[design.ab](trt = c(3, 2), r = 2, design = "crd") %>% glimpse() </code></pre> .overflow-scroll.h---340[ ``` ## List of 2 ## $ parameters:List of 8 ## ..$ design : chr "factorial" ## ..$ trt : chr [1:6] "1 1" "1 2" "2 1" "2 2" ... ## ..$ r : num [1:6] 2 2 2 2 2 2 ## ..$ serie : num 2 ## ..$ seed : int -751356955 ## ..$ kinds : chr "Super-Duper" ## ..$ : logi TRUE ## ..$ applied: chr "crd" ## $ book :'data.frame': 12 obs. of 4 variables: ## ..$ plots: num [1:12] 101 102 103 104 105 106 107 108 109 110 ... ## ..$ r : int [1:12] 1 1 1 1 1 2 2 1 2 2 ... ## ..$ A : chr [1:12] "3" "2" "3" "1" ... ## ..$ B : chr [1:12] "1" "2" "2" "2" ... ``` ] Note *not* A/B testing! <div class="plot-box" style="position:absolute;top: 200px; right: 50px;"> <br> <img src="images/ggfac-1.png" width="300px"> <br> </div> --- class: font_small # `agricolae::design.split()` **Split-plot design** for `\(t = 2 \times 4\)` treatments with `\(2\)` replication for each treatment <pre><code> trt1 <- c("I", "R"); trt2 <- LETTERS[1:4] agricolae::.bg-yellow[design.split](trt1 = trt1, trt2 = trt2, r = 2, design = "crd") %>% glimpse() </code></pre> .overflow-scroll.h---300[ ``` ## List of 2 ## $ parameters:List of 8 ## ..$ design : chr "split" ## ..$ : logi TRUE ## ..$ trt1 : chr [1:2] "I" "R" ## ..$ applied: chr "crd" ## ..$ r : num [1:2] 2 2 ## ..$ serie : num 2 ## ..$ seed : int 157974485 ## ..$ kinds : chr "Super-Duper" ## $ book :'data.frame': 16 obs. of 5 variables: ## ..$ plots : num [1:16] 101 101 101 101 102 102 102 102 103 103 ... ## ..$ splots: Factor w/ 4 levels "1","2","3","4": 1 2 3 4 1 2 3 4 1 2 ... ## ..$ r : int [1:16] 1 1 1 1 1 1 1 1 2 2 ... ## ..$ trt1 : chr [1:16] "R" "R" "R" "R" ... ## ..$ trt2 : chr [1:16] "C" "B" "A" "D" ... ``` ] <div class="plot-box" style="position:absolute;top: 300px; right: 200px;"> <img src="images/split-plot-graph-1.png" width="300px"> </div> --- name: edibble # 実験計画法の文法とは * Base R プロット覚えてますか? <a href="#base-plot" style="font-size:12pt"><i class="fas fa-caret-right"></i> base plot</a> -- * 🤔 "named experimental design" functions (`agricolae::design.crd`, etc.) are like "named statistical graphic" functions (`pie`, `barplot`) -- * 💡<i class="fas fa-wrench"></i> このコンセプトが `edibble` R-packageのもとです <br>https://github.com/emitanaka/edibble -- 名前の元 * `tibble` R-package とは modern reimagining of the `data.frame` * `edibble` とは **e**xperimental **d**esign t**ibble** .absolute.right-3.bottom-3[ <img src="images/edibble-hex.png" height="300px"> ] .footnote.f4.monash-black[ Müller & Wickham (2020) tibble: Simple Data Frames. *R package version 3.0.3* <br><br> ] --- # `edibble` プロトタイプ .flex[ .w-50[ * Consider a field experiment with 32 plots ] .w-50.f4[ ```r library(edibble) start_design(name = "cochran.crd") %>% * set_units(plot = 32) ``` ``` ## cochran.crd ## └─plot (32 levels) ``` ] ] --- count: false # `edibble` プロトタイプ .flex[ .w-50[ * Consider a field experiment with 32 plots * There are 7 different treatments ] .w-50.f4[ ```r library(edibble) start_design(name = "cochran.crd") %>% set_units(plot = 32) %>% * set_trts(trt = c("F12", "F3", "F6", "O", * "S12", "S3", "S6")) ``` ``` ## cochran.crd ## ├─plot (32 levels) ## └─trt (7 levels) ``` ] ] --- count: false # `edibble` プロトタイプ .flex[ .w-50[ * Consider a field experiment with 32 plots * There are 7 different treatments * Allocate treatments to plots ] .w-50.f4[ ```r library(edibble) start_design(name = "cochran.crd") %>% set_units(plot = 32) %>% set_trts(trt = c("F12", "F3", "F6", "O", "S12", "S3", "S6")) %>% * allocate_trts(trt ~ plot) ``` ``` ## cochran.crd ## ├─plot (32 levels) ## └─trt (7 levels) ``` ] ] --- count: false # `edibble` プロトタイプ .flex[ .w-50[ * Consider a field experiment with 32 plots * There are 7 different treatments * Allocate treatments to plots * Randomise treatments to plots ] .w-50.f4[ ```r library(edibble) start_design(name = "cochran.crd") %>% set_units(plot = 32) %>% set_trts(trt = c("F12", "F3", "F6", "O", "S12", "S3", "S6")) %>% allocate_trts(~ plot) %>% * randomise_trts() ``` ``` ## cochran.crd ## ├─plot (32 levels) ## └─trt (7 levels) ``` ] ] --- count: false # `edibble` プロトタイプ .flex[ .w-50[ * Consider a field experiment with 32 plots * There are 7 different treatments * Allocate treatments to plots * Randomise treatments to plots * The result is a **completely randomised design** ] .w-50.h---500.f4.overflow-scroll[ ```r library(edibble) start_design(name = "cochran.crd") %>% set_units(plot = 32) %>% set_trts(trt = c("F12", "F3", "F6", "O", "S12", "S3", "S6")) %>% allocate_trts(~ plot) %>% randomise_trts() %>% * serve_table() ``` ``` ## # An edibble: 32 x 2 ## plot trt ## <unit(32)> <trt(7)> ## 1 plot1 F12 ## 2 plot2 S6 ## 3 plot3 F6 ## 4 plot4 O ## 5 plot5 S6 ## 6 plot6 O ## 7 plot7 O ## 8 plot8 S3 ## 9 plot9 S6 ## 10 plot10 S12 ## # … with 22 more rows ``` ] ] --- # `edibble` プロトタイプ .flex[ .w-50[ * Consider a field experiment with 2 blocks each with 16 plots * There are 7 different treatments * Allocate treatments to plots * Randomise treatments to plots within blocks * Resulting design is a **randomised block design** <br> 前の実験研究法とどう違うか分かりますか? ] .w-50.h---500.overflow-scroll.f4[ ```r library(edibble) start_design(name = "cochran.crd") %>% * set_units(block = c("B1", "B2"), * plot = nested_in(block, 16)) %>% set_trts(trt = c("F12", "F3", "F6", "O", "S12", "S3", "S6")) %>% allocate_trts(~ plot) %>% randomise_trts() %>% serve_table() ``` ``` ## # An edibble: 32 x 3 ## block plot trt ## <unit(2)> <unit(32)> <trt(7)> ## 1 B1 plot1 S6 ## 2 B1 plot2 S3 ## 3 B1 plot3 F12 ## 4 B1 plot4 F6 ## 5 B1 plot5 S3 ## 6 B1 plot6 S6 ## 7 B1 plot7 S6 ## 8 B1 plot8 S12 ## 9 B1 plot9 F12 ## 10 B1 plot10 F3 ## # … with 22 more rows ``` ]] --- # `edibble` ユニット・ストラクチャー ```r start_design("complex unit structure") %>% set_units(city = c("tokyo", "nagano", "sydney", "melbourne", "washington"), school = nested_in(city, "tokyo" ~ 4, "sydney" ~ 1, . ~ 2)) %>% serve_table() ``` .h---240.overflow-scroll[ ``` ## # An edibble: 11 x 2 ## city school ## <unit(5)> <unit(11)> ## 1 tokyo school1 ## 2 tokyo school2 ## 3 tokyo school3 ## 4 tokyo school4 ## 5 nagano school5 ## 6 nagano school6 ## 7 sydney school7 ## 8 melbourne school8 ## 9 melbourne school9 ## 10 washington school10 ## 11 washington school11 ``` ] --- # `edibble` トリートメント・ストラクチャー ```r des <- start_design(name = "Effective teaching") %>% set_units(class = 4, student = nested_in(class, 30)) %>% set_trts(style = c("flipped", "traditional"), exam = c("take-home", "open-book", "closed-book")) %>% allocate_trts(style ~ class, exam ~ student) %>% randomise_trts() print(serve_table(des), n = 120) ``` .h---150.overflow-scroll[ ``` ## # An edibble: 120 x 4 ## class student style exam ## <unit(4)> <unit(120)> <trt(2)> <trt(3)> ## 1 class1 student1 flipped closed-book ## 2 class1 student2 flipped closed-book ## 3 class1 student3 flipped open-book ## 4 class1 student4 flipped open-book ## 5 class1 student5 flipped open-book ## 6 class1 student6 flipped take-home ## 7 class1 student7 flipped closed-book ## 8 class1 student8 flipped take-home ## 9 class1 student9 flipped open-book ## 10 class1 student10 flipped open-book ## 11 class1 student11 flipped open-book ## 12 class1 student12 flipped open-book ## 13 class1 student13 flipped take-home ## 14 class1 student14 flipped take-home ## 15 class1 student15 flipped closed-book ## 16 class1 student16 flipped take-home ## 17 class1 student17 flipped closed-book ## 18 class1 student18 flipped closed-book ## 19 class1 student19 flipped closed-book ## 20 class1 student20 flipped open-book ## 21 class1 student21 flipped take-home ## 22 class1 student22 flipped take-home ## 23 class1 student23 flipped open-book ## 24 class1 student24 flipped closed-book ## 25 class1 student25 flipped take-home ## 26 class1 student26 flipped take-home ## 27 class1 student27 flipped closed-book ## 28 class1 student28 flipped open-book ## 29 class1 student29 flipped take-home ## 30 class1 student30 flipped closed-book ## 31 class2 student31 flipped closed-book ## 32 class2 student32 flipped open-book ## 33 class2 student33 flipped closed-book ## 34 class2 student34 flipped take-home ## 35 class2 student35 flipped open-book ## 36 class2 student36 flipped take-home ## 37 class2 student37 flipped open-book ## 38 class2 student38 flipped open-book ## 39 class2 student39 flipped closed-book ## 40 class2 student40 flipped closed-book ## 41 class2 student41 flipped take-home ## 42 class2 student42 flipped closed-book ## 43 class2 student43 flipped open-book ## 44 class2 student44 flipped open-book ## 45 class2 student45 flipped take-home ## 46 class2 student46 flipped closed-book ## 47 class2 student47 flipped closed-book ## 48 class2 student48 flipped take-home ## 49 class2 student49 flipped open-book ## 50 class2 student50 flipped closed-book ## 51 class2 student51 flipped take-home ## 52 class2 student52 flipped take-home ## 53 class2 student53 flipped open-book ## 54 class2 student54 flipped take-home ## 55 class2 student55 flipped closed-book ## 56 class2 student56 flipped closed-book ## 57 class2 student57 flipped open-book ## 58 class2 student58 flipped take-home ## 59 class2 student59 flipped open-book ## 60 class2 student60 flipped take-home ## 61 class3 student61 traditional closed-book ## 62 class3 student62 traditional take-home ## 63 class3 student63 traditional open-book ## 64 class3 student64 traditional closed-book ## 65 class3 student65 traditional closed-book ## 66 class3 student66 traditional open-book ## 67 class3 student67 traditional take-home ## 68 class3 student68 traditional take-home ## 69 class3 student69 traditional open-book ## 70 class3 student70 traditional closed-book ## 71 class3 student71 traditional closed-book ## 72 class3 student72 traditional open-book ## 73 class3 student73 traditional take-home ## 74 class3 student74 traditional open-book ## 75 class3 student75 traditional closed-book ## 76 class3 student76 traditional closed-book ## 77 class3 student77 traditional closed-book ## 78 class3 student78 traditional open-book ## 79 class3 student79 traditional take-home ## 80 class3 student80 traditional closed-book ## 81 class3 student81 traditional take-home ## 82 class3 student82 traditional open-book ## 83 class3 student83 traditional take-home ## 84 class3 student84 traditional open-book ## 85 class3 student85 traditional open-book ## 86 class3 student86 traditional closed-book ## 87 class3 student87 traditional open-book ## 88 class3 student88 traditional take-home ## 89 class3 student89 traditional take-home ## 90 class3 student90 traditional take-home ## 91 class4 student91 traditional open-book ## 92 class4 student92 traditional closed-book ## 93 class4 student93 traditional closed-book ## 94 class4 student94 traditional take-home ## 95 class4 student95 traditional closed-book ## 96 class4 student96 traditional take-home ## 97 class4 student97 traditional take-home ## 98 class4 student98 traditional open-book ## 99 class4 student99 traditional closed-book ## 100 class4 student100 traditional take-home ## 101 class4 student101 traditional closed-book ## 102 class4 student102 traditional open-book ## 103 class4 student103 traditional open-book ## 104 class4 student104 traditional closed-book ## 105 class4 student105 traditional closed-book ## 106 class4 student106 traditional open-book ## 107 class4 student107 traditional open-book ## 108 class4 student108 traditional closed-book ## 109 class4 student109 traditional closed-book ## 110 class4 student110 traditional take-home ## 111 class4 student111 traditional open-book ## 112 class4 student112 traditional take-home ## 113 class4 student113 traditional take-home ## 114 class4 student114 traditional take-home ## 115 class4 student115 traditional take-home ## 116 class4 student116 traditional open-book ## 117 class4 student117 traditional take-home ## 118 class4 student118 traditional open-book ## 119 class4 student119 traditional open-book ## 120 class4 student120 traditional closed-book ``` ] --- # Recording variables in `edibble` ・記録 .f4[ ```r out <- des %>% record_vars(student = c(mark, gender), class = teacher) %>% expect_vars(mark = to_be_numeric(with_value(between = c(0, 100))), gender = to_be_factor(levels = c("female", "male", "other", "unknown"))) %>% serve_table() out ``` .h---240.overflow-scroll[ ``` ## # An edibble: 120 x 7 ## class student style exam mark gender teacher ## <unit(4)> <unit(120)> <trt(2)> <trt(3)> <rcrd> <rcrd> <rcrd> ## 1 class1 student1 flipped closed-book ■ ■ ■ ## 2 class1 student2 flipped closed-book ■ ■ x ## 3 class1 student3 flipped open-book ■ ■ x ## 4 class1 student4 flipped open-book ■ ■ x ## 5 class1 student5 flipped open-book ■ ■ x ## 6 class1 student6 flipped take-home ■ ■ x ## 7 class1 student7 flipped closed-book ■ ■ x ## 8 class1 student8 flipped take-home ■ ■ x ## 9 class1 student9 flipped open-book ■ ■ x ## 10 class1 student10 flipped open-book ■ ■ x ## # … with 110 more rows ``` ]] --- # `edibble` アウトプット ```r export_design(out, file = "design.xlsx") ``` .center[ <img class="ba" src="images/output.png" height="400px"> <img class="ba" src="images/output2.png" height="400px"> ] --- class: middle center .f1[実験計画は重要です!] <br> .f1[`edibble`の目的は実験計画を容易にする事です] .f1[[<i class="fas fa-link"></i> edibble.emitanaka.org](https://edibble.emitanaka.org/)] -- <br> .f1[🚧 `edibble`は開発中です] <br> .f1[コメントとフィードバックを歓迎します!] --- layout: false background-size: cover class: title-slide background-image: url("images/bg-03.png") This slide is made using the `xaringan` R-package and found at <br> .w-80.center[ [emitanaka.org/slides/TokyoR2021](https://emitanaka.org/slides/TokyoR2021) {{content}} ] .bottom_abs.width100[ *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> <br> ] -- <br> Thank you!