<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>emi tanaka</title>
<link>https://emitanaka.org/blog/</link>
<atom:link href="https://emitanaka.org/blog/index.xml" rel="self" type="application/rss+xml"/>
<description>Emi Tanaka&#39;s website and blog that mainly features about
statistics, data science, R and academia.
</description>
<generator>quarto-1.9.12</generator>
<lastBuildDate>Sun, 08 Jun 2025 14:00:00 GMT</lastBuildDate>
<item>
  <title>Exploring Data from ANU Research Portal</title>
  <dc:creator>Emi Tanaka</dc:creator>
  <link>https://emitanaka.org/blog/2025-06-09-anu-rp/</link>
  <description><![CDATA[ 

<!-- Title banner for blog posts (set in blog/_metadata.yml). Built from each
     post's front matter: title, date, author, categories, description and
     image (a pen sticker is shown when a post has no image). -->



<section id="data-source" class="level2">
<h2 class="anchored" data-anchor-id="data-source">Data Source</h2>
<p>The <a href="https://researchportalplus.anu.edu.au/en/">ANU Research Portal</a> provides a list of researchers and their affiliations at ANU. From this portal, I extracted 2,370 profiles along with their affiliations and if available their Scopus ID on 8th June 2025 (what does one do over the King’s birthday long weekend otherwise…). After some cleaning, I subset to <strong>1,880 profiles</strong> of ANU researchers who have either a Dr or Professor in their titles. The subsequent analysis are based on these profiles.</p>
<div class="callout callout-style-default callout-warning callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Warning
</div>
</div>
<div class="callout-body-container callout-body">
<p>Note that:</p>
<ul>
<li>Not all ANU researchers have activated their research portal account and some information stored in it may be incorrect. For example, some profiles had no title and are removed from subsequent analysis.</li>
<li>Some researchers are affiliated with multiple units and therefore counted multiple times in the analysis below.</li>
</ul>
</div>
</div>
</section>
<section id="academic-organisational-units" class="level2">
<h2 class="anchored" data-anchor-id="academic-organisational-units">Academic Organisational Units</h2>
<section id="academic-colleges" class="level3">
<h3 class="anchored" data-anchor-id="academic-colleges">Academic Colleges</h3>
<p>Figure&nbsp;1 shows that the CoSM is considerably bigger relative to the other colleges. CBE, known for bringing the largest student revenue, is much smaller than I thought. Note that this does not count profiles who are not affiliated with Colleges.</p>
<div class="cell">
<div class="cell-output-display">
<div id="fig-college" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-college-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://emitanaka.org/blog/2025-06-09-anu-rp/index_files/figure-html/fig-college-1.png" class="img-fluid figure-img" width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-college-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: The number of ANU researchers across ANU Colleges by their titles. Percentages shown are total percentage of researchers relative to the other Colleges.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Figure&nbsp;2 shows that CLGP is slightly top heavy compared to other colleges.</p>
<div class="cell">
<div class="cell-output-display">
<div id="fig-college-titles" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-college-titles-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://emitanaka.org/blog/2025-06-09-anu-rp/index_files/figure-html/fig-college-titles-1.png" class="img-fluid figure-img" width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-college-titles-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: The proportion of ANU researchers across ANU Colleges by their titles. Percentages shown are the title relative to the respective College.
</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="schools-and-centres" class="level3">
<h3 class="anchored" data-anchor-id="schools-and-centres">Schools and Centres</h3>
<p>Figure&nbsp;3 shows the breakdown of the ANU researchers by their School or Centre. School of Medicine and Psychology is bigger than I realised! RSE is quite top heavy compared to other schools in CoSM.</p>
<div class="cell">
<div class="cell-output-display">
<div id="fig-schools" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-schools-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://emitanaka.org/blog/2025-06-09-anu-rp/index_files/figure-html/fig-schools-1.png" class="img-fluid figure-img" width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-schools-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3: The number of ANU researchers by school or centre within their college.
</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="college-of-arts-and-social-science" class="level3">
<h3 class="anchored" data-anchor-id="college-of-arts-and-social-science">College of Arts and Social Science</h3>
<p>We’ll have a special look at CASS given that it’s also got another breakdown into smaller schools (Figure&nbsp;4). Now I don’t claim to understand what these smaller school structures mean. It’s possible that some staff belong to multiple schools. I haven’t delved into that aspect.</p>
<div class="cell">
<div class="cell-output-display">
<div id="fig-cass" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-cass-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://emitanaka.org/blog/2025-06-09-anu-rp/index_files/figure-html/fig-cass-1.png" class="img-fluid figure-img" width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-cass-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4: The number of ANU researchers by school or centre within CASS.
</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="research-school-of-biology" class="level3">
<h3 class="anchored" data-anchor-id="research-school-of-biology">Research School of Biology</h3>
<p>From personal interest, I also looked at the RSB (Figure&nbsp;5) which is part of CoSM. The Division of Plant Sciences is the largest group within RSB. This strength is perhaps reflected in the fact that it also houses the <a href="https://biology.anu.edu.au/research/facilities/australian-plant-phenomics-network-anu">Australian Plant Phenomics Network</a>, <a href="https://futurecropscentre.edu.au/">ARC Training Centre for Future Crops Development</a> and more recently, <a href="https://plantbiosecuritycentre.edu.au/">ARC Training Centre in Plant Biosecurity</a> .</p>
<div class="cell">
<div class="cell-output-display">
<div id="fig-rsb" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-rsb-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://emitanaka.org/blog/2025-06-09-anu-rp/index_files/figure-html/fig-rsb-1.png" class="img-fluid figure-img" width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-rsb-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;5: The number of ANU researchers by school or centre within their college.
</figcaption>
</figure>
</div>
</div>
</div>
</section>
</section>
<section id="publications" class="level2">
<h2 class="anchored" data-anchor-id="publications">Publications</h2>
<p>Of the 1,880 ANU researcher profiles who have either a Dr or Professor in their titles 1,658 have a Scopus ID in their profile. Every discipline has their own publication culture so this information shouldn’t be used to judge the research worth of any discipline.</p>
<p>Figure&nbsp;6 and Figure&nbsp;7 show the distribution of the number of publications by ANU researchers across Colleges and Schools/Centres, respectively. The number of publications is highly skewed, with some researchers having more than 1000 publications. The boxplots are shown on a log scale to better visualise the distribution.</p>
<div class="cell">
<div class="cell-output-display">
<div id="fig-college-pub" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-college-pub-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://emitanaka.org/blog/2025-06-09-anu-rp/index_files/figure-html/fig-college-pub-1.png" class="img-fluid figure-img" width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-college-pub-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;6: The boxplot of the number of publications of ANU researchers by colleges.
</figcaption>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<div id="fig-schools-pubs" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-schools-pubs-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://emitanaka.org/blog/2025-06-09-anu-rp/index_files/figure-html/fig-schools-pubs-1.png" class="img-fluid figure-img" width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-schools-pubs-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;7: The boxplot of the number of publications of ANU researchers by school or centres within their colleges.
</figcaption>
</figure>
</div>
</div>
</div>


</section>

 ]]></description>
  <guid>https://emitanaka.org/blog/2025-06-09-anu-rp/</guid>
  <pubDate>Sun, 08 Jun 2025 14:00:00 GMT</pubDate>
</item>
<item>
  <title>Final lecture at Monash University</title>
  <dc:creator>Emi Tanaka</dc:creator>
  <link>https://emitanaka.org/blog/2023-05-27-monash-teaching/</link>
  <description><![CDATA[ 

<!-- Title banner for blog posts (set in blog/_metadata.yml). Built from each
     post's front matter: title, date, author, categories, description and
     image (a pen sticker is shown when a post has no image). -->



<p>Since I started working at the Department of Econometrics and Business Statistics, Monash University in January 2020, I developed and taught across <strong>4 units</strong>, totalling development of <strong>36 unique 2-hour lectures</strong>, and developed an <strong>online resource</strong> on top of <strong>slide templates</strong> and <strong>utility scripts</strong>. The 3 units (<em>Wild-Caught Data</em>, <em>Exploratory Data Analysis</em>, and <em>Communicating with Data</em>) I taught were brand new units for the Master of Business Analytics and there were no past materials that I can leverage. The difficulty was compounded by the fact that my training was in classical statistics and almost all topics that I taught was actually never something I ever formally learnt. Needless to say it has been an absolutely exhausting time period! As much as I’m proud for surviving it, I hope to never repeat the experience again. I sacrificed a large quality of my life (particularly in 2020) just to finish developing my teaching materials. Fortunately or not, the series of lockdowns in Melbourne aided in giving me more time to focus on the development.</p>
<p>Teaching <em>Introduction to Machine Learning</em> was the highlight of all the teaching for me. Not only did I enjoy teaching the content but it was also the first time I got to teach in-person at Monash after 3 years (gasp!). Shout out to the students who got up early each week for the Monday 9am lecture despite how cold it has become!</p>
<p>I ended my last lecture (shown below) at Monash with the wrap-up for the Introduction to Machine Learning unit featuring the varied datasets and toolkits that was demonstrated in the unit. This would be the final lecture of the year for me but also the final lecture for me at Monash. From July 2023, I will be joining the Biological Data Science Institute at the Australian National University. As much as I enjoy teaching enthusiastic students and recognise the importance in training the next-generation, I hope I get more time to focus on research.</p>
<iframe width="600px" src="https://emitanaka.org/teaching/monash-iml/2023/lecture-12B.html" height="337.5px" style="border: 1px solid black;">
</iframe>
<p>So what did I develop? Below is the full list.</p>
<section id="introduction-to-machine-learning" class="level3">
<h3 class="anchored" data-anchor-id="introduction-to-machine-learning">Introduction to Machine Learning</h3>
<ul>
<li><a href="../../teaching/monash-iml/2023/lecture-01.html">Overview</a></li>
<li><a href="../../teaching/monash-iml/2023/lecture-02A.html">Non-parametric regression</a></li>
<li><a href="../../teaching/monash-iml/2023/lecture-02B.html">Variable selection</a><br>
</li>
<li><a href="../../teaching/monash-iml/2023/lecture-03A.html">Resampling</a></li>
<li><a href="../../teaching/monash-iml/2023/lecture-03B.html">Regularisation</a><br>
</li>
<li><a href="../../teaching/monash-iml/2023/lecture-04A.html">Logistic regression</a><br>
</li>
<li><a href="../../teaching/monash-iml/2023/lecture-04B.html">Discriminant analysis</a></li>
<li><a href="../../teaching/monash-iml/2023/lecture-05.html">Decision trees</a><br>
</li>
<li><a href="../../teaching/monash-iml/2023/lecture-06.html">Tree ensemble methods</a><br>
</li>
<li><a href="../../teaching/monash-iml/2023/lecture-07.html">k-nearest neighbours</a><br>
</li>
<li><a href="../../teaching/monash-iml/2023/lecture-08.html">Dimension reduction</a><br>
</li>
<li><a href="../../teaching/monash-iml/2023/lecture-09.html">Clustering</a><br>
</li>
<li><a href="../../teaching/monash-iml/2023/lecture-10.html">Support vector machines</a><br>
</li>
<li><a href="../../teaching/monash-iml/2023/lecture-11.html">Neural network Part I</a><br>
</li>
<li><a href="../../teaching/monash-iml/2023/lecture-12A.html">Neural network Part II</a><br>
</li>
<li><a href="../../teaching/monash-iml/2023/lecture-12B.html">Wrap-up</a></li>
</ul>
</section>
<section id="communicating-with-data" class="level3">
<h3 class="anchored" data-anchor-id="communicating-with-data">Communicating with Data</h3>
<ul>
<li><a href="../../teaching/monash-cwd/2022/lecture-01.html">Basic communication theory and practice</a><br>
</li>
<li><a href="../../teaching/monash-cwd/2022/lecture-02.html">Introduction to web technologies</a><br>
</li>
<li><a href="../../teaching/monash-cwd/2022/lecture-03.html">Communicating data with interactive web apps</a></li>
<li><a href="../../teaching/monash-cwd/2022/lecture-04.html">Data storytelling on the web</a><br>
</li>
<li><a href="../../teaching/monash-cwd/2022/lecture-05A.html">Statistical model outputs</a><br>
</li>
<li><a href="../../teaching/monash-cwd/2022/lecture-05B.html">Data tables</a><br>
</li>
<li><a href="../../teaching/monash-cwd/2022/lecture-06.html">Effective data visualisation</a><br>
</li>
<li><a href="../../teaching/monash-cwd/2022/lecture-07.html">Captivating statistical presentations</a><br>
</li>
<li><a href="../../teaching/monash-cwd/2022/lecture-08.html">Clearly communicating with code</a></li>
<li><a href="../../teaching/monash-cwd/2022/lecture-09.html">Stylishly communicating with code</a></li>
<li><a href="../../teaching/monash-cwd/2022/lecture-10.html">Narrative</a><br>
</li>
<li><a href="../../teaching/monash-cwd/2022/lecture-11.html">Visual</a><br>
</li>
<li><a href="../../teaching/monash-cwd/2022/lecture-12.html">Interactive</a></li>
</ul>
</section>
<section id="wild-caught-data" class="level3">
<h3 class="anchored" data-anchor-id="wild-caught-data">Wild-Caught Data</h3>
<ul>
<li><a href="../../teaching/monash-wcd/2020/week08-PISA.html#2">Synthetic and Simulated Data</a></li>
<li><a href="../../teaching/monash-wcd/2020/week09-DoE.html#2">The Language of Designed Experiments</a></li>
<li><a href="../../teaching/monash-wcd/2021/lecture-01.html#2">Introduction to Data Collection Methods</a></li>
<li><a href="../../teaching/monash-wcd/2022/lecture-04.html#2">Australian Census</a></li>
<li><a href="../../teaching/monash-wcd/2022/lecture-05.html#2">Australian Election</a></li>
<li><a href="../../teaching/monash-wcd/2022/lecture-06.html#2">Combining Australian Census and Election Data</a></li>
</ul>
</section>
<section id="exploratory-data-analysis" class="level3">
<h3 class="anchored" data-anchor-id="exploratory-data-analysis">Exploratory Data Analysis</h3>
<ul>
<li><a href="../../teaching/monash-eda/ida.html">Initial data analysis</a></li>
<li><a href="../../teaching/monash-eda/single-variable.html">Single variable</a><br>
</li>
<li><a href="../../teaching/monash-eda/comparisons.html">Comparisons</a><br>
</li>
<li><a href="../../teaching/monash-eda/model-diagnostics.html">Model diagnostics</a></li>
<li><a href="../../teaching/monash-eda/visual-inference-part1.html">Visual inference Part I</a></li>
<li><a href="../../teaching/monash-eda/visual-inference-part2.html">Visual inference Part II</a></li>
</ul>
</section>
<section id="templates-and-utility-scripts" class="level3">
<h3 class="anchored" data-anchor-id="templates-and-utility-scripts">Templates and utility scripts</h3>
<ul>
<li><a href="https://github.com/numbats/monash"><code>monash</code> R-package</a> that includes the templates for the teaching slides.</li>
<li>Various utility scripts that automated certain teaching tasks.</li>
</ul>
</section>
<section id="learn-r" class="level3">
<h3 class="anchored" data-anchor-id="learn-r">Learn R</h3>
<ul>
<li><a href="https://learnr.numbat.space/">https://learnr.numbat.space/</a></li>
</ul>


</section>

 ]]></description>
  <guid>https://emitanaka.org/blog/2023-05-27-monash-teaching/</guid>
  <pubDate>Fri, 26 May 2023 14:00:00 GMT</pubDate>
</item>
<item>
  <title>Getting the most out of your experimental data with design</title>
  <dc:creator>Emi Tanaka</dc:creator>
  <link>https://emitanaka.org/blog/2022-10-23-edibble-for-biometrics-bulletin/</link>
  <description><![CDATA[ 

<!-- Title banner for blog posts (set in blog/_metadata.yml). Built from each
     post's front matter: title, date, author, categories, description and
     image (a pen sticker is shown when a post has no image). -->



<section id="introduction" class="level2">
<h2 class="anchored" data-anchor-id="introduction">Introduction</h2>
<p>Experimental data are hallmarks of proving or disproving theories or hypotheses. Not all experimental data are of equal value however; the design of experiment and the execution to collect data greatly shape its downstream value. The seminal book by <span class="citation" data-cites="Fisher1935-qc">Fisher (1935)</span> outline the importance of randomisation, replication and (statistical) control in experimental designs motivated primary by agricultural field trials. <span class="citation" data-cites="Fisher1935-qc">Fisher (1935)</span> also introduce special cases of row-column designs, such as Latin Square and Graeco-Latin Square designs, factorial designs and the analysis of experimental data using analysis of variance (ANOVA), <img src="https://latex.codecogs.com/png.latex?t">-test, <img src="https://latex.codecogs.com/png.latex?%5Cchi%5E2">-test and other tests of significance. <span class="citation" data-cites="Montgomery2001-gh">Montgomery (2001)</span>, <span class="citation" data-cites="Box2005-yj">Box, Stuart Hunter, and Hunter (2005)</span>, and <span class="citation" data-cites="Hinkelmann2005-jq">Hinkelmann and Kempthorne (2005)</span> are classical textbooks in experimental designs taught in many courses in experimental design. Many of these textbooks, and the teaching of experimental designs, I would argue is focussed on statistical aspects, but in practice, the primary problem in carrying out an experiment is actually centered on human aspects. Consider the following simplified scenario:</p>
<ul>
<li>the <strong>domain expert</strong> wants an experiment to validate their hypothesis and needs a statistician to design the experiment;</li>
<li>the <strong>statistician</strong> elicits the experimental aim and structure from the domain expert and then design the experiment accounting appropriately for statistical issues and practical constraints;</li>
<li>the <strong>technician</strong> carries out the experimental protocol as directed by the experimental design generated by the statistician and enter the data; and then</li>
<li>the <strong>analyst</strong> (who may or may not be the same person as the statistician) interprets the experimental aim and design to appropriately analyse the data.</li>
</ul>
<p>How many people were involved in this experiment? Notice that we are reliant on communication between people, who likely have different discipline backgrounds, to transfer the correct information in order to successfully carry out the experiment. We know human communication is fraught with challenges; <strong><em>misunderstandings are common, not the exception</em></strong>. The unwritten assumption in experimental designs is that all parties involved in the experiment completely understood each other – the statistician understood all the intricacies that the domain expert knows that may affect the experimental outcome, and the technician will carry out the experiment exactly as the design of experiment with no possible error. This assumption is in contrary to what we know about human communication; human communication is a noisy process. What then can we do to mitigate errors in the process?</p>
</section>
<section id="the-grammar-of-experimental-designs" class="level2">
<h2 class="anchored" data-anchor-id="the-grammar-of-experimental-designs">The grammar of experimental designs</h2>
<p>The so-called “The Grammar of Experimental Designs” is the title of my work-in-progress book found at <a href="https://emitanaka.org/edibble-book">emitanaka.org/edibble-book</a>. More details can be found in the book, but briefly, the <strong>grammar of experimental designs</strong> is an object oriented programming system designed to capture elements of the origin of an experimental data encapsulated in a cognitive framework. It is an attempt to standardise the computational description of experimental components by fundamental terms so we are not lost in domain-specific jargon.</p>
<p>The motivation of the grammar of experimental designs is best explained by an analogy to the “grammar of graphics” <span class="citation" data-cites="Wilkinson2005-oz">(Wilkinson 2005)</span> with its most popular implementation as ggplot2 <span class="citation" data-cites="Wickham2016-yg">(Wickham 2016)</span> in the R language <span class="citation" data-cites="Rstats">(R Core Team 2021)</span>. When we specify a plot, we can specify using a complete recipe. For example, the functions <code>barplot()</code> and <code>pie()</code> create a barplot and a pie chart, respectively, in the base R language – these functions are for a single purpose, nothing more.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1">data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">duty =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"teaching"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"research"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"admin"</span>),</span>
<span id="cb1-2">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">percentage =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>))</span>
<span id="cb1-3"></span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">barplot</span>(data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>percentage, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names.arg =</span> data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>duty)</span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pie</span>(data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>percentage, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>duty)</span></code></pre></div></div>
<div class="cell quarto-layout-panel" data-layout-ncol="2">
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 50.0%;justify-content: center;">
<p><img src="https://emitanaka.org/blog/2022-10-23-edibble-for-biometrics-bulletin/index_files/figure-html/plot-base-1.png" class="img-fluid" width="672"></p>
</div>
<div class="quarto-layout-cell" style="flex-basis: 50.0%;justify-content: center;">
<p><img src="https://emitanaka.org/blog/2022-10-23-edibble-for-biometrics-bulletin/index_files/figure-html/plot-base-2.png" class="img-fluid" width="672"></p>
</div>
</div>
</div>
<p>When we specify plots using ggplot2, the system requires users to <em>specify components of the plot</em>, not the full plot. This not only gives greater control over the construction of the plot but it encourages the user to think about the relationship between data to plot elements. For example, below we create the pie chart and barplot using ggplot2. The first specification in ggplot2 is to initiate the object by <code>ggplot()</code> where the user can specify the data and the mapping of variable to plot aesthetic, then the user can append a layer like <code>geom_col()</code> to create a barplot. To construct a pie chart in ggplot2, the user must transform the default Cartesian coordinate system to a polar coordinate along one of the axis.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggplot2)</span>
<span id="cb2-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># bar plot</span></span>
<span id="cb2-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(data, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> duty, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> percentage)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col</span>() </span>
<span id="cb2-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># pie chart</span></span>
<span id="cb2-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(data, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> percentage, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> duty)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_polar</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>)</span></code></pre></div></div>
<div class="cell quarto-layout-panel" data-layout-ncol="2">
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 50.0%;justify-content: center;">
<p><img src="https://emitanaka.org/blog/2022-10-23-edibble-for-biometrics-bulletin/index_files/figure-html/plot-ggplot2-1.png" class="img-fluid" width="672"></p>
</div>
<div class="quarto-layout-cell" style="flex-basis: 50.0%;justify-content: center;">
<p><img src="https://emitanaka.org/blog/2022-10-23-edibble-for-biometrics-bulletin/index_files/figure-html/plot-ggplot2-2.png" class="img-fluid" width="672"></p>
</div>
</div>
</div>
<p>The ggplot2 system has a steep learning curve, however, the mastery of the system allows users to easily create a variety of plots. In a similar vein, the grammar of experimental designs is a system to construct experimental designs by experimental components – the users don’t need to specify the complete design but build up the experimental design by its basic components, like experimental units and treatments, giving them the flexibility in their thinking and specifciation of the experimental structure. The easiest way to grasp the grammar of experimental design is to see examples of its implementation as shown next.</p>
</section>
<section id="constructing-experimental-designs-with-the-edibble-r-package" class="level2">
<h2 class="anchored" data-anchor-id="constructing-experimental-designs-with-the-edibble-r-package">Constructing experimental designs with the <strong>edibble</strong> R package</h2>
<p>The edibble package is a system in the R language to facilitate the design of comparative experiments based on the grammar of experimental designs. The package is available on Comprehensive R Arhive Network (CRAN) with the developmental version available at <a href="https://github.com/emitanaka/edibble">github.com/emitanaka/edibble</a> and can be installed as below.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># installing from CRAN</span></span>
<span id="cb3-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install.packages</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"edibble"</span>) </span>
<span id="cb3-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># OR for the developmental version</span></span>
<span id="cb3-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install.packages</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"remotes"</span>) </span>
<span id="cb3-5">remotes<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install_github</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"emitanaka/edibble"</span>) </span></code></pre></div></div>
</div>
<section id="package-name" class="level3">
<h3 class="anchored" data-anchor-id="package-name">Package name</h3>
<p>The name of the package, edibble, stands for the <strong>e</strong>xperimental <strong>d</strong>esign table or t<strong>ibble</strong> for those that are familiar with tidyverse <span class="citation" data-cites="Wickham2019-mj">(Wickham et al. 2019)</span>. I often see people misspell it as eddible or edible (latter probably due to autocorrect), so I want to emphasise that is is edibble, i.e.&nbsp;one d and two b.</p>
<p>The package name itself relates to the aim of what it tries to produce, i.e.&nbsp;a table where columns specifies the unit and treatment factors in the experimental design and rows specify the characteristics of the observational unit, including the allocated treatment.</p>
</section>
<section id="example-usage" class="level3">
<h3 class="anchored" data-anchor-id="example-usage">Example usage</h3>
<p>Let’s suppose that we want to create a randomised complete block design (RCBD) with 6 blocks with 3 plots in each block to test 3 wheat varieties, labelled A, B and C. As not all of you may know what a RCBD is, to describe it more explicitly, the treatments (in this case the 3 wheat varieties) are randomly allocated to one of the plot (experimental unit) within a block; only one treatment level can be assigned to each plot; and each treatment level must appear exactly once in each block. The specification of this design in the edibble system is shown below and can be interpreted as follows:</p>
<ul>
<li>Line 1: load the library,</li>
<li>Line 2: set the seed to ensure replication of the randomised design,</li>
<li>Line 3: initialise the design object,</li>
<li>Line 4-5: set the unit factors, namely 6 blocks and 3 plots nested in each block,</li>
<li>Line 6: set the treatment factor, variety, with 3 levels (A, B, and C),</li>
<li>Line 7: specify the high-level treatment to unit allocation,</li>
<li>Line 8: assign the treatment randomly, and</li>
<li>Line 9: the design specification is complete, now convert the result to a table.</li>
</ul>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(edibble)</span>
<span id="cb4-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2022</span>) </span>
<span id="cb4-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">design</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Randomised Complete Block Design"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_units</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">block =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>,</span>
<span id="cb4-5">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nested_in</span>(block, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_trts</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variety =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"B"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"C"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">allot_trts</span>(variety <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> plot) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">assign_trts</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"random"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">serve_table</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code># Randomised Complete Block Design 
# An edibble: 18 x 3
       block       plot  variety
   &lt;unit(6)&gt; &lt;unit(18)&gt; &lt;trt(3)&gt;
 1    block1     plot1         A
 2    block1     plot2         B
 3    block1     plot3         C
 4    block2     plot4         A
 5    block2     plot5         B
 6    block2     plot6         C
 7    block3     plot7         A
 8    block3     plot8         C
 9    block3     plot9         B
10    block4     plot10        C
11    block4     plot11        B
12    block4     plot12        A
13    block5     plot13        B
14    block5     plot14        C
15    block5     plot15        A
16    block6     plot16        C
17    block6     plot17        B
18    block6     plot18        A</code></pre>
</div>
</div>
<p>Above table output shows the resulting allocation of the treatment to units, e.g.&nbsp;from the first row we see that first plot in the first block is assigned variety A.</p>
<p>Now consider the design specified below. How is this different to above?</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">design</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Do exam type matter?"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb6-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_units</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">school =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>,</span>
<span id="cb6-3">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">student =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nested_in</span>(school, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb6-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_trts</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">exam =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Oral"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Written"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Computer"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb6-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">allot_trts</span>(exam <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> school) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb6-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">assign_trts</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"random"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb6-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">serve_table</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code># Do exam type matter? 
# An edibble: 18 x 3
      school    student     exam
   &lt;unit(6)&gt; &lt;unit(18)&gt; &lt;trt(3)&gt;
 1   school1  student1  Oral    
 2   school1  student2  Oral    
 3   school1  student3  Oral    
 4   school2  student4  Computer
 5   school2  student5  Computer
 6   school2  student6  Computer
 7   school3  student7  Oral    
 8   school3  student8  Oral    
 9   school3  student9  Oral    
10   school4  student10 Written 
11   school4  student11 Written 
12   school4  student12 Written 
13   school5  student13 Computer
14   school5  student14 Computer
15   school5  student15 Computer
16   school6  student16 Written 
17   school6  student17 Written 
18   school6  student18 Written </code></pre>
</div>
</div>
<p>First, you may have noticed that the experimental factors are named differently. The names that you enter in <code>set_units()</code> and <code>set_trts()</code> are not fixed by the system – the user may enter the name that is appropriate for their experimental context. These are just simply labels but it captures the valuable experimental context. In fact, the unit structure is exactly the same as the previous experiment! But it’s easy to see that the first experiment is a wheat variety trial but the second experiment is comparing the exam type across schools.</p>
<p>Second, aside from labels, you may have noticed everything is the same as the previous experiment except line 5. The treatment (exam type) are randomly allocated to schools, not individual students within a school. You can see this in the resulting table output – each school gets only one type of exam. The resulting design is in fact called a completely randomised design. Here, the experimental units are the schools and the intended observational units are the students.</p>
<p>You may think the edibble system is only for balanced designs (where there is equal number of units within a block), but you can easily specify unbalanced designs as shown in line 3-5 below where there are two blocks (labelled I and II) where block I has 3 plots and block II has 6 plots.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">design</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Unbalanced design"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_units</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">block =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"I"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"II"</span>),</span>
<span id="cb8-3">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nested_in</span>(block, </span>
<span id="cb8-4">                              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"I"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,</span>
<span id="cb8-5">                             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"II"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_trts</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variety =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"B"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"C"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">allot_trts</span>(variety <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> plot) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">assign_trts</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"random"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">serve_table</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code># Unbalanced design 
# An edibble: 9 x 3
      block      plot  variety
  &lt;unit(2)&gt; &lt;unit(9)&gt; &lt;trt(3)&gt;
1        I      plot1        B
2        I      plot2        A
3        I      plot3        C
4        II     plot4        C
5        II     plot5        A
6        II     plot6        B
7        II     plot7        C
8        II     plot8        B
9        II     plot9        A</code></pre>
</div>
</div>
<p>There are more features in the edibble system. These features include setting responses using <code>set_rcrds()</code>, simulating responses with <code>simulate_rcrds()</code> (experimental only), and setting expectation of responses <code>expect_rcrds()</code>, e.g.&nbsp;when values should be positive numbers only. The latter allows files to be encoded with data validation rules, e.g.&nbsp;<code>export_design()</code> outputs the edibble table as an Excel file where values outside of expectation cannot be entered by exploiting Excel’s data validation system.</p>
<p>The edibble system has been designed so that developers can extend the system. If the <code>assign_trts()</code> is not suitable, then you can replace this with an alternative one. Likewise, if an Excel output is not desired then you can replace the exporting system with another system. The system exposes its components as modular functions to allow extensibility. The caveat of the edibble system is that there is a steep learning curve for both the user and the developer – but mastery of the grammar should help you flexibly specify a variety of experimental designs and deepen your thinking about the experimental design.</p>
</section>
</section>
<section id="recipe-experimental-designs" class="level2">
<h2 class="anchored" data-anchor-id="recipe-experimental-designs">Recipe experimental designs</h2>
<blockquote class="blockquote">
<p>“Good design considers units and treatments first, and then allocates treatments to units. It does not choose from a menu of named designs.” – <span class="citation" data-cites="Bailey2008-gw">Bailey (2008)</span></p>
</blockquote>
<p>I highly discourage the use of named experimental designs, but I acknowledge that the literature is littered with them. The compromise I have made is to include a set of functions that are prefixed with <code>menu_</code>. For example, below <code>menu_rcbd()</code> shows the code to generate a RCBD with 3 treatments and 6 blocks. If you must take this approach, I suggest that you copy the output code and replace the generic factor names with what is appropriate in the context of your own experiment.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">menu_rcbd</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">t =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>design("Randomised Complete Block Design") %&gt;%
  set_units(block = 6,
            unit = nested_in(block, 3)) %&gt;%
  set_trts(trt = 3) %&gt;%
  allot_trts(trt ~ unit) %&gt;%
  assign_trts("random", seed = 424) %&gt;%
  serve_table()</code></pre>
</div>
</div>
<p>If you want to actually see a table output then you can <code>takeout()</code> any named design (on the menu). Say below <code>menu_lsd()</code> shows the code for generating a Latin Square design; the <code>takeout()</code> of this design on the menu shows the table output of the Latin Square design with 4 treatments.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">takeout</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">menu_lsd</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">t =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>design("Latin Square Design") %&gt;%
  set_units(row = 4,
            col = 4,
            unit = crossed_by(row, col)) %&gt;%
  set_trts(trt = 4) %&gt;%
  allot_trts(trt ~ unit) %&gt;%
  assign_trts("random", seed = 794) %&gt;%
  serve_table() 

# Latin Square Design 
# An edibble: 16 x 4
         row       col       unit      trt
 * &lt;unit(4)&gt; &lt;unit(4)&gt; &lt;unit(16)&gt; &lt;trt(4)&gt;
 1      row1      col1     unit1      trt1
 2      row2      col1     unit2      trt3
 3      row3      col1     unit3      trt4
 4      row4      col1     unit4      trt2
 5      row1      col2     unit5      trt4
 6      row2      col2     unit6      trt2
 7      row3      col2     unit7      trt1
 8      row4      col2     unit8      trt3
 9      row1      col3     unit9      trt3
10      row2      col3     unit10     trt4
11      row3      col3     unit11     trt2
12      row4      col3     unit12     trt1
13      row1      col4     unit13     trt2
14      row2      col4     unit14     trt1
15      row3      col4     unit15     trt3
16      row4      col4     unit16     trt4</code></pre>
</div>
</div>
<p>The full list of available named experimental designs can be found in the <a href="https://emitanaka.org/edibble-book/cookbook.html">Cookbook chapter in The Grammar of Experimental Designs book</a>.</p>
</section>
<section id="conclusion" class="level2">
<h2 class="anchored" data-anchor-id="conclusion">Conclusion</h2>
<p>The design of an experiment is, without a doubt, of critical importance in the advancement of our knowledge. In fact, a good experimental design and well executed collection of data can eliminate or reduce the necessity of certain statistical analysis. The use of experimental designs in practice are arguably propagated by statistical software and interested readers can see <span class="citation" data-cites="tanaka2022">Tanaka and Amaliah (2022)</span> for a review of popular R packages in experimental design. The edibble R package is an attempt to specify designs by a paradigm that is flexible, yet human-centered. By building designs based on its components, users are required to think about the ingredients that make up the composition of the experimental structure – this system design I would hope translates to higher order thinking about experimental designs.</p>
<p>This article did not touch on much about optimal, adaptive, model-based nor domain-specific designs. The scope of work in the design of experiments is large and substantial work remain to bridge the gap between the principles and practice of experimental designs. Too often, teaching of experimental design is overshadowed by the analysis of experimental data and to get the most out of experimental data, we should remember that experimental context is invaluable in the design and no analysis can extract information from rubbish data.</p>



</section>

<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-Bailey2008-gw" class="csl-entry">
Bailey, Rosemary. 2008. <em>Design of Comparative Experiments</em>. Cambridge University Press.
</div>
<div id="ref-Box2005-yj" class="csl-entry">
Box, George E P, J Stuart Hunter, and William G Hunter. 2005. <em>Statistics for Experimenters: An Introduction to Design, Data Analysis, and Model Building</em>. 2nd ed. John Wiley &amp; Sons, Inc.
</div>
<div id="ref-Fisher1935-qc" class="csl-entry">
Fisher, Ronald Aylmer. 1935. <em>The Design of Experiments</em>. Oliver; Boyd.
</div>
<div id="ref-Hinkelmann2005-jq" class="csl-entry">
Hinkelmann, Klaus, and Oscar Kempthorne. 2005. <em>Design and Analysis of Experiments</em>. 2nd ed. Vol. 1. Wiley Blackwell.
</div>
<div id="ref-Montgomery2001-gh" class="csl-entry">
Montgomery, Doulgas C. 2001. <em>Design and Analysis of Experiments</em>. 5th ed. John Wiley &amp; Sons, Inc.
</div>
<div id="ref-Rstats" class="csl-entry">
R Core Team. 2021. <em>R: A Language and Environment for Statistical Computing</em>. Vienna, Austria: R Foundation for Statistical Computing. <a href="https://www.R-project.org/">https://www.R-project.org/</a>.
</div>
<div id="ref-tanaka2022" class="csl-entry">
Tanaka, Emi, and Dewi Amaliah. 2022. <span>“<span class="nocase">Current state and prospects of R-packages for the design of experiments</span>.”</span> arXiv. <a href="https://doi.org/10.48550/ARXIV.2206.07532">https://doi.org/10.48550/ARXIV.2206.07532</a>.
</div>
<div id="ref-Wickham2016-yg" class="csl-entry">
Wickham, Hadley. 2016. <em>Ggplot2: Elegant Graphics for Data Analysis</em>. Springer-Verlag New York.
</div>
<div id="ref-Wickham2019-mj" class="csl-entry">
Wickham, Hadley, Mara Averick, Jennifer Bryan, Winston Chang, Lucy D’agostino McGowan, Romain Francois, Garrett Grolemund, et al. 2019. <span>“Welcome to the Tidyverse.”</span> <em>Journal of Open Source Software</em> 4 (43): 1686.
</div>
<div id="ref-Wilkinson2005-oz" class="csl-entry">
Wilkinson, Leland. 2005. <em>The Grammar of Graphics</em>. 2nd ed. Springer.
</div>
</div></section></div> ]]></description>
  <guid>https://emitanaka.org/blog/2022-10-23-edibble-for-biometrics-bulletin/</guid>
  <pubDate>Sun, 11 Dec 2022 13:00:00 GMT</pubDate>
