<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-part-3/"></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-part-3/"> R Programming – DataScience+</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<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> and <a rel="nofollow" href="https://datascienceplus.com/six-sigma-dmaic-series-in-r-part-2/" target="_blank">Part 2</a> of this Series. In this Part 3, we will go through the tools used during the analyze phase of Six Sigma DMAIC cycle. In this phase, available data is used to identify the key process inputs and their relation to the output. </p>
<p>We will go through the following tools:</p>
<ul>
<li>Charts in R</li>
<li>Hypothesis Testing in R</li>
</ul>
<h2>Charts in R</h2>
<p>In Six Sigma projects, Charts plays a very important role. They are used to support the interpretation of data, as a graphical representation of data provides a better understanding of the process. So, Charts are used not only in analyze phase, but at every step of Six Sigma projects.</p>
<h3>Bar Chart</h3>
<p>A bar chart is a very simple chart where some quantities are shown as the height of bars. Each bar represents a factor where the variable under study is being measured. A bar chart is usually the best graphical representation for counts. For example, the printer cartridge manufacturer distributes its product to five regions. An unexpected amount of defective cartridges has been returned in the last month. Bar plot of defects by region is as below:</p>
<pre>
library(&quot;SixSigma&quot;)
with(ss.data.pc.r,
     barplot(pc.def,
             names.arg = pc.regions,
             las = 2,
             main = &quot;Barplot of defects by region&quot;,
             sub = &quot;Printer cartridge example&quot;))
