<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=R_-_Basic_Statistics</id>
	<title>R - Basic Statistics - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=R_-_Basic_Statistics"/>
	<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=R_-_Basic_Statistics&amp;action=history"/>
	<updated>2026-05-02T19:27:55Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://training-course-material.com/index.php?title=R_-_Basic_Statistics&amp;diff=29443&amp;oldid=prev</id>
		<title>Bernard Szlachta: /* Plotting Area Under normal distribution */</title>
		<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=R_-_Basic_Statistics&amp;diff=29443&amp;oldid=prev"/>
		<updated>2016-03-09T03:03:04Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Plotting Area Under normal distribution&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:Intro to R|01]]&lt;br /&gt;
&lt;br /&gt;
== Probability Distributions ==&lt;br /&gt;
Each probability distribution will have four associated functions starting with d, p, q, r. Below normal distribution example&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;dnorm&amp;#039;&amp;#039;&amp;#039; - probability density function&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;pnorm&amp;#039;&amp;#039;&amp;#039; - density function (cumulative density)&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;qnorm&amp;#039;&amp;#039;&amp;#039; - quantile function&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;rnorm&amp;#039;&amp;#039;&amp;#039; - random varies&lt;br /&gt;
&lt;br /&gt;
Other distributions will have similar functions, e.g. dt,pt,qt,rt, df, dbinom etc....&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
1. You flip a fair coin 10 times. What is the probability of getting 8 or more heads?&lt;br /&gt;
{{Show Answer|0.0546875}}&lt;br /&gt;
2. Assuming that the human height follows normal distribution with the mean of 174cm and standard deviation of 12cm, what proportion of goods a trouser manufacture should produce for people between 162 and 174cm?&lt;br /&gt;
{{Show Answer|Around 34%}}&lt;br /&gt;
&lt;br /&gt;
== Summarizing Distribution ==&lt;br /&gt;
Parts of this tutorial is based on:&lt;br /&gt;
http://cran.r-project.org/doc/manuals/R-intro.pdf&lt;br /&gt;
&lt;br /&gt;
 &amp;gt; attach(faithful)&lt;br /&gt;
 &amp;gt; summary(eruptions)&lt;br /&gt;
    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. &lt;br /&gt;
   1.600   2.163   4.000   3.488   4.454   5.100 &lt;br /&gt;
 &lt;br /&gt;
 &amp;gt; fivenum(eruptions)&lt;br /&gt;
 [1] 1.6000 2.1585 4.0000 4.4585 5.1000&lt;br /&gt;
 &lt;br /&gt;
 &amp;gt; stem(eruptions)&lt;br /&gt;
  The decimal point is 1 digit(s) to the left of the |&lt;br /&gt;
  16 | 070355555588&lt;br /&gt;
  18 | 000022233333335577777777888822335777888&lt;br /&gt;
  20 | 00002223378800035778&lt;br /&gt;
  22 | 0002335578023578&lt;br /&gt;
  24 | 00228&lt;br /&gt;
  26 | 23&lt;br /&gt;
  28 | 080&lt;br /&gt;
  30 | 7&lt;br /&gt;
  32 | 2337&lt;br /&gt;
  34 | 250077&lt;br /&gt;
  36 | 0000823577&lt;br /&gt;
  38 | 2333335582225577&lt;br /&gt;
  40 | 0000003357788888002233555577778&lt;br /&gt;
  42 | 03335555778800233333555577778&lt;br /&gt;
  44 | 02222335557780000000023333357778888&lt;br /&gt;
  46 | 0000233357700000023578&lt;br /&gt;
  48 | 00000022335800333&lt;br /&gt;
  50 | 0370&lt;br /&gt;
&lt;br /&gt;
 hist(eruptions)&lt;br /&gt;
 &lt;br /&gt;
 hist(eruptions, seq(1.6, 5.2, 0.2), prob=TRUE)&lt;br /&gt;