</item>
<item>
  <title>Affective colors in data visualisation</title>
  <dc:creator>Emi Tanaka</dc:creator>
  <link>https://emitanaka.org/blog/2022-10-15-affective-colors/</link>
  <description><![CDATA[ 

<!-- Title banner for blog posts (set in blog/_metadata.yml). Built from each
     post's front matter: title, date, author, categories, description and
     image (a pen sticker is shown when a post has no image). -->



<p><span class="citation" data-cites="Bartram2017-nd">Bartram, Patra, and Stone (2017)</span> conducted an experiment where participants were required to select 5 colors from a pool of available colors to make a <strong>5 color palette</strong> for a <strong>bar plot</strong> or <strong>map</strong> on a white background based on a set of emotive words, specifically “calm”, “disturbing”, “exciting”, “negative”, “playful”, “positive”, “serious” and “trustworthy”. The result of this experiment presented in their paper is shown in table below.</p>
<table class="caption-top table">
<thead>
<tr class="header">
<th>affect</th>
<th>frequency plot</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>calm</td>
<td><img src="https://emitanaka.org/blog/2022-10-15-affective-colors/calm.png" width="40%"></td>
</tr>
<tr class="even">
<td>disturbing</td>
<td><img src="https://emitanaka.org/blog/2022-10-15-affective-colors/disturbing.png" width="40%"></td>
</tr>
<tr class="odd">
<td>exciting</td>
<td><img src="https://emitanaka.org/blog/2022-10-15-affective-colors/exciting.png" width="40%"></td>
</tr>
<tr class="even">
<td>negative</td>
<td><img src="https://emitanaka.org/blog/2022-10-15-affective-colors/negative.png" width="40%"></td>
</tr>
<tr class="odd">
<td>playful</td>
<td><img src="https://emitanaka.org/blog/2022-10-15-affective-colors/playful.png" width="40%"></td>
</tr>
<tr class="even">
<td>positive</td>
<td><img src="https://emitanaka.org/blog/2022-10-15-affective-colors/positive.png" width="40%"></td>
</tr>
<tr class="odd">
<td>serious</td>
<td><img src="https://emitanaka.org/blog/2022-10-15-affective-colors/serious.png" width="40%"></td>
</tr>
<tr class="even">
<td>trustworthy</td>
<td><img src="https://emitanaka.org/blog/2022-10-15-affective-colors/trustworthy.png" width="40%"></td>
</tr>
</tbody>
</table>
<p>The paper is quite interesting but I actually couldn’t find the list of colors for each affect! So below is my simple analysis where I read in the image of the frequency plot, convert the colors to hex colors and remove white background to get the frequency of the colors. I plot then the top 10 colors for each affect.</p>
<div class="cell" data-hash="index_cache/html/setup_a7660e52d989f61dcf03b8079f06cac3">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(png)</span>
<span id="cb1-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># reads it as an 3d array where first two dimensions are</span></span>
<span id="cb1-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># the location on the image </span></span>
<span id="cb1-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># last dimension contains 4 columns which are r, g, b, alpha</span></span>
<span id="cb1-6">imgs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">calm =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">readPNG</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"calm.png"</span>),</span>
<span id="cb1-7">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">disturbing =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">readPNG</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"disturbing.png"</span>),</span>
<span id="cb1-8">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">exciting =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">readPNG</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"exciting.png"</span>),</span>
<span id="cb1-9">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">negative =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">readPNG</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"negative.png"</span>),</span>
<span id="cb1-10">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">playful =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">readPNG</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"playful.png"</span>),</span>
<span id="cb1-11">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">positive =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">readPNG</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"positive.png"</span>),</span>
<span id="cb1-12">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">serious =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">readPNG</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"serious.png"</span>),</span>
<span id="cb1-13">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trustworthy =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">readPNG</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"trustworthy.png"</span>))</span>
<span id="cb1-14"></span>
<span id="cb1-15">dims <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(imgs, dim)</span>
<span id="cb1-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># convert array to a matrix</span></span>
<span id="cb1-17">mats <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">imap</span>(imgs, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</span>(.x, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">prod</span>(dims[[.y]][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]), dims[[.y]][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>]))</span>
<span id="cb1-18"></span>
<span id="cb1-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># get the frequency of colors as a data frame</span></span>
<span id="cb1-20">colors <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">imap_dfr</span>(mats, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>{</span>
<span id="cb1-21">                  res <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rgb</span>(.x[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], .x[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>], .x[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>], .x[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>])</span>
<span id="cb1-22">                  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> res[res<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#FFFFFFFF"</span>]) </span>
<span id="cb1-23">                }, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.id =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"affect"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb1-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">count</span>(affect, color) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb1-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(affect) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb1-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prop =</span> n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n))</span></code></pre></div></div>
</div>
<div class="cell" data-hash="index_cache/html/plot-colors_6b0e9cd9f495bba243731658d244e76b">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">walk</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(imgs), <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>{</span>
<span id="cb2-2">  g <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> colors <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(affect <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> .x) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-4">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_max</span>(prop, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-5">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_reorder</span>(color, prop)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(prop, color)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-7">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">I</span>(color)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-8">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> .x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Proportion"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-9">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-10">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">14</span>),</span>
<span id="cb2-11">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.background =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(),</span>
<span id="cb2-12">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.grid.major.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>),</span>
<span id="cb2-13">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.ticks.length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mm"</span>))</span>
<span id="cb2-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(g)</span>
<span id="cb2-15">})</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-10-15-affective-colors/index_files/figure-html/plot-colors-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-10-15-affective-colors/index_files/figure-html/plot-colors-2.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-10-15-affective-colors/index_files/figure-html/plot-colors-3.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-10-15-affective-colors/index_files/figure-html/plot-colors-4.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-10-15-affective-colors/index_files/figure-html/plot-colors-5.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-10-15-affective-colors/index_files/figure-html/plot-colors-6.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-10-15-affective-colors/index_files/figure-html/plot-colors-7.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-10-15-affective-colors/index_files/figure-html/plot-colors-8.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>




<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-Bartram2017-nd" class="csl-entry">
Bartram, Lyn, Abhisekh Patra, and Maureen Stone. 2017. <span>“Affective Color in Visualization.”</span> In <em>Proceedings of the 2017 <span>CHI</span> Conference on Human Factors in Computing Systems</em>, 1364–74. CHI ’17. New York, NY, USA: Association for Computing Machinery. <a href="https://doi.org/10.1145/3025453.3026041">https://doi.org/10.1145/3025453.3026041</a>.
</div>
</div></section></div> ]]></description>
  <category>color</category>
  <guid>https://emitanaka.org/blog/2022-10-15-affective-colors/</guid>
  <pubDate>Fri, 14 Oct 2022 13:00:00 GMT</pubDate>
</item>
<item>
  <title>edibble experimental design with sensory discrimination tests</title>
  <dc:creator>Emi Tanaka</dc:creator>
  <link>https://emitanaka.org/blog/2022-03-27-sensory-discrimination-tests/sensory-discrimination-tests.html</link>
  <description><![CDATA[ 

<!-- Title banner for blog posts (set in blog/_metadata.yml). Built from each
     post's front matter: title, date, author, categories, description and
     image (a pen sticker is shown when a post has no image). -->



<p>This blog post attempts to describe the experimental design in <strong><span class="citation" data-cites="Williams2021-pa">Williams et al. (2021)</span></strong> for <strong>sensory discrimination test on vegemite</strong> using the <code>edibble</code> R package. Detailed descriptions are provided in <span class="citation" data-cites="Williams2021-pa">Williams et al. (2021)</span> and I only provide an abridged version in this blog, except where quoted.</p>
<p>First, I load the packages needed. The <code>edibble</code> package is currently only available on GitHub at https://github.com/emitanaka/edibble with plans to submit to <a href="https://cran.r-project.org/">CRAN</a> in the next couple of months.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(edibble)</span></code></pre></div></div>
</div>
<p><br></p>
<p>There are <strong>three types of sensory discrimination tests</strong> that are used by sensory scientists Drs Ciarán Forde and Patrick O’Riordan in an experiment <em><strong>to see if a story about an alternative to vegemite could sharpen the taste buds and improve the discriminative abilities of Australian consumers</strong></em>. The three sensory discrimination tests are as described below in <span class="citation" data-cites="Williams2021-pa">Williams et al. (2021)</span>:</p>
<blockquote class="blockquote">
<ol type="i">
<li>Triangle test. The consumer is presented with two samples of one product and one sample of the other and asked to pick the odd sample.</li>
<li>Paired preference test. The consumer is presented with a sample of the standard product and the alternative and asked ‘which sample do you prefer?’</li>
<li>Monadic ‘A not A’ test. Samples of the standard and alternative products are presented to the consumers in a sequential monadic order (one by one) and they are asked ‘is this your normal product?’</li>
</ol>
</blockquote>
<p>These test are abbreviated as T, PP, and M, respectively. The experimental structure is briefly summarised below:</p>
<ul>
<li>there are two versions of vegemite: normal (N) or spiked (S)</li>
<li>there are 168 consumers in total</li>
<li>half of the consumers tasted three pairs in the paired preference test and the other half tested two triplets in the triangle test</li>
<li>all consumers had six samples in the monadic test</li>
<li>experiment is conducted over 4 days</li>
<li>each consumer taste no more than 12 samples of vegemite</li>
<li>logistics allow only 42 consumers per day</li>
<li>cover story (or lack there of) is shown based on the day</li>
<li>the broad structure of the experiment is shown in Table @ref(tab:table1)</li>
</ul>
<div class="cell">
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<caption>From <span class="citation" data-cites="Williams2021-pa">Williams et al. (2021)</span>: broad structure of the vegemite experiment.</caption>
<thead>
<tr class="header">
<th style="text-align: left;">Day</th>
<th style="text-align: left;">1</th>
<th style="text-align: left;">2</th>
<th style="text-align: left;">3</th>
<th style="text-align: left;">4</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Cover story</td>
<td style="text-align: left;">no</td>
<td style="text-align: left;">no</td>
<td style="text-align: left;">yes</td>
<td style="text-align: left;">yes</td>
</tr>
<tr class="even">
<td style="text-align: left;">Test</td>
<td style="text-align: left;">T, M</td>
<td style="text-align: left;">PP, M</td>
<td style="text-align: left;">T, M</td>
<td style="text-align: left;">PP, M</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Consumer</td>
<td style="text-align: left;">1-42</td>
<td style="text-align: left;">43-84</td>
<td style="text-align: left;">85-126</td>
<td style="text-align: left;">127-168</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>The following is the experimental design description in <span class="citation" data-cites="Williams2021-pa">Williams et al. (2021)</span>:</p>
<blockquote class="blockquote">
<p>Within this structure a number of design features were introduced:</p>
<ol type="i">
<li>Test order. On each day half of the consumers took the sequence of monadic tests first and the other half after either the paired preference or triangle tests.</li>
<li>For the triangle test there are six possible triplets involving the two products (labelled N and S for normal and spiked vegemite respectively), namely: NNS, SNN, NSN, SSN, NSS and SNS. Two of these triplets were presented in sequence to each consumer and so an optimal row–column design was constructed for six treatments (triplets) in two rows (order of presentation) and 42 columns (consumers). The design generation package CycDesigN (http://www.vsni.co.uk/software/cycdesign/) was used to construct the layout. Furthermore the grouping option of the package was employed to ensure that each consumer sampled each product three times, that is, if the consumer received a triplet with two of the normal vegemite then the second triplet would contain two of the spiked vegemite. Separate randomisations of the design were used for 2 days.</li>
<li>For the paired preference test the normal vegemite in a pair can be presented either first or second. Hence an optimal row–column design was constructed for two treatments (pair order) in three rows (order of presentation) and 42 columns (consumers). Separate randomisations of the design were used for 2 days.</li>
<li>For the monadic test the six samples, three of each product (normal and spiked), were presented in a different sequential order to each consumer and so there was the chance to study the possibility of carryover effects from successive samples. CycDesigN was used to construct an optimal crossover design for two treatments (product type) in six periods (order of presentation) and 42 subjects (consumers). Separate randomisations of the design were used for 4 days.</li>
</ol>
</blockquote>
<section id="test-order" class="level2">
<h2 class="anchored" data-anchor-id="test-order">Test order</h2>
<blockquote class="blockquote">
<p>On each day half of the consumers took the sequence of monadic tests first and the other half after either the paired preference or triangle tests.</p>
</blockquote>
<p>Recall:</p>
<ul>
<li>experiment is conducted over 4 days</li>
<li>logistics allow only 42 consumers per day</li>
<li>cover story (or lack there of) is shown based on the day</li>
</ul>
<p>At first I couldn’t tell whether the cover story and the sensory tests (T and PP) were randomised or in systematic order, but in my communication with Emlyn Williams, he let me know it was randomised.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb2-2">des1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">design</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sensory evalution"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_units</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">day =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb2-4">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">consumer =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nested_in</span>(day, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">42</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_trts</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cover_story =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"yes"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"no"</span>),</span>
<span id="cb2-6">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">test =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"T,M"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PP,M"</span>),</span>
<span id="cb2-7">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">test_first =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"T/PP"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"M"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">allot_table</span>(test<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>cover_story <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> day,</span>
<span id="cb2-9">                    test_first <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> consumer)</span>
<span id="cb2-10"></span>
<span id="cb2-11"></span>
<span id="cb2-12">des1</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code># sensory evalution 
# An edibble: 168 x 5
         day    consumer cover_story     test test_first
   &lt;unit(4)&gt; &lt;unit(168)&gt;    &lt;trt(2)&gt; &lt;trt(2)&gt;   &lt;trt(2)&gt;
 1      day1  consumer1          yes      T,M       T/PP
 2      day1  consumer2          yes      T,M       M   
 3      day1  consumer3          yes      T,M       T/PP
 4      day1  consumer4          yes      T,M       T/PP
 5      day1  consumer5          yes      T,M       T/PP
 6      day1  consumer6          yes      T,M       M   
 7      day1  consumer7          yes      T,M       T/PP
 8      day1  consumer8          yes      T,M       M   
 9      day1  consumer9          yes      T,M       M   
10      day1  consumer10         yes      T,M       M   
# … with 158 more rows
# ℹ Use `print(n = ...)` to see more rows</code></pre>
</div>
</div>
<p>You can check the allocation of the cover story and test by nesting it by day:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">des1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nest_by</span>(day, cover_story, test)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 4 × 4
# Rowwise:  day, cover_story, test
        day cover_story     test               data
  &lt;unit(4)&gt;    &lt;trt(2)&gt; &lt;trt(2)&gt; &lt;list&lt;tibble[,2]&gt;&gt;
1      day1         yes     T,M            [42 × 2]
2      day2         no      PP,M           [42 × 2]
3      day3         yes     PP,M           [42 × 2]
4      day4         no      T,M            [42 × 2]</code></pre>
</div>
</div>
</section>
<section id="triangle-test" class="level2">
<h2 class="anchored" data-anchor-id="triangle-test">Triangle test</h2>
<blockquote class="blockquote">
For the triangle test there are six possible triplets involving the two products (labelled N and S for normal and spiked vegemite respectively), namely: NNS, SNN, NSN, SSN, NSS and SNS. Two of these triplets were presented in sequence to each consumer and so an optimal row–column design was constructed for six treatments (triplets) in two rows (order of presentation) and 42 columns (consumers)… if the consumer received a triplet with two of the normal vegemite then the second triplet would contain two of the spiked vegemite. Separate randomisations of the design were used for 2 days.
</blockquote>
<p>Recall:</p>
<ul>
<li>each consumer taste no more than 12 samples of vegemite</li>
<li>logistics allow only 42 consumers per day</li>
</ul>
<p>As every consumer also does the monadic test which uses 6 samples, only 6 samples remain for the triangle test. The product lineups took me a while to figure it out – the part that tripped me up was that the two lineups (out of NNS, SNN, NSN, SSN, NSS and SNS) that was presented to the consumer sequentially had to have the major product swapped, so you can’t choose something like NNS and NSN because both lineups have the major product as N. This precludes from just two random selections from NNS, SNN, NSN, SSN, NSS and SNS, and requires a conditional randomisation.</p>
<p>I decided to think of this as a two step process:</p>
<ol type="1">
<li>choose the main product, and</li>
<li>choose out of the sequences XXO, XOX and OXX where X denotes the major product.</li>
</ol>
<p>Since the product lineup is nested within the consumer, the major product allocation in <code>edibble</code> below automatically treats <code>consumer</code> as a block and in the assignment, it will try to ensure the major product is different in the two lineups for each consumer.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">des2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">design</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"triangle test"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb6-2">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_units</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">day =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>),</span>
<span id="cb6-3">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">consumer =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nested_in</span>(day, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">42</span>),</span>
<span id="cb6-4">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">product_lineup =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nested_in</span>(consumer, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb6-5">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_trts</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">major_product =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"spiked"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"normal"</span>),</span>
<span id="cb6-6">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sequence =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"XXO"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"XOX"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"OXX"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb6-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">allot_table</span>(major_product <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> product_lineup,</span>
<span id="cb6-8">                     sequence <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> product_lineup)</span>
<span id="cb6-9"></span>
<span id="cb6-10">des2</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code># triangle test 
# An edibble: 168 x 5
         day   consumer   product_lineup major_product sequence
   &lt;unit(2)&gt; &lt;unit(84)&gt;      &lt;unit(168)&gt;      &lt;trt(2)&gt; &lt;trt(3)&gt;
 1         1  consumer1 product_lineup1         normal      XOX
 2         1  consumer1 product_lineup2         spiked      OXX
 3         1  consumer2 product_lineup3         normal      XOX
 4         1  consumer2 product_lineup4         spiked      OXX
 5         1  consumer3 product_lineup5         normal      XXO
 6         1  consumer3 product_lineup6         spiked      XOX
 7         1  consumer4 product_lineup7         spiked      XXO
 8         1  consumer4 product_lineup8         normal      XOX
 9         1  consumer5 product_lineup9         normal      OXX
10         1  consumer5 product_lineup10        spiked      XOX
# … with 158 more rows
# ℹ Use `print(n = ...)` to see more rows</code></pre>
</div>
</div>
<p>I could alternatively design the above as a row-column design.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1">des2alt <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">design</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"triangle test"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-2">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_units</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">day =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>),</span>
<span id="cb8-3">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">consumer =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nested_in</span>(day, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">42</span>),</span>
<span id="cb8-4">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb8-5">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">product_lineup =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">crossed_by</span>(consumer, order)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_trts</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">major_product =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"spiked"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"normal"</span>),</span>
<span id="cb8-7">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sequence =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"XXO"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"XOX"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"OXX"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-8">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">allot_table</span>(major_product <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> product_lineup,</span>
<span id="cb8-9">                     sequence <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> product_lineup)</span>
<span id="cb8-10"></span>
<span id="cb8-11">deggust<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">autoplot</span>(des2alt)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-03-27-sensory-discrimination-tests/sensory-discrimination-tests_files/figure-html/des2alt-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="paired-test" class="level2">
<h2 class="anchored" data-anchor-id="paired-test">Paired test</h2>
<blockquote class="blockquote">
For the paired preference test the normal vegemite in a pair can be presented either first or second. Hence an optimal row–column design was constructed for two treatments (pair order) in three rows (order of presentation) and 42 columns (consumers). Separate randomisations of the design were used for 2 days.
</blockquote>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">des3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">design</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"paired test"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb9-2">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_units</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">day =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>),</span>
<span id="cb9-3">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">consumer =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nested_in</span>(day, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">42</span>),</span>
<span id="cb9-4">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,</span>
<span id="cb9-5">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">product_lineup =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">crossed_by</span>(consumer, order)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb9-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_trts</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">product_order =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SN"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NS"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb9-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">allot_table</span>(product_order <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> product_lineup)</span>
<span id="cb9-8"></span>
<span id="cb9-9">deggust<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">autoplot</span>(des3)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-03-27-sensory-discrimination-tests/sensory-discrimination-tests_files/figure-html/des3-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="monadic-test" class="level2">
<h2 class="anchored" data-anchor-id="monadic-test">Monadic test</h2>
<blockquote class="blockquote">
For the monadic test the six samples, three of each product (normal and spiked), were presented in a different sequential order to each consumer and so there was the chance to study the possibility of carryover effects from successive samples.
</blockquote>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1">des4 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">design</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"monadic test"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-2">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_units</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">day =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb10-3">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">consumer =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nested_in</span>(day, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">42</span>),</span>
<span id="cb10-4">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>,</span>
<span id="cb10-5">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">product_lineup =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">crossed_by</span>(consumer, order)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_trts</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">product =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"spiked"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"normal"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">allot_table</span>(product <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> product_lineup)</span>
<span id="cb10-8"></span>
<span id="cb10-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">deggust.nnode_max =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>)</span>
<span id="cb10-10">deggust<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">autoplot</span>(des4)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-03-27-sensory-discrimination-tests/sensory-discrimination-tests_files/figure-html/des4-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="conclusion" class="level2">
<h2 class="anchored" data-anchor-id="conclusion">Conclusion</h2>
<p>So you might be wondering if Australians can indeed distinguish the true taste of vegemite? Well this blog post is not about the analysis but the experimental design. A short analysis is provided, however, in <span class="citation" data-cites="Williams2021-pa">Williams et al. (2021)</span> … and the answer is yes Australians knows their vegemite 😉</p>
</section>
<section id="acknowldegement" class="level2">
<h2 class="anchored" data-anchor-id="acknowldegement">Acknowldegement</h2>
<p>I want to thank Emyln for being so prompt in answering my questions about this experiment and providing the data (which I didn’t end up using in this blog post), that was mistakenly missing in the initial publication but <a href="https://onlinelibrary.wiley.com/doi/10.1111/anzs.12364">available now on the website</a>.</p>



</section>

<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-Williams2021-pa" class="csl-entry">
Williams, E R, C G Forde, J Imaki, and K Oelkers. 2021. <span>“Experimental Design in Practice: The Importance of Blocking and Treatment Structures.”</span> <em>Australian &amp; New Zealand Journal of Statistics</em> 63 (3): 455–67. <a href="https://doi.org/10.1111/anzs.12343">https://doi.org/10.1111/anzs.12343</a>.
</div>
</div></section></div> ]]></description>
  <category>R</category>
  <category>experimental design</category>
  <category>edibble</category>
  <guid>https://emitanaka.org/blog/2022-03-27-sensory-discrimination-tests/sensory-discrimination-tests.html</guid>
  <pubDate>Fri, 29 Jul 2022 14:00:00 GMT</pubDate>