</pre>
<p>Output as below:<br>
<a rel="nofollow" href="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2018/07/barplot.png?ssl=1" target="_blank"><img sizes="(max-width: 377px) 100vw, 377px" src="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2018/07/barplot-377x490.png?resize=377%2C490&ssl=1" alt="" width="377" class="wp-image-15086" data-recalc-dims="1" height="490"></a></p>
<h3>Histogram</h3>
<p>A histogram is a bar chart for continuous variables. It shows the distribution of the measurements of variables. A histogram is used to find the distribution of a variable. That is, the variable is centered or biased. Are the observations close to the central values, or is it a spread distribution? Is it a normal distribution?</p>
<p>For example, histograms for the variables volume and density in the <code>ss.data.pc</code> data set.</p>
<pre>
hist(ss.data.pc$pc.volume,
     main=&quot;Printer Cartridge Volume&quot;,
     xlab=&quot;Volume&quot;,
     col=&quot;#DDDDDD&quot;)
</pre>
<p>Output as below:<br>
<a rel="nofollow" href="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2018/07/Rplot.png?ssl=1" target="_blank"><img sizes="(max-width: 377px) 100vw, 377px" src="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2018/07/Rplot-377x490.png?resize=377%2C490&ssl=1" alt="" width="377" class="wp-image-15087" data-recalc-dims="1" height="490"></a></p>
<p>Superimpose a density line for a theoretical normal distribution whose mean is 16 and standard deviation is 1</p>
<pre>
hist(ss.data.pc$pc.volume,
       main = &quot;Printer Cartridge Volume&quot;,
       xlab = &quot;Volume&quot;,
       col = &quot;#BBBBBB&quot;,
       border = &quot;white&quot;,
       bg = &quot;red&quot;,
       freq = FALSE,
       ylim = c(0,0.4))
curve(dnorm(x,16,1),
        add = TRUE,
        lty = 2,
        lwd = 2)
lines(density(ss.data.pc$pc.volume),
        lwd = 2)
</pre>
<p>Output as below:<br>
<a rel="nofollow" href="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2018/07/Rplot01.png?ssl=1" target="_blank"><img sizes="(max-width: 377px) 100vw, 377px" src="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2018/07/Rplot01-377x490.png?resize=377%2C490&ssl=1" alt="" width="377" class="wp-image-15088" data-recalc-dims="1" height="490"></a></p>
<h3>Scatterplot</h3>
<p>A scatter plot is an important tool to reveal relationships between two variables. There are three types of correlation between two variables: Positive correlation (high values of one variable lead to high values of the other one ). A negative correlation (Inversely proportional, high values of one variable lead to low values of the other one). No correlation: the variables are independent.</p>
<p>In the <code>ss.data.pc</code> dataset, we have two continuous variables: <code>pc.volume</code> and <code>pc.density</code>, Scatterplot can be used to find patterns for this relation.</p>
<pre>
plot(pc.volume ~ pc.density,
     data = ss.data.pc,
     main = &quot;Searching correlation between Density
     and Volume&quot;,
     col = &quot;#666666&quot;,
     pch = 16,
     sub = &quot;Printer Cartridge Example&quot;,
     xlab = &quot;Volume of Ink&quot;,
     ylab = &quot;Density&quot;)
</pre>
<p>Output as below:<br>
<a rel="nofollow" href="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2018/07/Rplot02.png?ssl=1" target="_blank"><img sizes="(max-width: 377px) 100vw, 377px" src="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2018/07/Rplot02-377x490.png?resize=377%2C490&ssl=1" alt="" width="377" class="wp-image-15089" data-recalc-dims="1" height="490"></a></p>
<h3>Boxplot</h3>
<p>The box-whisker chart is also known as the box plot. It graphically summarizes the distribution of a continuous variable. The sides of the box are the first and third quartiles (25th and 75th percentile, respectively). Thus, inside the box, we have the middle 50% of the data. The median is plotted as a line that crosses the box The box plot tells us if the distribution is centered or biased (the position of the median with respect to the rest of the data), if there are outliers (points outside the whiskers), or if the data are close to the center values (small whiskers or boxes).</p>
<p>It is useful when we want to compare groups and check if there are differences among them. Example: In a production line, we have three fillers for the printer cartridges. We want to determine if there are any differences among the fillers and identify outliers.</p>
<pre>
boxplot(pc.volume ~ pc.filler,
        data = ss.data.pc,
        col = &quot;#CCCCCC&quot;,
        main = &quot;Box Plot of Volume by Filler&quot;,
        sub = &quot;Printer Cartridge Example&quot;,
        xlab = &quot;Filler&quot;,
        ylab = &quot;Volume&quot;)
</pre>
<p>Output as below:<br>
<a rel="nofollow" href="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2018/07/Rplot03.png?ssl=1" target="_blank"><img sizes="(max-width: 377px) 100vw, 377px" src="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2018/07/Rplot03-377x490.png?resize=377%2C490&ssl=1" alt="" width="377" class="wp-image-15090" data-recalc-dims="1" height="490"></a></p>
<h2>Hypothesis Testing</h2>
<p>A statistical hypothesis is an assumption about a population parameter. This assumption may or may not be true. Hypothesis testing refers to the formal procedures used by statisticians to accept or reject statistical hypotheses. So it is intended to confirm or validate some conjectures about the process we are analyzing. For example, if we have data from a process that are normally distributed and we want to verify if the mean of the process has changed with respect to the historical mean, we should make the following hypothesis test:<br>
H0: μ = μ0<br>
H1: μ not equal μ0<br>
where H0 denotes the null hypothesis and H1 denotes the alternative hypothesis. Thus we are testing H0 (“the mean has not changed”) vs. H1 (“the mean has changed”).</p>
<p>Hypothesis testing can be performed in two ways: one-sided tests and two-sided tests. An example of the latter is when we want to know if the mean of a process has increased:<br>
H0: μ = μ0,<br>
H1: μ >μ0.<br>
Hypothesis testing tries to find evidence about the refutability of the null hypothesis using probability theory. We want to check if a situation of the alternative hypothesis is arising. Subsequently, we will reject the null hypothesis if the data do not support it with “enough evidence.” The threshold for enough evidence can be set by expressing a significance level α. A 5% significance level is a widely accepted value in most cases.</p>
<p>There are some functions in R to perform hypothesis tests, for example, <code>t.test</code> for means, <code>prop.test</code> for proportions, <code>var.test</code> and <code>bartlett.test</code> for variances, <code>chisq.test</code> for contingency table tests and <code>goodness-of-fit</code> tests, <code>poisson.test</code> for Poisson distributions, <code>binom.test</code> for binomial distributions, <code>shapiro.test</code> for normality tests. Usually, these functions also provide a confidence interval for the parameter tested.</p>
<p>Example: Hypothesis test to verify if the length of the strings is different from the target value of 950 mm:<br>
H0 : μ = 950,<br>
H1 : μ not equal to 950.</p>
<pre>
t.test(ss.data.strings$len,
       mu = 950,
       conf.level = 0.95)
<em>One Sample t-test
data: ss.data.strings$len
t = 0.6433, df = 119, p-value = 0.5213
alternative hypothesis: true mean is not equal to 950
95 percent confidence interval:
949.9674 950.0640
sample estimates:
mean of x 950.0157 </em>
</pre>
<p>As the p-value >0.05, we accept that the mean is not different from the target.</p>
<p>Two means can also be compared, for example, for two types of strings. To compare the length of the string types E6 and E1, we use the following code:</p>
<pre>
data.E1 &lt;- ss.data.strings$len[ss.data.strings$type == &quot;E1&quot;]
data.E6 &lt;- ss.data.strings$len[ss.data.strings$type == &quot;E6&quot;]
t.test(data.E1, data.E6)
<em>Welch Two Sample t-test
data: data.E1 and data.E6
t = -0.3091, df = 36.423, p-value = 0.759
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-0.1822016 0.1339911
sample estimates:
mean of x mean of y 949.9756 949.9997
</em>
</pre>
<p>Variances can be compared using the var.test function:</p>
<pre>
var.test(data.E1, data.E6)
<em>F test to compare two variances
data: data.E1 and data.E6
F = 1.5254, num df = 19, denom df = 19, p-value = 0.3655
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.6037828 3.8539181
sample estimates:
ratio of variances 1.525428 </em>
</pre>
<p>In this case, the statistic used is the ratio between variances, and the null hypothesis is “the ratio of variances is equal to 1,” that is, the variances are equal.<br>
Proportions can be compared using the prop.test function. Do we have the same defects for every string type? For example, compare types E1 and A5:</p>
<pre>
defects &lt;- data.frame(type = ss.data.strings$type, res = ss.data.strings$res &lt; 3)
defects &lt;- aggregate(res ~ type, data = defects, sum)
prop.test(defects$res, rep(20,6))
<em>6-sample test for equality of proportions without continuity correction
data: defects$res out of rep(20, 6)
X-squared = 5.1724, df = 5, p-value = 0.3952
alternative hypothesis: two.sided
sample estimates:
prop 1 prop 2 prop 3 prop 4 prop 5 prop 6 0.05 0.00 0.00 0.10 0.00 0.05 </em>
</pre>
<p>The p-value for the hypothesis test of equal proportions >0.05, so we cannot reject the null hypothesis, and therefore we do not reject that the proportions are equal.<br>
A normality test to check if the data follow a normal distribution can be performed with the <code>shapiro.test()</code> function:</p>
<pre>
shapiro.test(ss.data.strings$len)
<em>Shapiro-Wilk normality test
data: ss.data.strings$len
W = 0.98463, p-value = 0.1903
</em>
</pre>
<p>The statistic used to perform this hypothesis test is the Shapiro–Wilk statistic. In<br>
this test, the hypotheses are as follows:<br>
H0 : The data are normally distributed.<br>
H1 : The data are not normally distributed.</p>
<p>The p-value > 0.05, we cannot reject the hypothesis of normality for the data, so we do not have enough evidence to reject normality. </p>
<p>A type I error occurs when we reject the null hypothesis and it is true. We commit a type II error when we do not reject the null hypothesis and it is false. The probability of the former is represented as α, and it is the significance level of the hypothesis test (1 − α is the confidence level). The probability of the latter is represented as β, and the value 1−β is the statistical power of the test.<br>
The R functions <code>power.prop.test</code> and <code>power.t.test</code> can be used to determine the power or the sample size.</p>
<p>Example: Black belt plan to perform a new analysis to find out the sample size needed to estimate the mean length of the strings with a maximum error of δ = 0.1 cm. He sets the significance level (α = 0.05) and the power (1−β = 0.90). The sample size can be determined using the following command:</p>
<pre>
power.t.test(delta = 0.1, power = 0.9, sig.level = 0.05,
             sd = sd (ss.data.strings$len))
<em>Two-sample t test power calculation n = 151.2648
delta = 0.1
sd = 0.2674321
sig.level = 0.05
power = 0.9
alternative = two.sided
NOTE: n is number in *each* group</em>
</pre>
<p>So the sample size must be 152.</p>
<p>In next part, we will go through Improve 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>
<ul></ul>
<p><strong>
<p>Related Post</p>
<p></p></strong>
<ol>
<li><a rel="nofollow" href="https://datascienceplus.com/prediction-interval-the-wider-sister-of-confidence-interval/" title="Permanent Link toPrediction Interval, the wider sister of Confidence Interval" target="_blank">Prediction Interval, the wider sister of Confidence Interval</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/six-sigma-dmaic-series-in-r-part-2/" title="Permanent Link toSix Sigma DMAIC Series in R – Part 2" target="_blank">Six Sigma DMAIC Series in R – Part 2</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/six-sigma-dmaic-series-in-r-part-1/" title="Permanent Link toSix Sigma DMAIC Series in R – Part 1" target="_blank">Six Sigma DMAIC Series in R – Part 1</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/implementation-and-interpretation-of-control-charts-in-r/" title="Permanent Link toImplementation and Interpretation of Control Charts in R" target="_blank">Implementation and Interpretation of Control Charts in R</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/time-series-model-of-forecasting-future-power-demand/" title="Permanent Link toTime series model of forecasting future power demand" target="_blank">Time series model of forecasting future power demand</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-part-3/"> 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/JMuP9DAP14g" height="1"></a></div>