<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/six-sigma-dmaic-series-in-r-part4/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://datascienceplus.com/six-sigma-dmaic-series-in-r-part4/"> R Programming – DataScience+</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<ul></ul>
<p><strong>
<p>Categories</p>
<p></p></strong>
<ol>
<li><a rel="nofollow" href="https://datascienceplus.com/category/basic-statistics/" title="Permanent Link toBasic Statistics" target="_blank">Basic Statistics</a></li>
</ol>
<p><strong>
<p>Tags</p>
<p></p></strong>
<ol>
<li><a rel="nofollow" href="https://datascienceplus.com/tag/data-visualisation/" title="Permanent Link toData Visualisation" target="_blank">Data Visualisation</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/tag/linear-regression/" title="Permanent Link toLinear Regression" target="_blank">Linear Regression</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/tag/rstats/" title="Permanent Link toR Programming" target="_blank">R Programming</a></li>
</ol>
<p>Hope you liked the <a rel="nofollow" href="https://datascienceplus.com/six-sigma-dmaic-series-in-r-part-1/" target="_blank">Part 1</a> ,<a rel="nofollow" href="https://datascienceplus.com/six-sigma-dmaic-series-in-r-part-2/" target="_blank">Part 2</a> and <a rel="nofollow" href="https://datascienceplus.com/six-sigma-dmaic-series-in-r-part-3/" target="_blank">Part 3</a> of this Series. In this Part 4, we will go through the tools used during the Improve phase of Six Sigma DMAIC cycle. The most representative tool used during the Improve Phase is DOE-Design of experiments. Proper use of DOE can lead to process improvement, but a bad design of experiment can lead to undesired results – inefficiency, higher costs.</p>
<h2>What is experiment</h2>
<p>An experiment is a test or series of tests in which purposeful changes are made to input variables of a process or system so that we may observe and identify the reason for the change in output response.<br>
Consider the example of the simple process model, shown below, where we have controlled input factors X’s, output Y and uncontrolled factors Z’s. </p>
<p><a rel="nofollow" href="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2018/09/PM.jpg?ssl=1" target="_blank"><img sizes="(max-width: 490px) 100vw, 490px" src="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2018/09/PM-490x321.jpg?w=450&ssl=1" alt="" class="wp-image-17041" data-recalc-dims="1"></a></p>
<p>The objective of the experiment can be:</p>
<ol>
<li>Process Characterization: To know the relationship between X, Y &amp; Z.</li>
<li>Process Control: Capture changes in X, so that Y is always near the desired nominal value.</li>
<li>Process Optimization: Capture changes in X, so that the variability of Y is minimized.</li>
<li>Robust Design: Capture changes in X, so that effect of uncontrolled Z is minimized. </li>
</ol>
<h2>Importance of experiment</h2>
<p>Experiments allow to control the values of the Xs of the process and then measure the value of the Ys to discover what values of the independent variables will allow us to improve the performance of our process. On the contrary, in the case of Observational Studies, we don’t have any influence on the variables we are measuring. We just collect the data and use the appropriate statistical technique.<br>
There are some risks associated when the analysis is based on the data gathered directly during the normal performance of process: Inconsistent Data, Variable Value Range ( performance of X’s outside range not known ) &amp; Correlated Variables.</p>
<h2>Characteristics of well planned experiments</h2>
<p>Some of the Characteristics of well-planned experiments are:</p>
<ol>
<li>The degree of Precision:<br>
Probability should be high that experiment will be able to measure the differences with a degree of precision the experimenter desires. It implies appropriate design and sufficient replication.</li>
<li>Simplicity:<br>
As simple as possible consistent with the objectives of experiment.</li>
<li>The absence of Systematic Error:<br>
Units receiving one treatment should not differ in any systematic way from those receiving other treatment.</li>
<li>The range of Validity of Conclusions:<br>
Experiments replicated in time and space would increase the range of validity of conclusions.</li>
<li>Calculation of the degree of Uncertainty:<br>
A possibility of obtaining the observed results by chance alone.</li>
</ol>
<h2>Three basic principle of Experiments</h2>
<p>Three basic principles of experiments are Randomization, Repetition &amp; Blocking.</p>
<p><a rel="nofollow" href="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2018/11/doep.jpg?ssl=1" target="_blank"><img sizes="(max-width: 1249px) 100vw, 1249px" src="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2018/11/doep.jpg?w=450&ssl=1" alt="" class="wp-image-18234" data-recalc-dims="1"></a></p>
<p>Lets understand this through an example – A food manufacturer is searching for the best recipe for its main product: a pizza dough. The managers decided to perform an experiment to determine the optimal levels of the three main ingredients in the pizza dough: flour, salt, and baking powder. The other ingredients are fixed as they do not affect the flavor of the final cooked pizza. The flavor of the product will be determined by a panel of experts who will give a score to each recipe. Therefore, we have three factors that we will call flour, salt, and baking powder(bakPow), with two levels each (− and +). </p>
<pre>
pizzaDesign &lt;- expand.grid(flour = gl(2, 1, labels = c(&quot;-&quot;,
                                                       &quot;+&quot;)),
                           salt = gl(2, 1, labels = c(&quot;-&quot;, &quot;+&quot;)),
                           bakPow = gl(2, 1, labels = c(&quot;-&quot;, &quot;+&quot;)),
                           score = NA)