</item>
<item>
  <title>How to transition from xaringan to Quarto revealjs</title>
  <dc:creator>Emi Tanaka</dc:creator>
  <link>https://emitanaka.org/blog/2022-07-11-transitioning-from-xaringan-to-quarto-revealjs/transitioning-from-xaringan-to-quarto-revealjs.html</link>
  <description><![CDATA[ 

<!-- Title banner for blog posts (set in blog/_metadata.yml). Built from each
     post's front matter: title, date, author, categories, description and
     image (a pen sticker is shown when a post has no image). -->



<div class="cell">
<style type="text/css">
.revealjs, .xaringan {
 padding: 5px;
 font-size: 0.5em;
 border-radius: 10px;
 background-color: #006DAE;
 color: white;
}
.xaringan {
  background-color: #D93F00;
}
</style>
</div>
<section id="background" class="level1">
<h1>Background</h1>
<p>I first used the <a href="https://slides.yihui.org/xaringan/#1"><code>xaringan</code></a> R-package to make HTML slides in late 2016 when I saw <a href="https://twitter.com/xieyihui/status/808418548829847552">Yihui’s tweet</a> about it. It wasn’t until the beginning of 2018 that I fully switched from Beamer/Powerpoint/Keynote<sup>1</sup> presentation slides to using <code>xaringan</code>. Four years later, after over 120 <code>xaringan</code> slides<sup>2</sup> plus making a <a href="https://github.com/emitanaka/ninja-theme">whole theme</a> for it, I started using <a href="https://quarto.org/docs/presentations/revealjs/">Quarto revealjs slides</a> instead from the start of 2022. So far I’ve given 5 talks with Quarto revealjs slides and I’m using it to make slides for the foreseeable future.</p>
</section>
<section id="why" class="level1">
<h1>Why?</h1>
<p>Unlike reports or other documents with statistical outputs, I’m not really fussed about what technology people use to make their slides – the content and how you deliver it are far more important really – so don’t feel like you have to adopt these technology yourself. I for one won’t be judging you if you present a powerpoint slide, although if you do data analysis in Excel, we probably can’t be good friends<sup>3</sup>.</p>
<p><strong>Why HTML slides</strong></p>
<p>HTML slides really shine when you have animation or interactive content. From a philosophical view though, customising HTML slides requires you to know HTML, CSS, and/or JS, so after doing this process so many times, I’ve come to be better in HTML/CSS/JS. Making lots of HTML slides doesn’t guarantee you to become a good front-end web developer of course – you still have to study, think and reflect to develop your front-end web dev skills.</p>
<p><strong>Why Quarto revealjs slides</strong></p>
<p><code>xaringan</code> is actually using <a href="https://github.com/gnab/remark">remark.js</a> to render the slides. The development of remark.js started to become stagnant from about 2018, with the main author not as actively working on it. In the meanwhile, reveal.js had an expanding, active community with some fancy features. The <code>revealjs</code> R-package that ported reveal.js to Rmd, however, was clunky to do any serious customisation. I chose to use <code>xaringan</code> instead because customisation was more straight-forward, but the primary reason was that the main author Yihui was developing it.</p>
<p>So why switch over to Quarto revealjs slides now? For me, this is because the Quarto team did a serious job implementing it and I figured out most of the equivalent features in <code>xaringan</code> for it. I share these below.</p>
</section>
<section id="features" class="level1">
<h1>Features</h1>
<section id="making-your-own-title-slide" class="level2">
<h2 class="anchored" data-anchor-id="making-your-own-title-slide">Making your own title slide</h2>
<p>Both <code>xaringan</code> and Quarto revealjs slides create a default title slide if you supply the <code>title</code> in the YAML.</p>
<p><span class="xaringan">xaringan</span></p>
<p>In <code>xaringan</code>, you can disable this by using <code>seal: false</code>.</p>
<p><span class="revealjs">Quarto revealjs</span></p>
<p>For Quarto revealjs, replace the <code>title:</code> with <code>pagetitle:</code> in the YAML or alternatively do not include <code>title</code> in the YAML. The benefit of the former approach is that the metadata for the title is automatically created for you in the HTML output.</p>
<pre><code>---
pagetitle: "My title"
---</code></pre>
</section>
<section id="starting-a-new-slide" class="level2">
<h2 class="anchored" data-anchor-id="starting-a-new-slide">Starting a new slide</h2>
<p><span class="xaringan">xaringan</span></p>
<p>In <code>xaringan</code>, a new slide is started by separating the content with <code>---</code> in a new line where care needs to be taken <em>not</em> to have spaces after it.</p>
<p><span class="revealjs">Quarto revealjs</span></p>
<p>In Quarto revealjs slides, there are two primary ways to start a new slide:</p>
<ol type="1">
<li><code>---</code> just like in <code>xaringan</code> and</li>
<li>a first or second level header, i.e.&nbsp;a line starting with <code>#</code> or <code>##</code>.</li>
</ol>
</section>
<section id="shortcut-for-div-and-span-with-css-classes" class="level2">
<h2 class="anchored" data-anchor-id="shortcut-for-div-and-span-with-css-classes">Shortcut for div and span with CSS classes</h2>
<p><span class="xaringan">xaringan</span></p>
<p>In <code>xaringan</code>, div element with content, say “My content.”, and CSS class, say <code>myclass</code>, are created with</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode md code-with-copy"><code class="sourceCode markdown"><span id="cb2-1">.myclass[</span>
<span id="cb2-2">My content.</span>
<span id="cb2-3">]</span></code></pre></div></div>
<p>The above when processed by remark.js becomes:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode html code-with-copy"><code class="sourceCode html"><span id="cb3-1"><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&lt;</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">div</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;"> class</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"myclass"</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&gt;</span></span>
<span id="cb3-2">My content.</span>
<span id="cb3-3"><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&lt;/</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">div</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&gt;</span></span></code></pre></div></div>
<p>Similary for span element, the shortcut in <code>xaringan</code> is:</p>
<pre><code>.myclass[My content.]</code></pre>
<p>which becomes</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode html code-with-copy"><code class="sourceCode html"><span id="cb5-1"><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&lt;</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">span</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;"> class</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"myclass"</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&gt;</span>My content.<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&lt;/</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">span</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&gt;</span></span></code></pre></div></div>
<p>The difference between the two being that there is a new line required before the <code>]</code> for the div element.</p>
<p><span class="revealjs">Quarto revealjs</span></p>
<p>In Quarto revealjs slides, the shortcut for the div and span elements are (I believe) from <a href="https://pandoc.org/MANUAL.html#divs-and-spans">native Pandoc divs and spans</a>. This was actually one of the biggest reasons I wanted to switch from <code>xaringan</code>. All Rmd documents support Pandoc divs and spans <strong><em>except</em></strong> in <code>xaringan</code> where the markdown content is processed by remark.js instead of Pandoc. The lack of consistency even made me write <a href="https://emitanaka.org/slides/ISIWSC2019/assets/pandoc.js">my own naive javascript to mimic Pandoc div and span</a> for <code>xaringan</code>, but I still wanted the native support.</p>
<p>So you can create a div element in Quarto revealjs by:</p>
<pre><code>::: myclass

My content.

:::</code></pre>
<p>or equivalently,</p>
<pre><code>::: {.myclass}

My content.

:::</code></pre>
<p>In fact, it’s not limited to CSS classes but ids as well. E.g.</p>
<pre><code>::: {#myid}

My content.

:::</code></pre>
<p>is the same as</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode html code-with-copy"><code class="sourceCode html"><span id="cb9-1"><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&lt;</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">div</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;"> id</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"myid"</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&gt;</span></span>
<span id="cb9-2">My content.</span>
<span id="cb9-3"><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&lt;/</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">div</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&gt;</span></span></code></pre></div></div>
<p>For a span element in Quarto revealjs, it will be like below</p>
<pre><code>[My content.]{.myclass}</code></pre>
<p>where this is equivalent to below:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode html code-with-copy"><code class="sourceCode html"><span id="cb11-1"><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&lt;</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">span</span><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;"> class</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"myclass"</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&gt;</span>My content.<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&lt;/</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">span</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">&gt;</span></span></code></pre></div></div>
</section>
<section id="slide-css-classes" class="level2">
<h2 class="anchored" data-anchor-id="slide-css-classes">Slide CSS classes</h2>
<p><span class="xaringan">xaringan</span></p>
<p>In <code>xaringan</code>, a CSS class maybe specified to the <em>whole</em> slide by:</p>
<pre><code>class: myclass</code></pre>
<p>I used this sometimes to define a slide with different background colors.</p>
<p><span class="revealjs">Quarto revealjs</span></p>
<p>The HTML layout for revealjs slides is actually quite different to the layout for remarkjs slides. I won’t go into too much details this time, but the main thing is that a slide content is written within <code>&lt;section&gt;&lt;/section&gt;</code> and separate to this is a background element and other div (like footer and slide numbers). The latter elements are not nested within the slide itself, which makes the concept of applying the CSS class to the <em>whole</em> slide different in revealjs compared to <code>xaringan</code>/remarkjs.</p>
<p>To apply a CSS class to a slide with no title, you can do below:</p>
<pre><code>## {.myclass}</code></pre>
<p>and if you have a title, just write the title first before defining the class like below:</p>
<pre><code>## My title {.myclass}</code></pre>
<p>If you want to apply it to the <em>slide background</em> then only specific attributes work, e.g.&nbsp;below changes the background color of the slide to red:</p>
<pre><code>## {background-color="red"}</code></pre>
</section>
<section id="columns" class="level2">
<h2 class="anchored" data-anchor-id="columns">Columns</h2>
<p><span class="xaringan">xaringan</span></p>
<p>If you used the default <code>xaringan</code>, you may have used <code>.left[]</code> and <code>.right[]</code> to make two columns. These actually are setting the attributes of the elements to <code>float: left;</code> and <code>float:right;</code>, respectively, with <code>width: 48%;</code>.</p>
<p><span class="revealjs">Quarto revealjs</span></p>
<p>For multiple columns in Quarto revealjs, you can set something like below to make two columns, one with 40% width and the other with 60% width.</p>
<pre><code>:::: {.columns}

::: {.column width="40%"}
Left column
:::

::: {.column width="60%"}
Right column
:::

::::</code></pre>
<p>You can find more details <a href="https://quarto.org/docs/presentations/revealjs/#multiple-columns">here</a>.</p>
</section>
<section id="incremental-slides" class="level2">
<h2 class="anchored" data-anchor-id="incremental-slides">Incremental slides</h2>
<p>By incremental slides, I mean slides where you want to reveal the content of slide one at a time without rewriting separate slides with the same past content.</p>
<p><span class="xaringan">xaringan</span></p>
<p>In <code>xaringan</code>, you can use <code>--</code>. You can also use <code>{content}</code> to specify where the new content after <code>--</code> will be inserted. E.g.</p>
<pre><code>Slide 1 

--

{{content}}

This content will only appear in next slide below "Slide 1".

--

This content will appear on top of the last sentence but below "Slide 1".
</code></pre>
<p><span class="revealjs">Quarto revealjs</span></p>
<p>The <code>--</code> in <code>xaringan</code> is the same as the <code>. . .</code> (three dots separated by spaces) in Quarto revealjs.</p>
<pre><code>
Slide 1 

First content

. . . 

Second content after pause
</code></pre>
<p>A similar feat to <code>{content}</code> in <code>xaringan</code> can be achieved by using <a href="https://quarto.org/docs/presentations/revealjs/advanced.html#fragments">fragments</a> in Quarto revealjs, like below:</p>
<pre><code>
Slide 1 

::: {.fragment fragment-index=2}
This content will appear on top of the last sentence but below "Slide 1".
:::

::: {.fragment fragment-index=1}
This content will only appear in next slide below "Slide 1".
:::
</code></pre>
<p>You can find more details <a href="https://quarto.org/docs/presentations/revealjs/advanced.html#fragments">here</a> but the basic idea is that any HTML elements that have the class “fragment” will be incrementally shown and you can control the sequence of appearance by specifying the number for the attribute in <code>fragment-index</code>.</p>
<p>This is of course painful to do if you have a list! For this, there is a special case where incremental lists can be specified by class “incremental” like below:</p>
<pre><code>::: {.incremental}
- Task A
- Task B
:::</code></pre>
<p>More details on incremental list can be found <a href="https://quarto.org/docs/presentations/revealjs/#incremental-lists">here</a>.</p>
</section>
<section id="slide-names" class="level2">
<h2 class="anchored" data-anchor-id="slide-names">Slide names</h2>
<p><span class="xaringan">xaringan</span></p>
<p>In <code>xaringan</code>, you can use the <code>name: myname</code> to set slide names which can then be referenced in other parts of the slides by say <code>[see here](#myname)</code>.</p>
<p><span class="revealjs">Quarto revealjs</span></p>
<p>In Quarto revealjs, slides automatically have names that are transformed versions of the slide title (spaces replaced with <code>-</code>, lower cases, etc). But if you want to apply a custom name then you can pass define the attribute in the top level header of the slide:</p>
<pre><code>## Slide Title {#myname}</code></pre>
</section>
<section id="uncounted-slides" class="level2">
<h2 class="anchored" data-anchor-id="uncounted-slides">Uncounted slides</h2>
<p><span class="xaringan">xaringan</span></p>
<p>You can use <code>count: false</code> to not increment the slide number for particular slides.</p>
<p><span class="revealjs">Quarto revealjs</span></p>
<p>In Quarto revealjs, you can choose to not count the slide by setting <code>visibility="uncounted"</code> in the top level header:</p>
<pre><code>## Slide Title {visibility="uncounted"}</code></pre>
</section>
<section id="exclude-slides" class="level2">
<h2 class="anchored" data-anchor-id="exclude-slides">Exclude slides</h2>
<p><span class="xaringan">xaringan</span></p>
<p>You can use <code>exclude: true</code> to not increment the slide number for particular slides.</p>
<p><span class="revealjs">Quarto revealjs</span></p>
<p>In Quarto revealjs, you can specify the attribute <code>visibility="hidden"</code> in the top level header for the slide:</p>
<pre><code>## Slide Title {visibility="hidden"}</code></pre>
</section>
<section id="layouts-and-templates" class="level2">
<h2 class="anchored" data-anchor-id="layouts-and-templates">Layouts and templates</h2>
<p>The <code>layout</code> and <code>template</code> feature allowed you to use the same layout in subsequent slides in <code>xaringan</code>/remark.js. I don’t think there is an equivalent feature in Quarto revealjs for this.</p>


</section>
</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>I was never an <code>ioslides</code> or <code>revealjs</code> person (I have tried it but I didn’t like it)↩︎</p></li>
<li id="fn2"><p>Okay, I was surprised to count over 120 presentations but this includes all teaching slides too.↩︎</p></li>
<li id="fn3"><p>exceptions apply to my family and existing friends↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>Quarto</category>
  <category>xaringan</category>
  <category>revealjs</category>
  <category>remarkjs</category>
  <guid>https://emitanaka.org/blog/2022-07-11-transitioning-from-xaringan-to-quarto-revealjs/transitioning-from-xaringan-to-quarto-revealjs.html</guid>
  <pubDate>Sun, 10 Jul 2022 14:00:00 GMT</pubDate>
</item>
<item>
  <title>Academic ranks</title>
  <dc:creator>Emi Tanaka</dc:creator>
  <link>https://emitanaka.org/blog/2022-06-30-academic-ranks/academic-ranks.html</link>
  <description><![CDATA[ 

<!-- Title banner for blog posts (set in blog/_metadata.yml). Built from each
     post's front matter: title, date, author, categories, description and
     image (a pen sticker is shown when a post has no image). -->



<table class="caption-top table">
<colgroup>
<col style="width: 20%">
<col style="width: 20%">
<col style="width: 20%">
<col style="width: 20%">
<col style="width: 20%">
</colgroup>
<thead>
<tr class="header">
<th>Australia</th>
<th>Australia<br> (Research focussed)</th>
<th>New Zealand</th>
<th>North America</th>
<th>UK</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Associate Lecturer</td>
<td>Research Associate</td>
<td></td>
<td></td>
<td>Assistant Lecturer</td>
</tr>
<tr class="even">
<td>Lecturer</td>
<td>Research Fellow</td>
<td>Lecturer</td>
<td>Assistant Professor</td>
<td>Lecturer</td>
</tr>
<tr class="odd">
<td>Senior Lecturer</td>
<td>Senior Research Fellow</td>
<td>Senior Lecturer<br> (+over the bar)</td>
<td>Associate Professor</td>
<td>Senior Lecturer</td>
</tr>
<tr class="even">
<td>Associate Professor</td>
<td>Principal Research Fellow</td>
<td>Associate Professor</td>
<td>Professor</td>
<td>Reader/Principal Lecturer</td>
</tr>
<tr class="odd">
<td>Professor</td>
<td>Professor</td>
<td>Professor</td>
<td>Distinguished/Endowed Professor</td>
<td>Professor</td>
</tr>
</tbody>
</table>
<p>Information taken from these wikipedia articles: <a href="https://en.wikipedia.org/wiki/Academic_ranks_(Australia_and_New_Zealand)">Academic ranks in Australian and New Zealand</a> and <a href="https://en.wikipedia.org/wiki/Academic_ranks_in_the_United_Kingdom">Academic ranks in UK</a>.</p>



 ]]></description>
  <guid>https://emitanaka.org/blog/2022-06-30-academic-ranks/academic-ranks.html</guid>
  <pubDate>Wed, 29 Jun 2022 14:00:00 GMT</pubDate>
</item>
<item>
  <title>To new beginnings</title>
  <dc:creator>Emi Tanaka</dc:creator>
  <link>https://emitanaka.org/blog/2022-04-27-new-beginnings/new-beginnings.html</link>
  <description><![CDATA[ 

<!-- Title banner for blog posts (set in blog/_metadata.yml). Built from each
     post's front matter: title, date, author, categories, description and
     image (a pen sticker is shown when a post has no image). -->



<p>After being office-less for 10 days (technically 4 days not counting public holidays and weekends), many of us in the Menzies building have safely moved yesterday to our temporary offices in Building 6 while Menzies undergo renovations for the next 2+ years (anyone wanna bet it’ll take more than 2 years or not?).</p>
<p>My old office had a pretty nice view of the hex wall but I don’t know where it is now. Last I saw it was clearly labelled to be moved to level 3 corridors but maybe it’s yet to be moved. Impressively, they did manage to bring my big and small whiteboard as well as the large corkboard in my old office – now it just needs to be hanged and I need to figure out where the whiteboard markers are stored.</p>
<blockquote class="twitter-tweet blockquote">
<p lang="en" dir="ltr">
You should check out the view of the corridor from my office ;) <a href="https://t.co/8L0fCf6F0P">pic.twitter.com/8L0fCf6F0P</a>
</p>
— Emi Tanaka (田中愛美) 💉💉💉 (<span class="citation" data-cites="statsgen">(<strong>statsgen?</strong>)</span>) <a href="https://twitter.com/statsgen/status/1289475572347703296?ref_src=twsrc%5Etfw">August 1, 2020</a>
</blockquote>
<script async="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<p>While that’s happening, in the weekends I saw some twitter posts (yet again) about shade against academia. The specific post was referring to the lower pay in academia and said in industry there’s no penalty in walking away from a job with bad work culture (insinuating that’s not the case in academia). Give it another week or so, I’m sure I’ll see another post against the academic culture, a #quitlit post or how great an industry position is.</p>
<p>Based on the frequency you see these posts, you’d think academia is an awful place. It’s also not hard to find people who’ll affirm your belief. Then why do people stay in academia? There’s one reason I hear quite often – they get <em>freedom</em>. That answer always remind me of a page from this book I saw years ago – this page still makes me laugh 😂</p>
<p><img src="https://emitanaka.org/blog/2022-04-27-new-beginnings/free-will.png" alt="As you journey along the path you meet an old man. He tells you that modern neuroscience has proved that all our actions and decisions are merely the machinations of a predetermined universe and that our concept of 'free will' is naught but a comforting illusion. If you agree with his hypothesis, turn to page 72. If you disagree, turn to page 72."></p>
<p>There’s a well known experimental study by <span class="citation" data-cites="Festinger1959-op">L. Festinger and Carlsmith (1959)</span> that studied subjects that had to do repetitive, monotonous tasks and was told to lie to the next “subject” (actually a hired accomplice) that the task was interesting and enjoyable. Some subjects were paid $1 for lying while others were paid $20. There was a control group that didn’t have to lie. There were 20 subjects in each of the three groups. After the task, each subject was asked to rate (on a scale of -5 to +5 where -5 is dislike, and +5 is like) how much they enjoyed the tasks. The subjects that were paid $1 reported on average a higher level of enjoyment (1.35) than subjects who were paid $20 (-0.50); the average level of enjoyment for control group was -0.45.</p>
<p>The results aligned with the <strong>theory of cognitive dissonance</strong> by <span class="citation" data-cites="Festinger1957">Leon Festinger (1957)</span>, which suggests that we have an inner drive to hold our cognitive elements (attitudes, perceptions, knowledge and beliefs) in harmony and we feel discomfort when some of these elements are inconsistent. The study by <span class="citation" data-cites="Festinger1959-op">L. Festinger and Carlsmith (1959)</span> suggested that people who were paid $1 to lie felt they had to justify the poor payment by convincing themselves that they actually enjoyed the task, while those that were paid $20 were well rewarded and did not experience cognitive dissonance.</p>
<p>The experimental result in <span class="citation" data-cites="Festinger1959-op">L. Festinger and Carlsmith (1959)</span> reminded me of the often touted reason where industry is better than academia: money, and the academics that give reasons of why they stay in academia, despite the lower pay. If you are an academic, did you really choose to be in academia for some higher purpose? Or do you just stay because we tend to succumb to inertia and that was the path of least resistance? I tend to be skeptical of any rosy picture that either side presents. I don’t deny though that I get affected by the strong emotions that people display against academia – more so, because I know some comments are true – <em>academic culture and system needs to improve</em> – but the eternal question is who’s going to champion the change? The way I see it, it’s a collective responsibility so everyone should contribute to make it a better place, with more responsibility on those in higher echelon.</p>
<p>Reality is complex and as any job, academic job is a mix of good, bad, joy, and tediuous. Sometimes it’s just the small acts of people around that consider your best interest at heart – see you as a person and not an expendable tool – that makes it worthwhile even if the system doesn’t work for you. I can’t say academia is bad when my colleague is considerate of me, telling me of a pathway so I can get a bigger office, and another colleague allocating himself the smaller office so a large office can be allocated to someone else (despite himself being a former head of department and a professor). There are some bad apples of course, but plenty of good people in academia.</p>
<p>If a workplace culture is bad or it’s not working well for you though, by all means walk away – maybe giving a reasonable chance to see if people take actions to rectify the issues first. In my relatively short career, I’ve butted heads a number of times already (concidentally all professors – yeah, I’m harder on people with power because I expect better of them) so I won’t be surprised a number of people dislike me, but also at the same time, I know there are plenty of people that appreciate me for my conduct and contributions. If anything, it’s the difficult times that can be revealing of character and bring people together. It’s always the people’s conduct that make the workplace great or not – or at least bearable.</p>




<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-Festinger1959-op" class="csl-entry">
Festinger, L, and J M Carlsmith. 1959. <span>“Cognitive Consequences of Forced Compliance.”</span> <em>Journal of Abnormal Psychology</em> 58 (2): 203–10. <a href="https://doi.org/10.1037/h0041593">https://doi.org/10.1037/h0041593</a>.
</div>
<div id="ref-Festinger1957" class="csl-entry">
Festinger, Leon. 1957. <span>“A Theory of Cognitive Dissonance.”</span>
</div>
</div></section></div> ]]></description>
  <category>life</category>
  <guid>https://emitanaka.org/blog/2022-04-27-new-beginnings/new-beginnings.html</guid>
  <pubDate>Tue, 26 Apr 2022 14:00:00 GMT</pubDate>
</item>
<item>
  <title>Maximum potential</title>
  <dc:creator>Emi Tanaka</dc:creator>
  <link>https://emitanaka.org/blog/2022-03-12-maximum-potential/maximum-potential.html</link>
  <description><![CDATA[ 

<!-- Title banner for blog posts (set in blog/_metadata.yml). Built from each
     post's front matter: title, date, author, categories, description and
     image (a pen sticker is shown when a post has no image). -->



<p>When I read books, I almost exclusively read non-fiction books only. One of the books that left a strong impression on me is “Outliers” by the journalist, Malcolm Gladwell, that I read back in 2016. The name of the book sound awfully statistical but it’s definitely not like the statistic journal articles I read.</p>
<section id="ice-hockey-talent" class="level3 page-columns page-full">
<h3 class="anchored" data-anchor-id="ice-hockey-talent">Ice hockey talent</h3>
<p>In the beginning of the book, Gladwell presents a hockey player roster shown in Table @ref(tab:hat-tigers). He asks to take a closer look at this roster. <strong>Do you notice anything strange about the list?</strong></p>
<div class="cell">
<div class="cell-output-display">
<table class="lightable-classic caption-top table table-sm table-striped small">
<caption>The player roster of the 2007 Medicine Hat Tigers (a Canadian hockey team). Do you notice anything unusual?</caption>
<thead>
<tr class="header">
<th style="text-align: right;" data-quarto-table-cell-role="th">No</th>
<th style="text-align: left;" data-quarto-table-cell-role="th">Name</th>
<th style="text-align: left;" data-quarto-table-cell-role="th">Pos</th>
<th style="text-align: left;" data-quarto-table-cell-role="th">Shoots</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Height</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Weight</th>
<th style="text-align: left;" data-quarto-table-cell-role="th">Birthdate</th>
<th style="text-align: left;" data-quarto-table-cell-role="th">Hometown</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right;">9</td>
<td style="text-align: left;">Brennan Bosch</td>
<td style="text-align: left;">C</td>
<td style="text-align: left;">R</td>
<td style="text-align: right;">5.666667</td>
<td style="text-align: right;">173</td>
<td style="text-align: left;">1988-02-14</td>
<td style="text-align: left;">Martensville, SK</td>
</tr>
<tr class="even">
<td style="text-align: right;">11</td>
<td style="text-align: left;">Scott Wasden</td>
<td style="text-align: left;">C</td>
<td style="text-align: left;">R</td>
<td style="text-align: right;">6.083333</td>
<td style="text-align: right;">188</td>
<td style="text-align: left;">1988-01-04</td>
<td style="text-align: left;">Westbank, BC</td>
</tr>
<tr class="odd">
<td style="text-align: right;">12</td>
<td style="text-align: left;">Colton Grant</td>
<td style="text-align: left;">LW</td>
<td style="text-align: left;">L</td>
<td style="text-align: right;">5.750000</td>
<td style="text-align: right;">177</td>
<td style="text-align: left;">1989-03-20</td>
<td style="text-align: left;">Standard, AB</td>
</tr>
<tr class="even">
<td style="text-align: right;">14</td>
<td style="text-align: left;">Darren Helm</td>
<td style="text-align: left;">LW</td>
<td style="text-align: left;">L</td>
<td style="text-align: right;">6.000000</td>
<td style="text-align: right;">182</td>
<td style="text-align: left;">1987-01-21</td>
<td style="text-align: left;">St. Andrews, MB</td>
</tr>
<tr class="odd">
<td style="text-align: right;">15</td>
<td style="text-align: left;">Derek Dorsett</td>
<td style="text-align: left;">RW</td>
<td style="text-align: left;">L</td>
<td style="text-align: right;">5.916667</td>
<td style="text-align: right;">178</td>
<td style="text-align: left;">1986-12-20</td>
<td style="text-align: left;">Kindersley, SK</td>
</tr>
<tr class="even">
<td style="text-align: right;">16</td>
<td style="text-align: left;">Daine Todd</td>
<td style="text-align: left;">C</td>
<td style="text-align: left;">R</td>
<td style="text-align: right;">5.833333</td>
<td style="text-align: right;">173</td>
<td style="text-align: left;">1987-01-10</td>
<td style="text-align: left;">Red Deer, AB</td>
</tr>
<tr class="odd">
<td style="text-align: right;">17</td>
<td style="text-align: left;">Tyler Swystun</td>
<td style="text-align: left;">RW</td>
<td style="text-align: left;">R</td>
<td style="text-align: right;">5.916667</td>
<td style="text-align: right;">185</td>
<td style="text-align: left;">1988-01-15</td>
<td style="text-align: left;">Cochrane, AB</td>
</tr>
<tr class="even">
<td style="text-align: right;">19</td>
<td style="text-align: left;">Matt Lowry</td>
<td style="text-align: left;">C</td>
<td style="text-align: left;">R</td>
<td style="text-align: right;">6.000000</td>
<td style="text-align: right;">186</td>
<td style="text-align: left;">1988-03-02</td>
<td style="text-align: left;">Neepawa, MB</td>
</tr>
<tr class="odd">
<td style="text-align: right;">20</td>
<td style="text-align: left;">Kevin Undershute</td>
<td style="text-align: left;">LW</td>
<td style="text-align: left;">L</td>
<td style="text-align: right;">6.000000</td>
<td style="text-align: right;">178</td>
<td style="text-align: left;">1987-04-12</td>
<td style="text-align: left;">Medicine Hat, AB</td>
</tr>
<tr class="even">
<td style="text-align: right;">21</td>
<td style="text-align: left;">Jerrid Sauer</td>
<td style="text-align: left;">RW</td>
<td style="text-align: left;">R</td>
<td style="text-align: right;">5.833333</td>
<td style="text-align: right;">196</td>
<td style="text-align: left;">1987-09-12</td>
<td style="text-align: left;">Medicine Hat, AB</td>
</tr>
<tr class="odd">
<td style="text-align: right;">22</td>
<td style="text-align: left;">Tyler Ennis</td>
<td style="text-align: left;">C</td>
<td style="text-align: left;">L</td>
<td style="text-align: right;">5.750000</td>
<td style="text-align: right;">160</td>
<td style="text-align: left;">1989-10-06</td>
<td style="text-align: left;">Edmonton, AB</td>
</tr>
<tr class="even">
<td style="text-align: right;">23</td>
<td style="text-align: left;">Jordan Hickmott</td>
<td style="text-align: left;">C</td>
<td style="text-align: left;">R</td>
<td style="text-align: right;">6.000000</td>
<td style="text-align: right;">183</td>
<td style="text-align: left;">1990-04-11</td>
<td style="text-align: left;">Mission, BC</td>
</tr>
<tr class="odd">
<td style="text-align: right;">25</td>
<td style="text-align: left;">Jakub Rumpel</td>
<td style="text-align: left;">RW</td>
<td style="text-align: left;">R</td>
<td style="text-align: right;">5.666667</td>
<td style="text-align: right;">166</td>
<td style="text-align: left;">1987-01-27</td>
<td style="text-align: left;">Hrnciarovce, SLO</td>
</tr>
<tr class="even">
<td style="text-align: right;">28</td>
<td style="text-align: left;">Bretton Cameron</td>
<td style="text-align: left;">C</td>
<td style="text-align: left;">R</td>
<td style="text-align: right;">5.916667</td>
<td style="text-align: right;">168</td>
<td style="text-align: left;">1989-01-26</td>
<td style="text-align: left;">Didsbury, AB</td>
</tr>
<tr class="odd">
<td style="text-align: right;">36</td>
<td style="text-align: left;">Chris Stevens</td>
<td style="text-align: left;">LW</td>
<td style="text-align: left;">L</td>
<td style="text-align: right;">5.833333</td>
<td style="text-align: right;">197</td>
<td style="text-align: left;">1986-08-20</td>
<td style="text-align: left;">Dawson Creek, BC</td>
</tr>
<tr class="even">
<td style="text-align: right;">3</td>
<td style="text-align: left;">Gord Baldwin</td>
<td style="text-align: left;">D</td>
<td style="text-align: left;">L</td>
<td style="text-align: right;">6.416667</td>
<td style="text-align: right;">205</td>
<td style="text-align: left;">1987-03-01</td>
<td style="text-align: left;">Winnipeg, MB</td>
</tr>
<tr class="odd">
<td style="text-align: right;">4</td>
<td style="text-align: left;">David Schlemko</td>
<td style="text-align: left;">D</td>
<td style="text-align: left;">L</td>
<td style="text-align: right;">6.083333</td>
<td style="text-align: right;">195</td>
<td style="text-align: left;">1987-05-07</td>
<td style="text-align: left;">Edmonton, AB</td>
</tr>
<tr class="even">
<td style="text-align: right;">5</td>
<td style="text-align: left;">Trevor Glass</td>
<td style="text-align: left;">D</td>
<td style="text-align: left;">L</td>
<td style="text-align: right;">6.000000</td>
<td style="text-align: right;">190</td>
<td style="text-align: left;">1988-01-22</td>
<td style="text-align: left;">Cochrane, AB</td>
</tr>
<tr class="odd">
<td style="text-align: right;">10</td>
<td style="text-align: left;">Kris Russell</td>
<td style="text-align: left;">D</td>
<td style="text-align: left;">L</td>
<td style="text-align: right;">5.833333</td>
<td style="text-align: right;">177</td>
<td style="text-align: left;">1987-05-02</td>
<td style="text-align: left;">Caroline, AB</td>
</tr>
<tr class="even">
<td style="text-align: right;">18</td>
<td style="text-align: left;">Michael Sauer</td>
<td style="text-align: left;">D</td>
<td style="text-align: left;">R</td>
<td style="text-align: right;">6.250000</td>
<td style="text-align: right;">205</td>
<td style="text-align: left;">1987-08-07</td>
<td style="text-align: left;">Sartell, MN</td>
</tr>
<tr class="odd">
<td style="text-align: right;">24</td>
<td style="text-align: left;">Mark Isherwood</td>
<td style="text-align: left;">D</td>
<td style="text-align: left;">R</td>
<td style="text-align: right;">6.000000</td>
<td style="text-align: right;">183</td>
<td style="text-align: left;">1989-01-31</td>
<td style="text-align: left;">Abbotsford, BC</td>
</tr>
<tr class="even">
<td style="text-align: right;">27</td>
<td style="text-align: left;">Shayne Brown</td>
<td style="text-align: left;">D</td>
<td style="text-align: left;">L</td>
<td style="text-align: right;">6.083333</td>
<td style="text-align: right;">198</td>
<td style="text-align: left;">1989-02-20</td>
<td style="text-align: left;">Stony Plain, AB</td>
</tr>
<tr class="odd">
<td style="text-align: right;">29</td>
<td style="text-align: left;">Jordan Bendfeld</td>
<td style="text-align: left;">D</td>
<td style="text-align: left;">R</td>
<td style="text-align: right;">6.250000</td>
<td style="text-align: right;">230</td>
<td style="text-align: left;">1988-02-09</td>
<td style="text-align: left;">Leduc, AB</td>
</tr>
<tr class="even">
<td style="text-align: right;">31</td>
<td style="text-align: left;">Ryan Holfeld</td>
<td style="text-align: left;">G</td>
<td style="text-align: left;">L</td>
<td style="text-align: right;">5.916667</td>
<td style="text-align: right;">166</td>
<td style="text-align: left;">1989-06-29</td>
<td style="text-align: left;">LeRoy, SK</td>
</tr>
<tr class="odd">
<td style="text-align: right;">33</td>
<td style="text-align: left;">Matt Keetley</td>
<td style="text-align: left;">G</td>
<td style="text-align: left;">R</td>
<td style="text-align: right;">6.166667</td>
<td style="text-align: right;">189</td>
<td style="text-align: left;">1986-04-27</td>
<td style="text-align: left;">Medicine Hat, AB</td>
</tr>
</tbody>
</table>
</div>
</div>
<aside>
<p>Table @ref(tab:hat-tigers) data is stored in object <code>mht2007</code>.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(mht2007, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 25 × 8
      No Name     Pos   Shoots
   &lt;dbl&gt; &lt;chr&gt;    &lt;chr&gt; &lt;chr&gt; 
 1     9 Brennan… C     R     
 2    11 Scott W… C     R     
 3    12 Colton … LW    L     
 4    14 Darren … LW    L     
 5    15 Derek D… RW    L     
 6    16 Daine T… C     R     
 7    17 Tyler S… RW    R     
 8    19 Matt Lo… C     R     
 9    20 Kevin U… LW    L     
10    21 Jerrid … RW    R     
# … with 15 more rows, and 4
#   more variables:
#   Height &lt;dbl&gt;,
#   Weight &lt;dbl&gt;,
#   Birthdate &lt;date&gt;,
#   Hometown &lt;chr&gt;
# ℹ Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names</code></pre>
</div>
</div>
</aside>
<p>Did you notice anything unusual from the above table? If you didn’t that’s okay. Let’s instead look at Figure @ref(fig:mht-2007-bar) which shows the frequency of the birth month that the players are born. Now do you notice something?</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">mht2007 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb3-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">month =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">month</span>(Birthdate), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> month.abb)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb3-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(month)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#79003e"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_discrete</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">limits =</span> month.abb) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>))</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-03-12-maximum-potential/maximum-potential_files/figure-html/feature-mht-2007-bar-1.png" class="img-fluid figure-img" width="672"></p>
<figcaption>The barplot of the birth month of the Medicine Hat Tigers 2007 hockey players.</figcaption>
</figure>
</div>
</div>
</div>
<p>Without doing any statistical tests, you probably can see from Figure @ref(fig:mht-2007-bar) that there is an over-representation of players born in January. Gladwell postulates that this is a result of Canada’s eligibility cut-off for age-class hockey being January 1st. To explain further, coaches in Canada start training selected children at the age of 9 or 10. In preadolescence, a few months of gap can show a big difference in physical maturity, so for children born in the same year, the coaches tend to select the ones born earlier in the year. These selected children then get many more practice than the children who are not selected, and what started as a frivolous difference due to the month you were born turns into a big difference in talent in future.</p>
<p>I wanted to validate the claim about the birth month so I searched and scraped the player data at Medicine Hot Tiger from https://tigershockey.com/roster/ using <code>RSelenium</code> and <code>rvest</code> packages. The resulting data is stored in the object <code>roster</code> which include the player information for the following games:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">roster <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(WHL) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code> [1] "2021 - 22 Regular Season" "2021 Pre Season"         
 [3] "2020 - 21 Regular Season" "2019 - 20 Regular Season"
 [5] "2019 Pre Season"          "2019 WHL Playoffs"       
 [7] "2018 - 19 Regular Season" "2018 Pre Season"         
 [9] "2018 WHL Playoffs"        "2017 - 18 Regular Season"
[11] "2017 Pre Season"          "2017 WHL Playoffs"       
[13] "2016 - 17 Regular Season" "2016 Pre Season"         
[15] "16 Tie Break"             "2015-16 Regular Season"  
[17] "2015 Preseason"           "2015 WHL Playoffs"       
[19] "2014-15 Regular Season"   "2014 Preseason"          
[21] "2014 WHL Playoffs"        "2013-14 Regular Season"  
[23] "2013 WHL Preseason"       "2013 WHL Playoffs"       
[25] "2012-13 Regular Season"   "2012 WHL Preseason"      
[27] "2012 WHL Playoffs"        "2011-12 Regular Season"  
[29] "2011 WHL Preseason"       "2011 WHL Playoffs"       
[31] "2010-11 Regular Season"   "2010 WHL Playoffs"       
[33] "2009-10 Regular Season"   "2009 WHL Playoffs"       
[35] "2008-09 Regular Season"   "2008 WHL Playoffs"       
[37] "2007-08 Regular Season"   "2007 WHL Playoffs"       
[39] "2006-07 WHL Season"       "2006 WHL Playoffs"       
[41] "2005-06 WHL Season"       "2005 WHL Playoffs"       
[43] "2004-05 WHL Season"       "2004 WHL Playoffs"       
[45] "2003-2004 WHL Season"     "2003 WHL Playoffs"       
[47] "2002-03 WHL Season"       "2001-2002 WHL Season"    
[49] "2000-2001 WHL Season"     "1999-2000 WHL Season"    
[51] "1998-99 WHL Season"       "1997-98 WHL Season"      
[53] "1997 WHL Playoffs"        "1996-97 WHL Season"      
[55] "1996 WHL Playoffs"       </code></pre>
</div>
</div>
<p>After removing duplicate records of the players that appear across multiple games, I plot the frequency of the birth month of the rostered Medicine Hat Tigers hockey players from 1996 to 2021 in Figure @ref(fig:roster-bar). The frequency of players born in January are not strikingly over-represented with a larger sample size but it is noticeable that there are more players born in the first half of the year than second half of the year.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">roster_unique <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> roster <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb6-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">month =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">month</span>(DOB), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> month.abb)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb6-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">distinct</span>(Player, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.keep_all =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb6-4"></span>
<span id="cb6-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(roster_unique, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(month)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#79003e"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_discrete</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">limits =</span> month.abb) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>))</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>Warning: Removed 7 rows containing non-finite values (stat_count).</code></pre>
</div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-03-12-maximum-potential/maximum-potential_files/figure-html/roster-bar-1.png" class="img-fluid figure-img" width="672"></p>
<figcaption>The barplot of the birth month of the Medicine Hat Tigers hockey players from 1996 to 2021.</figcaption>
</figure>
</div>
</div>
</div>
<p>If you are keen, you can do some statistical tests to confirm this assuming equal probability of a person being born in the first or second half of the year.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1">birth_count <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> roster_unique <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">first_half =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">month</span>(DOB) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(first_half) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">count</span>()</span>
<span id="cb8-5"></span>
<span id="cb8-6">birth_count</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 3 × 2
# Groups:   first_half [3]
  first_half     n
  &lt;lgl&gt;      &lt;int&gt;
1 FALSE         76
2 TRUE         166
3 NA             7</code></pre>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chisq.test</span>(birth_count<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>
    Chi-squared test for given probabilities

data:  birth_count$n[1:2]
X-squared = 33.471, df = 1, p-value = 7.233e-09</code></pre>
</div>
</div>
</section>
<section id="changing-the-environment-for-your-growth" class="level3">
<h3 class="anchored" data-anchor-id="changing-the-environment-for-your-growth">Changing the environment for your growth</h3>
<p>You can extrapolate the ice hockey birth month scenario to other situations and Gladwell presents more examples of super successful (“outlier”) men like Bill Gates, Eric Schmidt, Steve Jobs and so on, of how essential they were in the <strong><em>right place at the right time</em></strong>. Sadly, Gladwell didn’t take the opportunity to discuss about “women outliers” or highlight an example about success based on sex, which very much like birth month is a random assignment beyond an individual’s control, but can make a difference in one’s career.</p>
<p>Gladwell’s writing cemented the idea within me of the <strong>importance of the environment</strong> particularly when you are still young. E.g. if you are busy trying to find a safe place for you and your family because of the <a href="https://emitanaka.org/posts/2022-03-06-the-war/">Ukraine-Russia war</a>, you’ll have little opportunity to do anything else <em>no matter how great of a talent you have</em>.</p>
<p>Those who are “successful” tend to be the ones who had the environment working in their favour earlier (if not most of the time) in their career. This is not to say they don’t have talent or didn’t work hard, but the <strong><em>tragedy</em></strong> in all this is that <em>those who have talent but didn’t have the environment to achieve their maximum potential</em>. I can see the traces of my thought on twitter about changing the environment if it’s not working for you creeping up every now and then. (Changing environments has costs though so I realise my advice doesn’t work for everyone.)</p>
<blockquote class="twitter-tweet blockquote">
<p lang="en" dir="ltr">
Yes this happens a lot. If you an ECR, it’s best to get out of that environment. You are young and it’s the best time to GROW. Surround yourself with people who are better in the skills you care about. If they are not in your workplace, go outside of workplace. Meetup, online
</p>
— Emi Tanaka (田中愛美) 💉💉💉 (<span class="citation" data-cites="statsgen">@statsgen</span>) <a href="https://twitter.com/statsgen/status/1103546291416555520?ref_src=twsrc%5Etfw">March 7, 2019</a>
</blockquote>
<script async="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<blockquote class="twitter-tweet blockquote">
<p lang="en" dir="ltr">
If you are the solo RSE or you don’t have anyone to talk deeply about the software engineering aspects, I don’t know if there will be motivation to stay in that kind of environment when you have other choices. (2/2)
</p>
— Emi Tanaka (田中愛美) 💉💉💉 (<span class="citation" data-cites="statsgen">@statsgen</span>) <a href="https://twitter.com/statsgen/status/1460964344305369093?ref_src=twsrc%5Etfw">November 17, 2021</a>
</blockquote>
<p>Above predicates on the goal of personal growth, but “success” ultimately comes in many forms. Personally, I feel frustrated when I feel that the environment gets in my way of my personal growth and this tends to drive me to change the environment. There’s a limit to what you can change though, and there’s a part of me that knows that I’m driving myself into a wall getting frustrated at every turn and I’ve got to chill. (I’m sorry if you’re ever on the receiving end of my frustration - but hey maybe you deserve it!… I kid :P)</p>
</section>
<section id="changing-the-environment-for-others-growth" class="level3">
<h3 class="anchored" data-anchor-id="changing-the-environment-for-others-growth">Changing the environment for others’ growth</h3>
<p>There’s been a few times in my life where the upper management was quite bad that it was causing havoc for those under the management and there is widespread discontent. Every time this happens, I always think about how I <em>don’t</em> want to be like that upper management, but I equally fear that I am going to be, perhaps unknowingly, like that when I’m in the same position. So I occasionally remind myself that I shouldn’t fault people, when you don’t know what other things are driving the behaviour or decision. But I’m no saint, so I still have a long way to go though to be that understanding and I might poke fun of the situation in a passive-aggressive drawing 🎨</p>
<blockquote class="twitter-tweet blockquote">
<p lang="en" dir="ltr">
Fun to draw again 💃 <a href="https://t.co/3uHQLi8biA">pic.twitter.com/3uHQLi8biA</a>
</p>
— Emi Tanaka (田中愛美) 💉💉💉 (<span class="citation" data-cites="statsgen">@statsgen</span>) <a href="https://twitter.com/statsgen/status/1097477768659386368?ref_src=twsrc%5Etfw">February 18, 2019</a>
</blockquote>
<script async="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<blockquote class="twitter-tweet blockquote">
<p lang="en" dir="ltr">
Branding and management gone wrong. "Precision Pen" <a href="https://t.co/SVd6uyxrSr">pic.twitter.com/SVd6uyxrSr</a>
</p>
— Emi Tanaka (田中愛美) 💉💉💉 (<span class="citation" data-cites="statsgen">@statsgen</span>) <a href="https://twitter.com/statsgen/status/1107182565796962309?ref_src=twsrc%5Etfw">March 17, 2019</a>
</blockquote>
<script async="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>


</section>

 ]]></description>
  <category>life</category>
  <category>outlier</category>
  <guid>https://emitanaka.org/blog/2022-03-12-maximum-potential/maximum-potential.html</guid>
  <pubDate>Fri, 11 Mar 2022 13:00:00 GMT</pubDate>
</item>
<item>
  <title>War</title>
  <dc:creator>Emi Tanaka</dc:creator>
  <link>https://emitanaka.org/blog/2022-03-06-the-war/the-war.html</link>
  <description><![CDATA[ 

<!-- Title banner for blog posts (set in blog/_metadata.yml). Built from each
     post's front matter: title, date, author, categories, description and
     image (a pen sticker is shown when a post has no image). -->



<p>The war that’s going on at Ukraine is terrible. There are now <a href="https://www.theguardian.com/global-development/2022/mar/05/ukraine-un-says-more-than-13-million-have-fled-since-russian-invasion-began">over 1.3 million people who have fled Ukraine since the Russian invasion</a>, many who would be living as refugees now in neighboring countries. The closest to war I have ever been is when the Japanese embassy told (warned?) my family to get out of Jordan during the Gulf War. We lived in Greece during this period.</p>
<p>When I lived in Greece, I was a young child with little comprehension of what’s going on. In the course of my life, this event had little effect on me but just a distant hazy memory. Today as a fully grown adult, I’m sure I would have been terrified being in the midst of uncertainty. War affects many citizens, including the creator of <a href="https://leafletjs.com/">Leaflet</a> as pointed out by <a href="https://twitter.com/yutannihilat_en/status/1497938887272189952">Hiroaki Yutani-san</a>. If ever you need a time to remind yourself how lucky you are to have shelter, food and water, now is probably the time.</p>
<p>Living in Melbourne, so far away from Ukraine, life is going on like normal, bickering over first world problems. What good is in a war? If you are in a good position to, please consider helping those in need. I donated US$500 to Ukraine Red Cross Society but I found later that there was the <a href="https://www.redcross.org.au/ukraine/">Ukraine Crisis Appeal in the Australian Red Cross</a>.</p>



 ]]></description>
  <category>life</category>
  <guid>https://emitanaka.org/blog/2022-03-06-the-war/the-war.html</guid>
  <pubDate>Sat, 05 Mar 2022 13:00:00 GMT</pubDate>
</item>
<item>
  <title>simulate: proof of concept R-package</title>
  <dc:creator>Emi Tanaka</dc:creator>
  <link>https://emitanaka.org/blog/2022-02-24-simulation-proof-of-concept/simulation-proof-of-concept.html</link>
  <description><![CDATA[ 

<!-- Title banner for blog posts (set in blog/_metadata.yml). Built from each
     post's front matter: title, date, author, categories, description and
     image (a pen sticker is shown when a post has no image). -->



<p>This blog post shows a proof of concept for a simulation framework, wrapped into (undocumented) R-package <code>simulate</code>. Let’s take the <code>penguins</code> data from the <code>palmerpenguins</code> package as an example data. You can see the form of the data below if you’re not familiar with it.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(palmerpenguins)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(simulate)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_set</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_bw</span>())</span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2022-02-24</span>)</span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str</span>(penguins)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>tibble [344 × 8] (S3: tbl_df/tbl/data.frame)
 $ species          : Factor w/ 3 levels "Adelie","Chinstrap",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ island           : Factor w/ 3 levels "Biscoe","Dream",..: 3 3 3 3 3 3 3 3 3 3 ...
 $ bill_length_mm   : num [1:344] 39.1 39.5 40.3 NA 36.7 39.3 38.9 39.2 34.1 42 ...
 $ bill_depth_mm    : num [1:344] 18.7 17.4 18 NA 19.3 20.6 17.8 19.6 18.1 20.2 ...
 $ flipper_length_mm: int [1:344] 181 186 195 NA 193 190 181 195 193 190 ...
 $ body_mass_g      : int [1:344] 3750 3800 3250 NA 3450 3650 3625 4675 3475 4250 ...
 $ sex              : Factor w/ 2 levels "female","male": 2 1 1 NA 1 2 1 2 NA NA ...
 $ year             : int [1:344] 2007 2007 2007 2007 2007 2007 2007 2007 2007 2007 ...</code></pre>
</div>
</div>
<p>Let’s now say you want to simulate a new response called <code>weight</code> which you assume is normally distributed where the mean is a function of species and variance is 10. We want to specify the mean separately by species such that Adelie, Chinstrap and Gentoo are 130kg, 200kg and 250kg respectively (These numbers are totally made up!!! And probably way heavey for a penguin?).</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">sim1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> penguins <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb3-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simulate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weight =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sim_normal</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>species, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb3-3">             <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">params</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mean"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">species =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Adelie"</span>    <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">130</span>,</span>
<span id="cb3-4">                                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Chinstrap"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>,</span>
<span id="cb3-5">                                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Gentoo"</span>    <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">250</span>)))</span></code></pre></div></div>
</div>
<p>Let’s visualise to see if the weight was simulated as expected:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(sim1, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(species, weight)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_violin</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_boxplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-02-24-simulation-proof-of-concept/simulation-proof-of-concept_files/figure-html/sim1-plot-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>You can make other parameters, like the standard deviation, as a function of species as well.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">sim2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> penguins <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb5-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simulate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weight =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sim_normal</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>species, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>species) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb5-3">             <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">params</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mean"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">species =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Adelie"</span>    <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">130</span>,</span>
<span id="cb5-4">                                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Chinstrap"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>,</span>
<span id="cb5-5">                                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Gentoo"</span>    <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">250</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb5-6">             <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">params</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sd"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">species =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Adelie"</span>    <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,</span>
<span id="cb5-7">                                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Chinstrap"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>,</span>
<span id="cb5-8">                                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Gentoo"</span>    <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>) ))</span></code></pre></div></div>
</div>
<p>And here’s the visualisation:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(sim2, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(species, weight)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_violin</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_boxplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-02-24-simulation-proof-of-concept/simulation-proof-of-concept_files/figure-html/sim2-plot-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>Okay one more before I call it a night. <code>sim_form</code> is a fixed function structure here and I’m simulating weight as a mixture distribution – the weight is either based on the sex or the species (perhaps simulating a situation where some genes aren’t expressed more based on sex sometimes, and sometimes more based on species?? These simulations are just made up.)</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">sim3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> penguins <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb7-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simulate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weight =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sim_form</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>p[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> sex <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> p[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> species) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb7-3">             <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">params</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">species =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Adelie"</span>    <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">130</span>,</span>
<span id="cb7-4">                                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Chinstrap"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>,</span>
<span id="cb7-5">                                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Gentoo"</span>    <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">250</span>),</span>
<span id="cb7-6">                    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># it can be unnamed as well</span></span>
<span id="cb7-7">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sex =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>),</span>
<span id="cb7-8">                    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># or specify a distribution</span></span>
<span id="cb7-9">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sim_multinominal</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>))))</span></code></pre></div></div>
</div>
<p>Note: the plot below is jittered so you can see all the points.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(sim3, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(species, weight)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_jitter</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb8-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(sex <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> species)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-02-24-simulation-proof-of-concept/simulation-proof-of-concept_files/figure-html/sim3-plot-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>The multivariate part is not shown but a keen user may find how this is envisioned at the moment if you dig deep into the source code… Hint: there is a <code>.cor</code> function to feed in a correlation matrix.</p>



 ]]></description>
  <category>R</category>
  <category>simulate</category>
  <guid>https://emitanaka.org/blog/2022-02-24-simulation-proof-of-concept/simulation-proof-of-concept.html</guid>
  <pubDate>Wed, 23 Feb 2022 13:00:00 GMT</pubDate>
