-
Notifications
You must be signed in to change notification settings - Fork 0
/
BasicFactorial.html
1896 lines (1822 loc) · 63.4 KB
/
BasicFactorial.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
<title>Randomized, Basic Factorial Experiments</title>
<script src="site_libs/header-attrs-2.14/header-attrs.js"></script>
<script src="site_libs/jquery-3.5.1/jquery-3.5.1.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="site_libs/bootstrap-3.3.5/css/cerulean.min.css" rel="stylesheet" />
<script src="site_libs/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/respond.min.js"></script>
<style>h1 {font-size: 34px;}
h1.title {font-size: 38px;}
h2 {font-size: 30px;}
h3 {font-size: 24px;}
h4 {font-size: 18px;}
h5 {font-size: 16px;}
h6 {font-size: 12px;}
code {color: inherit; background-color: rgba(0, 0, 0, 0.04);}
pre:not([class]) { background-color: white }</style>
<script src="site_libs/navigation-1.1/tabsets.js"></script>
<script src="site_libs/kePrint-0.0.1/kePrint.js"></script>
<link href="site_libs/lightable-0.0.1/lightable.css" rel="stylesheet" />
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
</style>
<style type="text/css">
code {
white-space: pre;
}
.sourceCode {
overflow: visible;
}
</style>
<style type="text/css" data-origin="pandoc">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ background-color: #f8f8f8; }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ef2929; } /* Alert */
code span.an { color: #8f5902; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #c4a000; } /* Attribute */
code span.bn { color: #0000cf; } /* BaseN */
code span.cf { color: #204a87; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4e9a06; } /* Char */
code span.cn { color: #000000; } /* Constant */
code span.co { color: #8f5902; font-style: italic; } /* Comment */
code span.cv { color: #8f5902; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #8f5902; font-weight: bold; font-style: italic; } /* Documentation */
code span.dt { color: #204a87; } /* DataType */
code span.dv { color: #0000cf; } /* DecVal */
code span.er { color: #a40000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #0000cf; } /* Float */
code span.fu { color: #000000; } /* Function */
code span.im { } /* Import */
code span.in { color: #8f5902; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #204a87; font-weight: bold; } /* Keyword */
code span.op { color: #ce5c00; font-weight: bold; } /* Operator */
code span.ot { color: #8f5902; } /* Other */
code span.pp { color: #8f5902; font-style: italic; } /* Preprocessor */
code span.sc { color: #000000; } /* SpecialChar */
code span.ss { color: #4e9a06; } /* SpecialString */
code span.st { color: #4e9a06; } /* String */
code span.va { color: #000000; } /* Variable */
code span.vs { color: #4e9a06; } /* VerbatimString */
code span.wa { color: #8f5902; font-weight: bold; font-style: italic; } /* Warning */
</style>
<script>
// apply pandoc div.sourceCode style to pre.sourceCode instead
(function() {
var sheets = document.styleSheets;
for (var i = 0; i < sheets.length; i++) {
if (sheets[i].ownerNode.dataset["origin"] !== "pandoc") continue;
try { var rules = sheets[i].cssRules; } catch (e) { continue; }
for (var j = 0; j < rules.length; j++) {
var rule = rules[j];
// check if there is a div.sourceCode rule
if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") continue;
var style = rule.style.cssText;
// check if color or background-color is set
if (rule.style.color === '' && rule.style.backgroundColor === '') continue;
// replace div.sourceCode by a pre.sourceCode rule
sheets[i].deleteRule(j);
sheets[i].insertRule('pre.sourceCode{' + style + '}', j);
}
}
})();
</script>
<link rel="stylesheet" href="styles.css" type="text/css" />
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
img {
max-width:100%;
}
.tabbed-pane {
padding-top: 12px;
}
.html-widget {
margin-bottom: 20px;
}
button.code-folding-btn:focus {
outline: none;
}
summary {
display: list-item;
}
details > summary > p:only-child {
display: inline;
}
pre code {
padding: 0;
}
</style>
<style type="text/css">
.dropdown-submenu {
position: relative;
}
.dropdown-submenu>.dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
border-radius: 0 6px 6px 6px;
}
.dropdown-submenu:hover>.dropdown-menu {
display: block;
}
.dropdown-submenu>a:after {
display: block;
content: " ";
float: right;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
border-width: 5px 0 5px 5px;
border-left-color: #cccccc;
margin-top: 5px;
margin-right: -10px;
}
.dropdown-submenu:hover>a:after {
border-left-color: #adb5bd;
}
.dropdown-submenu.pull-left {
float: none;
}
.dropdown-submenu.pull-left>.dropdown-menu {
left: -100%;
margin-left: 10px;
border-radius: 6px 0 6px 6px;
}
</style>
<script type="text/javascript">
// manage active state of menu based on current page
$(document).ready(function () {
// active menu anchor
href = window.location.pathname
href = href.substr(href.lastIndexOf('/') + 1)
if (href === "")
href = "index.html";
var menuAnchor = $('a[href="' + href + '"]');
// mark it active
menuAnchor.tab('show');
// if it's got a parent navbar menu mark it active as well
menuAnchor.closest('li.dropdown').addClass('active');
// Navbar adjustments
var navHeight = $(".navbar").first().height() + 15;
var style = document.createElement('style');
var pt = "padding-top: " + navHeight + "px; ";
var mt = "margin-top: -" + navHeight + "px; ";
var css = "";
// offset scroll position for anchor links (for fixed navbar)
for (var i = 1; i <= 6; i++) {
css += ".section h" + i + "{ " + pt + mt + "}\n";
}
style.innerHTML = "body {" + pt + "padding-bottom: 40px; }\n" + css;
document.head.appendChild(style);
});
</script>
<!-- tabsets -->
<style type="text/css">
.tabset-dropdown > .nav-tabs {
display: inline-table;
max-height: 500px;
min-height: 44px;
overflow-y: auto;
border: 1px solid #ddd;
border-radius: 4px;
}
.tabset-dropdown > .nav-tabs > li.active:before {
content: "";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li.active:before {
content: "";
border: none;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open:before {
content: "";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.tabset-dropdown > .nav-tabs > li.active {
display: block;
}
.tabset-dropdown > .nav-tabs > li > a,
.tabset-dropdown > .nav-tabs > li > a:focus,
.tabset-dropdown > .nav-tabs > li > a:hover {
border: none;
display: inline-block;
border-radius: 4px;
background-color: transparent;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li {
display: block;
float: none;
}
.tabset-dropdown > .nav-tabs > li {
display: none;
}
</style>
<!-- code folding -->
</head>
<body>
<div class="container-fluid main-container">
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-bs-toggle="collapse" data-target="#navbar" data-bs-target="#navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">Design and Analysis of Experiment</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Foundations of Experimental Design
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="RCommands.html">Principles of Experimentation</a>
</li>
<li>
<a href="RMarkdownHints.html">Choosing a response variable</a>
</li>
<li>
<a href="RCheatSheetsAndNotes.html">Choosing conditions</a>
</li>
<li>
<a href="DataSources.html">Choosing units/experimental material</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Specific Designs
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="BasicFactorial.html">Completely Randomized, Basic Factorial Designs</a>
</li>
<li>
<a href="Block.html">Block Designs</a>
</li>
<li>
<a href="Covariate.html">Covariate Designs</a>
</li>
<li>
<a href="NestedFactor.html">Nested Factor (aka Split Plot/Repeated Measure) Designs</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Broad Topics
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="anova_basics.html">ANOVA Model and Assumptions</a>
</li>
<li>
<a href="junko.html">quarto experiment</a>
</li>
<li>
<a href="LogisticRegression.html">Extending the Basic Designs</a>
</li>
<li>
<a href="ANOVA.html">Notation</a>
</li>
<li>
<a href="MakingInference.html">Multiple Pairwise Testing</a>
</li>
<li>
<a href="Kruskal.html">Power</a>
</li>
<li>
<a href="LogisticRegression.html">Random Factors</a>
</li>
<li>
<a href="WilcoxonTests.html">Unbalanced Datasets</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
R Instructions
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="DescribeData.html">Descriptive Summaries</a>
</li>
<li>
<a href="model_diagnostics.html">Model diagnostics</a>
</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Datasets
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="./Data/AnalysisRubric.html">XYZ</a>
</li>
<li>
<a href="./Data/StudentHousing.html">yadda yadda</a>
</li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
<div id="header">
<h1 class="title toc-ignore">Randomized, Basic Factorial
Experiments</h1>
</div>
<hr />
<p>The experimental designs in this section have 2 key characteristics
in common:</p>
<ul>
<li>Conditions are assigned to subjects (a.k.a. experimental units)
completely at random</li>
<li>The way error is accounted for in all these designs and the way the
requirements are checked can be approached the same way</li>
</ul>
<p>To assign something <strong>completely at random</strong> means that
each experimental unit has a known and equal chance of being selected
for a particular treatment and that no other considerations are taken
into account when making treatment assignments. Usually, for balance,
the same number of units are assigned to each treatment. For example, if
I have 4 treatment and 16 units, I may use a computer to randomly
shuffle the units into treatment groups.</p>
<p>Factorial experiments involve two or more factors that are crossed.
<strong>Factorial crossing</strong> means that each combination of
factor levels is considered as a treatment in the study. (A study with
just one factor is not technically a factorial design, but we will lump
it in with our discussion of factorial experiments her because of the
completely random treatment assignment).</p>
<p>Contrast a factorial design with the one-at-a-time approach. In a
one-at-a-time approach, if I had two factors I wanted to study I would
run two separate experiments to evaluate the effect of each factor on
the response one-at-time. Factorial designs have a couple of major
advantages over one-factor-at-a-time studies.</p>
<ol style="list-style-type: decimal">
<li>They are a more efficient use of our time and material: I can get
information about both of my factors from just one experimental
unit</li>
<li>Perhaps most importantly, factorial designs allow the researcher to
estimate interaction effects. Or in other words, we can observe how one
factor’s effect on the response variable changes for different levels of
the other factor.</li>
</ol>
<p>EXAMPLE of BF2???</p>
<p>In summary, “factorial” refers to how you determine which treatments
will be included in the study, and “completely randomized” refers to how
treatments are assigned to subjects.</p>
<hr />
<div id="bf1" class="section level2 tabset tabset-fade tabset-pills">
<h2 class="tabset tabset-fade tabset-pills">BF[1]</h2>
<p>A study with just one factor</p>
<div id="overview" class="section level3">
<h3>Overview</h3>
<p>In a basic one-way factorial design (BF[1]), only one factor is
purposefully varied. Each level of the factor is considered a treatment.
Each experimental unit is randomly assigned to exactly one
treatment.</p>
<div id="factor-structure" class="section level4">
<h4>Factor structure</h4>
<p>The factor structure for the model resulting from a completely
randomized, one factor with design is:</p>
<p><img src="images/BF1_factor_structure_with_equation.PNG" /></p>
<p>The above diagram illustrates a factor with 4 levels, 6 replications
at each level.</p>
</div>
<div id="hypotheses-and-model" class="section level4">
<h4>Hypotheses and model</h4>
<p>A more detailed description of the model for an ANOVA with just one
factor:</p>
<p><span class="math display">\[
y_{ij} = \mu + \alpha_i + \epsilon_{ij}
\]</span></p>
<p><span class="math inline">\(y_{ij}\)</span>: the <span
class="math inline">\(j^{th}\)</span> observation from treatment <span
class="math inline">\(i\)</span></p>
<p><span class="math inline">\(\mu\)</span>: the grand mean of the
dataset. Also referred to as an overall mean or benchmark.</p>
<p><span class="math inline">\(\alpha_i\)</span>: effect of treatment
<span class="math inline">\(i\)</span></p>
<p><span class="math inline">\(\epsilon_{ik}\)</span>: the error term,
or residual term of the model. There are <em>j</em> replicates for each
treatment. It represents the distance from an observation to its
treatment mean (or predicted value).</p>
<p>The null and alternative hypotheses can be expressed as:</p>
<p><span class="math display">\[
H_o: \alpha_1 = \alpha_2 = ... = 0
\]</span> <span class="math display">\[
H_a: \alpha_i \neq 0 \quad \text{for at least one }\ \alpha_i
\]</span></p>
</div>
<div id="assumptions" class="section level4">
<h4>Assumptions</h4>
<p>A one-way ANOVA model may be used to analyze data from a BF[1] design
if the following requirements are satisfied:</p>
<ol style="list-style-type: decimal">
<li>Each experimental unit is randomly assigned to only 1 treatment (or
factor level)</li>
<li>The error term of the model (<span
class="math inline">\(\epsilon_{ik}\)</span>) is normally distributed.
This assumption is met when the residuals are normally distributed (as
seen in a qq-plot).</li>
<li>The population variance of each group is equal. This is often called
the homogeneity of variance, or constant variance assumption. This is
considered met when each group of residuals in the residual
vs. fitted-values plot shows a similar vertical spread.</li>
</ol>
<hr />
</div>
</div>
<div id="design" class="section level3">
<h3>Design</h3>
<p>In a one factor design, one factor is purposefully varied and all
other factors are controlled in order to isolate the effect of just the
factor under study. Each level of the factor is considered a
treatment.</p>
<p>In a completely randomized design, each experimental unit is randomly
assigned to exactly 1 treatment. It is common to keep the number of
units assigned to each treatment the same to ensure balance. This can be
done by listing all the subjects, then listing the treatments, as seen
below:</p>
<table>
<thead>
<tr class="header">
<th align="center">Subject</th>
<th align="center">Treatment</th>
<th align="center">Order</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="center">Subject 1</td>
<td align="center">A</td>
<td align="center">1</td>
</tr>
<tr class="even">
<td align="center">Subject 2</td>
<td align="center">A</td>
<td align="center">2</td>
</tr>
<tr class="odd">
<td align="center">Subject 3</td>
<td align="center">B</td>
<td align="center">3</td>
</tr>
<tr class="even">
<td align="center">Subject 4</td>
<td align="center">B</td>
<td align="center">4</td>
</tr>
<tr class="odd">
<td align="center">Subject 5</td>
<td align="center">C</td>
<td align="center">5</td>
</tr>
<tr class="even">
<td align="center">Subject 6</td>
<td align="center">C</td>
<td align="center">6</td>
</tr>
</tbody>
</table>
<p>Then you randomly shuffle the treatment column. (You should also be
paying attention to the order in which subjects and treatments are being
experimented on as this could be a potential source of bias. In a BF[1],
you randomize the order also.) The result might look something like
this.</p>
<table>
<thead>
<tr class="header">
<th align="center">Subject</th>
<th align="center">Treatment</th>
<th align="center">Order</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="center">Subject 1</td>
<td align="center">A</td>
<td align="center">4</td>
</tr>
<tr class="even">
<td align="center">Subject 2</td>
<td align="center">B</td>
<td align="center">3</td>
</tr>
<tr class="odd">
<td align="center">Subject 3</td>
<td align="center">C</td>
<td align="center">6</td>
</tr>
<tr class="even">
<td align="center">Subject 4</td>
<td align="center">C</td>
<td align="center">5</td>
</tr>
<tr class="odd">
<td align="center">Subject 5</td>
<td align="center">A</td>
<td align="center">1</td>
</tr>
<tr class="even">
<td align="center">Subject 6</td>
<td align="center">B</td>
<td align="center">2</td>
</tr>
</tbody>
</table>
<p>You may notice in the above example that, even with randomization,
treatment C occurs in the last 2 observations. If we were truly
concerned about the order we could be more strategic and implement a
<em>blocked design</em> to prevent “unlucky” ordering and pairing.</p>
<p>Consider the following example. An experiment was done to asses
different modes of virtual training in how to launch a lifeboat. Sixteen
students in the maritime safety training institute were a part of the
study, and each of the students were assigned one of four possible
virtual training experiences. The four experiences included:
Lecture/Materials (Control) (1), Monitor/Keyboard (2), Head Monitor
Display/Joypad (3), and Head Monitor Display/Wearables (4). The response
variable was the student’s performance on a procedural knowledge
assessment (performance is defined as their level of improvement from
pre to post test).</p>
<p>To obtain a balanced design, we will want each treatment to be
assigned to four students. We could get 16 pieces of paper and write
“Treatment 1” on 4 pieces, “Treatment 2” on another 4 pieces, and so on
until each treatment has 4 pieces of paper. We could then put them in a
hat, mix them up and then randomly draw out a piece of paper to assign
it to a subject. Intuitively this makes sense, but writing and cutting
paper is slow and inefficient. We could implement a similar process in R
to assign treatments.</p>
<p>First, we list all the possible treatments, and repeat that listing
until it is the same size as our count of subjects. (Note, if your
number of subjects is not an exact multiple of the number of treatments,
you may need to decide which treatments deserve fewer observations)</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>treatment_list <span class="ot"><-</span> <span class="fu">rep</span>(<span class="dv">1</span><span class="sc">:</span><span class="dv">4</span>,<span class="dv">4</span>) <span class="co">#This repeats the sequence of 1 to 4, four times</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a>treatment_list</span></code></pre></div>
<pre><code>## [1] 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4</code></pre>
<p>Here it is reformatted in a easy to read table.</p>
<table>
<thead>
<tr class="header">
<th align="center">Subject</th>
<th align="center">Treatment</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="center">Subject 1</td>
<td align="center">1</td>
</tr>
<tr class="even">
<td align="center">Subject 2</td>
<td align="center">2</td>
</tr>
<tr class="odd">
<td align="center">Subject 3</td>
<td align="center">3</td>
</tr>
<tr class="even">
<td align="center">Subject 4</td>
<td align="center">4</td>
</tr>
<tr class="odd">
<td align="center">Subject 5</td>
<td align="center">1</td>
</tr>
<tr class="even">
<td align="center">Subject 6</td>
<td align="center">2</td>
</tr>
<tr class="odd">
<td align="center">Subject 7</td>
<td align="center">3</td>
</tr>
<tr class="even">
<td align="center">Subject 8</td>
<td align="center">4</td>
</tr>
<tr class="odd">
<td align="center">Subject 9</td>
<td align="center">1</td>
</tr>
<tr class="even">
<td align="center">Subject 10</td>
<td align="center">2</td>
</tr>
<tr class="odd">
<td align="center">Subject 11</td>
<td align="center">3</td>
</tr>
<tr class="even">
<td align="center">Subject 12</td>
<td align="center">4</td>
</tr>
<tr class="odd">
<td align="center">Subject 13</td>
<td align="center">1</td>
</tr>
<tr class="even">
<td align="center">Subject 14</td>
<td align="center">2</td>
</tr>
<tr class="odd">
<td align="center">Subject 15</td>
<td align="center">3</td>
</tr>
<tr class="even">
<td align="center">Subject 16</td>
<td align="center">4</td>
</tr>
</tbody>
</table>
<p>Then we randomly shuffle treatments with subjects to get the
following assignments. The R code could look like this</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="fu">set.seed</span>(<span class="dv">17</span>) <span class="co">#only use this if you want the exact same random selection as this example</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="fu">sample</span>(treatment_list, <span class="dv">16</span>)</span></code></pre></div>
<pre><code>## [1] 2 4 1 4 3 1 3 2 2 2 4 3 4 1 3 1</code></pre>
<p>We can see here that subject 1 should get treatment 2. Subject 2 gets
treatment 4, Subject 3 gets treatment 1 and so on.</p>
<table>
<thead>
<tr class="header">
<th align="center">Subject</th>
<th align="center">Treatment</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="center">Subject 1</td>
<td align="center">2</td>
</tr>
<tr class="even">
<td align="center">Subject 2</td>
<td align="center">4</td>
</tr>
<tr class="odd">
<td align="center">Subject 3</td>
<td align="center">1</td>
</tr>
<tr class="even">
<td align="center">Subject 4</td>
<td align="center">4</td>
</tr>
<tr class="odd">
<td align="center">Subject 5</td>
<td align="center">3</td>
</tr>
<tr class="even">
<td align="center">Subject 6</td>
<td align="center">1</td>
</tr>
<tr class="odd">
<td align="center">Subject 7</td>
<td align="center">3</td>
</tr>
<tr class="even">
<td align="center">Subject 8</td>
<td align="center">2</td>
</tr>
<tr class="odd">
<td align="center">Subject 9</td>
<td align="center">2</td>
</tr>
<tr class="even">
<td align="center">Subject 10</td>
<td align="center">2</td>
</tr>
<tr class="odd">
<td align="center">Subject 11</td>
<td align="center">4</td>
</tr>
<tr class="even">
<td align="center">Subject 12</td>
<td align="center">3</td>
</tr>
<tr class="odd">
<td align="center">Subject 13</td>
<td align="center">4</td>
</tr>
<tr class="even">
<td align="center">Subject 14</td>
<td align="center">1</td>
</tr>
<tr class="odd">
<td align="center">Subject 15</td>
<td align="center">3</td>
</tr>
<tr class="even">
<td align="center">Subject 16</td>
<td align="center">1</td>
</tr>
</tbody>
</table>
<hr />
</div>
<div id="decomposition-and-factor-structure" class="section level3">
<h3>Decomposition and Factor Structure</h3>
<p>This section serves as a bridge between the design and the analysis
of an experiment. It is equivalent to doing the analysis by hand. The
primary goal is to see how the design decisions impact the analysis;
including a deeper understanding of what the numbers in an ANOVA table
mean and how they are calculated.</p>
<p>A factor structure for an experimental design can help provide an
effective way to organize and plan for the type of data needed for an
experiment. For a basic one-way factorial design, three factors are
involved for the experiment: the benchmark (or grand mean), the
treatment, and the residual error. For example, an experiment was done
to help train people in the procedure to launch a lifeboat. This was a
Basic One-way Factorial Design, one where the treatments included:
Lecture/Materials (Control) (1), Monitor/Keyboard (2), Head Monitor
Display/Joypad (3), and Head Monitor Display/Wearables (4). The students
were then given a pre-test before training and a post-test after
training and the difference between the two scores was the measurement
used from each student in the analysis. Therefore, we have four levels
for the treatment with six replicates for each treatment (the actual
study used 16 observations per treatment). The diagram below gives the
factor structure of the design, and the accompanying mathematical
model.</p>
<p><img src="images/BF1_factor_structure_with_equation.PNG" /></p>
<p>A basic one-way factorial design has three factors: the benchmark,
treatment, and residual. The effects of these factors can be summed
together to find each observed value.</p>
<ul>
<li>The <strong>observed values</strong> on the left show that there are
24 distinct observations of performance score, represented by the 24
cells - one for each of the observed values.</li>
<li>The <strong>benchmark</strong> represents the grand mean (or overall
mean). The single large cell indicates that there is only one grand mean
and it is part of every observation.<br />
</li>
<li>The <strong>treatment factor</strong> involves the four levels of
the treatment represented by the four vertically long cells. Each
treatment may have a distinct mean (or effect).</li>
<li>The <strong>residual error</strong> represents the difference
between the observed value and the predicted value. The predicted value,
also called the fitted value, is the sum of the grand mean and treatment
effect. Each of the cells represent a distinct value for the residual
error.</li>
</ul>
<div id="inside-vs.-outside-factors" class="section level4">
<h4>Inside vs. Outside Factors</h4>
<p>Having a factor structure can help us determine the <strong>degrees
of freedom</strong> and the <strong>effects</strong> of each factor.
Before determining the degrees of freedom and the effects of each
factor, understanding <strong>outside and inside factors</strong> is
helpful.</p>
<p>A factor is inside of another factor if all the levels of one factor
(<strong>the inside factor</strong>) completely fits within a second
factor (<strong>the outside factor</strong>).</p>
<p>You may find this analogy helpful. Pretend that an outside factor is
a box, and the inside factor levels are blocks that fit perfectly within
the box.</p>
<center>
<img src="images/wooden_blocks_in_box.jpg" width = 200px;>
<!-- ![blocks in box](images/wooden_blocks_in_box.jpg) -->
<!-- picture from: https://www.amazon.com/MOD-Complete-Extra-Large-Size/dp/B079J8PB73 -->
</center>
<p>In our basic one-way factorial design there are three factors: the
benchmark, treatment, and residuals. In the picture below, benchmark is
represented in red, treatment is drawn in blue, and the residual factor
levels are depicted in black.</p>
<p><img src="images/inside_outside_1.JPG" /></p>
<p>In order to understand the relationship between the benchmark and
treatment factor, imagine picking up the levels of factor and placing
them in the other factor one at a time. We will start with taking the
levels of treatment and placing them inside of the benchmark.</p>
<p><img src="images/inside_outside_2.JPG" /></p>
<p>In this picture you can see that one entire level of treatment can
fit inside of a single level of benchmark. Even though they may share a
boundary line, the level does not cross over and start sharing
boundaries with any other level. You can repeat this for the other 3
levels of treatment with the same result. Therefore, we say that
treatment is inside of benchmark, which is the same as saying that
benchmark is outside of treatment.</p>
<p>Consider now the relationship between treatment and residual. If we
take a level of treatment and overlay it on the residual factor, we can
see it does not fit neatly inside one of the levels of residual error.
In fact, one level of treatment crosses the boundaries of many of the
levels of residual error. Therefore, we cannot say that treatment is
inside of residual error.</p>
<p><img src="images/inside_outside_3.JPG" /></p>
<p>Since treatment is not inside of residual error, does this
necessarily mean that treatment is outside of residual error? We can
determine this by taking one level of residual at a time and overlaying
it on the treatment factor structure, as is pictured below. It can be
seen that one level of residual error does NOT cross any of the
treatment level boundaries. Therefore, we can safely say that treatment
is indeed outside of residual error; or equivalently that treatment is
outside of residual error.</p>
<p><img src="images/inside_outside_4.JPG" /></p>
<p>To clarify a common misunderstanding, consider an experiment where we
are looking at the inside vs. outside relationship of two factors: A,
and B.</p>
<ul>
<li>When factor A is inside of factor B, we can also say factor B is
outside of factor A.</li>
<li>But, when factor A is <em>not</em> inside of factor B, this does
<em>not necessarily mean that factor A is outside of factor B</em>.
Later you will come across designs where the two factors are neither
outside nor inside of each other: they are crossed.</li>
</ul>
<p>In summary, inside and outside factors for every basic one-way
factorial design:</p>
<ul>
<li>The <strong>benchmark factor</strong> is the outside factor for all
the other factors (treatment and residual error)</li>
<li>The <strong>treatment factor</strong> is an inside factor to the
benchmark factor but an outside factor to the residual error.</li>
<li>The <strong>residual error</strong> is an inside factor for all
other factors (the benchmark and treatment factors).</li>
</ul>
</div>
<div id="degrees-of-freedom" class="section level4">
<h4>Degrees of Freedom</h4>
<p>We can use our understanding of inside and outside factors to
determine the degrees of freedom (df) for the
<strong>benchmark</strong>, <strong>treatment</strong>, and
<strong>residual errors</strong> factors.</p>
<p>The general formula for degrees of freedom for any factor in a design
is:</p>
<center>
<blockquote>
<p><strong>df = Total levels of a factor minus the sum of the df of all
outside factors</strong></p>
</blockquote>
</center>
<p>An alternative method of finding degrees of freedom is to count the
number of unique pieces of information in a factor.</p>
<p>Going back to the lifeboat training example (see example above), we
have 24 observations total and four levels of the treatment.</p>
<p><img src="images/BF1_factor_structure_with_equation.PNG" /></p>
<p>For <strong>benchmark</strong>, there is only one level of the factor
(shown by the one cell) and there are no outside factors for benchmark.
Therefore, the degrees of freedom for benchmark is one. Another way to
think of this is that the degrees of freedom represents the number of
unique pieces of information contributing to the estimation of the
effects for that factor. In this case, as soon as I know the benchmark
value (or better stated, as soon as I estimate the benchmark value) for
just one of the observations, I know it for all the observations.
Therefore, there is just one degree of freedom.</p>
<p>For <strong>treatment</strong>, there are four levels of the factor
(shown by the four vertically long cells for treatment). Benchmark is
the only factor outside of treatment. Take the number of levels for
treatment (4) and subtract the degrees of freedom for benchmark (1),
which yields 4-1 = <strong>3 degrees of freedom</strong> for
treatment.</p>
<p>We could just as easily have used the other approach to finding the
degrees of freedom: counting the unique pieces of information the
treatment effects really contains. Since all observations from the same
treatment will have the same treatment effect applied, we really only
need to know 4 pieces of information: the effect of each treatment. But
the answer is actually less than that. Because we know that the effects
must all sum to zero, only 3 of the effects are free to vary and the 4th
one is constrained to be whatever value will satisfy this mathematical