</pre>
<p><a rel="nofollow" href="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2018/11/piza.jpg?ssl=1" target="_blank"><img src="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2018/11/piza.jpg?resize=285%2C171&ssl=1" alt="" width="285" class="wp-image-18232" data-recalc-dims="1" height="171"></a></p>
<p>Now, we have eight different experiments (recipes) including all the possible combinations of the three factors at two levels.<br>
When we have more than 2 factors, the combination of levels of different factors may affect the response. Therefore, to discover the main effects and the interactions, we should vary more than one level at a time, performing experiments in all the possible combinations.<br>
The reason Why two-level factor experiments are widely used is that as the number of factor level increases, cost of doing the experiment increases. To study the variation under the same experimental conditions, replication needs to be done, making more than one trial per factor combination. The number of replications depends on several aspects (e.g budget).</p>
<p>Once an experiment has been designed, we will proceed with its randomization.</p>
<pre>
pizzaDesign$ord &lt;- sample(1:8, 8)
pizzaDesign[order(pizzaDesign$ord),]
</pre>
<p>Each time you repeat the command you get a different order due to randomization. </p>
<h2>2^k factorial Designs</h2>
<p>2k factorial designs are those whose number of factors to be studied are k, all of them with 2 levels. The number of experiments we need to carryout to obtain a complete replication is precisely the power(2 to the k). If we want n replications of the experiment, then the total number of experiments is n×2k.<br>
ANOVA can be used to estimate the effect of each factor and interaction and assess which of these effects are signiﬁcant.</p>
<p>Example contd.:- The experiment is carried out by preparing the pizzas at the factory following the package instructions, namely: “bake the pizza for 9 min in an oven at 180◦C.” </p>
<p>After a blind trial is conducted,the scores were given by the experts to each of the eight (2^3) recipes in each replication of the experiment. </p>
<pre>
ss.data.doe1 &lt;- data.frame(repl = rep(1:2, each = 8), rbind(pizzaDesign[, -6], pizzaDesign[, -6])) 
ss.data.doe1$score &lt;- c(5.33, 6.99, 4.23, 6.61, 2.26, 5.75, 3.26, 6.24, 5.7, 7.71, 5.13, 6.76, 2.79, 4.57, 2.48, 6.18)

</pre>
<p>The average for each recipe can be calculated as below:</p>
<pre>
aggregate(score ~ flour + salt + bakPow, FUN = mean, data = ss.data.doe1)
</pre>
<p><a rel="nofollow" href="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2018/12/agg.jpg?ssl=1" target="_blank"><img src="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2018/12/agg.jpg?resize=309%2C175&ssl=1" alt="" width="309" class="wp-image-19193" data-recalc-dims="1" height="175"></a></p>
<p>The best recipe seems to be the one with a high level of ﬂour and a low level of salt and baking powder. Fit a linear model and perform an ANOVA to ﬁnd the signiﬁcant effects.</p>
<pre>
doe.model1 &lt;- lm(score ~ flour + salt + bakPow + flour * salt + flour * bakPow + salt * bakPow + flour * salt * bakPow, data = ss.data.doe1) 


summary(doe.model1)

</pre>
<p><a rel="nofollow" href="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2018/12/doe1.jpg?ssl=1" target="_blank"><img sizes="(max-width: 748px) 100vw, 748px" src="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2018/12/doe1.jpg?w=450&ssl=1" alt="" class="wp-image-19195" data-recalc-dims="1"></a></p>
<p>p-values show that the main effects of the ingredients ﬂour and baking powder are signiﬁcant, while the effect of the salt is not signiﬁcant. Interactions among the ingredients are neither 2-way nor 3-way, making them insigniﬁcant. Thus, we can simplify the model, excluding the non signiﬁcant effects. Thus, the new model with the signiﬁcant effects is :</p>
<pre>
doe.model2 &lt;- lm(score ~ flour + bakPow, data = ss.data.doe1) 
summary(doe.model2)
</pre>
<p><a rel="nofollow" href="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2018/12/doe2.jpg?ssl=1" target="_blank"><img sizes="(max-width: 649px) 100vw, 649px" src="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2018/12/doe2.jpg?w=450&ssl=1" alt="" class="wp-image-19196" data-recalc-dims="1"></a></p>
<p>Therefore,the statistical model for our experiment is<br>
score =4.8306 + 2.4538*Flour-1.8662*bakpow<br>
Thus, the recipe with a high level of ﬂour and low level of baking powder will be the best one, regardless of the level of salt (high or low). The estimated score for this recipe is </p>
<p>`4.8306 + 2.4538 × 1 + (−1.8662) × 0 = 7.284.`</p>
<p>predict function can be used to get the estimation for all the experiment conditions.</p>
<pre>
 predict(doe.model2)