</item>
<item>
  <title>Colorblind checks for qualitative palettes</title>
  <dc:creator>Emi Tanaka</dc:creator>
  <link>https://emitanaka.org/blog/2022-02-20-color-considerations/color-considerations.html</link>
  <description><![CDATA[ 

<!-- Title banner for blog posts (set in blog/_metadata.yml). Built from each
     post's front matter: title, date, author, categories, description and
     image (a pen sticker is shown when a post has no image). -->



<details>
<summary>
Function to generate plot for colorblind friendly check
</summary>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggplot2)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(farver)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(colorspace)</span>
<span id="cb1-4">check_colorblindness <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(colors, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) {</span>
<span id="cb1-5">  ncolors <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(colors)</span>
<span id="cb1-6">  nrow <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ceiling</span>(ncolors <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> ncol)</span>
<span id="cb1-7">  cond <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Original"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Deutan"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Protan"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Tritan"</span>)</span>
<span id="cb1-8">  ncond <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(cond)</span>
<span id="cb1-9">  </span>
<span id="cb1-10">  df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(colors, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">deutan</span>(colors), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">protan</span>(colors), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tritan</span>(colors)),</span>
<span id="cb1-11">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cond =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(cond, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">each =</span> ncolors),</span>
<span id="cb1-12">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>ncol, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length.out =</span> ncolors), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">times =</span> ncond),</span>
<span id="cb1-13">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>nrow, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">each =</span> ncol)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>ncolors], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">times =</span> ncond)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb1-14">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cond =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(cond, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels =</span> .env<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>cond))</span>
<span id="cb1-15">  </span>
<span id="cb1-16">  </span>
<span id="cb1-17">  g <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(df, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(x, y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">I</span>(color))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-18">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_tile</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-19">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_void</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-20">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_equal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-21">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>cond, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-22">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_reverse</span>()</span>
<span id="cb1-23">  </span>
<span id="cb1-24">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(label) {</span>
<span id="cb1-25">      g <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> color, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">I</span>(label_col)), </span>
<span id="cb1-26">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(data) data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb1-27">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(cond <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Original"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb1-28">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hcl =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">decode_colour</span>(colors, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hcl"</span>),</span>
<span id="cb1-29">                       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label_col =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(hcl[, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"l"</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>)))</span>
<span id="cb1-30">  } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb1-31">    g</span>
<span id="cb1-32">  } </span>
<span id="cb1-33">}</span></code></pre></div></div>
</div>
</details>
<div class="cell-output-display">
<table class="caption-top table">
<thead>
<tr class="header">
<th style="text-align: left;">Name</th>
<th style="text-align: left;">Source</th>
<th style="text-align: left;">Colors</th>
<th style="text-align: right;"># of colors</th>
<th style="text-align: left;">Palette</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">High contrast</td>
<td style="text-align: left;"><a href="https://personal.sron.nl/~pault/#sec:qualitative">Paul Tol</a></td>
<td style="text-align: left;">#FFFFFF, #DDAA33, #BB5566, #004488, #000000</td>
<td style="text-align: right;">5</td>
<td style="text-align: left;"><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/high-contrast-showcase-1.png" style="width:200px;"></td>
</tr>
<tr class="even">
<td style="text-align: left;">Pale</td>
<td style="text-align: left;"><a href="https://personal.sron.nl/~pault/#sec:qualitative">Paul Tol</a></td>
<td style="text-align: left;">#BBCCEE, #CCEEFF, #CCDDAA, #EEEEBB, #FFCCCC, #DDDDDD</td>
<td style="text-align: right;">6</td>
<td style="text-align: left;"><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/pale-showcase-1.png" style="width:200px;"></td>
</tr>
<tr class="odd">
<td style="text-align: left;">Dark</td>
<td style="text-align: left;"><a href="https://personal.sron.nl/~pault/#sec:qualitative">Paul Tol</a></td>
<td style="text-align: left;">#222255, #225555, #225522, #666633, #663333, #555555</td>
<td style="text-align: right;">6</td>
<td style="text-align: left;"><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/dark-showcase-1.png" style="width:200px;"></td>
</tr>
<tr class="even">
<td style="text-align: left;">Bright</td>
<td style="text-align: left;"><a href="https://personal.sron.nl/~pault/#sec:qualitative">Paul Tol</a></td>
<td style="text-align: left;">#4477AA, #66CCEE, #228833, #CCBB44, #EE6677, #AA3377, #BBBBBB</td>
<td style="text-align: right;">7</td>
<td style="text-align: left;"><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/bright-showcase-1.png" style="width:200px;"></td>
</tr>
<tr class="odd">
<td style="text-align: left;">Vibrant</td>
<td style="text-align: left;"><a href="https://personal.sron.nl/~pault/#sec:qualitative">Paul Tol</a></td>
<td style="text-align: left;">#0077BB, #33BBEE, #009988, #EE7733, #CC3311, #EE3377, #BBBBBB</td>
<td style="text-align: right;">7</td>
<td style="text-align: left;"><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/vibrant-showcase-1.png" style="width:200px;"></td>
</tr>
<tr class="even">
<td style="text-align: left;">Medium constrast</td>
<td style="text-align: left;"><a href="https://personal.sron.nl/~pault/#sec:qualitative">Paul Tol</a></td>
<td style="text-align: left;">#FFFFFF, #EECC66, #EE99AA, #6699CC, #997700, #994455, #004488, #000000</td>
<td style="text-align: right;">8</td>
<td style="text-align: left;"><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/medium-constrast-showcase-1.png" style="width:200px;"></td>
</tr>
<tr class="odd">
<td style="text-align: left;">Okabe Ito</td>
<td style="text-align: left;"><a href="https://jfly.uni-koeln.de/color/">Okabe Ito</a></td>
<td style="text-align: left;">#E69F00, #56B4E9, #009E73, #F0E442, #0072B2, #D55E00, #CC79A7, #000000</td>
<td style="text-align: right;">8</td>
<td style="text-align: left;"><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/okabe-ito-showcase-1.png" style="width:200px;"></td>
</tr>
<tr class="even">
<td style="text-align: left;">Light</td>
<td style="text-align: left;"><a href="https://personal.sron.nl/~pault/#sec:qualitative">Paul Tol</a></td>
<td style="text-align: left;">#77AADD, #99DDFF, #44BB99, #BBCC33, #AAAA00, #EEDD88, #EE8866, #FFAABB, #DDDDDD</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;"><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/light-showcase-1.png" style="width:200px;"></td>
</tr>
<tr class="odd">
<td style="text-align: left;">Muted</td>
<td style="text-align: left;"><a href="https://personal.sron.nl/~pault/#sec:qualitative">Paul Tol</a></td>
<td style="text-align: left;">#332288, #88CCEE, #44AA99, #117733, #999933, #DDCC77, #CC6677, #882255, #AA4499, #DDDDDD</td>
<td style="text-align: right;">10</td>
<td style="text-align: left;"><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/muted-showcase-1.png" style="width:200px;"></td>
</tr>
<tr class="even">
<td style="text-align: left;">Safe</td>
<td style="text-align: left;"><code>rcartocolor</code></td>
<td style="text-align: left;">#88CCEE, #CC6677, #DDCC77, #117733, #332288, #AA4499, #44AA99, #999933, #882255, #661100, #6699CC, #888888</td>
<td style="text-align: right;">12</td>
<td style="text-align: left;"><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/safe-showcase-1.png" style="width:200px;"></td>
</tr>
<tr class="odd">
<td style="text-align: left;">Monash primary</td>
<td style="text-align: left;"><a href="https://www.monash.edu/__data/assets/pdf_file/0004/1656508/9.-Digital-Guidelines.pdf">Monash</a></td>
<td style="text-align: left;">#006DAE, #000000, #FFFFFF, #5A5A5A, #969696, #E6E6E6</td>
<td style="text-align: right;">6</td>
<td style="text-align: left;"><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/monash-primary-showcase-1.png" style="width:200px;"></td>
</tr>
<tr class="even">
<td style="text-align: left;">Monash secondary</td>
<td style="text-align: left;"><a href="https://www.monash.edu/__data/assets/pdf_file/0004/1656508/9.-Digital-Guidelines.pdf">Monash</a></td>
<td style="text-align: left;">#027EB6, #746FB2, #9651A0, #C8008F, #ee64a4, #EE0220, #D93F00, #795549, #6F7C4D, #008A25</td>
<td style="text-align: right;">10</td>
<td style="text-align: left;"><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/monash-secondary-showcase-1.png" style="width:200px;"></td>
</tr>
</tbody>
</table>
</div>
<section id="r-code-for-easy-copying" class="level2">
<h2 class="anchored" data-anchor-id="r-code-for-easy-copying">R code for easy copying</h2>
<div class="cell">
<div class="cell-output cell-output-stdout">
<pre><code>### High contrast 
c("#FFFFFF", "#DDAA33", "#BB5566", "#004488", "#000000")

### Pale 
c("#BBCCEE", "#CCEEFF", "#CCDDAA", "#EEEEBB", "#FFCCCC", "#DDDDDD"
)

### Dark 
c("#222255", "#225555", "#225522", "#666633", "#663333", "#555555"
)

### Bright 
c("#4477AA", "#66CCEE", "#228833", "#CCBB44", "#EE6677", "#AA3377", 
"#BBBBBB")

### Vibrant 
c("#0077BB", "#33BBEE", "#009988", "#EE7733", "#CC3311", "#EE3377", 
"#BBBBBB")

### Medium constrast 
c("#FFFFFF", "#EECC66", "#EE99AA", "#6699CC", "#997700", "#994455", 
"#004488", "#000000")

### Okabe Ito 
c("#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", 
"#CC79A7", "#000000")

### Light 
c("#77AADD", "#99DDFF", "#44BB99", "#BBCC33", "#AAAA00", "#EEDD88", 
"#EE8866", "#FFAABB", "#DDDDDD")

### Muted 
c("#332288", "#88CCEE", "#44AA99", "#117733", "#999933", "#DDCC77", 
"#CC6677", "#882255", "#AA4499", "#DDDDDD")

### Safe 
c("#88CCEE", "#CC6677", "#DDCC77", "#117733", "#332288", "#AA4499", 
"#44AA99", "#999933", "#882255", "#661100", "#6699CC", "#888888"
)

### Monash primary 
c(blue = "#006DAE", black = "#000000", white = "#FFFFFF", gray80 = "#5A5A5A", 
gray50 = "#969696", gray10 = "#E6E6E6")