&lt;br /&gt;
 lines(density(eruptions, bw=0.1))&lt;br /&gt;
&lt;br /&gt;
 rug(eruptions)&lt;br /&gt;
&lt;br /&gt;
=== Empirical Cumulative Distribution ===&lt;br /&gt;
 plot(ecdf(eruptions), do.points=FALSE, verticals=TRUE)&lt;br /&gt;
 &lt;br /&gt;
It seems there are two distributions (as two modes and histogram would suggest).&lt;br /&gt;
Let us try to split them.&lt;br /&gt;
&lt;br /&gt;
 long &amp;lt;- eruptions[eruptions &amp;gt; 3]&lt;br /&gt;
 plot(ecdf(long), do.points=FALSE, verticals=TRUE)&lt;br /&gt;
 x &amp;lt;- seq(3, 5.4, 0.01)&lt;br /&gt;
&lt;br /&gt;
Let us fit normal distribution cumulative distribution function&lt;br /&gt;
 lines(x, pnorm(x, mean=mean(long), sd=sd(long)), lty=3)&lt;br /&gt;
&lt;br /&gt;
And closer look at Quantile-quantile (Q-Q) plot&lt;br /&gt;
 par(pty=&amp;quot;s&amp;quot;)&lt;br /&gt;
 qqnorm(long); qqline(long)&lt;br /&gt;
&lt;br /&gt;
== Graphing Probability Distributions ==&lt;br /&gt;
Take example of calculating chances of getting 8 out of 10 heads.&lt;br /&gt;
 plot(dbinom(seq(1,10),10,0.5),type=&amp;quot;h&amp;quot;)&lt;br /&gt;
:[[File:ClipCapIt-160309-062559.PNG|300px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 old.par &amp;lt;- par(mfrow=c(1, 2))&lt;br /&gt;
 plot(dbinom(seq(1,10),10,0.5),type=&amp;quot;h&amp;quot;)&lt;br /&gt;
 plot(pbinom(seq(1,10),10,0.5),type=&amp;quot;h&amp;quot;,col=2)&lt;br /&gt;
 par(old.par)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 x &amp;lt;- seq(-4,4,length = 1000)&lt;br /&gt;
 plot(x, dnorm(x),type=&amp;quot;l&amp;quot;)&lt;br /&gt;
:[[File:ClipCapIt-160309-064847.PNG|300px]]&lt;br /&gt;
&lt;br /&gt;
 curve(dt(x,4),-4,4,add = T,col=2) &lt;br /&gt;
:[[File:ClipCapIt-160309-070228.PNG|300px]]&lt;br /&gt;
&lt;br /&gt;
== Plotting Area Under normal distribution ==&lt;br /&gt;
# Children&amp;#039;s IQ scores are normally distributed with a&lt;br /&gt;
# mean of 100 and a standard deviation of 15. What&lt;br /&gt;
# proportion of children are expected to have an IQ between&lt;br /&gt;
# 80 and 120?&lt;br /&gt;
&lt;br /&gt;
 mean=100; sd=15&lt;br /&gt;
 x &amp;lt;- seq(-4,4,length=100)*sd + mean&lt;br /&gt;
 hx &amp;lt;- dnorm(x,mean,sd)&lt;br /&gt;
 plot(x, hx,type=&amp;quot;l&amp;quot;)&lt;br /&gt;
 i &amp;lt;- x &amp;gt;= 80 &amp;amp; x &amp;lt;= 120&lt;br /&gt;
 polygon(c(80,x[i],120),&lt;br /&gt;
        c(0,hx[i],0),&lt;br /&gt;
        col=&amp;quot;red&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
# Orders are normally distributed (mean 100, sd=15). What proportion of  are expected to have an value between 80 and 120?&lt;br /&gt;
:[[File:ClipCapIt-160309-071611.PNG]]&lt;/div&gt;</summary>
		<author><name>Bernard Szlachta</name></author>
	</entry>
</feed>