</pre>
<p><a rel="nofollow" href="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2018/12/predictdoe2.jpg?ssl=1" target="_blank"><img sizes="(max-width: 1012px) 100vw, 1012px" src="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2018/12/predictdoe2.jpg?w=450&ssl=1" alt="" class="wp-image-19198" data-recalc-dims="1"></a></p>
<h2>Visualize Effect Plot and Interaction plot</h2>
<p>the ggplot2 package can be used to visualize the effect plot. The effect of flour is positive while the effect of baking powder is negative.</p>
<pre>
prinEf &lt;- data.frame(Factor = rep(c(&quot;A_Flour&quot;, &quot;C_Baking Powder&quot;), each = 2), Level = rep(c(-1, 1), 2), Score = c(aggregate(score ~ flour, FUN = mean, data = ss.data.doe1)[,2], aggregate(score ~ bakPow, FUN = mean, data = ss.data.doe1)[,2])) 
p &lt;- ggplot(prinEf, aes(x = Level, y = Score)) + geom_point() + geom_line() +geom_hline(yintercept =mean(ss.data.doe1$score),linetype=&quot;dashed&quot;, 
                                                                                        color = &quot;blue&quot;)+scale_x_continuous(breaks = c(-1, 1)) + facet_grid(. ~ Factor)+ggtitle(&quot;Plot of Factor Effects&quot;)
print(p)
</pre>
<p><a rel="nofollow" href="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2018/12/factorplot.jpg?ssl=1" target="_blank"><img sizes="(max-width: 750px) 100vw, 750px" src="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2018/12/factorplot.jpg?w=450&ssl=1" alt="" class="wp-image-19199" data-recalc-dims="1"></a></p>
<p>The interaction plot is as shown below.The lines don’t cross means that there is no interaction between the factors plotted.</p>
<pre>
intEf &lt;- aggregate(score ~ flour + bakPow, FUN = mean, data = ss.data.doe1) 
q &lt;- ggplot(intEf, aes(x = flour, y = score, color = bakPow )) + geom_point() + geom_line(aes(group=bakPow)) +geom_hline(yintercept =mean(ss.data.doe1$score),linetype=&quot;dashed&quot;, 
                                                                                                                        color = &quot;blue&quot;)+ggtitle(&quot;Interaction Plot&quot;)
print(q)
</pre>
<p><a rel="nofollow" href="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2018/12/interactionplot.jpg?ssl=1" target="_blank"><img sizes="(max-width: 748px) 100vw, 748px" src="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2018/12/interactionplot.jpg?w=450&ssl=1" alt="" class="wp-image-19200" data-recalc-dims="1"></a></p>
<p>The normality of residual can be checked with Shapiro test. As the p-value is large, fail to reject the Null hypothesis of Normality of residuals.</p>
<pre>
shapiro.test(residuals(doe.model2))
</pre>
<p><a rel="nofollow" href="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2018/12/N1.jpg?ssl=1" target="_blank"><img src="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2018/12/N1.jpg?resize=373%2C95&ssl=1" alt="" width="373" class="wp-image-19201" data-recalc-dims="1" height="95"></a></p>
<p>This was the brief introduction to DOE in R.<br>
In next part, we will go through Control Phase of Six Sigma DMAIC process. Please let me know your feedback in the comments section. Make sure to like &amp; share it. Happy Learning!!</p>
<h3>References</h3>
<ul>
<li><a rel="nofollow" href="http://www.sixsigmawithr.com/" target="_blank">Six Sigma wih R book and website</a></li>
<li><a rel="nofollow" href="https://cran.r-project.org/web/packages/SixSigma/index.html" target="_blank">Six Sigma Package</a></li>
</ul>
<p><strong>
<p>Related Post</p>
<p></p></strong>
<ol>
<li><a rel="nofollow" href="https://datascienceplus.com/nyc-buses-company-level-predictors-with-r/" title="Permanent Link toNYC buses: company level predictors with R" target="_blank">NYC buses: company level predictors with R</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/visualizations-for-correlation-matrices-in-r/" title="Permanent Link toVisualizations for correlation matrices in R" target="_blank">Visualizations for correlation matrices in R</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/interpretation-of-the-auc/" title="Permanent Link toInterpretation of the AUC" target="_blank">Interpretation of the AUC</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/simple-experiments-with-smoothed-scatterplots/" title="Permanent Link toSimple Experiments with Smoothed Scatterplots" target="_blank">Simple Experiments with Smoothed Scatterplots</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/understanding-the-covariance-matrix/" title="Permanent Link toUnderstanding the Covariance Matrix" target="_blank">Understanding the Covariance Matrix</a></li>
</ol>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://datascienceplus.com/six-sigma-dmaic-series-in-r-part4/"> R Programming – DataScience+</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/nUfLHclXm8k" height="1"></a></div>