### Monash secondary 
c(blue = "#027EB6", purple = "#746FB2", fuchsia = "#9651A0", 
ruby = "#C8008F", pink = "#ee64a4", red = "#EE0220", orange = "#D93F00", 
umber = "#795549", olive = "#6F7C4D", green = "#008A25")</code></pre>
</div>
</div>
</section>
<section id="closer-look" class="level2">
<h2 class="anchored" data-anchor-id="closer-look">Closer look</h2>
<div class="cell">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/high-contrast-1.png" class="img-fluid figure-img" width="576"></p>
<figcaption>High contrast palette: #FFFFFF, #DDAA33, #BB5566, #004488, #000000.</figcaption>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/pale-1.png" class="img-fluid figure-img" width="576"></p>
<figcaption>Pale palette: #BBCCEE, #CCEEFF, #CCDDAA, #EEEEBB, #FFCCCC, #DDDDDD.</figcaption>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/dark-1.png" class="img-fluid figure-img" width="576"></p>
<figcaption>Dark palette: #222255, #225555, #225522, #666633, #663333, #555555.</figcaption>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/bright-1.png" class="img-fluid figure-img" width="576"></p>
<figcaption>Bright palette: #4477AA, #66CCEE, #228833, #CCBB44, #EE6677, #AA3377, #BBBBBB.</figcaption>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/vibrant-1.png" class="img-fluid figure-img" width="576"></p>
<figcaption>Vibrant palette: #0077BB, #33BBEE, #009988, #EE7733, #CC3311, #EE3377, #BBBBBB.</figcaption>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/medium-constrast-1.png" class="img-fluid figure-img" width="576"></p>
<figcaption>Medium constrast palette: #FFFFFF, #EECC66, #EE99AA, #6699CC, #997700, #994455, #004488, #000000.</figcaption>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/okabe-ito-1.png" class="img-fluid figure-img" width="576"></p>
<figcaption>Okabe Ito palette: #E69F00, #56B4E9, #009E73, #F0E442, #0072B2, #D55E00, #CC79A7, #000000.</figcaption>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/light-1.png" class="img-fluid figure-img" width="576"></p>
<figcaption>Light palette: #77AADD, #99DDFF, #44BB99, #BBCC33, #AAAA00, #EEDD88, #EE8866, #FFAABB, #DDDDDD.</figcaption>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/muted-1.png" class="img-fluid figure-img" width="576"></p>
<figcaption>Muted palette: #332288, #88CCEE, #44AA99, #117733, #999933, #DDCC77, #CC6677, #882255, #AA4499, #DDDDDD.</figcaption>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/safe-1.png" class="img-fluid figure-img" width="576"></p>
<figcaption>Safe palette: #88CCEE, #CC6677, #DDCC77, #117733, #332288, #AA4499, #44AA99, #999933, #882255, #661100, #6699CC, #888888.</figcaption>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/monash-primary-1.png" class="img-fluid figure-img" width="576"></p>
<figcaption>Monash primary palette: #006DAE, #000000, #FFFFFF, #5A5A5A, #969696, #E6E6E6.</figcaption>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-02-20-color-considerations/images/monash-secondary-1.png" class="img-fluid figure-img" width="576"></p>
<figcaption>Monash secondary palette: #027EB6, #746FB2, #9651A0, #C8008F, #ee64a4, #EE0220, #D93F00, #795549, #6F7C4D, #008A25.</figcaption>
</figure>
</div>
</div>
</div>


</section>

 ]]></description>
  <category>R</category>
  <category>color</category>
  <guid>https://emitanaka.org/blog/2022-02-20-color-considerations/color-considerations.html</guid>
  <pubDate>Sat, 19 Feb 2022 13:00:00 GMT</pubDate>
</item>
<item>
  <title>Manipulating arrays with dynamic dimensions in R</title>
  <dc:creator>Emi Tanaka</dc:creator>
  <link>https://emitanaka.org/blog/2022-01-18-manipulating-arrays-in-R/manipulating-arrays-in-r.html</link>
  <description><![CDATA[ 

<!-- Title banner for blog posts (set in blog/_metadata.yml). Built from each
     post's front matter: title, date, author, categories, description and
     image (a pen sticker is shown when a post has no image). -->



<section id="introduction-to-arrays-in-r" class="level2">
<h2 class="anchored" data-anchor-id="introduction-to-arrays-in-r">Introduction to <code>array</code>s in R</h2>
<p>Below I am creating an array of dimensions <img src="https://latex.codecogs.com/png.latex?3%20%5Ctimes%202%20%5Ctimes%204"> with each entry containing a unique value.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1">x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">array</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>))</span>
<span id="cb1-2">x</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>, , 1

     [,1] [,2]
[1,]    1    4
[2,]    2    5
[3,]    3    6

, , 2

     [,1] [,2]
[1,]    7   10
[2,]    8   11
[3,]    9   12

, , 3

     [,1] [,2]
[1,]   13   16
[2,]   14   17
[3,]   15   18

, , 4

     [,1] [,2]
[1,]   19   22
[2,]   20   23
[3,]   21   24</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">class</span>(x)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "array"</code></pre>
</div>
</div>
<p>You can access the entry <img src="https://latex.codecogs.com/png.latex?(1,%201,%201)">, i.e.&nbsp;the cell value in first entries of each dimension, in R by:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">x[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 1</code></pre>
</div>
</div>
<p>If you want the entries <img src="https://latex.codecogs.com/png.latex?(i,%201,%201)"> where <img src="https://latex.codecogs.com/png.latex?i%20=%201,%202,%203"> then you can leave the first element blank in R like below:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">x[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 1 2 3</code></pre>
</div>
</div>
<p>In the above code, the result is a vector but if you wanted to keep the array structure as is then you could add <code>drop = FALSE</code> like below:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">x[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, drop <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>]</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>, , 1

     [,1]
[1,]    1
[2,]    2
[3,]    3</code></pre>
</div>
</div>
<p>If you want the entries <img src="https://latex.codecogs.com/png.latex?(1,%20j,%20k)"> where <img src="https://latex.codecogs.com/png.latex?j%20=%201,%202"> and <img src="https://latex.codecogs.com/png.latex?k%20=%201,%202,%203,%204">, then you can leave the first two entries in the square bracket like below:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">x[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, , ]</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>     [,1] [,2] [,3] [,4]
[1,]    1    7   13   19
[2,]    4   10   16   22</code></pre>
</div>
</div>
<p>The above result isn’t actually a vector but a two dimensional array, or more specifically it has the classes <code>matrix</code> and <code>array</code>.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">class</span>(x[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, , ])</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "matrix" "array" </code></pre>
</div>
</div>
<p>I can modify elements in an array by using the assignment operator (<code>&lt;-</code> or <code>=</code>) like below:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1">x3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> x2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> x</span>
<span id="cb15-2">x2[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, , ] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span></span>
<span id="cb15-3">x2</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>, , 1

     [,1] [,2]
[1,]   NA   NA
[2,]    2    5
[3,]    3    6

, , 2

     [,1] [,2]
[1,]   NA   NA
[2,]    8   11
[3,]    9   12

, , 3

     [,1] [,2]
[1,]   NA   NA
[2,]   14   17
[3,]   15   18

, , 4

     [,1] [,2]
[1,]   NA   NA
[2,]   20   23
[3,]   21   24</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1">x3[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, , ] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">array</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>))</span>
<span id="cb17-2">x3</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>, , 1

     [,1] [,2]
[1,]    1    2
[2,]    2    5
[3,]    3    6

, , 2

     [,1] [,2]
[1,]    3    4
[2,]    8   11
[3,]    9   12

, , 3

     [,1] [,2]
[1,]    5    6
[2,]   14   17
[3,]   15   18

, , 4

     [,1] [,2]
[1,]    7    8
[2,]   20   23
[3,]   21   24</code></pre>
</div>
</div>
</section>
<section id="the-challenge" class="level2">
<h2 class="anchored" data-anchor-id="the-challenge">The challenge</h2>
<section id="challenge-1-indexing" class="level3">
<h3 class="anchored" data-anchor-id="challenge-1-indexing">Challenge 1: indexing</h3>
<p>Up to this point, it’s pretty straight forward. But let’s say now we create a function that returns the first element of the first dimension.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1">index_first <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x) {</span>
<span id="cb19-2">  x[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, , ]</span>
<span id="cb19-3">}</span>
<span id="cb19-4"></span>
<span id="cb19-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">index_first</span>(x)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>     [,1] [,2] [,3] [,4]
[1,]    1    7   13   19
[2,]    4   10   16   22</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1">y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">array</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))</span>
<span id="cb21-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">index_first</span>(y)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>     [,1] [,2]
[1,]    1    1
[2,]    1    1
[3,]    1    1
[4,]    1    1</code></pre>
</div>
</div>
<p>The above function works fine for the arrays <code>x</code> and <code>y</code>. But what if the number of dimension is different?</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1">z <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">array</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))</span>
<span id="cb23-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">index_first</span>(z)</span></code></pre></div></div>
<div class="cell-output cell-output-error">
<pre><code>Error in x[1, , ]: incorrect number of dimensions</code></pre>
</div>
</div>
<p>So how do we change our function so it works for an array of any number of dimensions? This is where it gets quite challenging. And while I’m at it, let me throw another challenge.</p>
</section>
<section id="challenge-2-assignment" class="level3">
<h3 class="anchored" data-anchor-id="challenge-2-assignment">Challenge 2: assignment</h3>
<p>Suppose now I want a function that modifies the entries in the first element of the first dimension by a user supplied value.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1">modify_first <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x, value) {</span>
<span id="cb25-2">  x[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, ,] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> value</span>
<span id="cb25-3">}</span></code></pre></div></div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb26" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb26-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">modify_first</span>(x, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>)</span>
<span id="cb26-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">modify_first</span>(x, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">array</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)))</span></code></pre></div></div>
</div>
<p>Again this works fine until we have an array with different number of dimensions.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">modify_first</span>(z, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-error">
<pre><code>Error in x[1, , ] &lt;- value: incorrect number of subscripts</code></pre>
</div>
</div>
<p>So how would you modify the function so this can be generalised for arrays with a different number of dimensions?</p>
</section>
</section>
<section id="solutions" class="level2">
<h2 class="anchored" data-anchor-id="solutions">Solutions</h2>
<p>In the first instance, it’s useful to know that the square brackets are in fact functions so the codes below are equivalent:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb29" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb29-1"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">[</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>(x, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, , )</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>     [,1] [,2] [,3] [,4]
[1,]    1    7   13   19
[2,]    4   10   16   22</code></pre>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb31" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb31-1">x[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, , ]</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>     [,1] [,2] [,3] [,4]
[1,]    1    7   13   19
[2,]    4   10   16   22</code></pre>
</div>
</div>
<p>The assignment operator for arrays can be written like below where the last argument is the value to replace the indexed array.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb33" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb33-1"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">[&lt;-</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>(x2, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, , , <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>, , 1

     [,1] [,2]
[1,]    0    0
[2,]    2    5
[3,]    3    6

, , 2

     [,1] [,2]
[1,]    0    0
[2,]    8   11
[3,]    9   12

, , 3

     [,1] [,2]
[1,]    0    0
[2,]   14   17
[3,]   15   18

, , 4

     [,1] [,2]
[1,]    0    0
[2,]   20   23
[3,]   21   24</code></pre>
</div>
</div>
<p>Below is similar.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb35" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb35-1">x2[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, , ] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span></code></pre></div></div>
</div>
<p>I say similar because the above actually modifies <code>x2</code> but the call before that didn’t. Below is the actual equivalent operation.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb36" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb36-1">x2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">[&lt;-</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>(x2, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, , , <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span></code></pre></div></div>
</div>
<details>
<summary>
Solution for indexing
</summary>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb37" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb37-1">index_first <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x) {</span>
<span id="cb37-2">  d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dim</span>(x)</span>
<span id="cb37-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">do.call</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"["</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(x, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bquote</span>()), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(d) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)))</span>
<span id="cb37-4">}</span>
<span id="cb37-5"></span>
<span id="cb37-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">index_first</span>(x)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>     [,1] [,2] [,3] [,4]
[1,]    1    7   13   19
[2,]    4   10   16   22</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb39" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb39-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">index_first</span>(z)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>, , 1

     [,1] [,2]
[1,]   NA   NA
[2,]   NA   NA

, , 2

     [,1] [,2]
[1,]   NA   NA
[2,]   NA   NA</code></pre>
</div>
</div>
</details>
<details>
<summary>
Solution for assignment
</summary>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb41" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb41-1">modify_first <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x, value) {</span>
<span id="cb41-2">  d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dim</span>(x)</span>
<span id="cb41-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">do.call</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"[&lt;-"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(x, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bquote</span>()), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(d) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(value)))</span>
<span id="cb41-4">}</span>
<span id="cb41-5"></span>
<span id="cb41-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">modify_first</span>(x, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>, , 1

     [,1] [,2]
[1,]    3    3
[2,]    2    5
[3,]    3    6

, , 2

     [,1] [,2]
[1,]    3    3
[2,]    8   11
[3,]    9   12

, , 3

     [,1] [,2]
[1,]    3    3
[2,]   14   17
[3,]   15   18

, , 4

     [,1] [,2]
[1,]    3    3
[2,]   20   23
[3,]   21   24</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb43" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb43-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">modify_first</span>(z, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>, , 1, 1

     [,1] [,2]
[1,]    3    3
[2,]   NA   NA

, , 2, 1

     [,1] [,2]
[1,]    3    3
[2,]   NA   NA

, , 1, 2

     [,1] [,2]
[1,]    3    3
[2,]   NA   NA

, , 2, 2

     [,1] [,2]
[1,]    3    3
[2,]   NA   NA</code></pre>
</div>
</div>
</details>
</section>
<section id="practice" class="level2">
<h2 class="anchored" data-anchor-id="practice">Practice</h2>
<p>So you might wonder when you need such a result. I actually used this for the <a href="https://github.com/emitanaka/edibble"><code>edibble</code></a> R-package to create a kind of generalised version of Latin square design, i.e.&nbsp;an array that kind of stitches up multiple Latin squares.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb45" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb45-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb45-2">edibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">latin_array</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nt =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>, , 1

     [,1] [,2] [,3]
[1,]    1    3    2
[2,]    3    2    1
[3,]    2    1    3

, , 2

     [,1] [,2] [,3]
[1,]    2    1    3
[2,]    1    3    2
[3,]    3    2    1

, , 3

     [,1] [,2] [,3]
[1,]    3    2    1
[2,]    2    1    3
[3,]    1    3    2</code></pre>
</div>
</div>
<p>Beyond the above, I’m not sure who needs to manipulate arrays with dynamic dimensions. If you have a use case, I’d love to know.</p>
</section>
<section id="advanced-r-programming-unit" class="level2">
<h2 class="anchored" data-anchor-id="advanced-r-programming-unit">Advanced R Programming unit</h2>
<p>The above challenges are sort of challenges that I hope to include in the Advanced R Programming unit that’s planned for Honours level in the Business Analytics major at Monash University. If you want to learn more about R as a programming lanuage (instead of a data analysis tool) then I’d recommend the <a href="https://adv-r.hadley.nz/">Advanced R book by Hadley Wickham</a>.</p>
<div class="cell">
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.r-project.org/Rlogo.png" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
</div>


</section>

 ]]></description>
  <category>R</category>
  <category>programming</category>
  <guid>https://emitanaka.org/blog/2022-01-18-manipulating-arrays-in-R/manipulating-arrays-in-r.html</guid>
  <pubDate>Mon, 17 Jan 2022 13:00:00 GMT</pubDate>
  <media:content url="https://www.r-project.org/Rlogo.png" medium="image" type="image/png"/>
</item>
<item>
  <title>Are anime titles getting longer?</title>
  <dc:creator>Emi Tanaka</dc:creator>
  <link>https://emitanaka.org/blog/2022-01-16-anime-titles/anime-titles.html</link>
  <description><![CDATA[ 

<!-- Title banner for blog posts (set in blog/_metadata.yml). Built from each
     post's front matter: title, date, author, categories, description and
     image (a pen sticker is shown when a post has no image). -->



<div class="cell" data-layout-align="center" data-hash="cache/unnamed-chunk-1_4724481b55bd02f5a7ee4c50ea073b08">
<div class="toggle-code">
<style type="text/css">
.toggle-code {
  display: none;
}

button {
  border-radius: 10px;
  color: var(--aside-color, rgba(0, 0, 0, 0.6));
  border-color: var(--aside-color, rgba(0, 0, 0, 0.6));
}

.scroll-output {
  height: 200px;
  overflow-y: scroll!important;
}
</style>
</div>
</div>
<aside>
<p>
<button onclick="showscript()">
Click Me
</button>
to see all code in this article. You can also find the link to the source Rmd file at the footer.
</p>
</aside>
<div class="cell" data-layout-align="center">
<div class="toggle-code">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>✔ ggplot2 3.3.6     ✔ purrr   0.3.4
✔ tibble  3.1.8     ✔ dplyr   1.0.9
✔ tidyr   1.2.0     ✔ stringr 1.4.0
✔ readr   2.1.2     ✔ forcats 0.5.1</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(scales)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>
Attaching package: 'scales'</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>The following object is masked from 'package:purrr':

    discard</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>The following object is masked from 'package:readr':

    col_factor</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(anidb)</span>
<span id="cb9-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_set</span>(</span>
<span id="cb9-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.background =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_rect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>),</span>
<span id="cb9-4">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.grid =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#f6e5ee"</span>),</span>
<span id="cb9-5">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#79003e"</span>),</span>
<span id="cb9-6">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.line =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#79003e"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>),</span>
<span id="cb9-7">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.ticks.length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.4</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mm"</span>),</span>
<span id="cb9-8">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.ticks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#79003e"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>),</span>
<span id="cb9-9">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#79003e"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">face =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>),</span>
<span id="cb9-10">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">strip.background =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_rect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#79003e"</span>,</span>
<span id="cb9-11">                                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#AD0059"</span>),</span>
<span id="cb9-12">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">strip.text =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>),</span>
<span id="cb9-13">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.title.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"plot"</span>,</span>
<span id="cb9-14">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#79003e"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">face =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>)))</span></code></pre></div></div>
</div>
</div>
<div class="cell" data-layout-align="center" data-hash="cache/data_7e0e49aa50caf9bc484d87a92ee3fada">
<div class="toggle-code">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1">db <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> officialtitles <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ntitle =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nchar</span>(title_primary))</span>
<span id="cb10-3"></span>
<span id="cb10-4">anime_origin <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> db <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">count</span>(origin) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">deframe</span>()</span>
<span id="cb10-7"></span>
<span id="cb10-8">dbl <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> db <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">desc</span>(ntitle)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span></code></pre></div></div>
</div>
</div>
<p><a href="https://anidb.net/">AniDB</a> is a website that hosts extensive information on anime from China, Japan and Korea. There are currently information on <strong>13,951 anime</strong> of which 91% originated from Japan.</p>
<p>As an anime lover, I’ve watched over 700 anime (which is still less than 5% in the whole database!) but one thing I noticed over recent years is that some anime titles are bizzarely long… or more like anime titles are becoming sentences. To explore this, I decided to use the <a href="https://github.com/emitanaka/anidb"><code>anidb</code></a> R-package to look at the data.</p>
<p>First note that anime titles come in many forms. For example,</p>
<ul>
<li>“新世紀エヴァンゲリオン” is the <strong>Japanese title</strong>,</li>
<li>“Shinseiki Evangelion” is the <strong>primary title</strong> (the official title in the country of origin but in romanized form), and</li>
<li>“Neon Genesis Evangelion” is the <strong>English title</strong>. The English title may be unavailable if the anime is not licensed for English audiences.</li>
</ul>
<p>In the following explorations, I use the primary title.</p>
<p>Figure @ref(fig:title-length-distribution) shows that the distribution of the primary title length. We can see that most anime titles are less than 70 characters but there are some Japanese anime title that are double this length. The top 25 animes have title length greater than 107 characters.</p>
<div class="cell" data-layout-align="center" data-hash="cache/title-length-distribution_8ec286bd82ce90c3367c863d8e6ce91f">
<div class="toggle-code">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(db, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(ntitle)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">binwidth =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#79003e"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"The length of the romanised primary anime title by county of origin"</span>, </span>
<span id="cb11-4">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Count"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb11-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(origin <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> ., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free_y"</span>)</span></code></pre></div></div>
</div>
</div>
<div class="cell" data-layout-align="center" data-hash="cache/title-length-distribution_05daed4b83076b79c11583bf2123f489">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-01-16-anime-titles/figures/title-length-distribution-1.png" class="img-fluid figure-img" width="672"></p>
<figcaption>Title length of Japanese anime are right skewed.</figcaption>
</figure>
</div>
</div>
</div>
<p>The five longest titles from longest to shortest are:</p>
<ul>
<li>“Honzuki no Gekokujou: Shisho ni Naru Tame ni wa Shudan o Erande Iraremasen - Eustachius no Shitamachi Sennyuu Daisakusen / Corinna-sama no Otaku Houmon”</li>
<li>“Buta no Gotoki Sanzoku ni Torawarete Shojo o Ubawareru Kyonyuu Himekishi &amp; Onna Senshi: Zettai Chinpo Nanka ni Maketari Shinai!! The Animation”</li>
<li>“Yahari Ore no Seishun LoveCome wa Machigatte Iru. Kochira to Shite mo Karera Kanojora no Yukusue ni Sachi Ookaran Koto o Negawazaru o Enai.”</li>
<li>“Yuusha ni Narenakatta Ore wa Shibushibu Shuushoku o Ketsui Shimashita.: Yuusha ni Narenakatta Ore no Imouto ga Joukyou Shite Kimashita.”</li>
<li>“Dungeon ni Deai o Motomeru no wa Machigatte Iru Darouka: Familia Myth - Dungeon ni Onsen o Motomeru no wa Machigatte Iru Darouka”</li>
</ul>
<div class="cell" data-layout-align="center" data-hash="cache/info_208fccec6399a792f2fe0066036f3f1c">
<div class="toggle-code">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1">info <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">anime_info</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(dbl<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>aid)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb12-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(dbl, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"aid"</span>)</span></code></pre></div></div>
</div>
</div>
<p>Because of AniDB’s limit on API call (multiple requests can get you banned easily – turns out that the limit is quite small; about 13-14 calls already got me banned…), I’m going to just study the top 25 anime in terms of title length.</p>
<p>Figure @ref(fig:release-date) suggest that super long titles are more common in the last decade than in the past. But the analysis is only based on top 25 anime with the longest titles so it could benefit from more extensive study.</p>
<div class="cell" data-layout-align="center" data-hash="cache/release-date_ec1c1c11caaccf51de4175b7c1c36606">
<div class="toggle-code">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(info, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(start_date, ntitle)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb13-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#79003e"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb13-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Start date"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Title length"</span>)</span></code></pre></div></div>
</div>
</div>
<div class="cell" data-layout-align="center" data-hash="cache/release-date_6ad9bca34ad1dd2948914c509a0eeffb">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2022-01-16-anime-titles/figures/release-date-1.png" class="img-fluid figure-img" width="672"></p>
<figcaption>Top 25 anime in terms of title length. Looks like super long titles occur more in the last decade. Top 6 anime with the longest titles are all released after 2010.</figcaption>
</figure>
</div>
</div>
</div>
<div class="cell" data-layout-align="center" data-hash="cache/unnamed-chunk-2_50c2eb9e1d0c0e5ab717f044228eb42c">
<div class="toggle-code">
<script type="text/javascript">
function showscript() {
  var x = document.getElementsByClassName('toggle-code');
  var n = x.length;
  for (var i = 0; i < n; i++) {
    var e = x[i];
    if (e.style.display == "block") {
      e.style.display = "none";
    } else {
      e.style.display = "block";
    }
  }
}
</script>
</div>
</div>



 ]]></description>
  <category>anime</category>
  <category>R</category>
  <guid>https://emitanaka.org/blog/2022-01-16-anime-titles/anime-titles.html</guid>
  <pubDate>Sat, 15 Jan 2022 13:00:00 GMT</pubDate>
</item>
<item>
  <title>Current state of R packages for the design of experiments</title>
  <dc:creator>Emi Tanaka</dc:creator>
  <link>https://emitanaka.org/blog/2021-02-03-current-state-of-experimental-design-r-packages/current-state-of-experimental-design-r-packages.html</link>
  <description><![CDATA[ 

<!-- Title banner for blog posts (set in blog/_metadata.yml). Built from each
     post's front matter: title, date, author, categories, description and
     image (a pen sticker is shown when a post has no image). -->



<div class="cell" data-layout-align="center" data-hash="cache/unnamed-chunk-1_4724481b55bd02f5a7ee4c50ea073b08">
<div class="toggle-code">
<style type="text/css">
.toggle-code {
  display: none;
}

button {
  border-radius: 10px;
  color: var(--aside-color, rgba(0, 0, 0, 0.6));
  border-color: var(--aside-color, rgba(0, 0, 0, 0.6));
}

.scroll-output {
  height: 200px;
  overflow-y: scroll!important;
}
</style>
</div>
</div>
<aside>
<p>
<button onclick="showscript()">
Click Me
</button>
to see all code in this article. You can also find the link to the source Rmd file at the footer.
</p>
</aside>
<div class="cell" data-layout-align="center">
<div class="toggle-code">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>✔ ggplot2 3.3.6     ✔ purrr   0.3.4
✔ tibble  3.1.8     ✔ dplyr   1.0.9
✔ tidyr   1.2.0     ✔ stringr 1.4.0
✔ readr   2.1.2     ✔ forcats 0.5.1</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(rvest)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>
Attaching package: 'rvest'</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>The following object is masked from 'package:readr':

    guess_encoding</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(lubridate)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>
Attaching package: 'lubridate'</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>The following objects are masked from 'package:base':

    date, intersect, setdiff, union</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(cranlogs)</span>
<span id="cb11-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(glue)</span>
<span id="cb11-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(scales)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>
Attaching package: 'scales'</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>The following object is masked from 'package:purrr':

    discard</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>The following object is masked from 'package:readr':

    col_factor</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(colorspace)</span>
<span id="cb15-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidytext)</span>
<span id="cb15-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pluralize)</span>
<span id="cb15-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(kableExtra)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>
Attaching package: 'kableExtra'</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>The following object is masked from 'package:dplyr':

    group_rows</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(igraph)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>
Attaching package: 'igraph'</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>The following objects are masked from 'package:lubridate':

    %--%, union</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>The following objects are masked from 'package:dplyr':

    as_data_frame, groups, union</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>The following objects are masked from 'package:purrr':

    compose, simplify</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>The following object is masked from 'package:tidyr':

    crossing</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>The following object is masked from 'package:tibble':

    as_data_frame</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>The following objects are masked from 'package:stats':

    decompose, spectrum</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>The following object is masked from 'package:base':

    union</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggraph)</span>
<span id="cb27-2"></span>
<span id="cb27-3">myggtheme <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb27-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.background =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_rect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>),</span>
<span id="cb27-5">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.grid =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#f6e5ee"</span>),</span>
<span id="cb27-6">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#79003e"</span>),</span>
<span id="cb27-7">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.line =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#79003e"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>),</span>
<span id="cb27-8">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.ticks.length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.4</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mm"</span>),</span>
<span id="cb27-9">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.ticks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#79003e"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>),</span>
<span id="cb27-10">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#79003e"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">face =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>),</span>
<span id="cb27-11">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">strip.background =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_rect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#79003e"</span>,</span>
<span id="cb27-12">                                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#AD0059"</span>),</span>
<span id="cb27-13">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">strip.text =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>),</span>
<span id="cb27-14">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.title.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"plot"</span>,</span>
<span id="cb27-15">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#79003e"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">face =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>)) </span></code></pre></div></div>
</div>
</div>
<div class="cell" data-layout-align="center" data-hash="cache/cran-titles_f39207395ca4110f2f3ee8adb82586c5">
<div class="toggle-code">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb28" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb28-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Thanks to Dirk Eddelbuettel's answer on SO:</span></span>
<span id="cb28-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># https://stackoverflow.com/questions/11560865/list-and-description-of-all-packages-in-cran-from-within-r</span></span>
<span id="cb28-3">url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://cran.rstudio.com/web/packages/packages.rds"</span></span>
<span id="cb28-4">db <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">readRDS</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">url</span>(url)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb28-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.data.frame</span>()</span></code></pre></div></div>
</div>
</div>
<div class="cell" data-layout-align="center" data-hash="cache/unnamed-chunk-2_e20bb5742f5b840627ba3db629388806">
<div class="toggle-code">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb29" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb29-1">nanalysis <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> db <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb29-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_detect</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tolower</span>(Title), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"analysis"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb29-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>()</span>
<span id="cb29-4"></span>
<span id="cb29-5">ndesign <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> db <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb29-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_detect</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tolower</span>(Title), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"design"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb29-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>()</span></code></pre></div></div>
</div>
</div>
<section id="data-collection" class="level1">
<h1>Data collection</h1>
<p>As many know, it doesn’t matter how good your analytical tools is if your data are rubbish. This sentiment is often captured in the expression “garbage in, garbage out”. It’s something we all seem to know but there is still a tendency for many of us to place a greater focus on the analysis<sup>1</sup>. This is perhaps all natural given that a potential for discovery is just so much more exciting than ensuring the quality of the collected data.</p>
<p>So what is considered as good quality data? A lack of error in the data? Data containing enough range of variables and sample size for the downstream analysis? Giving an explicit definition of a good quality data is a fraught exercise, but if you <strong>know how the data were collected</strong> then you can better perform the <em>initial data analysis</em> <span class="citation" data-cites="Chatfield1985-yz">(Chatfield 1985)</span> to weed out (or fix) potential poor quality data. This step will likely get more value out of the data than fitting complex models to poor quality data.</p>
<p>Better than knowing how the data were collected, if you can <em>design the collection of data</em> so that it’s optimised for the purpose of the analysis<sup>2</sup>, then you can potentially get even a better value out of your data. Not all data collection starts with an explicit analytical plan though. Furthermore, you may have very little control of how the data are collected. Often these are <em>observational data</em> or making a secondary use of <em>experimental data</em>. This article will focus on data collection of an experiment where you have some control of the collection process.</p>
<section id="experimental-data" class="level2">
<h2 class="anchored" data-anchor-id="experimental-data">Experimental data</h2>
<p>All experiments are conducted with some objective in mind. This could be that a scientist may wish to test their hypothesis, a manufacturer wants to know which manufacturing process is better or a researcher wants to understand some cause-and-effect relationships. A characteristic part of an experiment is that the experimenter has control over some explanatory variables. In a <em>comparative experiment</em>, the control is over the allocation of treatments to subjects. Designing an experiment in the statistics discipline usually focus on this allocation, although it’s important to keep in mind that there are other decision factors in an experiment.</p>
<p>Data that are collected from experiments are what we refer to as <em>experimental data</em>. Because it was collected with some objective in mind followed by some data collection plan, experimental data are often thought of to be better quality than observational data. But then again if you can’t quantify the quality of data, you can’t really tell. Certain scientific claims (e.g.&nbsp;causation, better treatment) can only be substantiated by experiments and so experimental data is held to a higher standard in general.</p>
</section>
</section>
<section id="design-and-analysis-of-experiments" class="level1">
<h1>Design and analysis of experiments</h1>
<div class="cell" data-layout-align="center" data-hash="cache/doe-cran_b289ffe2415fb119a04acf674a928a96">
<div class="toggle-code">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb30" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb30-1">dat_DoE <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_html</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://cran.r-project.org/web/views/ExperimentalDesign.html"</span>)</span>
<span id="cb30-2">date_download <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.Date</span>()</span>
<span id="cb30-3">cran_names <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">available.packages</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">repos =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://cran.rstudio.com/"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb30-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rownames</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb30-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>() <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># it should be unique</span></span>
<span id="cb30-6">doe_pkgs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dat_DoE <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb30-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_nodes</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"li"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb30-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_nodes</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb30-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb30-10">  .[. <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> cran_names] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb30-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>()</span>
<span id="cb30-12"></span>
<span id="cb30-13">dat_survey <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_html</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://cran.r-project.org/web/views/OfficialStatistics.html"</span>)</span>
<span id="cb30-14">survey_pkgs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dat_survey <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb30-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_nodes</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"li"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb30-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_nodes</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb30-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb30-18">  .[. <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> cran_names] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb30-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>()</span></code></pre></div></div>
</div>
</div>
<p>There are all together 83 R-packages in the <a href="https://cran.r-project.org/web/views/ExperimentalDesign.html">CRAN Task View of Design of Experiments &amp; Analysis of Experimental Data</a> as of 2022-09-18.<sup>3</sup> I’m going to refer these packages as <strong><em>DoE packages</em></strong>, although there are some packages in the mix that are more about the analysis of experimental data rather than the design of experiments and there are some packages that are missing in the list (e.g.&nbsp;<code>DeclareDesign</code>). The DoE packages make up about 0.4% of the 18,592 packages available in CRAN.</p>
<p>The DoE packages don’t include survey design. These instead belong to the <a href="https://cran.r-project.org/web/views/OfficialStatistics.html">CRAN Task View of Official Statistics &amp; Survey Methodology</a> which contains 122 packages. While some surveys are part of an experimental study, most often they generate observational data.</p>
<p>Below I have a number of different analysis for these DoE packages. If you push the button on the top right corner of this article, you can toggle the display for the code or alternatively you can have a look at the source Rmd document.</p>
<section id="bigram-of-doe-package-titles-and-descriptions" class="level2">
<h2 class="anchored" data-anchor-id="bigram-of-doe-package-titles-and-descriptions">Bigram of DoE package titles and descriptions</h2>
<div class="cell" data-layout-align="center" data-hash="cache/bigram_84ccf4aa6b764cb980c60f05904ed9ed">
<div class="toggle-code">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb31" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb31-1">stop_words_ext <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(stop_words<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>word, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"doi"</span>)</span>
<span id="cb31-2"></span>
<span id="cb31-3">doe_db <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> db <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb31-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Package <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> doe_pkgs) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb31-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Description =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_replace_all</span>(Description, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" "</span>),</span>
<span id="cb31-6">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Description =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_squish</span>(Description),</span>
<span id="cb31-7">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_replace_all</span>(Title, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" "</span>))</span>
<span id="cb31-8"></span>
<span id="cb31-9">bigram_tab <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(data, col) {</span>
<span id="cb31-10">  data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb31-11">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unnest_tokens</span>(word, {{col}}, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">token =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ngrams"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb31-12">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">separate</span>(word, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"word1"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"word2"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" "</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb31-13">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">word1 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">singularize</span>(word1),</span>
<span id="cb31-14">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">word2 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">singularize</span>(word2)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb31-15">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># don't count the same bigram within the same package</span></span>
<span id="cb31-16">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">distinct</span>(Package, word1, word2) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb31-17">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>word1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> stop_words_ext,</span>
<span id="cb31-18">           <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>word2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> stop_words_ext,</span>
<span id="cb31-19">           <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_detect</span>(word1, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^[0-9.]+$"</span>),</span>
<span id="cb31-20">           <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_detect</span>(word2, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^[0-9.]+$"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb31-21">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">count</span>(word1, word2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sort =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)  </span>
<span id="cb31-22">}</span></code></pre></div></div>
</div>
</div>
<div class="cell" data-layout-align="center" data-hash="cache/bigram-desc_5f66569291fdb07c34d162d16e40cf8d">
<div class="toggle-code">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb32" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb32-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bigram_tab</span>(doe_db, Description) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb32-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb32-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">word =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(word1, word2)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb32-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(word, n) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb32-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kbl</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"The bigram of the R-package _descriptions_ as provided in the DESCRIPTION file in CRAN."</span>, </span>
<span id="cb32-6">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col.names =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Bigram"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Count"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb32-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable_classic</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">full_width =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span></code></pre></div></div>
</div>
</div>
<div class="cell" data-layout-align="center" data-hash="cache/bigram-title_e4b043b876e28343d3010c4548eb2a3c">
<div class="toggle-code">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb33" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb33-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bigram_tab</span>(doe_db, Title) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb33-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb33-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">word =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(word1, word2)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb33-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(word, n) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb33-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kbl</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"The bigram of the R-package _titles_ as provided in the DESCRIPTION file in CRAN."</span>, </span>
<span id="cb33-6">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col.names =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Bigram"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Count"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb33-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable_classic</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">full_width =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span></code></pre></div></div>
</div>
</div>
<p>Table @ref(tab:bigram-title) shows the most common bigrams in the title of the DoE packages. It’s perhaps not surprising but the words “optimal design” and “experimental design” are the top. It’s also likely that the words “design of experiments” appears often but because this is a bigram (two consecutive words) so it doesn’t appear. You might then wonder if that’s the case words like “design of” or “of experiments” should make an appearance, however “of” is a stop word and these are filtered out otherwise unwanted bigrams come up on the top.</p>
<p>There are couple of words like “clinical trial” and “dose finding” that suggests applications in medical experiments, as well as “microarray experiment” that suggests application in bioinformatics.</p>
<div class="cell" data-layout-align="center" data-hash="cache/bigram-title_081af0d14fda3ef38c8546658fdb4577">
<div class="cell-output-display">
<table class="lightable-classic caption-top table table-sm table-striped small">
<caption>The bigram of the R-package _titles_ as provided in the DESCRIPTION file in CRAN.</caption>
<thead>
<tr class="header">
<th style="text-align: left;" data-quarto-table-cell-role="th">Bigram</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Count</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">experimental design</td>
<td style="text-align: right;">6</td>
</tr>
<tr class="even">
<td style="text-align: left;">optimal design</td>
<td style="text-align: right;">6</td>
</tr>
<tr class="odd">
<td style="text-align: left;">clinical trial</td>
<td style="text-align: right;">5</td>
</tr>
<tr class="even">
<td style="text-align: left;">dose finding</td>
<td style="text-align: right;">5</td>
</tr>
<tr class="odd">
<td style="text-align: left;">sequential design</td>
<td style="text-align: right;">5</td>
</tr>
<tr class="even">
<td style="text-align: left;">block design</td>
<td style="text-align: right;">4</td>
</tr>
<tr class="odd">
<td style="text-align: left;">microarray experiment</td>
<td style="text-align: right;">4</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>The title alone might be too succinct for text analysis so I also had a look at the most common bigrams in the description of the DoE packages as shown in Table @ref(tab:bigram-desc). The counts in Table @ref(tab:bigram-desc) (and also Table @ref(tab:bigram-title)) is across the DoE packages. To be more clear, even if the bigram is mentioned multiple times within the description, it’s only counted once per package. This removes the inflation of the counts due to one package mentioning the same bigram over and over again.</p>
<p>Again not surprisingly “experimental design” and “optimal design” comes on top in the DoE package descriptions. The words “graphical user” and “user interface” implies that the trigram “graphical user interface” was probably common.</p>
<div class="cell" data-layout-align="center" data-hash="cache/bigram-desc_202383a8ff7542e3ecde0373579a6f4d">
<div class="cell-output-display">
<table class="lightable-classic caption-top table table-sm table-striped small">
<caption>The bigram of the R-package _descriptions_ as provided in the DESCRIPTION file in CRAN.</caption>
<thead>
<tr class="header">
<th style="text-align: left;" data-quarto-table-cell-role="th">Bigram</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Count</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">experimental design</td>
<td style="text-align: right;">7</td>
</tr>
<tr class="even">
<td style="text-align: left;">optimal design</td>
<td style="text-align: right;">7</td>
</tr>
<tr class="odd">
<td style="text-align: left;">block design</td>
<td style="text-align: right;">5</td>
</tr>
<tr class="even">
<td style="text-align: left;">clinical trial</td>
<td style="text-align: right;">5</td>
</tr>
<tr class="odd">
<td style="text-align: left;">factorial design</td>
<td style="text-align: right;">5</td>
</tr>
<tr class="even">
<td style="text-align: left;">graphical user</td>
<td style="text-align: right;">5</td>
</tr>
<tr class="odd">
<td style="text-align: left;">microarray experiment</td>
<td style="text-align: right;">5</td>
</tr>
<tr class="even">
<td style="text-align: left;">user interface</td>
<td style="text-align: right;">5</td>
</tr>
</tbody>
</table>
</div>
</div>
</section>
<section id="network-of-doe-package-imports-and-dependencies" class="level2">
<h2 class="anchored" data-anchor-id="network-of-doe-package-imports-and-dependencies">Network of DoE package imports and dependencies</h2>
<div class="cell" data-layout-align="center" data-hash="cache/unnamed-chunk-3_96b8cb9ee5fb8894c681d0cf16d368f8">
<div class="toggle-code">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb34" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb34-1">doe_imports <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> doe_db <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb34-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Depends =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_replace_all</span>(Depends, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" "</span>),</span>
<span id="cb34-3">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Depends =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_replace_all</span>(Depends, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fixed</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"("</span>), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" ("</span>),</span>
<span id="cb34-4">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Imports =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_replace_all</span>(Imports, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" "</span>),</span>
<span id="cb34-5">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Imports =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_replace_all</span>(Imports, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fixed</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"("</span>), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" ("</span>),</span>
<span id="cb34-6">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">imports =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_c</span>(Depends, Imports, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">","</span>),</span>
<span id="cb34-7">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">imports =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_split</span>(imports, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">","</span>),</span>
<span id="cb34-8">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">imports =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(imports, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>{</span>
<span id="cb34-9">                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_squish</span>(.x) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb34-10">                      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">word</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb34-11">                      .[.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>]}</span>
<span id="cb34-12">           ),</span>
<span id="cb34-13">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">imports_doe =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(imports, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>.x[.x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> doe_pkgs])) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb34-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Package, imports_doe) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb34-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unnest_longer</span>(imports_doe) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb34-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(imports_doe)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb34-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">from =</span> imports_doe, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">to =</span> Package) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb34-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(from, to)</span></code></pre></div></div>
</div>
</div>
<p>Figure @ref(fig:doe-network) shows the imports and dependency between the DoE packages. We can see here that <code>DoE.wrapper</code> imports a fair number of DoE packages that results in the major network cluster see in Figure @ref(fig:doe-network). <code>AlgDesign</code> and <code>DoE.base</code> are imported into four other DoE packages so form an important base in the DoE world.</p>
<div class="cell" data-layout-align="center" data-hash="cache/doe-network_52fc47ded26c03216e0f84afac9d319e">
<div class="toggle-code">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb35" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb35-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">graph_from_data_frame</span>(doe_imports) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb35-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggraph</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">layout =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'fr'</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb35-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_edge_link</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start_cap =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">label_rect</span>(node1.name),</span>
<span id="cb35-4">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end_cap =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">label_rect</span>(node2.name)), </span>
<span id="cb35-5">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">arrow =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrow</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'mm'</span>)),</span>
<span id="cb35-6">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#79003e"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb35-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_node_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> name),</span>
<span id="cb35-8">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#79003e"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb35-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.background =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_rect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#f6e5ee"</span>,</span>
<span id="cb35-10">                                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#79003e"</span>),</span>
<span id="cb35-11">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.margin =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">margin</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>))</span></code></pre></div></div>
</div>
</div>
<p>(ref:network) The network of imports and dependency among DoE packages alone. Each node represents a DoE package. DoE packages with no imports or dependency on other DoE packages are excluded. Each arrow represents the relationship between the packages such that the package on the tail is used by package on the head of the arrow.</p>
<div class="cell" data-layout-align="center" data-hash="cache/doe-network_88da89cc0bfeae084a3269d34fc5ca9c">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2021-02-03-current-state-of-experimental-design-r-packages/figures/doe-network-1.png" class="img-fluid figure-img" width="960"></p>
<figcaption>(ref:network)</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="cran-download-logs" class="level2">
<h2 class="anchored" data-anchor-id="cran-download-logs">CRAN download logs</h2>
<div class="cell" data-layout-align="center" data-hash="cache/cran-data_c156d6a8ccebe5d076347e6c17559b78">
<div class="toggle-code">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb36" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb36-1">end <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.Date</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># usually 1-2 days are not available yet</span></span>
<span id="cb36-2">start <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> end <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">years</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">days</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb36-3">dldat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cran_downloads</span>(doe_pkgs, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">from =</span> start, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">to =</span> end)</span></code></pre></div></div>
</div>
</div>
<div class="cell" data-layout-align="center" data-hash="cache/download-hist_e41b286fef5ac00841a1e3fef5930dd0">
<div class="toggle-code">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb37" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb37-1">dldat <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb37-2">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(package) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb37-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">total =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(count)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb37-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(total)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb37-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#AD0059"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb37-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_log10</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> comma) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb37-7">  myggtheme <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb37-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total download counts from {start} to {end}"</span>),</span>
<span id="cb37-9">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of packages"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb37-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>))</span></code></pre></div></div>
</div>
</div>
<p>Figure @ref(fig:download-hist) shows the distribution of the total download counts over the last 5 years<sup>4</sup> of the DoE packages. This graph doesn’t take into account that some DoE packages may only have been on CRAN in the last 5 years so the counts are in favour of DoE packages that’s been on CRAN longer.</p>
<p>(ref:hist) Histogram of the total download count over last 5 years of the DoE packages.</p>
<div class="cell" data-layout-align="center" data-hash="cache/download-hist_7eb855d386c29493d7b6a14e247802f8">
<div class="cell-output cell-output-stderr">
<pre><code>`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.</code></pre>
</div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2021-02-03-current-state-of-experimental-design-r-packages/figures/download-hist-1.png" class="img-fluid figure-img" width="672"></p>
<figcaption>(ref:hist)</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="top-5-doe-packages" class="level2">
<h2 class="anchored" data-anchor-id="top-5-doe-packages">Top 5 DoE packages</h2>
<div class="cell" data-layout-align="center" data-hash="cache/top5_a618f71090c20cb3a411e2b112d777cb">
<div class="toggle-code">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb39" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb39-1">ntop <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span></span>
<span id="cb39-2"></span>
<span id="cb39-3">top5sum_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dldat <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb39-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(package) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb39-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">total =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(count)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb39-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ungroup</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb39-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_max</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by =</span> total, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> ntop)</span>
<span id="cb39-8"></span>
<span id="cb39-9">top5 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> top5sum_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb39-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(package) </span>
<span id="cb39-11"></span>
<span id="cb39-12">top5_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dldat <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb39-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(package <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> top5) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb39-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">package =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_reorder</span>(package, count, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(x))) </span></code></pre></div></div>
</div>
</div>
<p>The top 5 downloaded DoE packages at the time of this writing are <code>AlgDesign</code>, <code>lhs</code>, <code>DiceDesign</code>, <code>DoE.base</code>, and <code>FrF2</code>. You can see the download counts in Figure @ref(fig:download-barplot).</p>
<div class="cell" data-layout-align="center" data-hash="cache/download-barplot_cf60946d88e2fa575c99b17193c85a0a">
<div class="toggle-code">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb40" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb40-1">top5sum_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb40-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">package =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_reorder</span>(package, total)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb40-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(total, package)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb40-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> package)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb40-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total downloads from {start} to {end}"</span>),</span>
<span id="cb40-6">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Package"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb40-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> comma, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb40-8">  myggtheme <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb40-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_discrete_qualitative</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rev =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb40-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span></code></pre></div></div>
</div>
</div>
<p>(ref:barplot) The above barplot shows the total downloads of the top 5 downloaded DoE packages from the period 2017-09-18 to 2022-09-16.</p>
<div class="cell" data-layout-align="center" data-hash="cache/download-barplot_6a4acaf1e4a1098a5bcfc8f319b5b0a2">
<div class="cell-output cell-output-stderr">
<pre><code>Warning: `guides(&lt;scale&gt; = FALSE)` is deprecated. Please use `guides(&lt;scale&gt; =
"none")` instead.</code></pre>
</div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2021-02-03-current-state-of-experimental-design-r-packages/figures/download-barplot-1.png" class="img-fluid figure-img" width="672"></p>
<figcaption>(ref:barplot)</figcaption>
</figure>
</div>
</div>
</div>
<p>We can have a look at further examination of the top 5 DoE packages by looking at the daily download counts as shown in Figure @ref(fig:download-barplot). The download counts are the raw values and these include downloads by CRAN mirror and bots. There is a noticeable spike when there is an update to the CRAN package. This is partly because when there is a new version of the package, when you install other packages that depend or import it then R will prompt you to install the new version. This means that the download counts are inflated and to some extent you can artificially boost them by making regular CRAN updates. The <code>adjustedcranlogs</code> <span class="citation" data-cites="adjustedcranlogs">(Morgan-Wall 2017)</span> makes a nice attempt to adjust the raw counts based on a certain heuristic. I didn’t use it since the adjustment is stochastic and I <a href="https://github.com/tylermorganwall/adjustedcranlogs/issues/6">appear to have hit a bug</a>.</p>
<div class="cell" data-layout-align="center" data-hash="cache/pkg-updates_55477ece477d4a50a82565d0549c4da6">
<div class="toggle-code">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb42" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb42-1">pkg_url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://cran.r-project.org/web/packages/{pkg}/index.html"</span></span>
<span id="cb42-2">pkg_archive <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://cran.r-project.org/src/contrib/Archive/{pkg}/"</span></span>
<span id="cb42-3">pkg_updates <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(top5, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(pkg) {</span>
<span id="cb42-4">    last_update <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_html</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(pkg_url)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb42-5">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_table</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb42-6">      .[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb42-7">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(X1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Published:"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb42-8">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(X2) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb42-9">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ymd</span>()</span>
<span id="cb42-10">      </span>
<span id="cb42-11">    archive_dates <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tryCatch</span>({ </span>
<span id="cb42-12">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_html</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(pkg_archive)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb42-13">          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_table</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb42-14">          .[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb42-15">          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Last modified</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb42-16">          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ymd_hm</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb42-17">          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na.omit</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb42-18">          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>()</span>
<span id="cb42-19">      }, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">error =</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(e) {</span>
<span id="cb42-20">        <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span></span>
<span id="cb42-21">      })</span>
<span id="cb42-22">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(archive_dates, last_update)</span>
<span id="cb42-23">  })</span>
<span id="cb42-24"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(pkg_updates) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> top5</span>
<span id="cb42-25"></span>
<span id="cb42-26">updates <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlist</span>(pkg_updates) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb42-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">enframe</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"package"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"update"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb42-28">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># unlist converts date to integers</span></span>
<span id="cb42-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">update =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(update, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">origin =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1970-01-01"</span>),</span>
<span id="cb42-30">         <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># need to get rid of the numbers appended to pkg names</span></span>
<span id="cb42-31">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">package =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(package, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(top5, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">collapse=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"|"</span>)),</span>
<span id="cb42-32">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">package =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(package, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels =</span> top5)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb42-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">between</span>(update, start, end))</span></code></pre></div></div>
</div>
</div>
<div class="cell" data-layout-align="center" data-hash="cache/download-timeplot_dd8a50e8d31ede7a87233a416f1668cb">
<div class="toggle-code">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb43" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb43-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(top5_df, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(date, count, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> package)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb43-2">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># add shadow lines</span></span>
<span id="cb43-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(top5_df, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">package2 =</span> package), </span>
<span id="cb43-4">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gray"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> package2)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb43-5">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># add date when package was updated</span></span>
<span id="cb43-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> updates, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> update),</span>
<span id="cb43-7">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#79003e"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb43-8">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># the trend line</span></span>
<span id="cb43-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb43-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_log10</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb43-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(package <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> .) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb43-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Top 5 downloaded DoE packages from {start} to {end}"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb43-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_discrete_qualitative</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb43-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb43-15">  myggtheme</span></code></pre></div></div>
</div>
</div>
<p>(ref:timeplot) The above plot shows the daily downloads of the top 5 downloaded DoE packages from the period 2017-09-18 to 2022-09-16. The vertical dotted bar corresponds to the date that a new version of the corresponding package was released on CRAN.</p>
<div class="cell" data-layout-align="center" data-preview="true" data-hash="cache/download-timeplot_a51458fcfd5fe0b35099ec51c76fa5ff">
<div class="cell-output cell-output-stderr">
<pre><code>Warning: `guides(&lt;scale&gt; = FALSE)` is deprecated. Please use `guides(&lt;scale&gt; =
"none")` instead.</code></pre>
</div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2021-02-03-current-state-of-experimental-design-r-packages/figures/download-timeplot-1.png" class="img-fluid figure-img" width="672"></p>
<figcaption>(ref:timeplot)</figcaption>
</figure>
</div>
</div>
</div>
</section>
</section>
<section id="r-packages" class="level1 page-columns page-full">
<h1>R-packages</h1>
<p>Here we have a closer look at the functions of the top 5 downloaded DoE packages below ordered by their download counts.</p>
<ol type="1">
<li><strong><code>AlgDesign</code></strong> <a href="https://cran.r-project.org/web/packages/AlgDesign/index.html"><i class="fab fa-r-project"></i> CRAN</a> <a href="https://github.com/jvbraun/AlgDesign"><i class="fab fa-github"></i> GitHub</a> <i class="fas fa-book"></i> <span class="citation" data-cites="AlgDesign">Wheeler (2019)</span><br>
<em>Algorithmic Experimental Design</em><br>
Originally written by <i class="fas fa-user"></i> Bob Wheeler but <i class="fas fa-user"></i> Jerome Braun have taken over maintenance of the package.</li>
<li><strong><code>agricolae</code></strong> <a href="https://cran.r-project.org/web/packages/agricolae/index.html"><i class="fab fa-r-project"></i> CRAN</a> <i class="fas fa-book"></i> <span class="citation" data-cites="agricolae">de Mendiburu (2020)</span><br>
<em>Statistical Procedures for Agricultural Research</em><br>
Written and maintained by <i class="fas fa-user"></i> Felipe de Mendiburu</li>
<li><strong><code>lhs</code></strong> <a href="https://cran.r-project.org/web/packages/lhs/index.html"><i class="fab fa-r-project"></i> CRAN</a> <a href="https://github.com/bertcarnell/lhs"><i class="fab fa-github"></i> GitHub</a> <i class="fas fa-book"></i> <span class="citation" data-cites="lhs">Carnell (2020)</span><br>
<em>Latin Hypercube Samples</em><br>
Written and maintained by <i class="fas fa-user"></i> Rob Carnell</li>
<li><strong><code>ez</code></strong> <a href="https://cran.r-project.org/web/packages/ez/index.html"><i class="fab fa-r-project"></i> CRAN</a> <a href="https://github.com/mike-lawrence/ez"><i class="fab fa-github"></i> GitHub</a> <i class="fas fa-book"></i> <span class="citation" data-cites="ez">Lawrence (2016)</span><br>
<em>Easy Analysis and Visualization of Factorial Experiments</em><br>
Written and maintained by <i class="fas fa-user"></i> Michael A. Lawrence</li>
<li><strong><code>DoE.base</code></strong> <a href="https://cran.r-project.org/web/packages/DoE.base/index.html"><i class="fab fa-r-project"></i> CRAN</a> <i class="fas fa-book"></i> <span class="citation" data-cites="DoE.base">Grömping (2018)</span><br>
<em>Full Factorials, Orthogonal Arrays and Base Utilities for DoE Packages</em><br>
Written and maintained by <i class="fas fa-user"></i> Ulrike Groemping.</li>
</ol>
<aside>
Interestingly these top 5 DoE packages have only <em>one active author</em>. Bob Wheeler doesn’t seem to actively contribute to <code>AlgDesign</code> any longer; and there are two contributors for <code>DoE.base</code> but are not listed as authors.
</aside>
<p>Before we look at the packages, let’s set a seed so we can reproduce the results.</p>
<div class="cell" data-layout-align="center" data-hash="cache/unnamed-chunk-5_0896e2a221a9672bd4c58e96dff969f0">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb45" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb45-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2021</span>)</span></code></pre></div></div>
</div>
<section id="algdesign" class="level2">
<h2 class="anchored" data-anchor-id="algdesign"><code>AlgDesign</code></h2>
<p>To start off, we begin with the most downloaded DoE package, <code>AlgDesign</code>. The examples below are taken directly from the <a href="https://cran.r-project.org/web/packages/AlgDesign/vignettes/AlgDesign.pdf">vignette of the <code>AlgDesign</code> package</a>.</p>
<div class="cell" data-layout-align="center" data-hash="cache/algdesign_4afde1513d3d4ec5a2087680af450b60">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb46" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb46-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(AlgDesign)</span></code></pre></div></div>
</div>
<p>You can create a balanced incomplete block design using the <code>optBlock</code> function. It’s using an optimal design framework where the default criterion is D criterion and the implied model is given in the first argument.</p>
<div class="cell" data-layout-align="center" data-hash="cache/algdesign-BIBD_c8a026d77b341a579995652104ac33b5">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb47" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb47-1">BIB <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">optBlock</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> ., </span>
<span id="cb47-2">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">withinData =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>), </span>
<span id="cb47-3">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">blocksize =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>))</span>
<span id="cb47-4">BIB</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre class="scroll-output"><code>$D
[1] 0.08033556

$diagonality
[1] 0.692

$Blocks
$Blocks$B1
  X1
1  1
3  3
4  4

$Blocks$B2
  X1
2  2
4  4
5  5

$Blocks$B3
  X1
4  4
6  6
7  7

$Blocks$B4
  X1
3  3
5  5
6  6

$Blocks$B5
  X1
2  2
3  3
7  7

$Blocks$B6
  X1
1  1
2  2
6  6

$Blocks$B7
  X1
1  1
5  5
7  7


$design
   X1
1   1
3   3
4   4
2   2
41  4
5   5
42  4
6   6
7   7
31  3
51  5
61  6
21  2
32  3
71  7
11  1
22  2
62  6
12  1
52  5
72  7

$rows
 [1] 1 3 4 2 4 5 4 6 7 3 5 6 2 3 7 1 2 6 1 5 7</code></pre>
</div>
</div>
<p><code>AlgDesign</code> also includes helper functions to generate a factorial structure.</p>
<div class="cell" data-layout-align="center" data-hash="cache/unnamed-chunk-6_37d477af94d3c8469f439ce7eaf2eb3d">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb49" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb49-1">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gen.factorial</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>)</span>
<span id="cb49-2">dat</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre class="scroll-output"><code>    X1 X2 X3 X4 X5 X6 X7
1   -1 -1 -1 -1 -1 -1 -1
2    1 -1 -1 -1 -1 -1 -1
3   -1  1 -1 -1 -1 -1 -1
4    1  1 -1 -1 -1 -1 -1
5   -1 -1  1 -1 -1 -1 -1
6    1 -1  1 -1 -1 -1 -1
7   -1  1  1 -1 -1 -1 -1
8    1  1  1 -1 -1 -1 -1
9   -1 -1 -1  1 -1 -1 -1
10   1 -1 -1  1 -1 -1 -1
11  -1  1 -1  1 -1 -1 -1
12   1  1 -1  1 -1 -1 -1
13  -1 -1  1  1 -1 -1 -1
14   1 -1  1  1 -1 -1 -1
15  -1  1  1  1 -1 -1 -1
16   1  1  1  1 -1 -1 -1
17  -1 -1 -1 -1  1 -1 -1
18   1 -1 -1 -1  1 -1 -1
19  -1  1 -1 -1  1 -1 -1
20   1  1 -1 -1  1 -1 -1
21  -1 -1  1 -1  1 -1 -1
22   1 -1  1 -1  1 -1 -1
23  -1  1  1 -1  1 -1 -1
24   1  1  1 -1  1 -1 -1
25  -1 -1 -1  1  1 -1 -1
26   1 -1 -1  1  1 -1 -1
27  -1  1 -1  1  1 -1 -1
28   1  1 -1  1  1 -1 -1
29  -1 -1  1  1  1 -1 -1
30   1 -1  1  1  1 -1 -1
31  -1  1  1  1  1 -1 -1
32   1  1  1  1  1 -1 -1
33  -1 -1 -1 -1 -1  1 -1
34   1 -1 -1 -1 -1  1 -1
35  -1  1 -1 -1 -1  1 -1
36   1  1 -1 -1 -1  1 -1
37  -1 -1  1 -1 -1  1 -1
38   1 -1  1 -1 -1  1 -1
39  -1  1  1 -1 -1  1 -1
40   1  1  1 -1 -1  1 -1
41  -1 -1 -1  1 -1  1 -1
42   1 -1 -1  1 -1  1 -1
43  -1  1 -1  1 -1  1 -1
44   1  1 -1  1 -1  1 -1
45  -1 -1  1  1 -1  1 -1
46   1 -1  1  1 -1  1 -1
47  -1  1  1  1 -1  1 -1
48   1  1  1  1 -1  1 -1
49  -1 -1 -1 -1  1  1 -1
50   1 -1 -1 -1  1  1 -1
51  -1  1 -1 -1  1  1 -1
52   1  1 -1 -1  1  1 -1
53  -1 -1  1 -1  1  1 -1
54   1 -1  1 -1  1  1 -1
55  -1  1  1 -1  1  1 -1
56   1  1  1 -1  1  1 -1
57  -1 -1 -1  1  1  1 -1
58   1 -1 -1  1  1  1 -1
59  -1  1 -1  1  1  1 -1
60   1  1 -1  1  1  1 -1
61  -1 -1  1  1  1  1 -1
62   1 -1  1  1  1  1 -1
63  -1  1  1  1  1  1 -1
64   1  1  1  1  1  1 -1
65  -1 -1 -1 -1 -1 -1  1
66   1 -1 -1 -1 -1 -1  1
67  -1  1 -1 -1 -1 -1  1
68   1  1 -1 -1 -1 -1  1
69  -1 -1  1 -1 -1 -1  1
70   1 -1  1 -1 -1 -1  1
71  -1  1  1 -1 -1 -1  1
72   1  1  1 -1 -1 -1  1
73  -1 -1 -1  1 -1 -1  1
74   1 -1 -1  1 -1 -1  1
75  -1  1 -1  1 -1 -1  1
76   1  1 -1  1 -1 -1  1
77  -1 -1  1  1 -1 -1  1
78   1 -1  1  1 -1 -1  1
79  -1  1  1  1 -1 -1  1
80   1  1  1  1 -1 -1  1
81  -1 -1 -1 -1  1 -1  1
82   1 -1 -1 -1  1 -1  1
83  -1  1 -1 -1  1 -1  1
84   1  1 -1 -1  1 -1  1
85  -1 -1  1 -1  1 -1  1
86   1 -1  1 -1  1 -1  1
87  -1  1  1 -1  1 -1  1
88   1  1  1 -1  1 -1  1
89  -1 -1 -1  1  1 -1  1
90   1 -1 -1  1  1 -1  1
91  -1  1 -1  1  1 -1  1
92   1  1 -1  1  1 -1  1
93  -1 -1  1  1  1 -1  1
94   1 -1  1  1  1 -1  1
95  -1  1  1  1  1 -1  1
96   1  1  1  1  1 -1  1
97  -1 -1 -1 -1 -1  1  1
98   1 -1 -1 -1 -1  1  1
99  -1  1 -1 -1 -1  1  1
100  1  1 -1 -1 -1  1  1
101 -1 -1  1 -1 -1  1  1
102  1 -1  1 -1 -1  1  1
103 -1  1  1 -1 -1  1  1
104  1  1  1 -1 -1  1  1
105 -1 -1 -1  1 -1  1  1
106  1 -1 -1  1 -1  1  1
107 -1  1 -1  1 -1  1  1
108  1  1 -1  1 -1  1  1
109 -1 -1  1  1 -1  1  1
110  1 -1  1  1 -1  1  1
111 -1  1  1  1 -1  1  1
112  1  1  1  1 -1  1  1
113 -1 -1 -1 -1  1  1  1
114  1 -1 -1 -1  1  1  1
115 -1  1 -1 -1  1  1  1
116  1  1 -1 -1  1  1  1
117 -1 -1  1 -1  1  1  1
118  1 -1  1 -1  1  1  1
119 -1  1  1 -1  1  1  1
120  1  1  1 -1  1  1  1
121 -1 -1 -1  1  1  1  1
122  1 -1 -1  1  1  1  1
123 -1  1 -1  1  1  1  1
124  1  1 -1  1  1  1  1
125 -1 -1  1  1  1  1  1
126  1 -1  1  1  1  1  1
127 -1  1  1  1  1  1  1
128  1  1  1  1  1  1  1</code></pre>
</div>
</div>
<p>This can be an input to specify the design using another function, say with <code>optFederov</code> which uses Federov’s exchange algorithm to generate the design.</p>
<div class="cell" data-layout-align="center" data-hash="cache/unnamed-chunk-7_cffea6d66189b29efc9c3688a61979ed">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb51" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb51-1">desF <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">optFederov</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> .<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, </span>
<span id="cb51-2">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> dat,</span>
<span id="cb51-3">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nTrials =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">32</span>,</span>
<span id="cb51-4">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nRepeats =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)</span>
<span id="cb51-5">desF</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre class="scroll-output"><code>$D
[1] 0.8867999

$A
[1] 1.296784

$Ge
[1] 0.412

$Dea
[1] 0.241

$design
    X1 X2 X3 X4 X5 X6 X7
4    1  1 -1 -1 -1 -1 -1
5   -1 -1  1 -1 -1 -1 -1
10   1 -1 -1  1 -1 -1 -1
11  -1  1 -1  1 -1 -1 -1
16   1  1  1  1 -1 -1 -1
17  -1 -1 -1 -1  1 -1 -1
23  -1  1  1 -1  1 -1 -1
28   1  1 -1  1  1 -1 -1
30   1 -1  1  1  1 -1 -1
33  -1 -1 -1 -1 -1  1 -1
38   1 -1  1 -1 -1  1 -1
44   1  1 -1  1 -1  1 -1
50   1 -1 -1 -1  1  1 -1
51  -1  1 -1 -1  1  1 -1
56   1  1  1 -1  1  1 -1
61  -1 -1  1  1  1  1 -1
66   1 -1 -1 -1 -1 -1  1
67  -1  1 -1 -1 -1 -1  1
72   1  1  1 -1 -1 -1  1
76   1  1 -1  1 -1 -1  1
77  -1 -1  1  1 -1 -1  1
84   1  1 -1 -1  1 -1  1
86   1 -1  1 -1  1 -1  1
90   1 -1 -1  1  1 -1  1
95  -1  1  1  1  1 -1  1
100  1  1 -1 -1 -1  1  1
105 -1 -1 -1  1 -1  1  1
110  1 -1  1  1 -1  1  1
111 -1  1  1  1 -1  1  1
117 -1 -1  1 -1  1  1  1
123 -1  1 -1  1  1  1  1
128  1  1  1  1  1  1  1

$rows
 [1]   4   5  10  11  16  17  23  28  30  33  38  44  50  51  56  61  66  67  72
[20]  76  77  84  86  90  95 100 105 110 111 117 123 128</code></pre>
</div>
</div>
<p>If you want to further randomise within blocks, you can pass the above result to <code>optBlock</code>.</p>
<div class="cell" data-layout-align="center" data-hash="cache/unnamed-chunk-8_237a8f8d61e37bce952f6f639f7d6a5c">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb53" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb53-1">desFBlk <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">optBlock</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> .<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, </span>
<span id="cb53-2">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">withinData =</span> desF<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>design,</span>
<span id="cb53-3">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">blocksizes =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>),</span>
<span id="cb53-4">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nRepeats =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>)</span>
<span id="cb53-5"></span>
<span id="cb53-6">desFBlk</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre class="scroll-output"><code>$D
[1] 0.8049815

$diagonality
[1] 0.836

$Blocks
$Blocks$B1
    X1 X2 X3 X4 X5 X6 X7
4    1  1 -1 -1 -1 -1 -1
17  -1 -1 -1 -1  1 -1 -1
23  -1  1  1 -1  1 -1 -1
33  -1 -1 -1 -1 -1  1 -1
77  -1 -1  1  1 -1 -1  1
84   1  1 -1 -1  1 -1  1
90   1 -1 -1  1  1 -1  1
123 -1  1 -1  1  1  1  1

$Blocks$B2
    X1 X2 X3 X4 X5 X6 X7
10   1 -1 -1  1 -1 -1 -1
16   1  1  1  1 -1 -1 -1
28   1  1 -1  1  1 -1 -1
50   1 -1 -1 -1  1  1 -1
61  -1 -1  1  1  1  1 -1
67  -1  1 -1 -1 -1 -1  1
86   1 -1  1 -1  1 -1  1
100  1  1 -1 -1 -1  1  1

$Blocks$B3
    X1 X2 X3 X4 X5 X6 X7
5   -1 -1  1 -1 -1 -1 -1
11  -1  1 -1  1 -1 -1 -1
30   1 -1  1  1  1 -1 -1
44   1  1 -1  1 -1  1 -1
56   1  1  1 -1  1  1 -1
66   1 -1 -1 -1 -1 -1  1
95  -1  1  1  1  1 -1  1
110  1 -1  1  1 -1  1  1

$Blocks$B4
    X1 X2 X3 X4 X5 X6 X7
38   1 -1  1 -1 -1  1 -1
51  -1  1 -1 -1  1  1 -1
72   1  1  1 -1 -1 -1  1
76   1  1 -1  1 -1 -1  1
105 -1 -1 -1  1 -1  1  1
111 -1  1  1  1 -1  1  1
117 -1 -1  1 -1  1  1  1
128  1  1  1  1  1  1  1


$design
    X1 X2 X3 X4 X5 X6 X7
4    1  1 -1 -1 -1 -1 -1
17  -1 -1 -1 -1  1 -1 -1
23  -1  1  1 -1  1 -1 -1
33  -1 -1 -1 -1 -1  1 -1
77  -1 -1  1  1 -1 -1  1
84   1  1 -1 -1  1 -1  1
90   1 -1 -1  1  1 -1  1
123 -1  1 -1  1  1  1  1
10   1 -1 -1  1 -1 -1 -1
16   1  1  1  1 -1 -1 -1
28   1  1 -1  1  1 -1 -1
50   1 -1 -1 -1  1  1 -1
61  -1 -1  1  1  1  1 -1
67  -1  1 -1 -1 -1 -1  1
86   1 -1  1 -1  1 -1  1
100  1  1 -1 -1 -1  1  1
5   -1 -1  1 -1 -1 -1 -1
11  -1  1 -1  1 -1 -1 -1
30   1 -1  1  1  1 -1 -1
44   1  1 -1  1 -1  1 -1
56   1  1  1 -1  1  1 -1
66   1 -1 -1 -1 -1 -1  1
95  -1  1  1  1  1 -1  1
110  1 -1  1  1 -1  1  1
38   1 -1  1 -1 -1  1 -1
51  -1  1 -1 -1  1  1 -1
72   1  1  1 -1 -1 -1  1
76   1  1 -1  1 -1 -1  1
105 -1 -1 -1  1 -1  1  1
111 -1  1  1  1 -1  1  1
117 -1 -1  1 -1  1  1  1
128  1  1  1  1  1  1  1

$rows
 [1]   4  17  23  33  77  84  90 123  10  16  28  50  61  67  86 100   5  11  30
[20]  44  56  66  95 110  38  51  72  76 105 111 117 128</code></pre>
</div>
</div>
</section>
<section id="agricolae" class="level2">
<h2 class="anchored" data-anchor-id="agricolae"><code>agricolae</code></h2>
<p><code>agricolae</code> is motivated by agricultural applications although the designs are applicable across a variety of fields.</p>
<div class="cell" data-layout-align="center" data-hash="cache/unnamed-chunk-9_c860247cb092e2fe0575fbad61b40dac">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb55" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb55-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(agricolae)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>
Attaching package: 'agricolae'</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>The following object is masked from 'package:igraph':

    similarity</code></pre>
</div>
</div>
<p>The functions to create the design all begin with the word “design.” and the names of the functions are remnant of the name of the experimental design. E.g. <code>design.rcbd</code> generates a Randomised Complete Block Design and <code>design.split</code> generates a Split Plot Design.</p>
<div class="cell" data-layout-align="center" data-hash="cache/unnamed-chunk-10_da76cccb097ba5b9479bb4e10da7ec3d">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb58" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb58-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ls</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"package:agricolae"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb58-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_subset</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^design."</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code> [1] "design.ab"      "design.alpha"   "design.bib"     "design.crd"    
 [5] "design.cyclic"  "design.dau"     "design.graeco"  "design.lattice"
 [9] "design.lsd"     "design.mat"     "design.rcbd"    "design.split"  
[13] "design.strip"   "design.youden" </code></pre>
</div>
</div>
<p>Rather than going through each of the functions, I’ll just show one. The command below generates a balanced incomplete block design with 7 treatments of block size 3. This the same design structure as the first example for <code>AlgDesign</code>. What do you think of the input and output?</p>
<div class="cell" data-layout-align="center" data-hash="cache/unnamed-chunk-11_dcf7606eec961b478252c1f5d585b864">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb60" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb60-1">trt <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> LETTERS[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>]</span>
<span id="cb60-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">design.bib</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trt =</span> trt, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">k =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre class="scroll-output"><code>
Parameters BIB
==============
Lambda     : 1
treatmeans : 7
Block size : 3
Blocks     : 7
Replication: 3 

Efficiency factor 0.7777778 

&lt;&lt;&lt; Book &gt;&gt;&gt;</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre class="scroll-output"><code>$parameters
$parameters$design
[1] "bib"

$parameters$trt
[1] "A" "B" "C" "D" "E" "F" "G"

$parameters$k
[1] 3

$parameters$serie
[1] 2

$parameters$seed
[1] 1804898417

$parameters$kinds
[1] "Super-Duper"


$statistics
       lambda treatmeans blockSize blocks r Efficiency
values      1          7         3      7 3  0.7777778

$sketch
     [,1] [,2] [,3]
[1,] "C"  "B"  "D" 
[2,] "A"  "E"  "B" 
[3,] "F"  "B"  "G" 
[4,] "G"  "C"  "E" 
[5,] "G"  "A"  "D" 
[6,] "A"  "F"  "C" 
[7,] "F"  "E"  "D" 

$book
   plots block trt
1    101     1   C
2    102     1   B
3    103     1   D
4    201     2   A
5    202     2   E
6    203     2   B
7    301     3   F
8    302     3   B
9    303     3   G
10   401     4   G
11   402     4   C
12   403     4   E
13   501     5   G
14   502     5   A
15   503     5   D
16   601     6   A
17   602     6   F
18   603     6   C
19   701     7   F
20   702     7   E
21   703     7   D</code></pre>
</div>
</div>
<p>More examples are given in the <a href="https://cran.r-project.org/web/packages/agricolae/vignettes/tutorial.pdf"><code>agricolae</code> tutorial</a>.</p>
</section>
<section id="lhs" class="level2">
<h2 class="anchored" data-anchor-id="lhs"><code>lhs</code></h2>
<p>The <code>lhs</code> package is completely different to the previous two packages. It implements methods for creating and augmenting Latin Hypercube Samples and Orthogonal Array Latin Hypercube Samples. The treatment variables here are the parameters and are continuous. In the example below, there are 10 parameters were 30 samples will be drawn from.</p>
<div class="cell" data-layout-align="center" data-hash="cache/unnamed-chunk-12_cc1867f7f2895e69af193709d63df4fd">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb63" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb63-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(lhs)</span>
<span id="cb63-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># a design with 30 samples from 10 parameters</span></span>
<span id="cb63-3">A <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">randomLHS</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb63-4">A</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre class="scroll-output"><code>            [,1]       [,2]       [,3]       [,4]        [,5]       [,6]
 [1,] 0.85115160 0.80153721 0.26562089 0.24240381 0.386617133 0.57523291
 [2,] 0.03162770 0.11851068 0.20750833 0.22137816 0.737580563 0.37572590
 [3,] 0.94326309 0.99286802 0.55167951 0.04431126 0.073908842 0.33729208
 [4,] 0.15341898 0.23664814 0.45088836 0.02736497 0.276594703 0.77521524
 [5,] 0.53987796 0.69129259 0.61068716 0.68112190 0.840092421 0.18545904
 [6,] 0.34338962 0.91067411 0.50772141 0.46340514 0.543650700 0.04848456
 [7,] 0.87984431 0.18530938 0.28391957 0.80767211 0.636091307 0.40499358
 [8,] 0.74093451 0.94142899 0.47633881 0.93482745 0.101815507 0.83195048
 [9,] 0.22679294 0.05950478 0.70384589 0.84840308 0.046119869 0.20549016
[10,] 0.59543890 0.14230001 0.91973016 0.38743743 0.008173053 0.11180544
[11,] 0.71222052 0.84574251 0.05719443 0.33460392 0.414795358 0.71230339
[12,] 0.31313954 0.55023270 0.67189798 0.98743475 0.480147544 0.14900939
[13,] 0.06589897 0.02727366 0.94372045 0.11200430 0.776188787 0.31845634
[14,] 0.67856942 0.64694630 0.11695731 0.57667893 0.576669680 0.68236586
[15,] 0.60779222 0.47346774 0.57803451 0.77359785 0.686925390 0.46043188
[16,] 0.77869112 0.45967726 0.97082607 0.72001527 0.158727598 0.52748006
[17,] 0.47753672 0.33965295 0.34264293 0.88078583 0.932636317 0.08469157
[18,] 0.24829930 0.28054142 0.82863690 0.48987801 0.831406425 0.28007202
[19,] 0.63438918 0.62665931 0.19339855 0.63126047 0.222550404 0.84219677
[20,] 0.42615936 0.78697269 0.31122846 0.54731724 0.618925200 0.98370876
[21,] 0.98558294 0.31283813 0.79937608 0.09708168 0.974254219 0.48614679
[22,] 0.82272308 0.72620385 0.63409490 0.51439160 0.888309555 0.94892286
[23,] 0.28216288 0.40678670 0.00747647 0.15786391 0.462001814 0.89070787
[24,] 0.44293885 0.88759165 0.87593133 0.17614748 0.301809115 0.03273681
[25,] 0.91903885 0.58769320 0.85344414 0.73340894 0.261399107 0.65831637
[26,] 0.39749211 0.21531852 0.40155710 0.40795272 0.175926862 0.54073941
[27,] 0.53326444 0.09494134 0.36906730 0.28462433 0.521423827 0.62613184
[28,] 0.12780125 0.76041647 0.14450865 0.32753635 0.958334555 0.25256769
[29,] 0.19956924 0.39260007 0.76646006 0.65147638 0.353769748 0.90342254
[30,] 0.09115621 0.53145384 0.09544316 0.91317843 0.722981039 0.74109078
            [,7]       [,8]       [,9]      [,10]
 [1,] 0.64829514 0.30957145 0.56063376 0.58060694
 [2,] 0.09386871 0.09460784 0.62699580 0.07496677
 [3,] 0.14971910 0.02306924 0.12609065 0.18310414
 [4,] 0.27273750 0.43275425 0.84548534 0.13991032
 [5,] 0.57024842 0.83876578 0.94430739 0.55675175
 [6,] 0.68468958 0.93462688 0.69388363 0.77296080
 [7,] 0.22736413 0.49914901 0.63951785 0.29475412
 [8,] 0.86262149 0.90864828 0.71549074 0.95154810
 [9,] 0.82450164 0.34137614 0.35590469 0.33383492
[10,] 0.99755568 0.77506400 0.90850387 0.04070513
[11,] 0.51386141 0.51188486 0.74575618 0.47042600
[12,] 0.62716610 0.60853776 0.19349115 0.85808318
[13,] 0.36810057 0.68906398 0.48416759 0.10075997
[14,] 0.46367072 0.53735362 0.97946521 0.53084746
[15,] 0.79151449 0.39841726 0.16295411 0.32738380
[16,] 0.73055037 0.10636268 0.45184454 0.60852297
[17,] 0.11492100 0.64512714 0.26197028 0.87144705
[18,] 0.90350371 0.27696270 0.41905694 0.25261507
[19,] 0.41560144 0.73423244 0.01653787 0.01640204
[20,] 0.54984313 0.26617569 0.32944947 0.20285318
[21,] 0.73515250 0.59964083 0.87721937 0.82147435
[22,] 0.89461948 0.05944528 0.27581653 0.97355201
[23,] 0.95209334 0.17557806 0.57880924 0.65490041
[24,] 0.35714952 0.82135876 0.80705301 0.91792197
[25,] 0.31657015 0.44139011 0.39117389 0.72964052
[26,] 0.03568867 0.88231315 0.53096409 0.45227701
[27,] 0.18195056 0.23326926 0.79716759 0.42737304
[28,] 0.48629095 0.72335715 0.07429013 0.67936824
[29,] 0.03184096 0.15672156 0.06023826 0.73960757
[30,] 0.23509647 0.98392432 0.20423196 0.38968498</code></pre>
</div>
</div>
<p><code>lhs</code> provides a number of methods to find the optimal design each with their own criteria.</p>
<div class="cell" data-layout-align="center" data-hash="cache/unnamed-chunk-13_770bf1a7d14cdbfc264319362fd8d090">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb65" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb65-1">A1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">optimumLHS</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxSweeps =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">eps =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>)</span>
<span id="cb65-2">A2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">maximinLHS</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dup =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)</span>
<span id="cb65-3">A3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">improvedLHS</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dup =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)</span>
<span id="cb65-4">A4 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geneticLHS</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pop =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gen =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pMut =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">criterium =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"S"</span>)</span>
<span id="cb65-5">A5 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geneticLHS</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pop =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gen =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pMut =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">criterium =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Maximin"</span>)</span></code></pre></div></div>
</div>
</section>
<section id="ez" class="level2">
<h2 class="anchored" data-anchor-id="ez"><code>ez</code></h2>
<p>This is mainly focussed on the analysis of experimental data but some functions such as <code>ezDesign</code> is useful for viewing the experimental structure.</p>
<div class="cell" data-layout-align="center" data-hash="cache/unnamed-chunk-14_131239d16ec23f053a61d08873e18e07">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb66" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb66-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ez)</span>
<span id="cb66-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data</span>(ANT2)</span>
<span id="cb66-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ezPrecis</span>(ANT2)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Data frame dimensions: 5760 rows, 10 columns</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>             type missing values      min         max
subnum    numeric       0     20        1          20
group      factor       0      2  Control   Treatment
block     numeric       0      6        1           6
trial      factor       0     48        1          48
cue        factor       0      4     None     Spatial
flank      factor       0      3  Neutral Incongruent
location   factor       0      2     down          up
direction  factor       0      2     left       right
rt        numeric     144   5617 179.5972    657.6986
error     numeric     144      3        0           1</code></pre>
</div>
</div>
<div class="cell" data-layout-align="center" data-hash="cache/unnamed-chunk-15_dbc9fdb23306a84644235cdd7eec11d9">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb69" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb69-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ezDesign</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> ANT2,</span>
<span id="cb69-2">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> trial, </span>
<span id="cb69-3">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> subnum,</span>
<span id="cb69-4">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row =</span> block, </span>
<span id="cb69-5">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> group)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2021-02-03-current-state-of-experimental-design-r-packages/figures/unnamed-chunk-15-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="doe.base" class="level2">
<h2 class="anchored" data-anchor-id="doe.base"><code>DoE.base</code></h2>
<p><code>DoE.base</code> provides utility functions for the special class <code>design</code> and as seen in Figure @ref(fig:doe-network), <code>DoE.base</code> is used by <a href="https://prof.beuth-hochschule.de/groemping/software/versuchsplanung/?print=232">four other DoE packages that is maintained also by Prof.&nbsp;Dr.&nbsp;Ulrike Grömping</a>.</p>
<p><code>DoE.base</code> contains functions to generate factorial designs easily.</p>
<div class="cell" data-layout-align="center" data-hash="cache/unnamed-chunk-16_6cdb8247d42c72e705ef792c1f1a0c0c">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb70" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb70-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(DoE.base)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>Loading required package: grid</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>Loading required package: conf.design</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>Registered S3 method overwritten by 'DoE.base':
  method           from       
  factorize.factor conf.design</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>
Attaching package: 'DoE.base'</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>The following objects are masked from 'package:stats':

    aov, lm</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>The following object is masked from 'package:graphics':

    plot.design</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>The following object is masked from 'package:base':

    lengths</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb78" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb78-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fac.design</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nlevels =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>), </span>
<span id="cb78-2">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">blocks =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>creating full factorial with 216 runs ...</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre class="scroll-output"><code>   run.no run.no.std.rp Blocks A B C D E
1       1        29.1.5      1 1 1 2 3 1
2       2       89.1.15      1 1 1 2 2 3
3       3      180.1.30      1 2 2 3 3 5
4       4         4.1.2      1 2 2 1 1 1
5       5       84.1.14      1 2 2 3 1 3
6       6      160.1.28      1 2 2 1 2 5
7       7      118.1.19      1 2 1 3 1 4
8       8      186.1.31      1 2 1 2 1 6
9       9       97.1.17      1 1 1 1 3 3
10     10       92.1.16      1 2 2 2 2 3
11     11      214.1.35      1 2 1 3 3 6
12     12      194.1.33      1 2 1 1 2 6
13     13        39.1.8      1 1 2 1 1 2
14     14         1.1.1      1 1 1 1 1 1
15     15      119.1.20      1 1 2 3 1 4
16     16      127.1.22      1 1 2 2 2 4
17     17      134.1.23      1 2 1 1 3 4
18     18        58.1.9      1 2 1 3 2 2
19     19      135.1.24      1 1 2 1 3 4
20     20      149.1.25      1 1 1 2 1 5
21     21       59.1.10      1 1 2 3 2 2
22     22        38.1.7      1 2 1 1 1 2
23     23       67.1.12      1 1 2 2 3 2
24     24      195.1.34      1 1 2 1 2 6
25     25        32.1.6      1 2 2 2 3 1
26     26       66.1.11      1 2 1 2 3 2
27     27      152.1.26      1 2 2 2 1 5
28     28        21.1.3      1 1 1 3 2 1
29     29      157.1.27      1 1 1 1 2 5
30     30      215.1.36      1 1 2 3 3 6
31     31      100.1.18      1 2 2 1 3 3
32     32      187.1.32      1 1 2 2 1 6
33     33      177.1.29      1 1 1 3 3 5
34     34      126.1.21      1 2 1 2 2 4
35     35       81.1.13      1 1 1 3 1 3
36     36        24.1.4      1 2 2 3 2 1
   run.no run.no.std.rp Blocks A B C D E
37     37        16.2.4      2 2 2 1 2 1
38     38      169.2.29      2 1 1 1 3 5
39     39        43.2.8      2 1 2 2 1 2
40     40      199.2.34      2 1 2 2 2 6
41     41      104.2.18      2 2 2 2 3 3
42     42      206.2.35      2 2 1 1 3 6
43     43      131.2.22      2 1 2 3 2 4
44     44      138.2.23      2 2 1 2 3 4
45     45      172.2.30      2 2 2 1 3 5
46     46      110.2.19      2 2 1 1 1 4
47     47      161.2.27      2 1 1 2 2 5
48     48         5.2.1      2 1 1 2 1 1
49     49        42.2.7      2 2 1 2 1 2
50     50       73.2.13      2 1 1 1 1 3
51     51      191.2.32      2 1 2 3 1 6
52     52       93.2.15      2 1 1 3 2 3
53     53      156.2.26      2 2 2 3 1 5
54     54       96.2.16      2 2 2 3 2 3
55     55       51.2.10      2 1 2 1 2 2
56     56      101.2.17      2 1 1 2 3 3
57     57        13.2.3      2 1 1 1 2 1
58     58      111.2.20      2 1 2 1 1 4
59     59      130.2.21      2 2 1 3 2 4
60     60       76.2.14      2 2 2 1 1 3
61     61      198.2.33      2 2 1 2 2 6
62     62      190.2.31      2 2 1 3 1 6
63     63        33.2.5      2 1 1 3 3 1
64     64      153.2.25      2 1 1 3 1 5
65     65      164.2.28      2 2 2 2 2 5
66     66        50.2.9      2 2 1 1 2 2
67     67      207.2.36      2 1 2 1 3 6
68     68       71.2.12      2 1 2 3 3 2
69     69        36.2.6      2 2 2 3 3 1
70     70         8.2.2      2 2 2 2 1 1
71     71       70.2.11      2 2 1 3 3 2
72     72      139.2.24      2 1 2 2 3 4
    run.no run.no.std.rp Blocks A B C D E
73      73       85.3.15      3 1 1 1 2 3
74      74      105.3.17      3 1 1 3 3 3
75      75        17.3.3      3 1 1 2 2 1
76      76      211.3.36      3 1 2 2 3 6
77      77      114.3.19      3 2 1 2 1 4
78      78        47.3.8      3 1 2 3 1 2
79      79       55.3.10      3 1 2 2 2 2
80      80      182.3.31      3 2 1 1 1 6
81      81      168.3.28      3 2 2 3 2 5
82      82      165.3.27      3 1 1 3 2 5
83      83      142.3.23      3 2 1 3 3 4
84      84      145.3.25      3 1 1 1 1 5
85      85       62.3.11      3 2 1 1 3 2
86      86      148.3.26      3 2 2 1 1 5
87      87      108.3.18      3 2 2 3 3 3
88      88        25.3.5      3 1 1 1 3 1
89      89         9.3.1      3 1 1 3 1 1
90      90       77.3.13      3 1 1 2 1 3
91      91      122.3.21      3 2 1 1 2 4
92      92        12.3.2      3 2 2 3 1 1
93      93        46.3.7      3 2 1 3 1 2
94      94       88.3.16      3 2 2 1 2 3
95      95        20.3.4      3 2 2 2 2 1
96      96        54.3.9      3 2 1 2 2 2
97      97      203.3.34      3 1 2 3 2 6
98      98       80.3.14      3 2 2 2 1 3
99      99      123.3.22      3 1 2 1 2 4
100    100      173.3.29      3 1 1 2 3 5
101    101        28.3.6      3 2 2 1 3 1
102    102      176.3.30      3 2 2 2 3 5
103    103      202.3.33      3 2 1 3 2 6
104    104      115.3.20      3 1 2 2 1 4
105    105      210.3.35      3 2 1 2 3 6
106    106      183.3.32      3 1 2 1 1 6
107    107       63.3.12      3 1 2 1 3 2
108    108      143.3.24      3 1 2 3 3 4
    run.no run.no.std.rp Blocks A B C D E
109    109      179.4.30      4 1 2 3 3 5
110    110      151.4.26      4 1 2 2 1 5
111    111       60.4.10      4 2 2 3 2 2
112    112        31.4.6      4 1 2 2 3 1
113    113         3.4.2      4 1 2 1 1 1
114    114        22.4.3      4 2 1 3 2 1
115    115       99.4.18      4 1 2 1 3 3
116    116        30.4.5      4 2 1 2 3 1
117    117       68.4.12      4 2 2 2 3 2
118    118      196.4.34      4 2 2 1 2 6
119    119       90.4.15      4 2 1 2 2 3
120    120        57.4.9      4 1 1 3 2 2
121    121      158.4.27      4 2 1 1 2 5
122    122      193.4.33      4 1 1 1 2 6
123    123      136.4.24      4 2 2 1 3 4
124    124       82.4.13      4 2 1 3 1 3
125    125       65.4.11      4 1 1 2 3 2
126    126        37.4.7      4 1 1 1 1 2
127    127      120.4.20      4 2 2 3 1 4
128    128      178.4.29      4 2 1 3 3 5
129    129      128.4.22      4 2 2 2 2 4
130    130      188.4.32      4 2 2 2 1 6
131    131         2.4.1      4 2 1 1 1 1
132    132       91.4.16      4 1 2 2 2 3
133    133      185.4.31      4 1 1 2 1 6
134    134      159.4.28      4 1 2 1 2 5
135    135       98.4.17      4 2 1 1 3 3
136    136        40.4.8      4 2 2 1 1 2
137    137      150.4.25      4 2 1 2 1 5
138    138      125.4.21      4 1 1 2 2 4
139    139       83.4.14      4 1 2 3 1 3
140    140      133.4.23      4 1 1 1 3 4
141    141        23.4.4      4 1 2 3 2 1
142    142      117.4.19      4 1 1 3 1 4
143    143      216.4.36      4 2 2 3 3 6
144    144      213.4.35      4 1 1 3 3 6
    run.no run.no.std.rp Blocks A B C D E
145    145      171.5.30      5 1 2 1 3 5
146    146      102.5.17      5 2 1 2 3 3
147    147      162.5.27      5 2 1 2 2 5
148    148      112.5.20      5 2 2 1 1 4
149    149      154.5.25      5 2 1 3 1 5
150    150       74.5.13      5 2 1 1 1 3
151    151      163.5.28      5 1 2 2 2 5
152    152        15.5.4      5 1 2 1 2 1
153    153       72.5.12      5 2 2 3 3 2
154    154       95.5.16      5 1 2 3 2 3
155    155      205.5.35      5 1 1 1 3 6
156    156        35.5.6      5 1 2 3 3 1
157    157         7.5.2      5 1 2 2 1 1
158    158      129.5.21      5 1 1 3 2 4
159    159         6.5.1      5 2 1 2 1 1
160    160       75.5.14      5 1 2 1 1 3
161    161      208.5.36      5 2 2 1 3 6
162    162        14.5.3      5 2 1 1 2 1
163    163       94.5.15      5 2 1 3 2 3
164    164      132.5.22      5 2 2 3 2 4
165    165        34.5.5      5 2 1 3 3 1
166    166       69.5.11      5 1 1 3 3 2
167    167      170.5.29      5 2 1 1 3 5
168    168      137.5.23      5 1 1 2 3 4
169    169       52.5.10      5 2 2 1 2 2
170    170      155.5.26      5 1 2 3 1 5
171    171        49.5.9      5 1 1 1 2 2
172    172      200.5.34      5 2 2 2 2 6
173    173        41.5.7      5 1 1 2 1 2
174    174      192.5.32      5 2 2 3 1 6
175    175        44.5.8      5 2 2 2 1 2
176    176      140.5.24      5 2 2 2 3 4
177    177      197.5.33      5 1 1 2 2 6
178    178      109.5.19      5 1 1 1 1 4
179    179      103.5.18      5 1 2 2 3 3
180    180      189.5.31      5 1 1 3 1 6
    run.no run.no.std.rp Blocks A B C D E
181    181      106.6.17      6 2 1 3 3 3
182    182      146.6.25      6 2 1 1 1 5
183    183       79.6.14      6 1 2 2 1 3
184    184        53.6.9      6 1 1 2 2 2
185    185      209.6.35      6 1 1 2 3 6
186    186       64.6.12      6 2 2 1 3 2
187    187      166.6.27      6 2 1 3 2 5
188    188        19.6.4      6 1 2 2 2 1
189    189      204.6.34      6 2 2 3 2 6
190    190        26.6.5      6 2 1 1 3 1
191    191       78.6.13      6 2 1 2 1 3
192    192       56.6.10      6 2 2 2 2 2
193    193      181.6.31      6 1 1 1 1 6
194    194      174.6.29      6 2 1 2 3 5
195    195       87.6.16      6 1 2 1 2 3
196    196        10.6.1      6 2 1 3 1 1
197    197      212.6.36      6 2 2 2 3 6
198    198      147.6.26      6 1 2 1 1 5
199    199      107.6.18      6 1 2 3 3 3
200    200        48.6.8      6 2 2 3 1 2
201    201      116.6.20      6 2 2 2 1 4
202    202       86.6.15      6 2 1 1 2 3
203    203      184.6.32      6 2 2 1 1 6
204    204        27.6.6      6 1 2 1 3 1
205    205      124.6.22      6 2 2 1 2 4
206    206      141.6.23      6 1 1 3 3 4
207    207      201.6.33      6 1 1 3 2 6
208    208        18.6.3      6 2 1 2 2 1
209    209        45.6.7      6 1 1 3 1 2
210    210      113.6.19      6 1 1 2 1 4
211    211      167.6.28      6 1 2 3 2 5
212    212      121.6.21      6 1 1 1 2 4
213    213      144.6.24      6 2 2 3 3 4
214    214       61.6.11      6 1 1 1 3 2
215    215      175.6.30      6 1 2 2 3 5
216    216        11.6.2      6 1 2 3 1 1
class=design, type= full factorial.blocked 
NOTE: columns run.no and run.no.std.rp  are annotation, 
 not part of the data frame</code></pre>
</div>
</div>
<p>It also contains functions to create orthogonal array designs.</p>
<div class="cell" data-layout-align="center" data-hash="cache/unnamed-chunk-17_c758fd1ba6dc7de7795bfea0062c0438">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb81" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb81-1">des <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">oa.design</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nlevels =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>))</span>
<span id="cb81-2">des</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre class="scroll-output"><code>   A B C D E F G H J
1  1 2 1 2 2 1 2 1 6
2  2 1 2 1 2 1 2 1 2
3  2 1 1 2 2 1 1 2 4
4  2 2 1 1 2 2 1 1 3
5  1 1 1 1 2 2 2 2 5
6  1 1 2 2 2 2 1 1 7
7  1 2 1 2 1 2 1 2 2
8  1 1 1 1 1 1 1 1 1
9  1 2 2 1 2 1 1 2 8
10 1 1 2 2 1 1 2 2 3
11 2 1 2 1 1 2 1 2 6
12 2 1 1 2 1 2 2 1 8
13 2 2 2 2 1 1 1 1 5
14 2 2 1 1 1 1 2 2 7
15 1 2 2 1 1 2 2 1 4
16 2 2 2 2 2 2 2 2 1
class=design, type= oa </code></pre>
</div>
</div>
<p>If you need to further randomise within a specified block, you can do this using <code>rerandomize.design</code>.</p>
<div class="cell" data-layout-align="center" data-hash="cache/unnamed-chunk-18_18c89fe26ab63262f68854eb65d3c3d2">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb83" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb83-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rerandomize.design</span>(des, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">block =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"J"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre class="scroll-output"><code>  run.no run.no.std.rp J A B C D E F G H
1      1         4.7.1 7 1 1 2 2 2 2 1 1
2      2        13.7.2 7 2 2 1 1 1 1 2 2
  run.no run.no.std.rp J A B C D E F G H
3      3         7.4.1 4 1 2 2 1 1 2 2 1
4      4        10.4.2 4 2 1 1 2 2 1 1 2
  run.no run.no.std.rp J A B C D E F G H
5      5        12.2.2 2 2 1 2 1 2 1 2 1
6      6         5.2.1 2 1 2 1 2 1 2 1 2
  run.no run.no.std.rp J A B C D E F G H
7      7        11.6.2 6 2 1 2 1 1 2 1 2
8      8         6.6.1 6 1 2 1 2 2 1 2 1
   run.no run.no.std.rp J A B C D E F G H
9       9         9.8.2 8 2 1 1 2 1 2 2 1
10     10         8.8.1 8 1 2 2 1 2 1 1 2
   run.no run.no.std.rp J A B C D E F G H
11     11         3.3.1 3 1 1 2 2 1 1 2 2
12     12        14.3.2 3 2 2 1 1 2 2 1 1
   run.no run.no.std.rp J A B C D E F G H
13     13        16.1.2 1 2 2 2 2 2 2 2 2
14     14         1.1.1 1 1 1 1 1 1 1 1 1
   run.no run.no.std.rp J A B C D E F G H
15     15         2.5.1 5 1 1 1 1 2 2 2 2
16     16        15.5.2 5 2 2 2 2 1 1 1 1
class=design, type= oa.blocked 
NOTE: columns run.no and run.no.std.rp  are annotation, 
 not part of the data frame</code></pre>
</div>
</div>
<p>So those were the top 5 DoE packages. The API of the packages are quite distinct. The object that it outputs can vary from a matrix to a list. DoE might be a dull area for many but it’s quite important for the downstream analysis. Perhaps if many of us talk more about it, it may help invigorate the area!</p>
<div class="cell" data-layout-align="center" data-hash="cache/unnamed-chunk-19_f7e0a9aa6b07fb3c87cffb453a727173">
<script type="text/javascript">
function showscript() {
  var x = document.getElementsByClassName('toggle-code');
  var n = x.length;
  for (var i = 0; i < n; i++) {
    var e = x[i];
    if (e.style.display == "block") {
      e.style.display = "none";
    } else {
      e.style.display = "block";
    }
  }
}
</script>
</div>



</section>
</section>


<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-lhs" class="csl-entry">
Carnell, Rob. 2020. <em>Lhs: Latin Hypercube Samples</em>. <a href="https://CRAN.R-project.org/package=lhs">https://CRAN.R-project.org/package=lhs</a>.
</div>
<div id="ref-Chatfield1985-yz" class="csl-entry">
Chatfield, C. 1985. <span>“The Initial Examination of Data.”</span> <em>Journal of the Royal Statistical Society. Series A</em> 148 (3): 214–53.
</div>
<div id="ref-agricolae" class="csl-entry">
de Mendiburu, Felipe. 2020. <em>Agricolae: Statistical Procedures for Agricultural Research</em>. <a href="https://CRAN.R-project.org/package=agricolae">https://CRAN.R-project.org/package=agricolae</a>.
</div>
<div id="ref-DoE.base" class="csl-entry">
Grömping, Ulrike. 2018. <span>“<span>R</span> Package <span class="nocase">DoE.base</span> for Factorial Experiments.”</span> <em>Journal of Statistical Software</em> 85 (5): 1–41. <a href="https://doi.org/10.18637/jss.v085.i05">https://doi.org/10.18637/jss.v085.i05</a>.
</div>
<div id="ref-ez" class="csl-entry">
Lawrence, Michael A. 2016. <em>Ez: Easy Analysis and Visualization of Factorial Experiments</em>. <a href="https://CRAN.R-project.org/package=ez">https://CRAN.R-project.org/package=ez</a>.
</div>
<div id="ref-adjustedcranlogs" class="csl-entry">
Morgan-Wall, Tyler. 2017. <em>Adjustedcranlogs: Remove Automated and Repeated Downloads from ’RStudio’ ’CRAN’ Download Logs</em>. <a href="https://CRAN.R-project.org/package=adjustedcranlogs">https://CRAN.R-project.org/package=adjustedcranlogs</a>.
</div>
<div id="ref-AlgDesign" class="csl-entry">
Wheeler, Bob. 2019. <em>AlgDesign: Algorithmic Experimental Design</em>. <a href="https://CRAN.R-project.org/package=AlgDesign">https://CRAN.R-project.org/package=AlgDesign</a>.
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>At least from my teaching experience, statistics subjects are primary about the analysis and most research grants I’ve seen are about an analytical method. The analytical focus is reflected also in the R packages; there are 1,907 R-packages on CRAN with the word “analysis” in the title as opposed to 287 R-packages with the word “design” in its title.↩︎</p></li>
<li id="fn2"><p>Keeping in mind though that your analysis plan may change once you actually have collected data. This is quite common in the analysis of plant breeding trials since some spatial variation only become apparent only after the data collection.↩︎</p></li>
<li id="fn3"><p>I originally had a webscrapping error where I didn’t remove duplicate entries so numbers presented at <a href="https://emitanaka.org/slides/TokyoR2021/#32">TokyoR</a> and <a href="https://emitanaka.org/slides/SSA2020/#52">SSA Webinar</a> had the wrong numbers.↩︎</p></li>
<li id="fn4"><p>As of 2022-09-18.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>experimental design</category>
  <category>R</category>
  <guid>https://emitanaka.org/blog/2021-02-03-current-state-of-experimental-design-r-packages/current-state-of-experimental-design-r-packages.html</guid>
  <pubDate>Tue, 02 Feb 2021 13:00:00 GMT</pubDate>
</item>
<item>
  <title>Drawing a UML Sequence Diagram</title>
  <dc:creator>Emi Tanaka</dc:creator>
  <link>https://emitanaka.org/blog/2021-01-29-uml-seq-diag/uml-seq-diag.html</link>
  <description><![CDATA[ 

<!-- Title banner for blog posts (set in blog/_metadata.yml). Built from each
     post's front matter: title, date, author, categories, description and
     image (a pen sticker is shown when a post has no image). -->



<p>A <strong>sequence diagram</strong>, as described in <a href="https://en.wikipedia.org/wiki/Sequence_diagram">wikipedia</a>, shows objects interactions arranged in time sequence. One of the standards for drawing this is using the <strong>Unified Modelling Language</strong> (UML) managed by the Object Management Group (OMG).</p>
<p>UML was developed in the field of software engineering to provide a standard way to visualise the design of a system. It’s a language that describes standards for all sorts of diagrams, not just the sequence diagram, e.g.&nbsp;communication diagram, interaction overview diagram and so on.</p>
<p>The interaction of <em>actors</em> with the system depicted as <em>objects</em> with passage of time depicted as a vertical dotted line (a.k.a. lifeline) seemed like a good fit to use for illustrating the concept of <a href="https://edibble.emitanaka.org/">edibble</a>.</p>
<section id="omnigraffle" class="level2">
<h2 class="anchored" data-anchor-id="omnigraffle">Omnigraffle</h2>
<p>I always find drawing complicated diagrams to be tricky via programming so I initially drew the diagram using OmniGraffle. There were some UML stencils and I thought it was going well (result in Figure @ref(fig:omni)). Aligning the objects as a sequence diagram, even with OmniGraffle’s precise object placement, was a bit difficult but it got the job done in the end.</p>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2021-01-29-uml-seq-diag/seq-diag-omnigraffle.png" class="img-fluid figure-img" width="432"></p>
<figcaption>Drawn using OmniGraffle</figcaption>
</figure>
</div>
</div>
</div>
<p>Then I wanted to change and reorder some elements of the diagram. It’s already taken me half a day to make a Figure @ref(fig:omni), I really didn’t want to repeat the process. Surely, there must be another tool that will make this easier?</p>
</section>
<section id="online-tools" class="level2">
<h2 class="anchored" data-anchor-id="online-tools">Online tools</h2>
<p>And thus began my journey (and what felt like a rabbit hole) in finding other tools to draw a sequence diagram. I found several online mapping solutions including <a href="https://www.lucidchart.com/pages/examples/uml_diagram_tool">Lucidchart</a> and <a href="https://online.visual-paradigm.com/diagrams/features/uml-tool/">Visual Paradigm</a> but it wasn’t what I was after. Eventually I came across <a href="https://gitmind.com/">GitMind</a>. It was the most promising to me: it has a nice user interface, the features that I want and it happened to be completely free! It was easier than OmniGraffle to make sequence diagrams. You can find the result of the drawing in Figure @ref(fig:gitmind).</p>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2021-01-29-uml-seq-diag/seq-diagram-eg.png" class="img-fluid figure-img" width="861"></p>
<figcaption>Drawn using GitMind.</figcaption>
</figure>
</div>
</div>
</div>
<p>One thing to keep in mind is that the font for the PDF version is not rendered correctly. This is perhaps I’ve chosen a font available only in my system (“Fira Code”).</p>
<p>Okay, looks like I’m good with this. Let’s use this in the edibble documentation… Wait the interaction between the <em>statisitican</em> and <em>Design</em> doesn’t fit the narrative well, I need to modify the diagram again!</p>
<p>This was a point when I realise I really need to programmatically create the diagram. Being somewhat of an anti click-and-point statistical software, I should have perhaps pursued the programmatic route earlier.</p>
</section>
<section id="r" class="level2">
<h2 class="anchored" data-anchor-id="r">R</h2>
<p>The most comprehensive R-package to draw a diagram is <a href="https://rich-iannone.github.io/DiagrammeR/">DiagrammeR</a>. When you go to the website (which has an impressively interface) it has the tagline “Sometimes You Want To Create Nice Diagrams: WHY NOT DO THAT WITH R?”. That’s a good question to ask past Emi.</p>
<section id="diagrammer" class="level3">
<h3 class="anchored" data-anchor-id="diagrammer">DiagrammeR</h3>
<p>Under the hood, DiagrammeR it’s powered by <strong>Graphviz</strong> and <strong>mermaid</strong>. <a href="https://mermaid-js.github.io/mermaid/#/sequenceDiagram">Sequence diagrams are supported by mermaid</a> but there seems to be no distinguishment between an actor and an object. It seems like you always have to a message when actor/object is interacting.</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1">DiagrammeR<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mermaid</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb1-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">sequenceDiagram</span></span>
<span id="cb1-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    domain expert-&gt;&gt;statistician: consult</span></span>
<span id="cb1-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    statistician--&gt;&gt;domain expert: query</span></span>
<span id="cb1-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    statistician-&gt;&gt;Design: start_design()</span></span>
<span id="cb1-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    statistician-&gt;&gt;Design: set_units()"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div id="htmlwidget-4b5fbbcd00f3552906ce" style="width:100%;height:464px;" class="DiagrammeR html-widget"></div>
<script type="application/json" data-for="htmlwidget-4b5fbbcd00f3552906ce">{"x":{"diagram":"\nsequenceDiagram\n    domain expert->>statistician: consult\n    statistician-->>domain expert: query\n    statistician->>Design: start_design()\n    statistician->>Design: set_units()"},"evals":[],"jsHooks":[]}</script>
<p>Drawn using mermaid via DiagrammeR</p>
</div>
</div>
<p>It’s fairly good and you can further customise the look using CSS, but it doesn’t have the actor symbol and some other standard UML symbols, it will be too much effort by me to recreate what I made using GitMind.</p>
</section>
<section id="nomnoml" class="level3">
<h3 class="anchored" data-anchor-id="nomnoml">nomnoml</h3>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2021-01-29-uml-seq-diag/nomnoml.png" class="img-fluid figure-img" width="623"></p>
<figcaption>Drawn using nomnoml.com</figcaption>
</figure>
</div>
</div>
</div>
<p>The <a href="https://github.com/rstudio/nomnoml">nomnoml R-package</a> describes itself as a Sassy UML Diagrams for R. It’s powered by the <a href="https://nomnoml.com/">nomnoml tool</a> which has a nice simple website to create the diagrams you want. I quite enjoy using the website version where the graph renders instantenously using a simple syntax. The graph made using the web (Figure @ref(fig:nomnoml)) is different to the one produced via R shown below along with the nomnoml syntax.</p>
<div class="cell" data-layout-align="center">
<pre class="nomnoml cell-code"><code>[&lt;actor&gt;domain expert] -- [&lt;hidden&gt; fin1]
[&lt;actor&gt;statistician] -- [&lt;hidden&gt; fin2]
[design] -- [&lt;end&gt; end]
[&lt;database&gt; data] -- [&lt;hidden&gt; hid]
[&lt;actor&gt;technician] -- [&lt;hidden&gt; fin3]</code></pre>
<div class="cell-output-display">
<div id="htmlwidget-fe50990c763cc57fd589" style="width:100%;height:464px;" class="nomnoml html-widget"></div>
<script type="application/json" data-for="htmlwidget-fe50990c763cc57fd589">{"x":{"code":"\n#fill: #FEFEFF\n#lineWidth: 1\n#zoom: 4\n#direction: right\n\n[<actor>domain expert] -- [<hidden> fin1]\n[<actor>statistician] -- [<hidden> fin2]\n[design] -- [<end> end]\n[<database> data] -- [<hidden> hid]\n[<actor>technician] -- [<hidden> fin3]","svg":false,"png":null},"evals":[],"jsHooks":[]}</script>
<p>Drawn using nomnoml</p>
</div>
</div>
<p>It turns out thought that the nomnoml <a href="https://github.com/skanaar/nomnoml/issues/1">doesn’t support sequence diagrams</a> and it doesn’t look like it will support it any time either.</p>
</section>
<section id="plantuml" class="level3">
<h3 class="anchored" data-anchor-id="plantuml">plantuml</h3>
<p>I came across another R-package for UML diagrams called <a href="https://github.com/rkrug/plantuml">plantuml</a>. It’s powered by the the <a href="https://plantuml.com/">plantUML tool</a> which has a <a href="https://plantuml.com/sequence-diagram">extensive support for a sequence diagram</a> (yes!).</p>
<p>This one is not on CRAN yet. I initially had trouble getting it to work but managed to work re-installing GraphViz. I could get the example code to work but the code for sequence diagram didn’t work for me so I used the online version of plantUML directly.</p>
<p>I expanded a lot more than previous graphs with plantUML code below. The problem I realise now is that the image has become too big and too much text to be concise. So I’ll have to tweak some more (when does this end?). At least now making an adjustment isn’t hard this time!</p>
<pre><code>@startuml
actor "domain expert" as expert #fff
actor statistician as stat #AD0059
participant design as design #fff
database data as data #fff
actor technician as tech #fff
== Conceptualizing the experiment ==
group Consultation
expert -&gt; stat: I want to test which wheat variety is best
stat -&gt; design: library(edibble)\nstart_design(name = "wheat")
activate design
stat -&gt; design: set_context(aim = "identify best variety")
stat -&gt; expert: What varieties are you testing?
expert --&gt;&gt; stat: I'm testing Mace and RockStar
stat -&gt; design: set_trts(var = c("Mace", "RockStar"))
expert --&gt;&gt; stat: I have a field with 20 plots each at Narrabri and\n10 plots at Roseworthy that I can use for testing
stat -&gt; design: set_units(site = c("Narrabri", "Roseworthy"),\n.               plot = nested_in( site,\n                                    "Narrabri" ~ 20,\n                              "Roseworthy" ~ 10))
stat -&gt; expert: What do you consider as "best"?
expert -&gt; stat: For now, I just want to select one that'll give me\nthe highest yield.
stat -&gt; design: set_rcrds(yield = plot)
stat -&gt; expert: What's range of values do you expect for the yield?
expert --&gt;&gt; stat: Well it never goes over 10 tonnes per hectre in my fields!
stat -&gt; design: expect_rcrds(yield = to_be_numeric( with_value( between = c(0, 10))))
stat -&gt; expert: Do you have any restrictions in allocation of varieties at site or plots?
expert --&gt;&gt; stat: No.
stat -&gt; design: allocate_trts(var ~ plot)
stat -&gt; design: plot()
design --&gt;&gt; stat
stat -&gt; expert: Well, this is my current understanding of the structure.\nHave I understood it correctly?
expert --&gt;&gt; stat: That looks right.
stat --&gt;&gt; expert: Okay I'll send the design when it's ready.
end 
stat -&gt; design: **randomise_trts()**
stat -&gt; design: serve_table()
design -&gt; data: export_design()
activate data
deactivate design
stat -&gt; design !!: end session
expert -&gt; data: inspect
tech -&gt; data: inquire
tech -&gt; data: data entry
group opt [invalid entry]
data --&gt;&gt; tech: error
end
== Import data and analyse==
@enduml</code></pre>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://emitanaka.org/blog/2021-01-29-uml-seq-diag/seq-diag-uml.png" class="img-fluid figure-img" width="668"></p>
<figcaption>Drawn using plantUML</figcaption>
</figure>
</div>
</div>
</div>
<p>In the end the solution wasn’t quite R, but perhaps it will be when the plantuml package upgrades or other solutions are developed.</p>


</section>
</section>

 ]]></description>
  <category>visualisation</category>
  <category>diagram</category>
  <guid>https://emitanaka.org/blog/2021-01-29-uml-seq-diag/uml-seq-diag.html</guid>
  <pubDate>Thu, 28 Jan 2021 13:00:00 GMT</pubDate>
</item>
<item>
  <title>My Travel Schedule 2019: Building an interactive visualisation as twitter card</title>
  <dc:creator>Emi Tanaka</dc:creator>
  <link>https://emitanaka.org/blog/travel2019/travel2019.html</link>
  <description><![CDATA[ 

<!-- Title banner for blog posts (set in blog/_metadata.yml). Built from each
     post's front matter: title, date, author, categories, description and
     image (a pen sticker is shown when a post has no image). -->



<div class="cell">
<div class="cell-output-display">
<div id="htmlwidget-c406a8b8ec2a17ca231b" style="width:100%;height:225px;" class="widgetframe html-widget"></div>
<script type="application/json" data-for="htmlwidget-c406a8b8ec2a17ca231b">{"x":{"url":"travel2019_files/figure-html//widgets/widget_travelschedule.html","options":{"xdomain":"*","allowfullscreen":false,"lazyload":false}},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<p><br> Hovering over the above graph will show you more details. This year I have a fair bit of travel scheduled including:</p>
<ul>
<li>Eco Sta 2019 at Taichung, Taiwan,</li>
<li>ISI WSC 2019 at Kuala Lumpur, Malaysia,</li>
<li>YSC 2019 at Canberra, Australia, and</li>
<li>Biometrics by the Botanic Garden 2019 at Adelaide, Australia.</li>
</ul>
<p>If you happen to be going to the same conference as myself, do get in touch and maybe you can pay for my taxi? :) (I forgot to put it in my budget …)</p>
<p>The code to make the above graph is shown below. This post benefit largely from this post <a href="https://datatitian.com/how-to-turn-your-ggplot2-visualization-into-an-interactive-tweet/">here</a> to turn <code>plotly</code> output into interactive twitter card.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tsibble)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(googlesheets4)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(highcharter)</span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(widgetframe)</span>
<span id="cb1-6"></span>
<span id="cb1-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># get the data</span></span>
<span id="cb1-8">date_range <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(</span>
<span id="cb1-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Dates =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"06/03/2019"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"12/31/2019"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%m/%d/%Y"</span>),</span>
<span id="cb1-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Location =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sydney, Australia"</span></span>
<span id="cb1-11">) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># the start to end for schedule show</span></span>
<span id="cb1-12">travel_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_sheet</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1T7aH5PzQghU0htnqOjzzEyfe0qdWs_L-1Ybu9PX-rYY"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb1-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Start =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(Start, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%m/%d/%Y"</span>),</span>
<span id="cb1-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">End =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(End, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%m/%d/%Y"</span>)</span>
<span id="cb1-16">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(Start<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>End, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Time"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dates"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as_tsibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">key =</span> Event, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">index =</span> Dates) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill_gaps</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Time =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Between"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(Event) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(FullEvent, URL, Location, What, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.direction =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"down"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ungroup</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># this part feels clumsy.. probably better way to do this</span></span>
<span id="cb1-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(date_range) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as_tibble</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Key =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"All"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as_tsibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">key =</span> Key, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">index =</span> Dates) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill_gaps</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Location =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sydney, Australia"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Event =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">What =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FullEvent =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb1-29">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Day =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substring</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weekdays</span>(Dates), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>),</span>
<span id="cb1-30">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Week =</span> lubridate<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">isoweek</span>(Dates)</span>
<span id="cb1-31">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Week <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span></code></pre></div></div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">fntltp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">JS</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"function(){</span></span>
<span id="cb2-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">              return '&lt;b style=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\"</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">color:#DC5084</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\"</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">&gt;' + this.point.event + '&lt;/b&gt;&lt;br&gt;&lt;span style=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\"</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">font-size:0.7em</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\"</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">&gt;' +  this.series.yAxis.categories[this.point.y] + ', ' +</span></span>
<span id="cb2-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">             this.point.date + '&lt;/span&gt;&lt;br&gt;&lt;span style=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\"</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">font-size:0.7em</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\"</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">&gt;' + this.point.name + '&lt;/span&gt;&lt;br&gt;&lt;span style=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\"</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">font-size:0.7em;color:#FFFFCC</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\"</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">&gt;' + this.point.what + '&lt;/span&gt;&lt;br&gt;'+ this.point.loc;</span></span>
<span id="cb2-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">             }"</span>)</span>
<span id="cb2-5"></span>
<span id="cb2-6">hcout <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hchart</span>(travel_df, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"heatmap"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hcaes</span>(</span>
<span id="cb2-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Week),</span>
<span id="cb2-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Day, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sun"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sat"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Fri"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Thu"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Wed"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Tue"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mon"</span>)),</span>
<span id="cb2-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> Location,</span>
<span id="cb2-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">loc =</span> Location,</span>
<span id="cb2-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">event =</span> Event,</span>
<span id="cb2-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">what =</span> What,</span>
<span id="cb2-13">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name =</span> FullEvent,</span>
<span id="cb2-14">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date =</span> Dates</span>
<span id="cb2-15">),</span>
<span id="cb2-16"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fontSize =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2em"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fontFamily =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Helvetica"</span>)</span>
<span id="cb2-17">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hc_tooltip</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formatter =</span> fntltp) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-19">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># hc_tooltip(crosshairs=TRUE, pointFormat = "y: {point.y}&lt;br&gt;x: {point.x}") %&gt;%</span></span>
<span id="cb2-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hc_title</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"My 2019 Travel Schedule"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fontWeight =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hc_subtitle</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Hover over the tile to see more information"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hc_size</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">225</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hc_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">enabled =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hc_yAxis</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hc_xAxis</span>(</span>
<span id="cb2-26">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">categories =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Jun"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Jul"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Aug"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sep"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Oct"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Nov"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dec"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>),</span>
<span id="cb2-27">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">endOnTick =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb2-28">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hc_add_theme</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hc_theme_538</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hc_plotOptions</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">heatmap =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">borderColor =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">borderWidth =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb2-31"></span>
<span id="cb2-32"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">frameWidget</span>(hcout)</span></code></pre></div></div>
</div>



 ]]></description>
  <category>visualisation</category>
  <category>interactive</category>
  <guid>https://emitanaka.org/blog/travel2019/travel2019.html</guid>
  <pubDate>Mon, 25 Mar 2019 13:00:00 GMT</pubDate>
</item>
<item>
  <title>Making a Hexagon Sticker</title>
  <dc:creator>Emi Tanaka</dc:creator>
  <link>https://emitanaka.org/blog/hexsticker/hexsticker.html</link>
  <description><![CDATA[ 

<!-- Title banner for blog posts (set in blog/_metadata.yml). Built from each
     post's front matter: title, date, author, categories, description and
     image (a pen sticker is shown when a post has no image). -->



<p><img src="https://user-images.githubusercontent.com/7620319/38168572-71e4543e-3593-11e8-9487-9c6c484b896a.png" height="120px" style="width:120px!important" align="right"> Making hexagon stickers have become popular for R-packages with the range of packages associated with RStudio, such as <code>ggplot2</code>, <code>knitr</code>, <code>devtools</code> and so on, having its <a href="https://www.rstudio.com/products/rpackages/">own hex stickers</a>.</p>
<p>This trend even spanned a R-package <code>hexSticker</code> that can be found <a href="https://github.com/GuangchuangYu/hexSticker">here</a>.</p>
<section id="powerpoint-template-for-hex-stickers" class="level2">
<h2 class="anchored" data-anchor-id="powerpoint-template-for-hex-stickers">Powerpoint template for hex stickers</h2>
<p>For the sticker that I made for my R-package <a href="https://github.com/emitanaka/shinycustomloader"><code>shinycustomloader</code></a>, I found it easier, partly due to its long name, to use powerpoint to manipulate the image and create a semi-circular text. It took longer than what I had hoped to get the hexagon shape right. You may like to save your own time by <strong>downloading my powerpoint template</strong> <a href="hexsticker.pptx">here</a> as a base to make your own.</p>
<p>The dimensions were set, as it is in <code>hexSticker</code>, so that you can print it according to http://hexb.in/sticker.html.</p>
</section>
<section id="using-copyright-images-in-hex-stickers" class="level2">
<h2 class="anchored" data-anchor-id="using-copyright-images-in-hex-stickers">Using copyright images in hex stickers</h2>
<p>It’s worth noting about copyright of images since you may like to use images in your hex sticker. If you created the image on your own then the copyright in general will rest with you and there is no problem. If you borrow images from others, you may need to provide attribution depending on their license permission.</p>
<p>In hex stickers, you don’t really have a room to add citations so you may like to use those that require no attribution. For free ones, you can find these using sites such as <a href="https://www.flickr.com/creativecommons/">flickr</a> under Public Domain works (CC0).</p>
<p>It is a bit painful to consider copyright issues but it is important to give due credit, acknowledgement, attribution etc to the creator of the work. I’ve gone to great lengths at times to search for CC0 images or have paid for work. Afterall, creative work is valuable and should be properly rewarded.</p>
<p><strong>UPDATE 22/06</strong> My sticker arrived! They are pretty good quality! I also got 16 which is more than the 10 sample they said on the website <i class="fa-solid fa-face-smile"></i></p>
<p><img src="https://emitanaka.org/blog/hexsticker/hexsticker.gif" width="400px"></p>
<p>These are from sticker mule. If you sign up with referral code <a href="https://www.stickermule.com/au/unlock?ref_id=9651301701">here</a>, both you and I will get some credit. You are, of course, welcomed to just go directly to the site to make the purchase.</p>
<p><a href="https://www.stickermule.com/au/unlock?ref_id=9651301701&amp;utm_content=728x90&amp;utm_medium=embed&amp;utm_source=invite" target="_blank"><img alt="Custom Stickers, Die Cut Stickers, Bumper Stickers - Sticker Mule" border="0" height="90" src="https://res.cloudinary.com/print-bear/image/upload/v1531752798/banners/stickermule-invite-friends-large.jpg" width="728"></a></p>
<p><strong>UPDATE 20/06/2021</strong> When ordering an R-package hex sticker from <a href="https://www.stickermule.com/">sticker mule</a>, I choose Stickers &gt; Die cut stickers &gt; Custom dimension of 1.73” x 1.99”.</p>


</section>

 ]]></description>
  <category>fun</category>
  <guid>https://emitanaka.org/blog/hexsticker/hexsticker.html</guid>
  <pubDate>Thu, 05 Apr 2018 14:00:00 GMT</pubDate>
  <media:content url="https://emitanaka.org/blog/hexsticker/featured.png" medium="image" type="image/png" height="159" width="144"/>
</item>
</channel>
</rss>
