<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-542053665666511781</atom:id><lastBuildDate>Sat, 31 Aug 2024 17:41:05 +0000</lastBuildDate><category>R</category><category>Statistics</category><category>Tutorial</category><category>Course</category><category>Scatterplot</category><category>Case-III</category><category>Labeled Scatterplot</category><category>NASA</category><category>SPACE</category><title>~Krishna Dagli</title><description></description><link>https://krishnadagli.blogspot.com/</link><managingEditor>noreply@blogger.com (Unknown)</managingEditor><generator>Blogger</generator><openSearch:totalResults>27</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-3656083572854430964</guid><pubDate>Mon, 15 Mar 2010 17:48:00 +0000</pubDate><atom:updated>2010-03-15T23:26:55.914+05:30</atom:updated><title>Measure of Center: Mean Vs. Median</title><description>&lt;span style=&quot;font-family: verdana;font-size:100%; color:black;&quot;&gt; 

So now we know that to measure center of a distribution we have two
most common numerical measures; &lt;strong&gt;Mean&lt;/strong&gt; and
&lt;strong&gt;Median&lt;/strong&gt;.


&lt;br/&gt;

The mean describes the center as an average value, where the actual
values of the data points play an important role since we are summing
values and then dividing by count (number of values).  The median, on
the other hand, locates the middle value as the center, and the order
of the data is the key to finding it (here we are sorting and only
counting).

&lt;br/&gt;&lt;br/&gt;
Lets understand difference between two with an example.&lt;br/&gt;

Assume we have following two data sets:

&lt;span style=&quot;font-family: trebuchet ms; color:#003300;&quot;&gt;
&lt;pre&gt;
Data set A -&gt; 64 65 66 68 70 71 73
Data set B -&gt; 64 65 66 68 70 71 730
&lt;/pre&gt;&lt;/span&gt;

Please observe that only last value changes in these two sets, ie. 73
in data set A becomes 730 in data set B.&lt;br/&gt;&lt;br/&gt;


For data set A, the mean is 68.1, and the median is 68. Visually
comparing these two data sets we know that the observation 730 is very
large and is certainly an outlier.  In this case the median is still
68, but the mean will be influenced by the high outlier, and shifted
up to 162.  The message that we should take from this example is:

&lt;strong&gt;The mean is very sensitive to outliers (as it factors in their
magnitude), while the median is resistant to outliers. &lt;/strong&gt;

&lt;br/&gt;&lt;br/&gt;
&lt;Strong&gt;Types of distributions and mean and median:&lt;/strong&gt;&lt;br/&gt;
Lets see what happens to mean and median with our 3 basic
distributions.

&lt;UL&gt;&lt;LI&gt;&lt;Strong&gt;Symmetric distributions with no outliers:&lt;/strong&gt;

Mean (X&amp;#772;) is approximately equal to median (M).

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZ7z43vKKX_3uhLdCNtV2wBRPZB4NTdOrfQO61iwTuuj0JNmw-pOTlResuAQnKgFWUYjuvhPwfXcqnUjXg0KyUoxqUfhRdwLBwKXgfGvE9Yvoq5ekPiZvWZO69jGDYqsrLa5K3N5Se9DwK/s1600-h/mean-skewed-left.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 303px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZ7z43vKKX_3uhLdCNtV2wBRPZB4NTdOrfQO61iwTuuj0JNmw-pOTlResuAQnKgFWUYjuvhPwfXcqnUjXg0KyUoxqUfhRdwLBwKXgfGvE9Yvoq5ekPiZvWZO69jGDYqsrLa5K3N5Se9DwK/s400/mean-skewed-left.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5448920490604893282&quot; /&gt;&lt;/a&gt;

&lt;LI&gt;&lt;strong&gt;Skewed right distributions and/or datasets with high outliers:&lt;/strong&gt;

Mean (X&amp;#772;) is always greater than median (M). (X&amp;#772; &gt; M)
&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMUtM1-eaK7BBMs6S7fvMd6ZtMN78vKq0Fwj3fq1vx6Gu9i3uit-7V71y7YueNAW1tg1tZsgS9Du9WihwqX2wKmN4a1idO3BhhTfRr-KAO7UvrA2rj5MJ9MiEKdR2PfqYY55N_Xpza3BGl/s1600-h/mean-skewed-right.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 298px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMUtM1-eaK7BBMs6S7fvMd6ZtMN78vKq0Fwj3fq1vx6Gu9i3uit-7V71y7YueNAW1tg1tZsgS9Du9WihwqX2wKmN4a1idO3BhhTfRr-KAO7UvrA2rj5MJ9MiEKdR2PfqYY55N_Xpza3BGl/s400/mean-skewed-right.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5448920482914900306&quot; /&gt;&lt;/a&gt;

&lt;LI&gt;&lt;strong&gt;Skewed left distributions and/or datasets with low outliers:&lt;/strong&gt;

Mean (X&amp;#772;) is always less than median (M). (X&amp;#772; &lt; M)

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdQsaCYel5J_YkLMU8VHfChD15fYtj4OwJS2oitDaFnqGd6t0qV8PQ6ZP-TEzDseaKwM0GBC0RE6YEp9wTWHnj5y1Xe0_tF7vL_bBqGK-1dDwuEjqdEjNtRxzcF-CEtnblA5j9jzEveNHp/s1600-h/mean-sym.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 271px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdQsaCYel5J_YkLMU8VHfChD15fYtj4OwJS2oitDaFnqGd6t0qV8PQ6ZP-TEzDseaKwM0GBC0RE6YEp9wTWHnj5y1Xe0_tF7vL_bBqGK-1dDwuEjqdEjNtRxzcF-CEtnblA5j9jzEveNHp/s400/mean-sym.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5448920479992872642&quot; /&gt;&lt;/a&gt;

&lt;/UL&gt;

&lt;br/&gt;&lt;br/&gt;
&lt;strong&gt;Let&#39;s Summarize&lt;/strong&gt;

&lt;UL&gt;

    &lt;LI&gt; The two main numerical measures for the center of a
    distribution are the mean (X&amp;#772;) and the median (M). The mean is the
    average of the values, while the median is the middle value.


    &lt;LI&gt; The mean is very sensitive to outliers (as it factors in
      their magnitude), while the median is resistant to outliers.


    &lt;LI&gt; The mean is an appropriate measure of center only for
      symmetric distributions with no outliers. In all other cases,
      the median should be used to describe the center of the
      distribution.

&lt;/UL&gt;
&lt;/span&gt;</description><link>https://krishnadagli.blogspot.com/2010/03/measure-of-center-mean-vs-median.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZ7z43vKKX_3uhLdCNtV2wBRPZB4NTdOrfQO61iwTuuj0JNmw-pOTlResuAQnKgFWUYjuvhPwfXcqnUjXg0KyUoxqUfhRdwLBwKXgfGvE9Yvoq5ekPiZvWZO69jGDYqsrLa5K3N5Se9DwK/s72-c/mean-skewed-left.gif" height="72" width="72"/><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-9183663805633640475</guid><pubDate>Wed, 03 Mar 2010 18:07:00 +0000</pubDate><atom:updated>2010-03-10T23:06:02.712+05:30</atom:updated><title>Why numerical measures? Mean and Median</title><description>&lt;span style=&quot;font-family: verdana;font-size:100%; color:black;&quot;&gt; 

As we show in previous example only graphical representation of
quantitative variable is not enough. Using graphical representation we
can only get a rough estimate for the center and spread. A description
of the distribution of a quantitative variable must include, in
addition to the graphical display, a more precise numerical
description of the center and spread of the distribution.

So we learn:

&lt;UL&gt;

&lt;LI&gt; how to quantify the center and spread of a distribution with
various numerical measures.


&lt;LI&gt; Few important properties of numerical measures

&lt;LI&gt; how to choose the appropriate numerical measures of center and
spread to supplement the histogram/graphical representation.
&lt;/UL&gt;

&lt;br/&gt;

&lt;strong&gt;Measue of Center (1 of 2):&lt;/strong&gt;&lt;br/&gt;

Two most important measure of center of a distribution are
&lt;strong&gt;mean &lt;/strong&gt; and &lt;strong&gt;median&lt;/strong&gt;. These two have
completely different approach and idea of describing center of a
distribution.

&lt;UL&gt;
&lt;LI&gt; &lt;strong&gt;Mean/Arithmetic mean:&lt;/strong&gt; is the sum of the
observations (values) divided by the number(count) of observations. If
X1, X2, X3,...Xn are total &#39;n&#39; number of observations then their mean
X&amp;#772; (x bar) is : &lt;br/&gt;&lt;br/&gt;

X&amp;#772; = (X1 + X2 + X3 + ... + Xn)/ n

&lt;br/&gt;&lt;br/&gt; 


Lets take one example using random values. We use R&#39;s
&lt;strong&gt;runif&lt;/strong&gt; function to generate 10 random values and then
compute its mean:

&lt;span style=&quot;font-family: trebuchet ms; color:#003300;&quot;&gt;
&lt;pre&gt;

# runif will generate 10 random observation/values.
&gt; observation &lt;- runif(10) 
&gt; print(observation) 
 [1] 0.7080567 0.6582278 0.2415265 0.4169798 0.4172357 0.2258143 0.3805531
 [8] 0.4568466 0.5952122 0.4650702
&gt; mean(observation)
[1] 0.4565523
&gt; sum(observation)/10.00
[1] 0.4565523
&lt;/pre&gt;&lt;/span&gt;&lt;br/&gt;


If we take our Best Actress Oscar winners from 1970 to 2001 example
then following are the different age when actress have won Oscar:

&lt;br/&gt;
34 34 26 37 42 41 35 31 41 33 30 74 33 49 38 61 21 41 26 80 43 29 33 35 45 49 39 34 26 25 35 33
&lt;br/&gt;&lt;br/&gt;

Their sum: 34+34+26+37+42......+35+33=1233 &lt;br/&gt;
and their count (total number of observations): 32. Hence the mean age of this dataset is :

&lt;br/&gt;
X&amp;#772; = 1233/32 = 38.5


&lt;br/&gt;&lt;br/&gt;

&lt;LI&gt; &lt;strong&gt;Median:&lt;/strong&gt; M is the center/midpoint of the
distribution. M is such a number that half of the the observations
fall above and half fall below. To find the median:

 &lt;UL&gt;&lt;LI&gt; Order the data from smallest to largest. (sort).

     &lt;LI&gt; Consider whether n, the number of observations, is even or
     odd.

     &lt;UL&gt;&lt;LI&gt; If n is odd, the median M is the center observation in
     the ordered list. This observation is the one &quot;sitting&quot; in the
     (n+1)/2 spot in the ordered list.


          &lt;LI&gt; If n is even, the median M is the mean of the two
          center observations in the ordered list. These two
          observations are the ones &quot;sitting&quot; in the n/2 and n/2 + 1
          spots in the ordered list.
     &lt;/UL&gt;
 &lt;/UL&gt;   

This is better explained using a visualization provided at course website:

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDS8ERReeZwv2YtqzSg_M_fG5sjgpLJptLokhyphenhyphenriXHKjx_tv_d0SIgk0RhQ8wu2521kMAtQQWAsgg6x73R7w1bC_x0PvyTk42Ytg1VF17-uwrdOyn0b85YZaiCiBXslJdHVWxSe9qbzjtU/s1600-h/median.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 392px; height: 280px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDS8ERReeZwv2YtqzSg_M_fG5sjgpLJptLokhyphenhyphenriXHKjx_tv_d0SIgk0RhQ8wu2521kMAtQQWAsgg6x73R7w1bC_x0PvyTk42Ytg1VF17-uwrdOyn0b85YZaiCiBXslJdHVWxSe9qbzjtU/s400/median.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5444471313258743698&quot; /&gt;&lt;/a&gt;


Now lets again take our Best Actress Oscar winners from 1970 to 2001 example, following are the ages:

&lt;br/&gt;
34 34 26 37 42 41 35 31 41 33 30 74 33 49 38 61 21 41 26 80 43 29 33 35 45 49 39 34 26 25 35 33
&lt;br/&gt;&lt;br/&gt;

We paste these values (ages) into simple R vector:

&lt;span style=&quot;font-family: trebuchet ms; color:#003300;&quot;&gt;
&lt;pre&gt;
&gt;age = c(34, 34, 26, 37, 42, 41, 35, 31, 41, 33, 30, 74, 33, 49, 38, 61, 21, 41, 26, 80, 43, 29, 33, 35, 45, 49, 39, 34, 26, 25, 35, 33)

# first check mean so we know that we have copied all values.
&gt;mean(age)
[1] 38.53125
# Good, in R we can order/sort this dataset with one command.
&gt;sort(age)
 [1] 21 25 26 26 26 29 30 31 33 33 33 33 34 34 34 35 35 35 37 38 39 41 41 41 42
[26] 43 45 49 49 61 74 80
&gt;length(age)
[1] 32
# so we know its median would be mean of 16th and 17th  observation that (35+35)/2.
&gt; (sort(age)[16] + sort(age)[17])/2
[1] 35
# so the 16th observation is 35 and 17th is also 35, lets cross check using R&#39;s function.
&gt; median(age)
[1] 35
&gt; median(sort(age))
[1] 35
# So R&#39;s median function correctly returns 35 even when dataset is not sorted. but if we do
&gt; (age[16]+age[17])/2
[1] 41
# then answer is incorrect since age dataset is not sorted. 
&lt;/pre&gt;&lt;/span&gt;
&lt;/ul&gt;
&lt;/span&gt;</description><link>https://krishnadagli.blogspot.com/2010/03/linear-relationships-1-of-8-why.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDS8ERReeZwv2YtqzSg_M_fG5sjgpLJptLokhyphenhyphenriXHKjx_tv_d0SIgk0RhQ8wu2521kMAtQQWAsgg6x73R7w1bC_x0PvyTk42Ytg1VF17-uwrdOyn0b85YZaiCiBXslJdHVWxSe9qbzjtU/s72-c/median.gif" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-7706300889328655006</guid><pubDate>Wed, 07 Jan 2009 18:32:00 +0000</pubDate><atom:updated>2010-03-10T23:02:27.085+05:30</atom:updated><title>Why numerical measures?</title><description>So far we used scatterplots to study the relationships between two
quantitative variables, we studied the overall pattern of the
relationship by looking at its direction (positive, negative, or
neither), form (linear, curvilinear etc), and strength (eg. stronger,
weaker).
&lt;br/&gt;&lt;br/&gt;
We also noted that assessing the strength of a relationship just by
looking at the scatterplot is quite hard, and therefore we need to
supplement the scatterplot with some kind of numerical measure that
will help us assess the strength, this numerical measure we are going
to learn.

&lt;br/&gt;&lt;br/&gt;

Lets have a look at following two images (from the course website) to
see why numerical measures are required along with scatterplot to
assess strength of linear relationship.

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_VVi9U5LiV2c96b5OqHZksnCyDCvMCyMO5BwDAvhrgxzOfoW_bT15ThLsB-WWHx6aHkUnK5fVgHsXv-71FnJyjgw0N_oKfTn1lSPn3q_VfMqz0jvkC41P9RjMA-j_QZ3kVdun4RpkdAGd/s1600-h/why-numerical-measure.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 307px; height: 400px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_VVi9U5LiV2c96b5OqHZksnCyDCvMCyMO5BwDAvhrgxzOfoW_bT15ThLsB-WWHx6aHkUnK5fVgHsXv-71FnJyjgw0N_oKfTn1lSPn3q_VfMqz0jvkC41P9RjMA-j_QZ3kVdun4RpkdAGd/s400/why-numerical-measure.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5288622153219843218&quot; /&gt;&lt;/a&gt;
&lt;span style=&quot;font-family: verdana;font-size:100%; color:black;&quot;&gt;
&lt;br/&gt;
We can see that in both cases, the direction of the relationship is
positive and the form of the relationship is linear. What about the
strength? Recall that the strength of a relationship is the extent to
which the data follow its form.  

&lt;br/&gt;&lt;br/&gt; At first glance it looks like strength of the first graph is
stronger but at course website clarifies, both graphs are for same
data, just drawn using two different scales!

&lt;br/&gt;&lt;br/&gt; The purpose of this example was to illustrate how assessing
the strength of the linear relationship from a scatterplot alone is
problematic, since our judgment might be affected by the range of
values that are plotted.  This example, therefore, provides a
motivation for the need to supplement the scatterplot with a numerical
summary that will measure the strength of the linear relationship
between two quantitative variables.

&lt;/span&gt;</description><link>https://krishnadagli.blogspot.com/2009/01/linear-relationships-1-of-8-why.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_VVi9U5LiV2c96b5OqHZksnCyDCvMCyMO5BwDAvhrgxzOfoW_bT15ThLsB-WWHx6aHkUnK5fVgHsXv-71FnJyjgw0N_oKfTn1lSPn3q_VfMqz0jvkC41P9RjMA-j_QZ3kVdun4RpkdAGd/s72-c/why-numerical-measure.gif" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-3788658698873855187</guid><pubDate>Mon, 13 Oct 2008 12:33:00 +0000</pubDate><atom:updated>2009-01-07T22:37:42.907+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Labeled Scatterplot</category><category domain="http://www.blogger.com/atom/ns#">R</category><category domain="http://www.blogger.com/atom/ns#">Scatterplot</category><title>Learning Statistics Using R: Role Type Classification: Case III (5 of 5)</title><description>&lt;span style=&quot;font-family: verdana;font-size:100%; color:black;&quot;&gt; 

Now we learn to create a labeled scatterplot using R. In labeled
scatterplot we indicate different subgroups or categories within the
data on the plot; by labeling each subgroup differently. 

&lt;br/&gt;&lt;br/&gt; Note till now we were using &quot;plot&quot; or &quot;scatter.smooth&quot;
function to create our scatter plot, but I have not found a nice and
easy method of creating labeled scatterplot using these functions. So
instead of these functions we will use another function from &lt;b&gt;&quot;car&quot;
package/library. &lt;/b&gt;

&lt;br/&gt;&lt;br/&gt;
&lt;a href=&quot;http://krishnadagli.blogspot.com/2008/07/learning-statistics-using-r-role-type.html&quot;&gt;
Recall the hot dog example from case I&lt;/a&gt;, in which 54 major hot dog
brands were examined. In this study both the calorie content and the
sodium level of each brand was recorded, as well as the type of hot
dog: beef, poultry, and meat (mostly pork and beef, but up to 15%
poultry meat).  In this example we will explore the relationship
between the sodium level and calorie content of hot dogs, and use the
three different types of hot dogs to create a labeled scatterplot.

&lt;br/&gt;&lt;b&gt;Lets do this with R using scatter.smooth function&lt;/b&gt;&lt;br/&gt;
&lt;span style=&quot;font-family: trebuchet ms;color:#003300; font-size:100%; weight:bold;&quot;&gt;
&lt;pre&gt;
# hotdog.txt is same as TA01_009.TXT
&gt; hotdogdata &lt;- read.table(&quot;hotdog.txt&quot;, sep=&quot;\t&quot;, header=T)
&gt; attach(hotdogdata)
&gt; names(hotdogdata)
[1] &quot;HotDog&quot;   &quot;Calories&quot; &quot;Sodium&quot;  
# lets try firt with scatter.smooth function.
# As of version R version 2.6.2 (2008-02-08), &#39;quanlity&#39; argument
# does not result in a warning but newer version does; pointed out by Gabriele Righetti.
&gt; png(&quot;/tmp/hotdogtry1.png&quot;, quality=100, width=480)
&gt; scatter.smooth(Sodium, Calories)
# We try added label to this plot using text command/function.
# Bug-Fix: Gabriele Righetti
&gt; text(Sodium,Calories, HotDog)
&gt; dev.off()
&lt;/pre&gt;
&lt;/span&gt;

So here is our image, but this is not what we wanted. Here we have
tried to add text/label to this using &quot;text&quot; function but it has
become too ugly to look at. So now lets try creating a better labeled
scatter plot using &quot;car&quot; library.

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh08ibV03FYb_Pd9bMOvGIQkwNdLvyU3IvTar460hEegoXPke8T8rD8dhHaZ9-MFoFl5moUQ-eNB8CJUFMcFYGOGNseo9un-NvQdUxFgz_QpQ9b43xQful3M_V2sbgC4u_TPrSzTZ73Avwp/s1600-h/hotdogtry1.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh08ibV03FYb_Pd9bMOvGIQkwNdLvyU3IvTar460hEegoXPke8T8rD8dhHaZ9-MFoFl5moUQ-eNB8CJUFMcFYGOGNseo9un-NvQdUxFgz_QpQ9b43xQful3M_V2sbgC4u_TPrSzTZ73Avwp/s400/hotdogtry1.png&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5256616397854037778&quot; /&gt;&lt;/a&gt;

&lt;br/&gt;&lt;b&gt;Lets do this with R using &quot;car&quot; library&lt;/b&gt;&lt;br/&gt;
&lt;span style=&quot;font-family: trebuchet ms;color:#003300; font-size:100%; weight:bold;&quot;&gt;
&lt;pre&gt;
# we already have data that is attached. so let first load the
# library.
&gt; library(&quot;car&quot;)
&gt; png(&quot;/tmp/hotdogtry2.png&quot;, quality=100, width=480)
&gt; scatterplot(Calories ~ Sodium | HotDog)
&gt; dev.off()
&lt;/pre&gt;&lt;/span&gt;


&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgj5dC7dXaxNGW1Fp40KWlTjoA-E0EEfNnUozVFsumb7o8e4S1ynIRFvy1HgI4BoiMZcEBx34-rLCRKnN7HvK82dg76O1S6cwkL_E7hANdbL7f4JeyuTB8LCw89ISkzsDETRGp3aPfj48IC/s1600-h/hotdogtry2.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgj5dC7dXaxNGW1Fp40KWlTjoA-E0EEfNnUozVFsumb7o8e4S1ynIRFvy1HgI4BoiMZcEBx34-rLCRKnN7HvK82dg76O1S6cwkL_E7hANdbL7f4JeyuTB8LCw89ISkzsDETRGp3aPfj48IC/s400/hotdogtry2.png&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5256616674355928354&quot; /&gt;&lt;/a&gt;

So this is out second graph and this looks much better than our
earlier. Also there is an entire moive explaining concept of labeled
scatterplot at the &lt;a
href=&quot;https://oli.web.cmu.edu/jcourse/workbook/activity/page?context=859d4b1f80020c6901c7ceae194171df&quot;&gt;
course website.&lt;/a&gt; 

&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;Lets Summarize:&lt;/b&gt;
&lt;UL&gt;

&lt;LI&gt;The relationship between two quantitative variables is visually
displayed using the scatterplot, where each point represents an
individual. We always plot the explanatory variable on the horizontal,
X-axis, and the response variable on the vertical, Y-axis.

&lt;LI&gt;When we explore a relationship using the scatterplot we should
describe the overall pattern of the relationship and any deviations
from that pattern. To describe the overall pattern consider the
direction, form and strength of the relationship. Assessing the
strength could be problematic.

&lt;LI&gt;Adding labels to the scatterplot, indicating different groups or
categories within the data, might help us get more insight about the
relationship we are exploring.

&lt;/UL&gt;
&lt;/span&gt;</description><link>https://krishnadagli.blogspot.com/2008/10/learning-statistics-using-r-role-type_13.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh08ibV03FYb_Pd9bMOvGIQkwNdLvyU3IvTar460hEegoXPke8T8rD8dhHaZ9-MFoFl5moUQ-eNB8CJUFMcFYGOGNseo9un-NvQdUxFgz_QpQ9b43xQful3M_V2sbgC4u_TPrSzTZ73Avwp/s72-c/hotdogtry1.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-3601723694681113604</guid><pubDate>Thu, 02 Oct 2008 09:25:00 +0000</pubDate><atom:updated>2008-10-02T17:02:15.715+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Case-III</category><category domain="http://www.blogger.com/atom/ns#">R</category><category domain="http://www.blogger.com/atom/ns#">Scatterplot</category><title>Learning Statistics Using R: Role Type Classification: Case III (4 of 5)</title><description>&lt;span style=&quot;font-family: verdana;font-size:100%; color:black;&quot;&gt; 

To remind; we are learning to examine relationship between a response
and a exaplanatory variable. In our case III both variables are
quantitative (numerical).

&lt;br/&gt;&lt;br/&gt;

We looked at the method to examine case III relationship between two
quantitative variables in &lt;a href=&quot;&quot;&gt;previous post.&lt;/a&gt; Lets
understand it better with few more examples.

&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;Example:&lt;/b&gt; The average gestation period, or time of pregnancy, of
an animal is closely related to its longevity (the length of its
lifespan.)  Data on the average gestation period and longevity (in
captivity) of 40 different species of animals have been examined, with
the purpose of examining how the gestation period of an animal is
related to (or can be predicted from) its longevity. (Reference:
Rossman and Chance, Workshop Statistics. Discovery with Data and
Minitab (2001). Original source: The 1993 World Almanac and Book of
Facts). &lt;br/&gt;&lt;br/&gt; The actual dataset for this example is available &lt;a
href=&quot;ftp://www.rossmanchance.com/pub/ws2/mtw/animals.dat&quot;&gt;here &lt;/a&gt;
and also as &lt;a
href=&quot;http://krishnadagli.blogspot.com/2008/07/learning-statistics-using-r-data-sets.html&quot;&gt;single
zip file&lt;/a&gt; that includes all dataset of this site.

&lt;br/&gt;&lt;b&gt;Lets examine this dataset using R:&lt;/b&gt;&lt;br/&gt;
&lt;span style=&quot;font-family: trebuchet ms;color:#003300; font-size:100%; weight:bold;&quot;&gt;
&lt;pre&gt;
# Lets read the dataset animals.dat into R.
# dataset is separated by a tab (\t) and header row 
# is present but not very intitutive so we will 
# change it later.

&gt; animals &lt;- read.table(&quot;animals.dat&quot;, sep=&quot;\t&quot;, header=TRUE)
# print names of the rows.
&gt; names(animals)
[1] &quot;animal&quot;   &quot;gestati3&quot; &quot;longevi4&quot;
# we want to change &quot;gestati3&quot; and &quot;logevi4&quot;
&gt; names(animals) &lt;- c(&quot;animal&quot;, &quot;gestation&quot;, &quot;longevity&quot;)
&gt; names(animals)
[1] &quot;animal&quot;    &quot;gestation&quot; &quot;longevity&quot;
# so assigning values to names() changes the names.
# now lets draw the scatterplot and examine the dataset.
# we want to create scatterplot in a png file for upload.
&gt; png(&quot;/tmp/animal.png&quot;, quanlity=100, width=480)
&gt; scatter.smooth(animals$long, main=&quot;Lifespan and Pregnancy&quot;, 
  xlab=&quot;Longevity (Years)&quot;, ylab=&quot;Gestation (Days)&quot;)
# following writes the graph to file. 
&gt; dev.off()
&lt;/pre&gt;&lt;/span&gt;


&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQI8VZWF2KL9B0XfhuJDvIUNx5PnMtAi42i8vfE97366JxBKZkwU2lpGEdw2dPEr3SvR8Qfj2ta36_VkIgTlLvrxceO4TV8gU3r6V62Zi5ntMLbdKKzY2M9OuBbVyhjHOiIvvsn_CjdUva/s1600-h/animals.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQI8VZWF2KL9B0XfhuJDvIUNx5PnMtAi42i8vfE97366JxBKZkwU2lpGEdw2dPEr3SvR8Qfj2ta36_VkIgTlLvrxceO4TV8gU3r6V62Zi5ntMLbdKKzY2M9OuBbVyhjHOiIvvsn_CjdUva/s400/animals.png&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5252500360224090162&quot; /&gt;&lt;/a&gt;

&lt;UL&gt;
&lt;LI&gt;Direction: The direction of relationship is essentially
positive, that is longer lifespan tends to have have longer times of
pregnancy. 

&lt;LI&gt;Form: Again the form of relationship (between response and
explanatory) variable is linear.

&lt;LI&gt;Outliers: There seems to be one outlier at around 40 years. Lets
use R to find out which observation is this?
&lt;span style=&quot;font-family: trebuchet ms;color:#003300; font-size:102%; weight:bold;&quot;&gt;
&lt;pre&gt;
# we search for more than 35 year, just to be careful.
&gt; which(animals$longevity &gt; 35)
[1] 15
# &#39;which&#39; provides us with the observation number that has 
# logevity &gt; 35. Lets display that observation.
# combination of which along with dataset give following:
&gt; animals [which(animals$longevity &gt; 35), ]
     animal gestation longevity
15 elephant       645        40
&lt;/pre&gt;&lt;/span&gt;

&lt;br/&gt; So our outlier is an observation for elephant. Note that while
this outlier definitely deviates from the rest of the data in term of
its magnitude, it does follow the direction of the data.
&lt;/ul&gt;

&lt;b&gt;Comments from course site:&lt;/b&gt; Another feature of the
scatterplot that is worthwhile observing is how the variation in
Gestation increases as Longevity increases. Note that gestation period
for animal who live 5 years ranges from about 30 days up to about 120
days. On the other hand the gestation period of animals who live 12
years varies much more, and ranges from about 60 days and up to above
400 days.

&lt;br/&gt;&lt;br/&gt;&lt;b&gt;Example:&lt;/b&gt; As another example, consider the relationship between
the average fuel usage (in liters) for driving a fixed distance in a
car (100 kilometers), and the speed at which the car drives (in
kilometers per hour).  (Reference: Moore and McCabe, Introduction to
the Practice of Statistics, 2003. Original source: T.N. Lam
&quot;Estimating fuel consumption for engine size&quot;, Journal of
transportation Engineering,111 (1985))

&lt;br/&gt;&lt;br/&gt; The actual dataset for this example is available &lt;a
href=&quot;http://bcs.whfreeman.com/ips5e/content/cat_060/PCDataSets/PC_Text.zip&quot;&gt;here
(See chapter 2)&lt;/a&gt; and also as &lt;a
href=&quot;http://krishnadagli.blogspot.com/2008/07/learning-statistics-using-r-data-sets.html&quot;&gt;single
zip file&lt;/a&gt; that includes all dataset of this site.

&lt;br/&gt;&lt;b&gt;Lets examine this dataset using R:&lt;/b&gt;&lt;br/&gt;
&lt;span style=&quot;font-family: trebuchet ms;color:#003300;&quot;&gt;&lt;pre&gt;
&gt; sf &lt;- read.table(&quot;speedfuel.txt&quot;, sep=&quot;\t&quot;, header=TRUE)
&gt; png(&quot;/tmp/speedfuel.png&quot;, quanlity=100, width=480)
# check column names..
&gt; scatter.smooth(sf$Speed, sf$Fuel, main=&quot;&quot;,   xlab=&quot;Speed (km/h)&quot;, 
  ylab=&quot;Fuel Used (liters/100km)&quot;)
&gt; dev.off()
&lt;/pre&gt;&lt;/span&gt;


&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRB5yOZnoY_0jnVuW5wDHQ0RvzH6cv2Ktk3gTy7vCcQnwelL9zYI1aUZ2_WznlN0HTjZxSMvRufCWXZCLmkOhy_UuiDE_kwPOrpYol8WRShslcsJxsIf7IY2w0svOwlZ8UBbmAb8AGpSfM/s1600-h/speedfuel.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRB5yOZnoY_0jnVuW5wDHQ0RvzH6cv2Ktk3gTy7vCcQnwelL9zYI1aUZ2_WznlN0HTjZxSMvRufCWXZCLmkOhy_UuiDE_kwPOrpYol8WRShslcsJxsIf7IY2w0svOwlZ8UBbmAb8AGpSfM/s400/speedfuel.png&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5252517113631768914&quot; /&gt;&lt;/a&gt;

The data describe a relationship that decreases and then increases -
the amount of fuel consumed decreases rapidly to a minimum for a car
driving 60 kilometers per hour, and then increases gradually for
speeds exceeding 60 kilometers per hour. This suggests that the speed
at which a car economizes on fuel the most is about 60 km/h. This
forms a curvilinear relationship which seems to be very strong, as the
observations seem to perfectly fit the curve.  Finally, there do not
appear to be any outliers.

&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;Example:&lt;/b&gt; Another example and scatterplot taken from course
website provides a great opportunity for interpretation of the form of
the relationship in context. The example examines how the percentage
of participants who completed a survey is affected by the monetary
incentive that researchers promised to participants. Here, is the
scatterplot which displays the relationship:


&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDK6YIb49lI6R30tgHbW_-uKDAjkNOxrfP4QCQcO-mQXtPeAtu1I5cM8FDNcP73ivhtIgiMtzaAsuixRLC3Ta6zk8ZQUy47aBltzg-cpYCS-ZxbYE5hr4MKfmFuJtl52jfQlvvOkOo62zI/s1600-h/scatterplot26.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDK6YIb49lI6R30tgHbW_-uKDAjkNOxrfP4QCQcO-mQXtPeAtu1I5cM8FDNcP73ivhtIgiMtzaAsuixRLC3Ta6zk8ZQUy47aBltzg-cpYCS-ZxbYE5hr4MKfmFuJtl52jfQlvvOkOo62zI/s400/scatterplot26.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5252517680508490002&quot; /&gt;&lt;/a&gt;

The positive relationship definitely makes sense in context, but what
is the interpretation of the curvilinear form in the context of the
problem? How can we explain (in context) the fact that the
relationship seems at first to be increasing very rapidly, but then
slows down? 
&lt;br/&gt;&lt;br/&gt;
Note that when the monetary incentive increases from $0 to $10, the
percentage of returned surveys increases sharply - an increase of 27%
(from 16% to 43%). However, the same increase of $10 from $30 to $40
doesn&#39;t show the same dramatic increase on the percentage of returned
surveys - an increase of only 3% (from 54% to 57%).  The form displays
the phenomenon of &quot;diminishing returns&quot; - a return rate that after a
certain point fails to increase proportionately to additional outlays
of investment.  $10 is worth more to people relative to $0 than to
$30.






&lt;/span&gt;</description><link>https://krishnadagli.blogspot.com/2008/10/learning-statistics-using-r-role-type.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQI8VZWF2KL9B0XfhuJDvIUNx5PnMtAi42i8vfE97366JxBKZkwU2lpGEdw2dPEr3SvR8Qfj2ta36_VkIgTlLvrxceO4TV8gU3r6V62Zi5ntMLbdKKzY2M9OuBbVyhjHOiIvvsn_CjdUva/s72-c/animals.png" height="72" width="72"/><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-6588123341367225065</guid><pubDate>Mon, 08 Sep 2008 19:14:00 +0000</pubDate><atom:updated>2008-09-09T00:53:53.531+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Case-III</category><category domain="http://www.blogger.com/atom/ns#">R</category><category domain="http://www.blogger.com/atom/ns#">Scatterplot</category><title>Learning Statistics Using R: Role Type Classification: Case III (3 of 5)</title><description>&lt;span style=&quot;font-family: verdana;font-size:100%; color:black;&quot;&gt; 

In next few posts we try to understand direction, form, strength and
outliers of our Sign Legibility Distance Vs. Age scatterplot.

&lt;br/&gt;&lt;br/&gt; We try with simple scatterplot and then try to find its
direction using R. So this is how our scatterplot looks when drawn
using R.

&lt;span style=&quot;font-family: trebuchet ms;color:#003300; font-size:100%; weight:bold;&quot;&gt; &lt;pre&gt;
# read the signdistance datafile that is included in here
# http://krishnadagli.blogspot.com/2008/07/learning-statistics-using-r-data-sets.html

&gt; sigdist &lt;- read.table(&quot;signdistance.txt&quot;, header=T, sep=&#39;\t&#39;)
# we want to create scatterplot in a png file, that is easy to upload.
&gt; png(&quot;/tmp/signdist.png&quot;, quality=100, width=480)
&gt; plot(sigdist, main=&quot;Sign Distance&quot;, xlab=&quot;Driver Age(years)&quot;, ylab=&quot;Sign Legibility Distance(feet)&quot;)
&gt; dev.off()
&lt;/pre&gt;&lt;/span&gt;

&lt;br/&gt;&lt;br/&gt; So this how our scatterplot looks, we try to first find the
direction of this plot.

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5AMwhcQUregWK37SpV7mKniOcfvSKYtyx8UoPu3fVtzc6lilahfldC2MQACWnwgPSZXxg9fzloPDoXccsHmo6k4y145R8eNUc3tkjxYgLEjp3x_8ReOMK8Eaph8ip2wsLo5v9ho7yrsuz/s1600-h/signdist.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5AMwhcQUregWK37SpV7mKniOcfvSKYtyx8UoPu3fVtzc6lilahfldC2MQACWnwgPSZXxg9fzloPDoXccsHmo6k4y145R8eNUc3tkjxYgLEjp3x_8ReOMK8Eaph8ip2wsLo5v9ho7yrsuz/s400/signdist.png&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5243732831219693298&quot; /&gt;&lt;/a&gt;


&lt;br/&gt;
&lt;b&gt;Find direction: &lt;/b&gt; (FIXME: Is this correct, what alternatives?):
For finding direction of scatter plot we use one of R&#39;s function
&#39;scatter.smooth&#39;. The help page says that it plot and add a smooth
curve computed by &#39;loess&#39; to a scatter plot, and Wiki entry &lt;a
href=&quot;http://en.wikipedia.org/wiki/Local_regression&quot;&gt;here &lt;/a&gt;
mentions loess, or locally weighted scatterplot smoothing, as one of
many &quot;modern&quot; modeling methods. Here is the R code to add a curve to
our plot.
&lt;span style=&quot;font-family: trebuchet ms;color:#003300; font-size:100%; weight:bold;&quot;&gt; &lt;pre&gt;
# we have already read data in sigdist object, lets use it.
# As we want to create and save the plot, we use png function.
&gt;png(&quot;/tmp/sigdistsmooth.png&quot;, width=480, quality=100)
&gt; scatter.smooth(sigdist, main=&quot;Sign Distance Smooth&quot;, 
  xlab=&quot;Drive Age(years)&quot;, ylab=&quot;Sign Legibility Distance(feet)&quot;)
&lt;/pre&gt;&lt;/span&gt;

&lt;br/&gt;&lt;br/&gt;
Here is how our scatterplot along with a curve looks. 

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglXglDn-sTtn5WBdOOBud8zzdLBMG11N98q8k8MwNDKFJKiucrM1MvC1ZaIK6sVLxCYIA-HqbHcDZaBfovGab71lzKSa4itTa4hd2qk9agtVNen4ZMsIu6Erf4gY3HrEyCNRLrXMq83Haz/s1600-h/sigdistsmooth.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglXglDn-sTtn5WBdOOBud8zzdLBMG11N98q8k8MwNDKFJKiucrM1MvC1ZaIK6sVLxCYIA-HqbHcDZaBfovGab71lzKSa4itTa4hd2qk9agtVNen4ZMsIu6Erf4gY3HrEyCNRLrXMq83Haz/s400/sigdistsmooth.png&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5243733083714010082&quot; /&gt;&lt;/a&gt;

&lt;br/&gt;

We can see that the direction of the relationship is negative, which
makes sense in context since as you get older your eyesight weakens,
and in particular older drivers tend to be able to read signs only at
lesser distances.  (How do we get an arrow drawn over the scatterplot
just like its shown in the course?)

&lt;br/&gt;&lt;br/&gt; 

&lt;b&gt;Find form: &lt;/b&gt;The form of the relationship seems to be linear.  Notice
how the points tend to be scattered about the line.  Although, as we
mentioned earlier, it is problematic to assess the strength without a
numerical measure, the relationship appears to be moderately strong,
as the data is fairly tightly scattered about the line. Finally, all
the data points seem to &quot;obey&quot; the pattern- &lt;b&gt;there do not appear to be
any outliers.&lt;/b&gt;


&lt;/span&gt;</description><link>https://krishnadagli.blogspot.com/2008/09/learning-statistics-using-r-role-type_09.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5AMwhcQUregWK37SpV7mKniOcfvSKYtyx8UoPu3fVtzc6lilahfldC2MQACWnwgPSZXxg9fzloPDoXccsHmo6k4y145R8eNUc3tkjxYgLEjp3x_8ReOMK8Eaph8ip2wsLo5v9ho7yrsuz/s72-c/signdist.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-3091898527025290676</guid><pubDate>Fri, 05 Sep 2008 16:39:00 +0000</pubDate><atom:updated>2008-09-05T23:38:19.987+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Case-III</category><category domain="http://www.blogger.com/atom/ns#">R</category><category domain="http://www.blogger.com/atom/ns#">Scatterplot</category><title>Learning Statistics Using R: Role Type Classification: Case III (2 of 5)</title><description>&lt;span style=&quot;font-family: verdana;font-size:100%; color:black;&quot;&gt; 

As we have seen in &lt;a
href=&quot;http://krishnadagli.blogspot.com/2008/08/learning-statistics-using-r-role-type_25.html&quot;&gt;
our previous scatterplot&lt;/a&gt;, it is always the case that
&lt;b&gt;exaplanatory variable is plotted on horizontal, X-axis and response
variable on Y-axis. &lt;/b&gt; If, at times we are not able to clearly
identify explanatory and response variables then each of them can be
plotted on either axis.

&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;Interperting scatterplot: &lt;/b&gt; In our case-I we did comparative box
plot and in case-II we did comparative bar plot/histogram but now how
do we interpret scatterplot? What we dis is to describe the overall
pattern of the distribution (of response variable) and any deviations
(outliers) from that pattern, we take same approach for
scatterplot. That is we describe overall pattern by looking at
distribution&#39;s &lt;b&gt;&quot;Direction&quot;, &quot;Form&quot;, and, &quot;Strength&quot; &lt;/b&gt;, and along with
this we find outliers. Following from the course site puts it in a
nice figure.  &lt;br/&gt;&lt;br/&gt;

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIoEgMs6ZJ4ODVPy8OZcxsBPkxhtuXFk94IncVPG2ydG4yCif8duqEnF2j7r07AdXuqos5tX6QazSO5aZdltMzn8X00AnQIJVFYhahWtf2RNV5YMApx-eJjIOLRArZ0yO2S7tUWZULuGVU/s1600-h/scatterplot5.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIoEgMs6ZJ4ODVPy8OZcxsBPkxhtuXFk94IncVPG2ydG4yCif8duqEnF2j7r07AdXuqos5tX6QazSO5aZdltMzn8X00AnQIJVFYhahWtf2RNV5YMApx-eJjIOLRArZ0yO2S7tUWZULuGVU/s400/scatterplot5.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5242596450483362418&quot; /&gt;&lt;/a&gt;

&lt;br/&gt;

Lets discuss each of these three in details that describes overall
pattern of relationship.
&lt;OL&gt;

&lt;LI&gt;Direction: The direction of the relationship can be positive,
negative, or neither. We identify the direction of relationship by
looking at how scatterplot&#39;s points are moving along with x-y plane.
Following figures shows example of positive, negative, and neither
directions.

&lt;UL&gt;
&lt;LI&gt; Positive direction: A positive (or increasing) relationship means
that an increase in one of the variables is associated with an
increase in the other.&lt;br/&gt; 

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyc6vmSQzPHkpHnGkPiFqX5DNcEkDi5q_J1kKvWXZnq1ig1iCDe8SO4ygOB0ivRDZjL-KzG6G34wZvmmA0wjEEbxwewrFY0gjRGyTvXUeudGLKefiobTPLF6GVmfpyND629iCPCji6Eyii/s1600-h/scatterplot6.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyc6vmSQzPHkpHnGkPiFqX5DNcEkDi5q_J1kKvWXZnq1ig1iCDe8SO4ygOB0ivRDZjL-KzG6G34wZvmmA0wjEEbxwewrFY0gjRGyTvXUeudGLKefiobTPLF6GVmfpyND629iCPCji6Eyii/s400/scatterplot6.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5242596679003072050&quot; /&gt;&lt;/a&gt;


&lt;LI&gt; Negative direction: A negative (or decreasing) relationship means
that an increase in one of the variables is associated with a decrease
in the other. &lt;br/&gt; 

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigzFS1w931fgNMRFpd41NA09AaGRt7alYDJJ73qxZAruwHxzKRRpN73an5KYRhOUhTNedtIp4CV3xXassLZ_XYH2Nl2_6Fl5Qozg5LqUP9p7FUOzFqkSZ_qqgHKl8XQwBoZfNURgQOk0iJ/s1600-h/scatterplot7.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigzFS1w931fgNMRFpd41NA09AaGRt7alYDJJ73qxZAruwHxzKRRpN73an5KYRhOUhTNedtIp4CV3xXassLZ_XYH2Nl2_6Fl5Qozg5LqUP9p7FUOzFqkSZ_qqgHKl8XQwBoZfNURgQOk0iJ/s400/scatterplot7.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5242596951727869746&quot; /&gt;&lt;/a&gt;


&lt;LI&gt; Neither: Not all relationships can be classified as either
positive or negative.  

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvX6Zgwe5Pk3nUlD8BxKZjkpCOKakhRXm68j-rvoIXJEAeoEro9__QmwNzS4wdGC8FCTAutXFSzO7Oy5xiEMncxFiFN64wOXcBAAtkVcpy3oI0lkSOkV1UkrzYQk7QHY-JpoRTJMWC-wZ2/s1600-h/scatterplot8.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvX6Zgwe5Pk3nUlD8BxKZjkpCOKakhRXm68j-rvoIXJEAeoEro9__QmwNzS4wdGC8FCTAutXFSzO7Oy5xiEMncxFiFN64wOXcBAAtkVcpy3oI0lkSOkV1UkrzYQk7QHY-JpoRTJMWC-wZ2/s400/scatterplot8.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5242597196653606514&quot; /&gt;&lt;/a&gt;


&lt;/UL&gt;

&lt;LI&gt;Form: The form of the relationship is its general shape. When
identifying the form, we try to find the simplest way to describe the
shape of the scatterplot. There are many possible forms. Here are a
couple that are quite common:

&lt;UL&gt;
&lt;LI&gt;Linear Form: Relationships with a linear form are most simply
described as points scattered about a line: 

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibififfCmHb4iNp7NgWW7MGQkOckBKAMsMpocSnAm8yC4Edt-E3XHoHNFbrjCM5Iadt43HP1UoMYs1c1IcI-1-TaR6svLVMRyVd5Hz-iXck2_zXLs4gjYSx5dRuRXw70ktEmHujJwimb9G/s1600-h/scatterplot9.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibififfCmHb4iNp7NgWW7MGQkOckBKAMsMpocSnAm8yC4Edt-E3XHoHNFbrjCM5Iadt43HP1UoMYs1c1IcI-1-TaR6svLVMRyVd5Hz-iXck2_zXLs4gjYSx5dRuRXw70ktEmHujJwimb9G/s400/scatterplot9.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5242597821588371298&quot; /&gt;&lt;/a&gt;

&lt;LI&gt;Curvilinear Form: Relationships with a curvilinear form are most
simply described as points dispersed around the same curved line:

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaDJOTlw6z1FJawPIsQhF5cvGFjjlGgmNqhKQnex8iptqXFtdkY9Vqtglzp-Rgfhz0LFerT3yj0p7jebV0v1SksuzzaiiBT7_XLV4p9B5xU9DnmLnmgjpGujP3QLog5Knrr7KY6jKSHE9d/s1600-h/scatterplot10.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaDJOTlw6z1FJawPIsQhF5cvGFjjlGgmNqhKQnex8iptqXFtdkY9Vqtglzp-Rgfhz0LFerT3yj0p7jebV0v1SksuzzaiiBT7_XLV4p9B5xU9DnmLnmgjpGujP3QLog5Knrr7KY6jKSHE9d/s400/scatterplot10.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5242598353114399858&quot; /&gt;&lt;/a&gt;



&lt;LI&gt; Other Forms: There are many other possible forms for the
relationship between two quantitative variables, but linear and
curvilinear forms are quite common and easy to identify.  Another
form-related pattern that we should be aware of is &lt;b&gt;clusters in the
data&lt;/b&gt;:

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNRgl6M16T7ga93AMQLFbsiDJFy3k3uhEFuxBUHmjud4Rs8mcmMVFkgQCzAbxxYPRmmez0XqhMBQQBAov_tp9DEN4_VpeFx59aNdYZP0vCGBUR_EJZf6fs-Pxarr3Wi2xFNs_jUV46t8zO/s1600-h/scatterplot11.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNRgl6M16T7ga93AMQLFbsiDJFy3k3uhEFuxBUHmjud4Rs8mcmMVFkgQCzAbxxYPRmmez0XqhMBQQBAov_tp9DEN4_VpeFx59aNdYZP0vCGBUR_EJZf6fs-Pxarr3Wi2xFNs_jUV46t8zO/s400/scatterplot11.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5242598661349489026&quot; /&gt;&lt;/a&gt;


&lt;/UL&gt;

&lt;LI&gt;Strength: The strength of the relationship is determined by how
closely the data follow the form of the relationship. Let&#39;s look, for
example, at the following two scatterplots displaying a positive,
linear relationship:


&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcWIRNP85jlSsc63FQsP2-ycedcpigbWPXAFfmoxpmy26fcjWHQH3dBzB2HjQl0ZFZyHZBkrWQjuzGS5_Vv63vpbu2TPGjtCtc9Ii-VjfrcT76GMEsRo2toaDi-mByjLmdEDyB95MTatr8/s1600-h/scatterplot12.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcWIRNP85jlSsc63FQsP2-ycedcpigbWPXAFfmoxpmy26fcjWHQH3dBzB2HjQl0ZFZyHZBkrWQjuzGS5_Vv63vpbu2TPGjtCtc9Ii-VjfrcT76GMEsRo2toaDi-mByjLmdEDyB95MTatr8/s400/scatterplot12.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5242599038944206386&quot; /&gt;&lt;/a&gt;

&lt;br/&gt;

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfyQN-lzEZI112e08de6Z7TY9n8bg0gWgX6iHl_5u-fzTI7YDFLrK7qp3DQYQtP-z4zYNl4WsfRHVcACxdOf1lHJF9CqSNexVanyO8zVLZIdy8aAcSySnOaMQaQLU7iqmvh-sM3gNF9wkB/s1600-h/scatterplot13.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfyQN-lzEZI112e08de6Z7TY9n8bg0gWgX6iHl_5u-fzTI7YDFLrK7qp3DQYQtP-z4zYNl4WsfRHVcACxdOf1lHJF9CqSNexVanyO8zVLZIdy8aAcSySnOaMQaQLU7iqmvh-sM3gNF9wkB/s400/scatterplot13.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5242599441919196050&quot; /&gt;&lt;/a&gt;


The strength of the relationship is determined by how closely the data
points follow the form. We can see that in the top scatterplot the the
data points follow the linear patter quite closely. This is an example
of a strong relationship. In the bottom scatterplot the points also
follow the linear pattern but much less closely, and therefore we can
say that the relationship is weaker. In general, though, assessing the
strength of a relationship just by looking at the scatterplot is quite
problematic, and we need a numerical measure to help us with that. We
will discuss this later in this section.

&lt;LI&gt;Outliers: Data points that deviate from the pattern of the
relationship are called outliers.  We will see several examples of
outliers during this section.  Two outliers are illustrated in the
scatterplot below: 

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7fctuZ2qhECJp_bLOVS4hYZGf0FUTSVH63xpE3CJjBRasiSizjdGIAXqma-5sCLZPGmQO6FAh_S1BoEVWC9Wb7CL6PHTZwgly0vhmVfXczr-nOP6d0efwb0vmnKQsaAT7ne8pn1z649f_/s1600-h/scatterplot14.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7fctuZ2qhECJp_bLOVS4hYZGf0FUTSVH63xpE3CJjBRasiSizjdGIAXqma-5sCLZPGmQO6FAh_S1BoEVWC9Wb7CL6PHTZwgly0vhmVfXczr-nOP6d0efwb0vmnKQsaAT7ne8pn1z649f_/s400/scatterplot14.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5242599813284219874&quot; /&gt;&lt;/a&gt;

&lt;/OL&gt;
&lt;/span&gt;</description><link>https://krishnadagli.blogspot.com/2008/09/learning-statistics-using-r-role-type.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIoEgMs6ZJ4ODVPy8OZcxsBPkxhtuXFk94IncVPG2ydG4yCif8duqEnF2j7r07AdXuqos5tX6QazSO5aZdltMzn8X00AnQIJVFYhahWtf2RNV5YMApx-eJjIOLRArZ0yO2S7tUWZULuGVU/s72-c/scatterplot5.gif" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-5310887426672010429</guid><pubDate>Sun, 24 Aug 2008 19:41:00 +0000</pubDate><atom:updated>2009-01-07T22:12:43.327+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">R</category><category domain="http://www.blogger.com/atom/ns#">Scatterplot</category><title>Learning Statistics Using R: Role Type Classification: Case III (1 of 5)</title><description>&lt;span style=&quot;font-family: verdana;font-size:100%; color:black;&quot;&gt; 

Lets start with our next example; understanding relationship between
two quantitative variables, ie. both explanatory and response
variables are quantitative.

&lt;br/&gt;&lt;br/&gt;

As in previous two cases we compared distribution of response variable
with that of explanatory variables. To be specific, in case I we
compared distribution of quantitative response with categorical
explanatory variable and in case II we compared distribution of
categorical response variable with categorical explanatory variable.

&lt;br/&gt;

Now we have both variables as quantitative, more importantly we have a
explanatory variable that is quantitiave. We will start understanding
their relationship using &quot;scatterplot&quot;.

&lt;br/&gt;&lt;br/&gt; 


We start with an example taken from course site. &lt;br/&gt;

A Pennsylvania research firm conducted a study in which 30 drivers (of
ages 18 to 82 years old) were sampled and for each one the maximum
distance at which he/she could read a newly designed sign was
determined.  The goal of this study was to explore the relationship
between driver&#39;s age and the maximum distance at which signs were
legible, and then use the study&#39;s findings to improve safety for older
drivers.  (Reference: Utts and Heckard, Mind on Statistics
(2002). Originally source: Data collected by Last Resource, Inc,
Bellfonte, PA.)  &lt;br/&gt;&lt;br/&gt;

Since the purpose of this study is to explore the effect of age on
maximum legibility distance,&lt;br/&gt;


&lt;UL&gt;
&lt;LI&gt; the explanatory variable is Age, and
&lt;LI&gt; the response variable is Distance.
&lt;/UL&gt;

Here is what the raw data look like and its available &lt;a
href=&quot;http://math.fullerton.edu/mori/Math120/Data/ascii/signdist.txt&quot;&gt;here.&lt;/a&gt;


&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrwzmh9GCke-2Ze4XOM8HFN_64-tqD6a4wAu4_nhhkiv4FP_8WHf3YEQmPwQfK73DOTUcL3NAd4GTT3c3L_5RFLovM-ylArVARRHkKrQ3lrhQplz5lkb8vyGaHVw54RcgkmgoMmke_0uGl/s1600-h/scatterplot2.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrwzmh9GCke-2Ze4XOM8HFN_64-tqD6a4wAu4_nhhkiv4FP_8WHf3YEQmPwQfK73DOTUcL3NAd4GTT3c3L_5RFLovM-ylArVARRHkKrQ3lrhQplz5lkb8vyGaHVw54RcgkmgoMmke_0uGl/s320/scatterplot2.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5238172823851780706&quot; /&gt;&lt;/a&gt;



&lt;br/&gt;

Note that the data structure is such that for each individual (in this
case driver 1....driver 30) we have a pair of value (in this case
representing the driver&#39;s age and distance).  We can therefore think
about this data as 30 pairs of values: (18,510), (32,410),
(55,420)........(82,360).
&lt;br/&gt;&lt;br/&gt;
The first step in exploring the relationship between driver age and
sign legibility distance is to create an appropriate and informative
graphical display.  The appropriate graphical display for examining
the relationship between two quantitative variables is the
&lt;b&gt;scatterplot&lt;/b&gt;. &lt;br/&gt;&lt;br/&gt;


Here is how a scatterplot is constructed for our example: &lt;br/&gt;&lt;br/&gt;

To create a scatterplot, each pair of values is plotted, so that the
value of the explanatory variable (X) is plotted on the horizontal
axis, and the value of the response variable (Y) is plotted on the
vertical axis. In other words, each individual (driver, in our
example) appears on the scatterplot as a single point whose
x-coordinate is the value of the explanatory for that individual, and
the y-coordinate is the value of the response. Following images taken
from course website illustrate the same.


&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcLFuKz4xirboZqF4GBfqqgGmG1QpHvhKdUAlZvEzY3tRe5-pa-p9hGVWvIEJcaEnu0VzXgCYo1wSGaRJougTEkqA811dzMCW7vaBXqBQ23FQ03VaxKbIpZqabpwZsB1LDaGjQ3KszLEv5/s1600-h/scatterplot3.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcLFuKz4xirboZqF4GBfqqgGmG1QpHvhKdUAlZvEzY3tRe5-pa-p9hGVWvIEJcaEnu0VzXgCYo1wSGaRJougTEkqA811dzMCW7vaBXqBQ23FQ03VaxKbIpZqabpwZsB1LDaGjQ3KszLEv5/s400/scatterplot3.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5238173301714752722&quot; /&gt;&lt;/a&gt;



&lt;br/&gt;&lt;br/&gt; 
&lt;b&gt;As we have data set, lets start doing the same using R.&lt;/b&gt;&lt;br/&gt;&lt;br/&gt;

&lt;span style=&quot;font-family: trebuchet ms;color:#003300; font-size:100%; weight:bold;&quot;&gt; &lt;pre&gt;
# Read data using read.csv function, here separator is tab.
# Bug-Fix: Gabriele Righetti 
&gt; signdist &lt;- read.csv (&quot;signdistance.txt&quot;, sep=&quot;\t&quot;, header=T)
&gt; plot(signdist, type=&quot;b&quot;, main=&quot;Sign and Distance&quot;, col=&quot;blue&quot;, xlab=&quot;Driver Age&quot;, 
ylab=&quot;Sign Legibility Distance (Feet)&quot;)
&lt;/pre&gt;&lt;/span&gt;

The output of above simple command plot draws our scatter plot. Also
note our scatter plot is different, that is we have lines along with
points. That is possible with simple parameter &quot;type=b&quot; in plot
commands. See the help page of plot command to see all types. 

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLhTJDiYtBa69SV24ACU49i0vUNm3sEqvIPXPDE5tDhK1NT2T7d1iZn2E_mXk2T6-JhTzQgXlLtX1kyEKk88yO_Lzl-fphncQYQievBfnGdPv8XQesMMeNcz_dabzmiw6W1EXn3gxaxyIw/s1600-h/myscatterplot.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLhTJDiYtBa69SV24ACU49i0vUNm3sEqvIPXPDE5tDhK1NT2T7d1iZn2E_mXk2T6-JhTzQgXlLtX1kyEKk88yO_Lzl-fphncQYQievBfnGdPv8XQesMMeNcz_dabzmiw6W1EXn3gxaxyIw/s400/myscatterplot.png&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5238174475432773874&quot; /&gt;&lt;/a&gt;

&lt;br/&gt;
Another using &quot;type=p&quot; argument. &lt;br/&gt;

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBO68gaZ_T6tbWFseNdCvXiGuv_tAgkvWNNSzItLVOlUx8kHwv2pIggYc2ucrbIEWGGOC9RjVU7xVt5CU5sVI8qsxjDPSz0njz16HN_DlxnQV9bC8cajK8PJIVFzejuLY3V9mrrkjGvgW7/s1600-h/myscatterplot1.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBO68gaZ_T6tbWFseNdCvXiGuv_tAgkvWNNSzItLVOlUx8kHwv2pIggYc2ucrbIEWGGOC9RjVU7xVt5CU5sVI8qsxjDPSz0njz16HN_DlxnQV9bC8cajK8PJIVFzejuLY3V9mrrkjGvgW7/s400/myscatterplot1.png&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5238175705625250370&quot; /&gt;&lt;/a&gt;


&lt;/span&gt;</description><link>https://krishnadagli.blogspot.com/2008/08/learning-statistics-using-r-role-type_25.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrwzmh9GCke-2Ze4XOM8HFN_64-tqD6a4wAu4_nhhkiv4FP_8WHf3YEQmPwQfK73DOTUcL3NAd4GTT3c3L_5RFLovM-ylArVARRHkKrQ3lrhQplz5lkb8vyGaHVw54RcgkmgoMmke_0uGl/s72-c/scatterplot2.gif" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-5908913800224014506</guid><pubDate>Sun, 03 Aug 2008 09:17:00 +0000</pubDate><atom:updated>2008-08-03T15:07:03.005+05:30</atom:updated><title>Learning Statistics Using R: Role Type Classification : Case II (2 of 2)</title><description>&lt;span style=&quot;font-family: verdana;font-size:100%; color:black;&quot;&gt; 

Following example from the course website provides an opportunity to
analyze relationship between two categorical variables using R.

&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;Study:&lt;/b&gt; An associated press article captured the attentions of
readers with the headline &quot;Night lights bad for kids?&quot;  The article
was based on a 1999 study at the University of Pennsylvania and
Children&#39;s Hospital of Philadelphia, in which parents were surveyed
about the lighting conditions under which their children slept between
birth and age 2 (lamp, night-light, or no light) and whether or not
their children developed nearsightedness (myopia.) &lt;b&gt;The purpose of the
study was to explore the effect of a young child&#39;s night-time exposure
to light on later nearsightedness.&lt;/b&gt;

&lt;br&gt; &lt;br/&gt;&lt;i&gt;The actual excel file can be downloaded from &lt;a
href=&quot;https://oli.web.cmu.edu/repository/webcontent/859044f080020c690045b50e228faf24/_u2_summarizing_data/webcontent/excel/nightlight.xls&quot;&gt;here&lt;/a&gt;. Or
it can be downloaded as and csv file along with other data sets from
&lt;a
href=&quot;http://krishnadagli.blogspot.com/2008/07/learning-statistics-using-r-data-sets.html&quot;&gt;here.&lt;/a&gt;&lt;/i&gt;&lt;br/&gt;

&lt;br/&gt; 
Lets try to do this analysis using R.
&lt;br/&gt;

&lt;OL&gt;
&lt;LI&gt; Find out explanatory and response variables:

    &lt;UL&gt;
    &lt;LI&gt; Light:(No light/Night light/Lamp) this categorical variable is
      explanatory variable.

     &lt;LI&gt; Nearsightedness: (Yes/No) this categorical variable is response
     variable since values (yes/no) depends on the value of Light variable.
     &lt;/UL&gt;
&lt;br/&gt;
&lt;LI&gt; Create a two-way summary table: Following steps shows how we
summarize the data in a two-way table using R. Note there are multiple
ways of creating two-way table in R but I have not successful at them.

&lt;span style=&quot;font-family: trebuchet ms;color:#003300; font-size:100%; weight:bold;&quot;&gt; 
&lt;pre&gt; # Read data usingread.csv function.  
&gt; nightlight&lt;-read.csv(&quot;nightlight.csv&quot;, header=T,sep=&quot;,&quot;)

# Find row and column totals using addmargins function.
&gt; addmargins(table(nightlight),FUN=sum, quiet=F)
Margins computed over dimensions
in the following order:
1: Light
2: Nearsightedness
             Nearsightedness
Light          No Yes sum
  lamp         34  41  75
  night light 153  79 232
  no light    155  17 172
  sum         342 137 479
&lt;/pre&gt;
&lt;/span&gt;

As we have seen earlier &quot;table&quot; command is used to tabulate data but
we need row and column totals; that is possible using &quot;addmargins&quot;
function. (I think this can also be achieved using combination of
apply, t, cut and few other functions but I am not able to do so
due to limited knowledge of R. Have a look at &lt;a
href=&quot;http://tolstoy.newcastle.edu.au/R/devel/02b/0137.html&quot;&gt; this
discussion thread.&lt;/a&gt;)
&lt;br/&gt;&lt;br/&gt;

&lt;LI&gt; Find percentage: As noted earlier, having sum does not help; we
need to find percentage for comparing distribution of response
variable. 

&lt;br&gt;
Again, as I am learning R I could not do this percentage calculation
using combination of R commands but found a package (rather two) that
does exactly what we want.

&lt;br/&gt;
&lt;UL&gt;&lt;LI&gt;Using &quot;CrossTable&quot; function from library &lt;a
href=&quot;http://cran.r-project.org/web/packages/gregmisc/index.html&quot;&gt;
&quot;gregmisc&quot;: &lt;/a&gt;&lt;br/&gt;

&lt;span style=&quot;font-family: trebuchet ms;color:#003300; font-size:100%; weight:bold;&quot;&gt; 
&lt;pre&gt; # load the library 
&gt; library(&quot;gregmisc&quot;)
Loading required package: gdata
Loading required package: gmodels
Loading required package: gplots
Loading required package: gtools

# Read data usingread.csv function.  
&gt; nightlight &lt;- read.csv(&quot;nightlight.csv&quot;, header=T,sep=&quot;,&quot;)
&gt; CrossTable(table(nightlight), prop.t=FALSE, prop.c=FALSE, prop.r=TRUE, prop.chisq=F)

   Cell Contents
|-------------------------|
|                       N |
|           N / Row Total |
|-------------------------|
 
Total Observations in Table:  479 
 
             | Nearsightedness 
       Light |        No |       Yes | Row Total | 
-------------|-----------|-----------|-----------|
        lamp |        34 |        41 |        75 | 
             |     0.453 |     0.547 |     0.157 | 
-------------|-----------|-----------|-----------|
 night light |       153 |        79 |       232 | 
             |     0.659 |     0.341 |     0.484 | 
-------------|-----------|-----------|-----------|
    no light |       155 |        17 |       172 | 
             |     0.901 |     0.099 |     0.359 | 
-------------|-----------|-----------|-----------|
Column Total |       342 |       137 |       479 | 
-------------|-----------|-----------|-----------|
&lt;/pre&gt;&lt;/span&gt;

&lt;br/&gt; As we can see from the above output, &quot;CrossTable&quot; function
provides us what we want. ( &quot;prop.r=TRUE&quot; provides us with row
proportions.)
&lt;br/&gt;&lt;br/&gt;
&lt;LI&gt;Using &lt;a
href=&quot;http://cran.r-project.org/web/packages/Rcmdr/index.html&quot;&gt;
&quot;Rcmdr&quot; &lt;/a&gt;library&lt;br/&gt;
 
This library provides nice GUI using which we can find row percentage
and other details. Here is the screen shot of the same.

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglzEYrxjspmTvpD9nuBV5SemKVVjBP086Cl7YFyFyp2EkitQbau5MWWN3WBPS-PRmq1v4ocMrn1EWvw-ZbEy3hKSdoQmGTMZTCLDYKVExdfVmwfsuesCzj_ZuwT07hd3PSO2XkEhs_ifLq/s1600-h/rcmdr.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglzEYrxjspmTvpD9nuBV5SemKVVjBP086Cl7YFyFyp2EkitQbau5MWWN3WBPS-PRmq1v4ocMrn1EWvw-ZbEy3hKSdoQmGTMZTCLDYKVExdfVmwfsuesCzj_ZuwT07hd3PSO2XkEhs_ifLq/s400/rcmdr.png&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5230220406292063090&quot; /&gt;&lt;/a&gt;
&lt;span style=&quot;font-family: verdana;font-size:100%; color:black;&quot;&gt; 
&lt;/ul&gt;
&lt;br/&gt;
&lt;LI&gt; Interpret these results: Lets try to analyze these results. We
want explore the effect of a young child&#39;s night-time exposure to
light on later nearsightedness.  From the above results lets note few
things:

&lt;UL&gt;
&lt;LI&gt; The results suggest that propotion of children 0.547 (or 54.7%)
developed nearsightedness when exposed to lamp. This propotion is
higher when we compare this to night light and no light propotion;
that are 0.341 (or 34.1 %) and 0.099 (or 9.9 %) respectively.

&lt;LI&gt; That is there are 5 times higher chances of children developing
nearsightedness when slept with lamp compared to children who slept
without any lights.

&lt;LI&gt; Though 9.9 % of children developed nearsightedness when slept
without any lights.
&lt;/UL&gt;

&lt;/OL&gt;
&lt;/span&gt;</description><link>https://krishnadagli.blogspot.com/2008/08/learning-statistics-using-r-role-type.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglzEYrxjspmTvpD9nuBV5SemKVVjBP086Cl7YFyFyp2EkitQbau5MWWN3WBPS-PRmq1v4ocMrn1EWvw-ZbEy3hKSdoQmGTMZTCLDYKVExdfVmwfsuesCzj_ZuwT07hd3PSO2XkEhs_ifLq/s72-c/rcmdr.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-5407901998929351790</guid><pubDate>Wed, 16 Jul 2008 18:47:00 +0000</pubDate><atom:updated>2008-08-03T14:47:05.994+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Course</category><category domain="http://www.blogger.com/atom/ns#">R</category><category domain="http://www.blogger.com/atom/ns#">Statistics</category><category domain="http://www.blogger.com/atom/ns#">Tutorial</category><title>Learning Statistics Using R: Role Type Classification : Case II (1 of 2)</title><description>Case II of our role type classification includes study of relationship
between a Categorical Explanatory and a Categorical Response variable.

&lt;br/&gt;&lt;br/&gt; 

We start with an example from the course web site to explore
relationship between two categorical variables. &lt;br/&gt;

Example: In a survey, 1200 U.S. college students were asked about
their body-image, underweight, overweight, or about right. We have to
find answer to following questions: &lt;br/&gt;

If we had separated our sample of 1200 U.S. college students by gender
and looked at males and females separately, would we have found a
similar distribution across body-image categories?  &lt;br/&gt;

More specifically,are men and women just as likely to think their
weight is about right?  Among those students who do not think their
weight is about right, is there a difference between the genders in
feelings about body-image? &lt;br/&gt;&lt;br/&gt;

So for answering these questions requires us to study the relationship
between two categorical variables. Both response and explanatory
variables are categorical since we want to find how gender
(male/female) affects body image (underweight, overweight, right
weight). 


Here in this study we have following:
&lt;UL&gt;

&lt;LI&gt; Gender: (Male/Female) as explanatory variable and it is a
categorical variable.

&lt;LI&gt; Body-image:(underweight, overweight, right weight) as response
variable and it is a categorical variable.

&lt;/UL&gt;

&lt;br/&gt; &lt;B&gt;As I could not find raw data for these example; we will
directly use results derived at the course site instead of reading raw
data in R and finding results.&lt;/B&gt;&lt;br/&gt;&lt;br/&gt;

To understand how body image is related to gender, we need an
informative display that summarizes the data.  In order to summarize
the relationship between two categorical variables, we create a
display called a two-way table.&lt;br/&gt;&lt;br/&gt;

Here is the two-way table for our example:&lt;br/&gt;

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKf4AHRcAjOCtNHqWhm_60gE-EENNp7PGcGZAYzASWJuYAFgU7cmAxGwJL4IIHT5F5zEVRNjQlzUrdSni4b4fCEdveJmZ1DDAYYJtgQm7ZyP5J742Gp0CfoGswdEcStVMC2HnRX22cCLLh/s1600-h/caseii-1.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKf4AHRcAjOCtNHqWhm_60gE-EENNp7PGcGZAYzASWJuYAFgU7cmAxGwJL4IIHT5F5zEVRNjQlzUrdSni4b4fCEdveJmZ1DDAYYJtgQm7ZyP5J742Gp0CfoGswdEcStVMC2HnRX22cCLLh/s320/caseii-1.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5225897770901237618&quot; /&gt;&lt;/a&gt;

&lt;br/&gt;
So our two-way table summarizes data of all 1200 students by gender and their body image as counts. 

The &quot;Total&quot; row or column is a summary of one of the two categorical
variables, ignoring the other. In our example:
&lt;UL&gt;
&lt;LI&gt;The Total row gives the summary of the categorical variable
Body-image:
&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjG-qzM_zIp_eBJd8_un5p4AAmD9gSLLUAZOUJfIUqoUioMrhr8G9LzuANeHdjHqRVwv_1jIevwYGvgLOepYhuOBNBS3z-bff8NaOyAO0boW9JWpfx16VnFARYIqRgoxNaFjAuXgkrsFPuI/s1600-h/caseii-2.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjG-qzM_zIp_eBJd8_un5p4AAmD9gSLLUAZOUJfIUqoUioMrhr8G9LzuANeHdjHqRVwv_1jIevwYGvgLOepYhuOBNBS3z-bff8NaOyAO0boW9JWpfx16VnFARYIqRgoxNaFjAuXgkrsFPuI/s320/caseii-2.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5225898502691087266&quot; /&gt;&lt;/a&gt;
&lt;br/&gt;

&lt;LI&gt;The Total column gives the summary of the categorical variable
Gender:
&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilq52SytOvEDvtgaDh6xWEb57tmo_UM_29od7yvauMXIByyGlhr_fS-d71Fq_T_E7NcxPBZpx4J2SGjMSbLWpIDlgnfS1YDcInlDWW5MMCPxmFtVKzw28XL4hRUkv5pGa1hmxEyK6V4xVs/s1600-h/caseii-3.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilq52SytOvEDvtgaDh6xWEb57tmo_UM_29od7yvauMXIByyGlhr_fS-d71Fq_T_E7NcxPBZpx4J2SGjMSbLWpIDlgnfS1YDcInlDWW5MMCPxmFtVKzw28XL4hRUkv5pGa1hmxEyK6V4xVs/s320/caseii-3.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5225898732061567218&quot; /&gt;&lt;/a&gt;

&lt;br/&gt;
&lt;/UL&gt;

&lt;br/&gt;

Remember, though, that our primary goal is to explore how body image
is related to gender.  Exploring the relationship between two
categorical variables (in this case Body-image and Gender) amounts to
comparing the distributions of the response (in this case Body-image)
across the different values of the explanatory (in this case males and
females):

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0NLa2BrtBxfOKeV-fPs0u7hwi0wDrdrX7iXia6qL2D5ebcoE4ceJEkYcIV5215V7j9gdO4zln4wT4Pt7CC2vDX1ykEaKKEflht3-iELplHUvhM8a7Rl4kLzWt5gNAUtHXRBuMSuXExpYH/s1600-h/caseii-4.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0NLa2BrtBxfOKeV-fPs0u7hwi0wDrdrX7iXia6qL2D5ebcoE4ceJEkYcIV5215V7j9gdO4zln4wT4Pt7CC2vDX1ykEaKKEflht3-iELplHUvhM8a7Rl4kLzWt5gNAUtHXRBuMSuXExpYH/s320/caseii-4.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5225899369655780594&quot; /&gt;&lt;/a&gt;
&lt;span style=&quot;font-family: verdana;font-size:100%; color:black;&quot;&gt; 
&lt;br/&gt;

Note that it does not make sense to compare raw counts, because there
are more females than males overall.  So for example, it is not very
informative to say &quot;there are 560 females who responded &#39;About Right&#39;
compared to only 295 males,&quot; since the 560 females are out of a total
of 760, and the 295 males are only out of a total of 440).

We need to supplement our display, the two-way table, with some
numerical summaries that will allow us to compare the
distributions. These numerical summaries are found by simply
converting the counts to percents within (or restricted to) each value
of the explanatory variable separately!

In our example:

We look at each gender separately, and convert the counts to percents
within that gender.  Let&#39;s start with females:
&lt;br/&gt;
&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTSWAHTNAVehZasBUueUhHcrCb4WozecnFvX-0h9Ltv17JGx-pSlqhXtVyJQ62hQyWKxtYFS3Ux-OZfMzg84AjKH2npefJsvtVX5Q4VmChz2s4ko6vz4UIpPsPe_cwaqBUnzIPQ75hIVPP/s1600-h/caseii-5.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTSWAHTNAVehZasBUueUhHcrCb4WozecnFvX-0h9Ltv17JGx-pSlqhXtVyJQ62hQyWKxtYFS3Ux-OZfMzg84AjKH2npefJsvtVX5Q4VmChz2s4ko6vz4UIpPsPe_cwaqBUnzIPQ75hIVPP/s320/caseii-5.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5225899641791837698&quot; /&gt;&lt;/a&gt;
&lt;br/&gt;

Note that each count is converted to percents by dividing by the total
number of females, 760.  These numerical summaries are called
conditional percents, since we find them by conditioning on one of the
genders
&lt;br/&gt;
&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0X7F72ExMZ9bSPS_zReL2Az68WMxxeupR_U9K6SUQe7ZCZbAlEPf5t95rwUn2MeCOhOk4jj35LWg50x-Z_ksfS-jJb-UQXb0foFkLY9DYSjqToZpNoClbbipdF30wisePdo5sm2t-6_cD/s1600-h/caseii-5.5.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0X7F72ExMZ9bSPS_zReL2Az68WMxxeupR_U9K6SUQe7ZCZbAlEPf5t95rwUn2MeCOhOk4jj35LWg50x-Z_ksfS-jJb-UQXb0foFkLY9DYSjqToZpNoClbbipdF30wisePdo5sm2t-6_cD/s320/caseii-5.5.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5225900954420427378&quot; /&gt;&lt;/a&gt;
&lt;br/&gt;

&lt;b&gt;Comments&lt;/b&gt;

&lt;OL&gt;
&lt;LI&gt;In our example, we chose to organize the data with the explanatory
 variable Gender in rows and the response variable Body-image in
 columns, and thus our conditional percents were row percents,
 calculated within each row separately.  Similarly, if the explanatory
 variable happens to sit in columns and the response variable in rows,
 our conditional percents will be column percents, calculated within
 each column separately. 

&lt;LI&gt;Another way to visualize the conditional percents, instead of a
table, is the double bar chart. This display is quite common in
newspapers.

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8V1UsMykBKgoMDoma2rsCI2Tj-CE6D4fQgtUS13nMNVmlJF6vuotoEkDJIY13PK1EgtpYMyVgidmuaUkJ6SgIrGxEvaaMs39njNT5FbtTi9HFOlSB5mxqMdRUonKyn2cOLjaJ3fdED1I6/s1600-h/caseii-6.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8V1UsMykBKgoMDoma2rsCI2Tj-CE6D4fQgtUS13nMNVmlJF6vuotoEkDJIY13PK1EgtpYMyVgidmuaUkJ6SgIrGxEvaaMs39njNT5FbtTi9HFOlSB5mxqMdRUonKyn2cOLjaJ3fdED1I6/s320/caseii-6.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5225901283049355618&quot; /&gt;&lt;/a&gt;
&lt;/OL&gt;


&lt;br/&gt;
After looking at the numerical summary and graph lets try to put the results in words: 
&lt;UL&gt;
&lt;LI&gt;The results suggest that propotion of males who are happy with their body image &#39;About right&#39; is slightly less than among female student. That is 73.3 % of female students are happy with their body image compared to only 67 % of males.

&lt;LI&gt; Female students who are not happy with their body image often feel they are overweight. That is 73.3 % are happy but remaining 21.4 % feel they are overweight compared to only 4.9 % feeling underweight. 

&lt;LI&gt; Male students who are not happy with their body image feel they are overweight about often as they feel they are underweight. That is 16.6 % student feel they are overweight while rougly same 16.2 % student feel they are underweight.
&lt;/UL&gt;


&lt;/span&gt;</description><link>https://krishnadagli.blogspot.com/2008/07/learning-statistics-using-r-role-type_17.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKf4AHRcAjOCtNHqWhm_60gE-EENNp7PGcGZAYzASWJuYAFgU7cmAxGwJL4IIHT5F5zEVRNjQlzUrdSni4b4fCEdveJmZ1DDAYYJtgQm7ZyP5J742Gp0CfoGswdEcStVMC2HnRX22cCLLh/s72-c/caseii-1.gif" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-5361615336906561971</guid><pubDate>Mon, 14 Jul 2008 19:55:00 +0000</pubDate><atom:updated>2009-01-04T19:14:51.658+05:30</atom:updated><title>Learning Statistics Using R: Role Type Classification : Case I (1 of 1)</title><description>As we show earlier, Case I of our role type classification includes
study of a relationship between a Categorical Explanatory and a
Quantitative Response variable.

&lt;br/&gt;&lt;br/&gt;

We start with an example from the course website. &lt;br/&gt;

Example:People who are concerned about their health may prefer hot
dogs that are low in calories. A study was conducted by a concerned
health group in which 54 major hot dog brands were examined, and their
calorie contents recorded. In addition, each brand was classified by
type: beef, poultry, and meat (mostly pork and beef, but up to 15%
poultry meat).

&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;
The purpose of the study was to examine whether the number of calories
a hot dog has is related to (or affected by) its type.&lt;/b&gt;

(Reference: Moore, David S., and George P. McCabe (1989). Introduction
to the Practice of Statistics. Original source: Consumer Reports, June
1986, pp. 366-367.)

Answering this question requires us to examine the relationship
between the categorical variable Type and the quantitative variable
Calories. Because the question of interest is whether the type of hot
dog affects calorie content,
&lt;UL&gt;

&lt;LI&gt;the explanatory variable is Type, and
&lt;LI&gt;the response variable is Calories.
&lt;/UL&gt;

To explore how the number of calories is related to the type of hot
dog, we need an informative visual display of the data that will
compare the three types of hot dogs with respect to their calorie
content.

The visual display that we&#39;ll use is side-by-side boxplots. The
side-by-side boxplots will allow us to compare the distribution of
calorie counts within each category of the explanatory variable, hot
dog type. We use R to do side-by-side box plot:



&lt;span style=&quot;font-family: trebuchet ms; color:#003300; font-size:100%;&quot;&gt;
&lt;pre&gt;
&gt; hotdogdata &lt;- read.csv (&quot;TA01_009.TXT&quot;, header=T, sep=&quot;\t&quot;)
&gt; attach(hotdogdata)
&gt; boxplot(Calories[HotDog == &#39;Beef&#39;], Calories[HotDog == &#39;Meat&#39;], Calories[HotDog == &#39;Poul&#39;], 
  border=c(&#39;blue&#39;, &#39;magenta&#39;,&#39;red&#39;), 
  names=c(&#39;Beef&#39;,&#39;Meat&#39;, &#39;Poul&#39;), 
  ylab=&#39;Calories&#39;, 
  main=&#39;Side By Side Comparative Boxplot of Calories&#39;)
&lt;/pre&gt;&lt;/span&gt;

&lt;br/&gt;
&lt;b&gt;Gabriele Righetti&lt;/b&gt; from Italy pointed out that it should be &quot;names&quot; and not &quot;xlab&quot; for 
naming boxplots. Thanks Gabriele.&lt;br/&gt;

&lt;br/&gt;
The output of the above command displays a boxplot like following:

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtMpjFGsauvtFmtE0UMBDtBnljXAbVdiZ6CfHrp3RL4r_ReWfwTIHdW4owyjNvPB1mGdY_-FZ_8BpGJ-SuT9ccu8GfPILrZLdGSOyR-JeTnu1-WUOpwtm62ip5Kk6IFHry4GfA-3N4tJWJ/s1600-h/boxplot-case1.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtMpjFGsauvtFmtE0UMBDtBnljXAbVdiZ6CfHrp3RL4r_ReWfwTIHdW4owyjNvPB1mGdY_-FZ_8BpGJ-SuT9ccu8GfPILrZLdGSOyR-JeTnu1-WUOpwtm62ip5Kk6IFHry4GfA-3N4tJWJ/s320/boxplot-case1.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5222961495184869666&quot; /&gt;&lt;/a&gt;
&lt;span style=&quot;font-family: verdana;font-size:100%; color:black;&quot;&gt; 

&lt;br/&gt; Lets also find five number summary for each type using R. Here
is the output of the same:

&lt;span style=&quot;font-family: trebuchet ms; color:#003300; font-size:100%;&quot;&gt;
&lt;pre&gt;
&gt; summary(Calories[HotDog==&#39;Beef&#39;])
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  111.0   140.5   152.5   156.8   177.2   190.0 
&gt; summary(Calories[HotDog==&#39;Meat&#39;])
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  107.0   139.0   153.0   158.7   179.0   195.0 
&gt; summary(Calories[HotDog==&#39;Poul&#39;])
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   86.0   102.0   129.0   122.5   143.0   170.0 
&lt;/pre&gt;&lt;/span&gt; 


Let&#39;s summarize the results we got and interpret them in the context of the question we posed:

By examining the three side-by-side boxplots and the numerical
summaries, we see at once that poultry hotdogs as a group contain
fewer calories than beef or meat. &lt;br/&gt;The median number of calories in
poultry hotdogs (129) is less than the median (and even the first
quartile) of either of the other two distributions (medians 152.5 and
153). &lt;br/&gt;The spread of the three distributions is about the same, if IQR
is considered (all slightly above 40), but the (full) ranges vary
slightly more (beef: 79, meat:88, poultry 84). The general
recommendation to the health conscious consumer is to eat poultry
hotdogs. &lt;br/&gt;It should be noted, though, that since each of the three
types of hotdogs shows quite a large spread among brands, simply
buying a poultry hotdog does not guarantee a low calorie food.


What we learn from this example is that when exploring the
relationship between a categorical explanatory variable and a
quantitative response (Case I), we essentially compare the
distributions of the quantitative response for each category of the
explanatory variable using side-by-side boxplots supplemented by
descriptive statistics. 

&lt;br/&gt;&lt;br/&gt;
So we can safely say, the relationship between a categorical explanatory and a quantitative response variable is summarized using:
&lt;UL&gt;
&lt;LI&gt; Data display: side-by-side boxplots
&lt;LI&gt; Numerical summaries: descriptive statistics
&lt;/UL&gt;

That is we compare the distributions of the quantitative (response) variables for each category (of categorical variable or factors as in R).


&lt;/span&gt;</description><link>https://krishnadagli.blogspot.com/2008/07/learning-statistics-using-r-role-type.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtMpjFGsauvtFmtE0UMBDtBnljXAbVdiZ6CfHrp3RL4r_ReWfwTIHdW4owyjNvPB1mGdY_-FZ_8BpGJ-SuT9ccu8GfPILrZLdGSOyR-JeTnu1-WUOpwtm62ip5Kk6IFHry4GfA-3N4tJWJ/s72-c/boxplot-case1.gif" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-3106257223624592517</guid><pubDate>Tue, 08 Jul 2008 13:39:00 +0000</pubDate><atom:updated>2008-07-08T21:12:42.366+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">R</category><category domain="http://www.blogger.com/atom/ns#">Statistics</category><category domain="http://www.blogger.com/atom/ns#">Tutorial</category><title>Learning Statistics using R: Role-type classification (2 of 2)</title><description>&lt;span style=&quot;font-family: verdana;font-size:100%; color:black;&quot;&gt; 

Lets try few examples from the course web site. In these example we
are presented with a brief description of a study involving two
variables. We are required to determine which of the four cases
represents the data sets of the problem. That is we need to identify
if a variable is Categorical or Quantitative and which variable is
Response and Explanatory variable.

&lt;br/&gt;

&lt;OL&gt;

&lt;LI&gt;A store asked 250 of its customers whether they were satisfied
with the service or not. The purpose of this study was to examine the
relationship between the customer&#39;s satisfaction and gender. 
&lt;br/&gt;
&lt;br/&gt;
In this example, Gender is explanatory variable and Statifaction based
on gender is response variable.  Both these variables are Categorical
and hence this is an example of Case II.

&lt;br/&gt;
&lt;br/&gt;
&lt;LI&gt;A study was conducted in order to explore the relationship between
the number of beers a person drinks, and his/her Blood Alcohol Level
(in %). 

&lt;br/&gt;
In this example; Both the explanatory (number of beers) and response
(BAC) variables are quantitative in this case, and therefore this is
an example of case III. Hence this is an example of case I.  
&lt;br/&gt;
&lt;br/&gt;
&lt;LI&gt;A study was conducted in order to determine whether longevity (how
long a person lives) is somehow related to the person&#39;s handedness
(right-handed/left-handed).

&lt;br/&gt;&lt;br/&gt;

In this case the explanatory variable (handedness) is categorical and
the response variables (longevity) is quantitative. This is, therefore
an example of case I.


&lt;/OL&gt;
&lt;/span&gt;</description><link>https://krishnadagli.blogspot.com/2008/07/test.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-1405178900728433081</guid><pubDate>Tue, 08 Jul 2008 13:27:00 +0000</pubDate><atom:updated>2008-10-02T17:17:07.537+05:30</atom:updated><title>Learning Statistics using R: Data sets used in examples</title><description>The actual data is available from the course website but lately my links to actual data set is not working; perhaps those are changed? I am also not sure on how to upload these data sets on blogger. So I have uploaded a zip file containing all data sets at MegaShare. Here is the link to download file : &lt;a href=&quot;http://www.MegaShare.com/497357&quot;&gt;http://www.MegaShare.com/497357&lt;/a&gt;
(Updated : 01-OCT-2008, size: ~5.2 K)</description><link>https://krishnadagli.blogspot.com/2008/07/learning-statistics-using-r-data-sets.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-9093507304489193197</guid><pubDate>Wed, 18 Jun 2008 17:28:00 +0000</pubDate><atom:updated>2008-09-10T23:18:55.717+05:30</atom:updated><title>Learning Statistics using R: Role-type classification (1 of 2)</title><description>&lt;span style=&quot;font-family: verdana;font-size:100%; color:black;&quot;&gt; 
&lt;strong&gt;&lt;em&gt;Most of the material here is taken from the course website!&lt;/em&gt;&lt;/strong&gt;&lt;br/&gt;

The second module of the course explains the relationship between two
variables. In earlier sections we learned how to work with a
distribution of a single variable, either quantitative or categorical.

&lt;br/&gt;

This section start with Role-Type classification of two variable:In
most studies involving two variables, each of the variables has a
role. We distinguish between:
&lt;UL&gt;
&lt;LI&gt;Response variable: the outcome of study.
&lt;LI&gt;Explanatory varible: the variable that claims to explain, predict or affect the response.
&lt;/UL&gt;

The response variables are also known as &quot;Dependent&quot; variables and the
explanatory variables as &quot;Independent&quot; variables. Dependent variable
depend on the Independent variable and hence the name. A simple
example would be of a function that computes the sum of passed
arguments; in this case arguments (the values whose sum we need to
find) are independent variables while output (sum of these values) is
dependent variable.

&lt;br/&gt; Lets take 8 example from course website to make this clear. We
will be using these examples for further variable type
classification.&lt;br/&gt; 

&lt;OL&gt;

&lt;LI&gt; We want to explore whether the outcome of the study - the score
on a test - is affected by the test-taker&#39;s gender.  Therefore:
&lt;UL&gt;&lt;LI&gt;Gender is the explanatory variable
&lt;LI&gt;Test score is the response variable
&lt;/UL&gt;


&lt;LI&gt;How does the number of calories a hot dog has related to (or
 effected by) the type of hot dog (beef, meat or poultry)?  (in other
 words, are there differences in the number of calories between the
 three type of hot dogs?)
&lt;UL&gt;&lt;LI&gt;Number of calories is response variable
&lt;LI&gt;Type of hot dog is explanatory variable
&lt;/UL&gt;


&lt;LI&gt;In this study we explore whether nearsightedness of a person can
be explained by the type of light that person slept with as a baby.
Therefore:
&lt;UL&gt;&lt;LI&gt;Light Type is the explanatory variable
&lt;LI&gt;Nearsightedness is the response variable
&lt;/UL&gt;

&lt;LI&gt;Are the smoking habits of a person (yes/no) related to the
person&#39;s gender?
&lt;UL&gt;&lt;LI&gt;Gender of person (male/female) is explanatory variable
&lt;LI&gt;Smoking habit is response variable
&lt;/UL&gt;


&lt;LI&gt;Here we are examining whether a student&#39;s SAT score is a good
predictor for the student&#39;s GPA in freshman year.  Therefore:
&lt;UL&gt;&lt;LI&gt;SAT score is the explanatory variable
&lt;LI&gt;GPA of Freshman Year is the response variable
&lt;/UL&gt;

&lt;LI&gt;In an attempt to improve highway safety for older drivers, a
government agency funded a research that explored the relationship
between drivers&#39; age and sign legibility distance (the maximum
distance at which the driver can read a sign).
&lt;UL&gt;&lt;LI&gt;Driver&#39;s age is  the explanatory variable
&lt;LI&gt; Sign legibility distance is response variable
&lt;/UL&gt;

&lt;LI&gt;Here we are examining whether a person&#39;s outcome on the driving test
(pass/fail) can be explained by the length of time this person has
practiced driving prior to the test.  Therefore:
&lt;UL&gt;&lt;LI&gt;Time is the explanatory variable
&lt;LI&gt;Driving Test Outcome is the response variable
&lt;/UL&gt;

&lt;LI&gt;Can you predict a person&#39;s favorite type of music
(Classical/Rock/Jazz) based on his/her IQ level?
&lt;UL&gt;&lt;LI&gt;IQ Level is explanatory variable
&lt;LI&gt;Type of music is response variable
&lt;/UL&gt;
&lt;/OL&gt;
&lt;br/&gt;
&lt;b&gt;
Above examples helps in identifying response and explanatory variable
but is it always clear what is the role classification? In other
words, is it always clear which of the variables is the explanatory
and which is the response?  &lt;br/&gt;

&lt;Big&gt;Answer:&lt;/Big&gt; NO! There are studies in which the role classification
is not really clear.  This mainly happens in cases when both variables
are categorical or both are quantitative.  An example could be a study
that explores the relationship between the SAT Math and SAT Verbal
scores.  In cases like this, any classification choice would be fine
(as long as it is consistent throughout the analysis).&lt;/b&gt;  &lt;br/&gt;&lt;br/&gt;


We know that a variable is either categorical variable or quantitative
variable. We use this information to further classify response and
explanatory variables. With this role-type classification we get
following 4 possibilities:
&lt;OL&gt;
&lt;LI&gt; Case I: Explanatory is Categorical and Response is Quantitative variable.
&lt;LI&gt; Case II: Explanatory is Categorical and Response is Categorical variable.
&lt;LI&gt; Case III:Explanatory is Quantitative and Response is Quantitative variable.
&lt;LI&gt; Case IV: Explanatory is Quantitative and Response Categorical variable.
&lt;/OL&gt;

Following table taken from course web summarizes above 4 cases:
&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwlhknngo-Kqd-cr3DbEa2wRv4cNKORfYr-9GYAbVHAHBuKz8uzP8lFbt_v2WIAwVRYkow8WDwNPMz6wS1kdQtPINuoZ6xTshccFoq4ke0qNtKCkwJIL5muZ7Y8LrNIc5AZY7flVfE2Ht-/s1600-h/relationships_overview1.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwlhknngo-Kqd-cr3DbEa2wRv4cNKORfYr-9GYAbVHAHBuKz8uzP8lFbt_v2WIAwVRYkow8WDwNPMz6wS1kdQtPINuoZ6xTshccFoq4ke0qNtKCkwJIL5muZ7Y8LrNIc5AZY7flVfE2Ht-/s320/relationships_overview1.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5213275882518472418&quot; /&gt;&lt;/a&gt;
&lt;br/&gt;
The couse warns us that this role-type classification serves as the
infrastructure for the entire section. In each of the 4 cases,
different statistical tools (displays and numerical measures) should be
used in order to explore the relationship between the two variables.

&lt;br/&gt;&lt;br/&gt;

Along with this course also suggest us following important rule:

&lt;br/&gt;

&lt;b&gt;Principle:&lt;/b&gt;&lt;br/&gt;
When confronted with a research question that involves exploring the
relationship between two variables, the first and most crucial step is
to determine which of the 4 cases represents the data structure of the
problem. In other words, the first step should be classifying the two
relevant variables according to their role and type, and only then can
we determine the appropriate statistical tools.  &lt;br/&gt;


Lets go back to our 8 examples and try to classify explanatory and
response variables to categorical or quantitative variable. 

&lt;OL&gt;

&lt;LI&gt; We want to explore whether the outcome of the study - the score
on a test - is affected by the test-taker&#39;s gender.  Therefore:
&lt;UL&gt;
&lt;LI&gt;Gender is the explanatory variable and it is categorical variable.
&lt;LI&gt;Test score is the response variable and it is quantitative variable.
&lt;LI&gt; Therefore this is an example of Case I.
&lt;/UL&gt;


&lt;LI&gt;How does the number of calories a hot dog has related to (or
 effected by) the type of hot dog (beef, meat or poultry)?  (in other
 words, are there differences in the number of calories between the
 three type of hot dogs?)
&lt;UL&gt;
&lt;LI&gt;Type of hot dog is explanatory variable and it is categorical variable.
&lt;LI&gt;Number of calories is response variable and it is quantitative variable.
&lt;LI&gt; Therefore this is an example of Case I.
&lt;/UL&gt;


&lt;LI&gt;In this study we explore whether nearsightedness of a person can
be explained by the type of light that person slept with as a baby.
Therefore:
&lt;UL&gt;&lt;LI&gt;Light Type is the explanatory variable and it is categorical variable.
&lt;LI&gt;Nearsightedness is the response variable and it is categorical variable.
&lt;LI&gt; Therefore this is an example of Case II.
&lt;/UL&gt;

&lt;LI&gt;Are the smoking habits of a person (yes/no) related to the
person&#39;s gender?
&lt;UL&gt;
&lt;LI&gt;Gender of person (male/female) is explanatory variable and it is categorical variable.
&lt;LI&gt;Smoking habit is response variable and it is categorical variable.
&lt;LI&gt; Therefore this is an example of Case II.
&lt;/UL&gt;


&lt;LI&gt;Here we are examining whether a student&#39;s SAT score is a good
predictor for the student&#39;s GPA in freshman year.  Therefore:
&lt;UL&gt;
&lt;LI&gt;SAT score is the explanatory variable and it is quantitative variable.
&lt;LI&gt;GPA of Freshman Year is the response variable and it is quantitiative variable.
&lt;LI&gt; Therefore this is an example of Case III.
&lt;/UL&gt;

&lt;LI&gt;In an attempt to improve highway safety for older drivers, a
government agency funded a research that explored the relationship
between drivers&#39; age and sign legibility distance (the maximum
distance at which the driver can read a sign).
&lt;UL&gt;
&lt;LI&gt;Driver&#39;s age is  the explanatory variable and it is quantitiave variable.
&lt;LI&gt;Sign legibility distance is response variable and it is quantitative variable.
&lt;LI&gt; Therefore this is an example of Case III.
&lt;/UL&gt;

&lt;LI&gt;Here we are examining whether a person&#39;s outcome on the driving test
(pass/fail) can be explained by the length of time this person has
practiced driving prior to the test.  Therefore:
&lt;UL&gt;
&lt;LI&gt;Time is the explanatory variable and it is qunatitative variable.
&lt;LI&gt;Driving Test Outcome is the response variable and it is categorical variable.
&lt;LI&gt; Therefore this is an example of Case IV.
&lt;/UL&gt;

&lt;LI&gt;Can you predict a person&#39;s favorite type of music
(Classical/Rock/Jazz) based on his/her IQ level?
&lt;UL&gt;
&lt;LI&gt;IQ Level is explanatory variable and it is quantitiave variable.
&lt;LI&gt;Type of music is response variable and it is categorical variable.
&lt;LI&gt; Therefore this is an example of Case IV.
&lt;/UL&gt;
&lt;/OL&gt;

After this we learn more about role-type classification and which tool
to use in which cases.
&lt;/span&gt;</description><link>https://krishnadagli.blogspot.com/2008/06/learning-statistics-using-r-role-type.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwlhknngo-Kqd-cr3DbEa2wRv4cNKORfYr-9GYAbVHAHBuKz8uzP8lFbt_v2WIAwVRYkow8WDwNPMz6wS1kdQtPINuoZ6xTshccFoq4ke0qNtKCkwJIL5muZ7Y8LrNIc5AZY7flVfE2Ht-/s72-c/relationships_overview1.gif" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-1772632619933075076</guid><pubDate>Mon, 16 Jun 2008 19:30:00 +0000</pubDate><atom:updated>2008-09-10T23:18:31.774+05:30</atom:updated><title>Learning Statistics using R: Rule Of Standard Deviation</title><description>&lt;strong&gt;&lt;em&gt;Most of the material here is taken from the course website!
&lt;/em&gt;&lt;/strong&gt;&lt;br/&gt;

Following explains the rule of standard deviation, also known as The
Empirical Rule. The rule is applied only to normal (symmetric)
data distribution.
&lt;UL&gt;
&lt;LI&gt;Approximately 68% of the observations fall within 1 standard
deviation of the mean.

&lt;LI&gt;Approximately 95% of the observations fall within 2 standard
deviations of the mean.

&lt;LI&gt;Approximately 99.7% (or virtually all) of the observations fall
within 3 standard deviations of the mean.
&lt;/UL&gt;

This rule provides more insights about standard deviation and
following picture taken from course web site illustrates the same rule:

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEik9Vi0L6uRGAtikCC6FGTNOLoXzTcw4_OOzUcU_wVIUWoxa9RfdvgZ_9PADlX7tXrx6mdBb5rpj5gBMBW8_bZAHA9TRkilq5_3SSguBXMMyGV9JQS3S_DGPxPR7FOkyIcgf_DzqZ273JEb/s1600-h/sdgraph2.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEik9Vi0L6uRGAtikCC6FGTNOLoXzTcw4_OOzUcU_wVIUWoxa9RfdvgZ_9PADlX7tXrx6mdBb5rpj5gBMBW8_bZAHA9TRkilq5_3SSguBXMMyGV9JQS3S_DGPxPR7FOkyIcgf_DzqZ273JEb/s320/sdgraph2.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5212913230084116098&quot; /&gt;&lt;/a&gt;

Lets understand this with an example: The following data represents
height data of 50 males. Lets use R to find 5 number summary of these
and to confirm if the distribution is nomal - mound shaped.

&lt;span style=&quot;font-family: trebuchet ms; color:#003300;&quot;&gt;&lt;pre&gt;
# We use &#39;c&#39; command to populate male vector; on which we will carry our operations.
male &lt;- c(64, 66, 66, 67, 67, 67, 67, 68, 68, 68, 68, 68, 68, 69, 69, 69, 69, 69, 70, 70, 70, 70, 70, 70, 70, 71, 71, 71, 71, 71, 71, 71, 72, 72, 72, 72, 72, 72, 73, 73, 73, 74, 74, 74, 74, 74, 75, 76, 76, 77)
&gt; hist(male)
&lt;/pre&gt;&lt;/span&gt;

In above code sample &#39;hist&#39; command draws a histogram that has almost
normal-mound shape. Here is the image that R draws for us.

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOuUNT-IQdu7XGIo4Rf7brkepF9o6hQSlZYWaEcYPvI0babrDuGllbOti8l39MbVroZdQEmuezn1H5cPxp3E9yhZA_AGhnhyphrdfRvvGKdJvKjDOyhbhH2emEz8sK3oPbfLj39bBT9dkx/s1600-h/mail-height.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOuUNT-IQdu7XGIo4Rf7brkepF9o6hQSlZYWaEcYPvI0babrDuGllbOti8l39MbVroZdQEmuezn1H5cPxp3E9yhZA_AGhnhyphrdfRvvGKdJvKjDOyhbhH2emEz8sK3oPbfLj39bBT9dkx/s320/mail-height.png&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5212913475592416498&quot; /&gt;&lt;/a&gt;
&lt;span style=&quot;font-family: verdana;font-size:100%; color:black;&quot;&gt; 

Lets find five number summary and confirm if standard deviation rule
applies correctly to this data set.
&lt;span style=&quot;font-family: trebuchet ms; color:#003300;&quot;&gt;&lt;pre&gt;
# Just a simple summary command gives five point summary
&gt; summary(male)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  64.00   68.25   70.50   70.58   72.00   77.00
&gt; sd(male)
[1] 2.857786
# Lets apply first rule - 68% of data points are within (mean - 1 * SD) and (mean + 1 * SD)
&gt; male &gt;= (mean(male) - (1 * sd(male))) &amp; male &lt;= (mean(male) + (1 * sd(male)))
 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
[13]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[25]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[37]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[49] FALSE FALSE
# above command gives us the indices of male vector as TRUE where our condition satisfies.
# Lets count how many such obervations are there.
&gt; length(male[male &gt;= (mean(male) - (1 * sd(male))) &amp; male &lt;= (mean(male) + (1 * sd(male)))])
[1] 34
# So out of 50 observation 34 observation are with in mean +/- 1 SD. ie.
&gt; 34/50 * 100
[1] 68
# So as rule suggests, 68% observations are with in mean +/- 1 SD.

# Lets check second rule - 95% of data points are within (mean - 2 * SD) and (mean + 2 * SD)
&gt; length(male[male &gt;= (mean(male) - (2 * sd(male))) &amp; male &lt;= (mean(male) + (2 * sd(male)))])
[1] 48
&gt; 48/50 * 100
[1] 96
# So indeed 95% of data points are within mean +/- 2 SD.

# Lets check third rule - 99.7% of data points are within (mean - 3 * SD) and (mean + 3 * SD)
&gt; length(male[male &gt;= (mean(male) - (3 * sd(male))) &amp; male &lt;= (mean(male) + (3 * sd(male)))])
[1] 50
&gt; 50/50*100
[1] 100
# this shows that 99.7% of data points are with in mean +/- 3 SD.
&lt;/pre&gt;&lt;/span&gt;

Following table taken from course website makes this more clear:

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEha7PGmmfCHVI0nLPBvvAZhVfGzWIyQeM4txPCzuAhwiTtGvRlJX3A1tA_TwR6Xkxo5-qGc0XVqnN4KeA6mQmTGJ_ljHFCXAJE7EldWNtV8EdZTrDnvIg53ZgwFZ_XT9Gfrwv46O_W-ktwB/s1600-h/table-male-height.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 20px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEha7PGmmfCHVI0nLPBvvAZhVfGzWIyQeM4txPCzuAhwiTtGvRlJX3A1tA_TwR6Xkxo5-qGc0XVqnN4KeA6mQmTGJ_ljHFCXAJE7EldWNtV8EdZTrDnvIg53ZgwFZ_XT9Gfrwv46O_W-ktwB/s320/table-male-height.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5212913868728805746&quot; /&gt;&lt;/a&gt;

&lt;br/&gt;&lt;Big&gt;Summary:&lt;/Big&gt;&lt;br/&gt;
&lt;UL&gt;
&lt;LI&gt; The standard deviation measures the spread by reporting a typical (average) distance between the data points and their average.
&lt;LI&gt; It is appropriate to use the SD as a measure of spread with the mean as the measure of center.
&lt;LI&gt;Since the mean and standard deviations are highly influenced by extreme observations, they should be used as numerical descriptions of the center and spread only for distributions that are roughly symmetric, and have no outliers.
&lt;LI&gt; For symmetric mound-shaped distributions, the Standard Deviation Rule tells us what percentage of the observations falls within 1, 2, and 3 standard deviations of the mean, and thus provides another way to interpret the standard deviation&#39;s value for distributions of this type.
&lt;/UL&gt;
&lt;/SPAN&gt;</description><link>https://krishnadagli.blogspot.com/2008/06/test-page.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEik9Vi0L6uRGAtikCC6FGTNOLoXzTcw4_OOzUcU_wVIUWoxa9RfdvgZ_9PADlX7tXrx6mdBb5rpj5gBMBW8_bZAHA9TRkilq5_3SSguBXMMyGV9JQS3S_DGPxPR7FOkyIcgf_DzqZ273JEb/s72-c/sdgraph2.gif" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-9039752469689502143</guid><pubDate>Thu, 12 Jun 2008 19:25:00 +0000</pubDate><atom:updated>2008-09-10T23:18:09.161+05:30</atom:updated><title>Learning Statistics using R: Standard Deviation and Histogram</title><description>&lt;span style=&quot;font-family: verdana;font-size:90%; color:black;&quot;&gt; 
&lt;strong&gt;&lt;em&gt;Most of the material here is taken from the course website!
&lt;/em&gt;&lt;/strong&gt;&lt;br/&gt;

In following example we will see how histogram can help us to clarify
the concept of Standard Deviation.
&lt;br/&gt;

&lt;strong&gt;Example:&lt;/strong&gt;&lt;br/&gt;

At the end of a statistics course, the 27 students in the class were
asked to rate the instructor on a number scale of 1 to 9 (1 being
&quot;very poor&quot;, and 9 being &quot;best instrctor I&#39;ve ever had&quot;).  The
following table provides three hypothetical rating data:
&lt;br/&gt;

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwX4LzJjtkS8kNBhvqy8Du0G2AYIzyYwEutsJ2Z2WOmiaxZ8E4nUlyqyvWObwUUACqPWBnOCIuJ1OC472QLFUYLFVY5ZIepT-ej6WYHQWfa4eqckQ5HdxU3LxPpC9EAem2Nvto27hLc1hf/s1600-h/deviationexample.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwX4LzJjtkS8kNBhvqy8Du0G2AYIzyYwEutsJ2Z2WOmiaxZ8E4nUlyqyvWObwUUACqPWBnOCIuJ1OC472QLFUYLFVY5ZIepT-ej6WYHQWfa4eqckQ5HdxU3LxPpC9EAem2Nvto27hLc1hf/s320/deviationexample.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5211079054891555058&quot; /&gt;&lt;/a&gt;

Following are the histogram of data of each class:&lt;br/&gt;

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijvX0FutsEo1ms9sqvAAQnIG4WfH0F7MZHAnHlh7k5vbVeakayDLYV1qsYMFeKsiqrAIiyYdbCgyakSRTUuZVRDN9fzrY1ZiFu5QcNnRQg6BX6u1S8akpNkUXrow9ElkSiiY3ZxD993K4_/s1600-h/class1.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijvX0FutsEo1ms9sqvAAQnIG4WfH0F7MZHAnHlh7k5vbVeakayDLYV1qsYMFeKsiqrAIiyYdbCgyakSRTUuZVRDN9fzrY1ZiFu5QcNnRQg6BX6u1S8akpNkUXrow9ElkSiiY3ZxD993K4_/s320/class1.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5211079296758458386&quot; /&gt;&lt;/a&gt;


&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQfrtYs4NcSYcGnx2rQkRzYaNRahfWS7-YMR2HHTdOJZriEk9zjkEnix4pF2v15ukKguh5QwV7ZmAjc_rrX2Qj0WZw_4aWMGn9jU5lnF2bJ47_Cb7WirTV61aJlIvNqXGUf_dOekqcG6C5/s1600-h/class2.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQfrtYs4NcSYcGnx2rQkRzYaNRahfWS7-YMR2HHTdOJZriEk9zjkEnix4pF2v15ukKguh5QwV7ZmAjc_rrX2Qj0WZw_4aWMGn9jU5lnF2bJ47_Cb7WirTV61aJlIvNqXGUf_dOekqcG6C5/s320/class2.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5211079479879214130&quot; /&gt;&lt;/a&gt;


&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0kSnPfWSzGKJOYGoHZGJcwcG07QI0H6kAxl0d5w5ruoub8iCAF3_86ED_XmPR5hgb5miiBO0-RxgfgNKvB7nCffu_Mt5nJDitlUkZUc2M-VapfmQTGwwx4N3EYbF2JfDGU9hwXXP4C6qX/s1600-h/class3.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0kSnPfWSzGKJOYGoHZGJcwcG07QI0H6kAxl0d5w5ruoub8iCAF3_86ED_XmPR5hgb5miiBO0-RxgfgNKvB7nCffu_Mt5nJDitlUkZUc2M-VapfmQTGwwx4N3EYbF2JfDGU9hwXXP4C6qX/s320/class3.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5211079666811022082&quot; /&gt;&lt;/a&gt;


What can we say about standard deviation by looking at these histogram and
data set? &lt;br/&gt;

Lets assume that the mean of all three data set is 5 (which is
reasonable clear by looking at histograms) and we know (roughly) that
standard deviation is average distance of all data points from their
mean.

&lt;UL&gt;

&lt;LI&gt;For class I histogram most of the ratings are at 5 which is also
the mean of the data set. So the average distance between mean and
data points would be very small (since most of the data points are at
mean).

&lt;LI&gt;For class II histogram most of the ratings are at far points from
mean - 5. In this case most of the data points are at two extrems at 1
and 9. So the average distance between mean and data points would be
larger.

&lt;LI&gt;For class III histgram data points are evenly distributed around
mean. We can safely say that in this case the average distance between
mean and data points would be greater than that of class I but smaller
than that of class II. ie. in-between class I and class II standard
deviation.

&lt;/UL&gt;
&lt;br/&gt; 

Lets check our assumption by loading these data set into R and
verifying standard deviation of each. The excel contained data set can be downloaded from &lt;a href=&quot;https://oli.web.cmu.edu/repository/webcontent/859044f080020c690045b50e228faf24/_u2_summarizing_data/webcontent/excel/sdintuition.xls&quot;&gt;here.&lt;/a&gt;

&lt;span style=&quot;font-family: trebuchet ms; color:#003300;&quot;&gt;&lt;pre&gt;
&gt; class1 &lt;- c(1,1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,9,9)
&gt; sd(class1)
[1] 1.568929
&gt; summary(class1)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
      1       5       5       5       5       9 

&gt; class2 &lt;- c(1,1,1,1,1,1,1,1,1,1,1,1,1,5,9,9,9,9,9,9,9,9,9,9,9,9,9)
&gt; sd(class2)
[1] 4
&gt; summary(class2)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
      1       1       5       5       9       9 

&gt; class3 &lt;- c(1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9)
&gt; sd(class3)
[1] 2.631174
&gt; summary(class3)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
      1       3       5       5       7       9 
&lt;/pre&gt;
&lt;/span&gt;

So we have following standard deviation for our 3 class ratings
&lt;UL&gt;
&lt;LI&gt;Class I   : 1.568929
&lt;LI&gt;Class II  : 4.0
&lt;LI&gt;Class III : 2.631174 
&lt;/UL&gt;

(Note that excel may vary a bit in results of standard deviation if you are using
stdev function.)  So calculated standard deviation confirm our
assumption that we made by looking at histograms. 
&lt;/span&gt;</description><link>https://krishnadagli.blogspot.com/2008/06/learning-statistics-using-r-standard_13.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwX4LzJjtkS8kNBhvqy8Du0G2AYIzyYwEutsJ2Z2WOmiaxZ8E4nUlyqyvWObwUUACqPWBnOCIuJ1OC472QLFUYLFVY5ZIepT-ej6WYHQWfa4eqckQ5HdxU3LxPpC9EAem2Nvto27hLc1hf/s72-c/deviationexample.gif" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-5147010870913321586</guid><pubDate>Wed, 04 Jun 2008 18:20:00 +0000</pubDate><atom:updated>2008-09-10T23:17:48.408+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Course</category><category domain="http://www.blogger.com/atom/ns#">R</category><category domain="http://www.blogger.com/atom/ns#">Statistics</category><category domain="http://www.blogger.com/atom/ns#">Tutorial</category><title>Learning Statistics using R: Standard Deviation</title><description>&lt;span style=&quot;font-family: verdana;font-size:90%; color:black;&quot;&gt; 

&lt;strong&gt;&lt;em&gt;Most of the material here is taken from the course website!&lt;/em&gt;&lt;/strong&gt;&lt;br/&gt;


Earlier we examined measure of spread using Range(max - min) and
IQR(the range covered by middle 50% data). We also noted that IQR
should be used when median is used as measure of center. Now we move
to another measure of spread called standard deviation.  

&lt;br/&gt;&lt;br/&gt;

The idea behind standard deviation is to quantify the spread of
distribution by measuring how far the observations are from mean of
distribution. That is how distant observations are located from the
mean of all observations. The standard deviation gives average (or
typical distance) between an observation/data point and the mean,
X-bar.
&lt;br/&gt;&lt;br/&gt;

Lets understand standard deviation using an example; we calculate
standard deviation step by step using R commands. (There is a single R
function to do the same!)
&lt;br/&gt;
Assume we have following data set of 8 observations: &lt;br/&gt;

      7, 9, 5, 13, 3, 11, 15, 9
&lt;UL&gt;
&lt;LI&gt;Calculate mean: &lt;br/&gt;
We use R&#39;s &#39;c&#39; function to combine them in a vector and then use mean
function to calculate mean of the data set.

&lt;span style=&quot;font-family: trebuchet ms; color:#003300; font-size:100%; weight:bold&quot;&gt;&lt;pre&gt;
&gt; dataset &lt;- c(7, 9, 5, 13, 3, 11, 15, 9)
&gt; is.vector(dataset)
[1] TRUE
# we have stored our observation in a vector called dataset
&gt; mean(dataset)
[1] 9
# so we have 9 as the mean of our data set; now we need to find
# distance of each observation from this value : 9.
&gt; deviation &lt;- c (dataset - 9)
&gt; deviation
[1] -2  0 -4  4 -6  2  6  0
# above command directly gives us deviation of each observation from 
# the mean; that we have stored in another vector called deviation.
&lt;/pre&gt;&lt;/span&gt;

&lt;strong&gt; Thinking about the idea behind the standard deviation being
an average (typical) distance between the data points and their mean,
it will make sense to average the deviations we got.  Note, however,
that the sum of the deviations from the mean is always 0.  &lt;/strong&gt;

&lt;br/&gt;&lt;br/&gt;
&lt;LI&gt; Square of deviation:&lt;br/&gt;

So we square each of the deviation and then take its average;
which following R code does:&lt;br/&gt;

&lt;span style=&quot;font-family: trebuchet ms; color:#003300;font-size:100%; weight:bold&quot;&gt;&lt;pre&gt;
# we can use either of following two methods to calculate square of
# deviations.
&gt; deviation ^ 2
[1]  4  0 16 16 36  4 36  0

&gt; deviation * deviation
[1]  4  0 16 16 36  4 36  0
&lt;/pre&gt;&lt;/span&gt;


&lt;LI&gt;Average the square deviations by adding them up, and dividing by
n-1, (one less than the sample size): Lets do that in R.


&lt;span style=&quot;font-family: trebuchet ms; color:#003300; font-size:100%; weight:bold&quot;&gt;&lt;pre&gt;
&gt; (sum(deviation ^ 2)) / (length(dataset) - 1)
[1] 16
&lt;/pre&gt;&lt;/span&gt;

&lt;Big&gt;This average of the squared deviations is called the variance of the data.&lt;/big&gt;
&lt;br/&gt;&lt;br/&gt;

&lt;LI&gt; Find standard deviation:&lt;br/&gt; 
The standard deviation of the data is the square root of the
variance. So in our case it would be square root of 16.
&lt;span style=&quot;font-family: trebuchet ms; color:#003300; font-size:100%; weight:bold&quot;&gt;&lt;pre&gt;
&gt;sqrt(16)
[1] 4
&lt;/pre&gt;&lt;/span&gt;

Why do we take the square root? Note that 16 is an average of the
squared deviations, and therfore has different units of
measurement. In this case 16 is measured in &quot;squared deviation&quot;, which
obviously cannot be interpreted. We therefore, take the square root in
order to compensate for the fact that we squared our deviations, and
in order to go back to the original units of measurement.
&lt;/UL&gt;

&lt;br/&gt;
&lt;Big&gt;&lt;strong&gt;Properties of the Standard Deviation:&lt;/strong&gt;&lt;/Big&gt;
&lt;OL&gt;
&lt;LI&gt;
It should be clear from the discussion thus far that the standard
deviation should be paired as a measure of spread with the mean as a
measure of center.

&lt;LI&gt; Note that the only way, mathematically, in which the standard
deviation = 0, is when all the observations have the same value.
Indeed in this case not only the standard deviation is 0, but also the
range and the IQR are 0.

&lt;LI&gt;Like the mean, the SD is strongly influenced by outliers in the
data. Consider our last example: 3, 5, 7, 9, 9, 11, 13, 15 (data
ordered). If the largest observation was wrongly recorded as 150,
then: the average would jump up to 25.9, and the standard deviation
jumps up to 50.3 Note that in this simple example it is easy to see
that while the standard is strongly influenced by outliers, the IQR is
not! In both cases, the IQR will be the same since, like the median,
the calculation of the quartiles depends only on the order of the data
rather than the actual values.
&lt;/OL&gt;
&lt;br/&gt;

&lt;Big&gt;&lt;Strong&gt;Choosing Numerical Summaries&lt;/strong&gt;&lt;/big&gt;&lt;br/&gt;

&lt;UL&gt;
&lt;LI&gt;Use mean and the standard deviation as measures of center and spread
only for reasonably symmetric distributions with no outliers.

&lt;LI&gt;Use the five-number summary (which gives the median, IQR and
range) for all other cases.  &lt;/UL&gt; 

&lt;Big&gt;&lt;strong&gt;R function for Standard Deviation:&lt;/strong&gt;&lt;/Big&gt;
There is a single R function &quot;sd&quot; that calculates Standard Deviation of dataset, just be careful to use &quot;na.rm=TRUE&quot; argument if you have NA values in your dataset. This function would return vector of SD of columns if dataset is dataframe or matrix. Remember its column&#39;s SD and not rows by default.

&lt;/span&gt;</description><link>https://krishnadagli.blogspot.com/2008/06/learning-statistics-using-r-standard.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-2483845856320614320</guid><pubDate>Tue, 13 May 2008 16:35:00 +0000</pubDate><atom:updated>2009-01-07T22:08:28.085+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Course</category><category domain="http://www.blogger.com/atom/ns#">R</category><category domain="http://www.blogger.com/atom/ns#">Statistics</category><category domain="http://www.blogger.com/atom/ns#">Tutorial</category><title>Learning Statistics using R: Five Number Summary</title><description>&lt;span style=&quot;font-family: verdana;font-size:90%; color:black;&quot;&gt; 

&lt;strong&gt;&lt;em&gt;Most of the material here is taken from the course website!
 &lt;/em&gt;&lt;/strong&gt;&lt;br/&gt;

Before we go ahead and learn how graphical representation of Five
Number Summary, let check out few intersting course problems. &lt;br/&gt;

Here they are:&lt;br/&gt;

&lt;OL&gt;
&lt;LI&gt;Example 1: A survey taken of 140 sports fans asked the question:
&quot;What is the most you have ever spent for a ticket to a sporting
event?&quot;&lt;br/&gt;

The five-number summary for the data collected is: &lt;br/&gt;

min = 85 Q1 =130 median = 145 Q3 = 150 max = 250  &lt;br/&gt;

Should the smallest observation be classified as an outlier?

&lt;LI&gt; Example 2: A survey taken in a large statistics class contained
the question: &quot;What&#39;s the fastest you have driven a car (in mph)?&quot; &lt;br/&gt;

The five-number summary for the 87 males surveyed is: &lt;br/&gt;
min=55    Q1=95    Median=110     Q3=120     Max=155 &lt;br/&gt;

Should the largest observation in this data set be classified as an
outlier?

&lt;/OL&gt;
&lt;br/&gt;

&lt;Big&gt;Important Summary About Spread &lt;/Big&gt;
&lt;UL&gt;
&lt;LI&gt; The range covered by the data is the most intuitive measure of
spread and is exactly the distance between the smallest data point -
min and the largest one - Max.

&lt;LI&gt;Another measure of spread is the inter-quartile range (IQR) which is
the range covered by the middle 50% of the data.

&lt;LI&gt;IQR = Q3-Q1, the difference between the third and first
quartiles. The first quartile (Q1) is the value such that one quarter
(25%) of the data points fall below it. The third quartile is the
value such that three quarters (75%) of the data points fall below it.

&lt;LI&gt;The IQR should be used as a measure of spread of a distribution
only when the median is used as a measure of center.

&lt;LI&gt;The IQR can be used to detect outliers using the 1.5 * IQR (1.5 times
IQR) criterion.
&lt;/UL&gt;
&lt;br/&gt;

&lt;em&gt;&lt;Strong&gt;Five Number Summary:&lt;/strong&gt;&lt;/em&gt;
So far, in our discussion about measures of spread, the key players were:&lt;br/&gt;
&lt;UL&gt;
&lt;LI&gt;The extremes (min and Max) which provide the range covered by
all the data, and

&lt;LI&gt;The quartiles (Q1, M and Q3), which together provide the IQR, the
range covered by the middle 50% of the data.
&lt;/UL&gt;
The combination of all five numbers (min, Q1, M, Q3, Max) is
called the five number summary, and provides a quick numerical
description of both the center and spread of a distribution.
&lt;br/&gt;
&lt;strong&gt;Boxplot&lt;/strong&gt; can be used for graphically summarizing these five
number summary of the distribution of a quantitative. Lets start doing boxplots in R.

&lt;br/&gt;&lt;br&gt;
&lt;Big&gt;Example: Best Actor Oscar Winners:&lt;/big&gt;&lt;br/&gt;
This time we use best actor Oscar winners instead of actress and draw a boxplot using R.
&lt;span style=&quot;font-family: trebuchet ms; color:#003300;&quot;&gt;
&lt;pre&gt;
# read the actor.csv file.
&gt;actor&lt;-read.csv(&quot;actor.csv&quot;, header=T, sep=&quot;,&quot;)
&gt; attach(actor)
&gt;boxplot(Age, border=c(&#39;blue&#39;), xlab=&#39;Actor Age&#39;)
&lt;/pre&gt;&lt;/span&gt;
Here is how our boxplot of actor data set looks:&lt;br/&gt;
&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfVOGpZG7UyjAFch5fVwjRaJC9JZsuKe7x3U6Lcefrx2D9RkDpLZ0Frl-QXsrHw-KWrYTKn2EhyKCq24VqqBdRle811i2VTMSzbfI7A6x2HwOCR-DOykeCDANesk53kycEd02P28dViJ-3/s1600-h/a.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfVOGpZG7UyjAFch5fVwjRaJC9JZsuKe7x3U6Lcefrx2D9RkDpLZ0Frl-QXsrHw-KWrYTKn2EhyKCq24VqqBdRle811i2VTMSzbfI7A6x2HwOCR-DOykeCDANesk53kycEd02P28dViJ-3/s320/a.png&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5199915251156857842&quot; /&gt;&lt;/a&gt;


The boxplot graphically represents the distribution of a quantitative variable by visually 
displaying the five number summary and any observation that was classified as a suspected
outlier using the 1.5(IQR) criterion.
&lt;br/&gt;&lt;br/&gt;
&lt;Big&gt;Example: Best Actress Oscar Winners:&lt;/big&gt;&lt;br/&gt;
We use our actress data set again to draw another box plot:
&lt;span style=&quot;font-family: trebuchet ms; color:#003300;&quot;&gt;
&lt;pre&gt;
# read the actress.csv file.
&gt;actress&lt;-read.csv(&quot;actress.csv&quot;, header=T, sep=&quot;,&quot;)
&gt; attach(actress)
&gt; boxplot(Age, border=c(&#39;magenta&#39;), xlab=&#39;Actress Age&#39;)
&lt;/pre&gt;&lt;/span&gt;

Here is how our actress box plot looks drawn using R:
&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiy-mbxgtYeiDkmn9UtsVPvI7ujwAlIBI5L5Rt0hQmLSfX7MwY2cjSmWfB3XNZgn4QQ4wBoCIgolW9a2BzqgcCyRUtrCMoP5ON9TfZFvNiwKZDk20RvK-HVYvdgGX9-I6XDC4F2vDuPJGTW/s1600-h/actressbox.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiy-mbxgtYeiDkmn9UtsVPvI7ujwAlIBI5L5Rt0hQmLSfX7MwY2cjSmWfB3XNZgn4QQ4wBoCIgolW9a2BzqgcCyRUtrCMoP5ON9TfZFvNiwKZDk20RvK-HVYvdgGX9-I6XDC4F2vDuPJGTW/s320/actressbox.png&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5199921238341268514&quot; /&gt;&lt;/a&gt;

&lt;Big&gt;Following graph taken from the course website highlights various details of boxplot done for actress data set.&lt;/Big&gt;

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWQCWSWRkxxg4ibEBeZJLxVn_s1dXY32PnRwD63AjMCXhXe08Otwt5AOMRUzkjrKhRmiAIEP3qo_IchDs6-uMv2V-k_LSkPj39gTDiAjep3hCSc8nryexNHHEL7bFqeqHrwCfea9s_wD4_/s1600-h/boxplot6.gif&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWQCWSWRkxxg4ibEBeZJLxVn_s1dXY32PnRwD63AjMCXhXe08Otwt5AOMRUzkjrKhRmiAIEP3qo_IchDs6-uMv2V-k_LSkPj39gTDiAjep3hCSc8nryexNHHEL7bFqeqHrwCfea9s_wD4_/s320/boxplot6.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5199920349283038210&quot; /&gt;&lt;/a&gt;

There are &lt;a href=”https://oli.web.cmu.edu/jcourse/workbook/activity/page?context=859d4ac480020c6900ccc10e7813a437”&gt;couple of interactive examples&lt;/a&gt; of boxplot at course website, try doing them.

&lt;br/&gt;&lt;br/&gt;

&lt;big&gt;Example: Best Actress and Actor Oscar Winners: Side by Side Comparative Boxplots.&lt;/big&gt;

So far we have examined the age distributions of Oscar winners for males and females separately.
It will be interesting to compare the age distributions of actors and actresses who won the best acting Oscar. To do that we will look at side-by-side boxplots of the age distributions by gender. 
&lt;br/&gt;
Its quite easy to do side by side boxplots in R. Following code shows how to do it:
&lt;span style=&quot;font-family: trebuchet ms; color:#003300;&quot;&gt;
&lt;pre&gt;
# read the actor.csv file.
&gt;actor &lt;-read.csv(&quot;actor.csv&quot;, header=T, sep=&quot;,&quot;)
&gt;actress &lt;-read.csv(&quot;actress.csv&quot;, header=T, sep=&quot;,&quot;)
# Following is one single command 
# Bug-Fix: Gabriele Righetti 
&gt; boxplot(actor$Age, actress$Age, border=c(&#39;blue&#39;,&#39;magenta&#39;), names=c(&#39;Actor&#39;,&#39;Actress&#39;), ylab=&#39;Age&#39;,main=&#39;Side-By-Side (Comparative) Boxplots\nAge of Best Actor/Actress Winners (1970-2001)&#39;)
&gt;
&lt;/pre&gt;&lt;/span&gt;
This is how our final output from R look:
&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZADgiMxitfUuMUjhfwwhjQSn4qavIx0LOryZ07uxNheBf7QmHTMAWK6fVyoC5cUl2zqLg-rilvcQTy-2dswx51yjlITL3V5t7dyqEBwRKOBOBUGkzoOKclGgg3WKXvYn4Mbp1SY7sDoTh/s1600-h/sidebyside.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZADgiMxitfUuMUjhfwwhjQSn4qavIx0LOryZ07uxNheBf7QmHTMAWK6fVyoC5cUl2zqLg-rilvcQTy-2dswx51yjlITL3V5t7dyqEBwRKOBOBUGkzoOKclGgg3WKXvYn4Mbp1SY7sDoTh/s320/sidebyside.png&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5199920692880421906&quot; /&gt;&lt;/a&gt;

&lt;br/&gt;
Recall also that we found the five-number summary and means for both distributions: 
&lt;UL&gt;&lt;LI&gt;Actors: min=31, Q1=37.25, M=42.5, Q3=50.25, Max=76 
&lt;LI&gt; Actresses: min=21, Q1=32, M=35, Q3=41.5, Max 80
&lt;/UL&gt;
Based on the graph and numerical measures, we can make the following comparison between the two distributions:&lt;br&gt;
&lt;UL&gt;&lt;LI&gt;Center: The graph reveals that the age distribution of the males is higher than the females&#39; age distribution. This is supported by the numerical measures. The median age for females (35) is lower than for the males (42.5). Actually, it should be noted that even the third quartile of the females&#39; distribution (41.5) is lower than the median age for males. We therefore conclude that in general, actresses win the Best Actress Oscar at a younger age than the actors do. 
&lt;LI&gt;Spread: Judging by the range of the data, there is much more variability in the females&#39; distribution (range=59) than there is in the males&#39; distribution (range=35). On the other hand, if we look at the IQR, which measures the variability only among the middle 50% of the distribution, we see more spread among males (IQR=13) than the females (IQR=9.5). We conclude that among all the winners, the actors&#39; ages are more alike than the actresses&#39; ages. However, the middle 50% of the age distribution of actresses is more homogeneous than the actors&#39; age distribution. 
&lt;LI&gt;Outliers: We see that we have outliers in both distributions. There is only one high outlier in the actors&#39; distribution (76, Henry Fonda, On Golden Pond), compared with three high outliers in the actresses&#39; distribution. 
&lt;/UL&gt;


&lt;/span&gt;</description><link>https://krishnadagli.blogspot.com/2008/05/learning-statistics-using-r-five-number.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfVOGpZG7UyjAFch5fVwjRaJC9JZsuKe7x3U6Lcefrx2D9RkDpLZ0Frl-QXsrHw-KWrYTKn2EhyKCq24VqqBdRle811i2VTMSzbfI7A6x2HwOCR-DOykeCDANesk53kycEd02P28dViJ-3/s72-c/a.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-2038479353753138028</guid><pubDate>Mon, 05 May 2008 13:59:00 +0000</pubDate><atom:updated>2008-05-05T20:07:43.637+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">NASA</category><category domain="http://www.blogger.com/atom/ns#">SPACE</category><title>Send Your Name to the Moon</title><description>&lt;p&gt;NASA invites people of all ages to join the lunar exploration journey with an opportunity to &lt;a href=&quot;http://lro.jhuapl.edu/NameToMoon/index.php&quot;&gt;send their names to the moon&lt;/a&gt; aboard the Lunar Reconnaissance Orbiter, or LRO, spacecraft.
&lt;/p&gt;
&lt;center&gt;&lt;Strong&gt;Here is my certificate of participation!&lt;/strong&gt;&lt;/center&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-clodMWpG8zalr-axJaD9xKXxKhTc7tQtg2y69KPGJz4vQErE9fnwoLFZ1_lxfRJP1gQEvAqhzeevrs43BknQoF-h1d9LvMZa1_yThaO70_nnItN9Q_lt_6Gugbg4iy8KjYenNT2mSFso/s1600-h/mymoon.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-clodMWpG8zalr-axJaD9xKXxKhTc7tQtg2y69KPGJz4vQErE9fnwoLFZ1_lxfRJP1gQEvAqhzeevrs43BknQoF-h1d9LvMZa1_yThaO70_nnItN9Q_lt_6Gugbg4iy8KjYenNT2mSFso/s400/mymoon.png&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5196902140943165762&quot; /&gt;&lt;/a&gt;
&lt;br/&gt;</description><link>https://krishnadagli.blogspot.com/2008/05/send-your-name-to-moon.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-clodMWpG8zalr-axJaD9xKXxKhTc7tQtg2y69KPGJz4vQErE9fnwoLFZ1_lxfRJP1gQEvAqhzeevrs43BknQoF-h1d9LvMZa1_yThaO70_nnItN9Q_lt_6Gugbg4iy8KjYenNT2mSFso/s72-c/mymoon.png" height="72" width="72"/><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-6489331505066969072</guid><pubDate>Sat, 03 May 2008 18:46:00 +0000</pubDate><atom:updated>2008-09-10T23:17:07.176+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Course</category><category domain="http://www.blogger.com/atom/ns#">R</category><category domain="http://www.blogger.com/atom/ns#">Statistics</category><category domain="http://www.blogger.com/atom/ns#">Tutorial</category><title>Learning Statistics using R:Detecting Outliers with IQR</title><description>&lt;span style=&quot;font-family: verdana;font-size:90%; color:black;&quot;&gt; 

&lt;strong&gt;&lt;em&gt;Most of the material here is taken from the course website!
&lt;/em&gt;&lt;/strong&gt;&lt;br/&gt;

An Outlier is an observation/data-point in set of observations (data
set) that is far removed in values from other observations.  An
outlier is either very large or very small value and as noted earlier
affects the mean of the data set. More about Outlier is &lt;a
href=&quot;http://en.wikipedia.org/wiki/Outlier&quot;&gt;here.&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;

&lt;strong&gt;The (1.5 * IQR) criteria for finding outliers (1.5 times IQR):&lt;/strong&gt;&lt;br/&gt;
An observation is suspected outliers if it is:&lt;br/&gt;
&lt;OL&gt;
&lt;LI&gt;Below Q1 - (1.5 * IQR): that is Q1 minus 1.5 times IQR.
&lt;LI&gt;Above Q3 + (1.5 * IQR): that is Q2 minus 1.5 times IQR.
&lt;/OL&gt;
&lt;br/&gt;
The following picture illustrates the 1.5 * IQR rule:
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7eDTPxtW5aIJ-woNG4mfvF0kpTiOUhqiuYJDNOA7QwvVILggs8Q4ZbQATK_dYjVtXq7zO5NYZuLloZ1pdrrgySjVfVNjnV3TGOFQjjWvfrxMOSHcA2x0o4BUlbNjo9mIEbJIUZNW_e6L5/s1600-h/IQR-Outlier.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7eDTPxtW5aIJ-woNG4mfvF0kpTiOUhqiuYJDNOA7QwvVILggs8Q4ZbQATK_dYjVtXq7zO5NYZuLloZ1pdrrgySjVfVNjnV3TGOFQjjWvfrxMOSHcA2x0o4BUlbNjo9mIEbJIUZNW_e6L5/s320/IQR-Outlier.png&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5196226993559071026&quot; /&gt;&lt;/a&gt;
&lt;br/&gt;

&lt;big&gt;Example: Best Actress Oscar Winners:&lt;/big&gt;&lt;br/&gt; 
We continue with our Best Actress Oscar winner data set.  Here we will
try to locate names of actress whose age is beyond the 1.5 * IQR
range.
&lt;span style=&quot;font-family: trebuchet ms; color:#003300; font-size:100%; font-weight:bold;&quot;&gt;
&lt;pre&gt;
# we have data in &#39;actress&#39; data frame; just check the quantile
&gt; quantile(Age, names=T)   
0%   25%   50%   75%  100% 
21.00 32.50 35.00 41.25 80.00 

# Lets check the IQR 
&gt; IQR(Age)
[1] 8.75

# Now lets see how to retrieve value for Q1 - First quantile
&gt; quantile(Age,0.25) 
25% 32.5

# (Is this correct method?)
# As can be seen above passing a value 0.25 returns value of the first quantile. 
# now lets see what is the value for Q1 - (1.5 * IQR)
&gt;quantile(Age, 0.25) - (IQR(Age) * 1.5) 
  25% 19.375
# Okay so this also works!

# now how do we get names of all actress whose age is less than 19.375?
&gt;which(Age &lt; (quantile(Age, 0.25) - IQR(Age) * 1.5))
integer(0)
# So in our data set there is no actress whose age is less than 19.375 since the smallest is of age 21!

# now lets try to find upper/higher suspected outliers. 
# Remember its Q3 + (IQR * 1.5)
&gt;quantile(Age,0.75) + (IQR(Age) * 1.5) 
  75% 
54.375

# Okay so far so good; lets get age that are greater than 54.375
&gt; Age &gt; quantile(Age,0.75) + (IQR(Age) * 1.5 ) 
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE
[13] FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
[25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE

# See it returns TRUE in the indices where our condition matches.

&gt; which(Age &gt; quantile(Age,0.75) + (IQR(Age) * 1.5 ))
[1] 12 16 20
# which command returns the same but actual index number; but how do we get names?

&gt; actress[which(Age &gt; quantile(Age,0.75) + (IQR(Age) * 1.5 )),]   
    Year      Name                   Movie              Age
12 1981   Kathryn Hepburn    On Golden Pond             74
16 1985   Geraldine Page     A Trip to the Bountiful    61
20 1989   Jessica Tandy      Driving Miss Daisy         80

# so the comma (,) at the end does the trick. Lets try to do without &quot;which&quot; command.


&gt;actress[ Age &gt; (quantile(Age,.75, names=T) + (IQR(Age) * 1.5)),]  
    Year      Name                   Movie              Age
12 1981   Kathryn Hepburn    On Golden Pond             74
16 1985   Geraldine Page     A Trip to the Bountiful    61
20 1989   Jessica Tandy      Driving Miss Daisy         80

# so finally we got suspected outliers!
&lt;/pre&gt;
&lt;/span&gt;

&lt;strong&gt;&lt;em&gt;Other methods:&lt;/em&gt;&lt;/strong&gt;&lt;br/&gt;
We can draw boxplot to visually detect outliers. (But following does not seem that helpful?)

&lt;span style=&quot;font-family: trebuchet ms; color:#003300; font-size:100%; font-weight:bold;&quot;&gt;&lt;pre&gt;

&gt; boxplot(Age)
# or
&gt; plot(lm(Age ~ 1))
# or using library car
&gt; library(&quot;car&quot;)
&gt; outlier.test(lm(Age ~ 1))

max|rstudent| = 3.943262, degrees of freedom = 30,
unadjusted p = 0.0004461754, Bonferroni p = 0.01427761

Observation: 20
&lt;/pre&gt;&lt;/span&gt;






&lt;/span&gt;</description><link>https://krishnadagli.blogspot.com/2008/05/learning-statistics-using-rdetecting.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7eDTPxtW5aIJ-woNG4mfvF0kpTiOUhqiuYJDNOA7QwvVILggs8Q4ZbQATK_dYjVtXq7zO5NYZuLloZ1pdrrgySjVfVNjnV3TGOFQjjWvfrxMOSHcA2x0o4BUlbNjo9mIEbJIUZNW_e6L5/s72-c/IQR-Outlier.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-8817983702844087404</guid><pubDate>Fri, 02 May 2008 17:04:00 +0000</pubDate><atom:updated>2008-05-02T23:11:17.704+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Course</category><category domain="http://www.blogger.com/atom/ns#">R</category><category domain="http://www.blogger.com/atom/ns#">Statistics</category><category domain="http://www.blogger.com/atom/ns#">Tutorial</category><title>Learning Statistics using R: IQR</title><description>&lt;span style=&quot;font-family: verdana;font-size:90%; color:black;&quot;&gt;
&lt;strong&gt;&lt;em&gt;I am including the notes from the course itself. None of material is
mine other than errors! &lt;/em&gt;&lt;/strong&gt;&lt;br/&gt;
As seen earlier range gives us over all range of the
distribution while IQR measures the spread of distribution by giving
us the range covered by the middle 50% of the data.
&lt;br/&gt;
The &lt;a
href=https://oli.web.cmu.edu/repository/webcontent/859044f080020c690045b50e228faf24/_u2_summarizing_data/_m1_examining_distributions/webcontent/spread2.gif&gt;
picture &lt;/a&gt; taken from course website makes it more clear.

&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9ymba-vCdUmX2RRwdI_0fN21EMwI0PuFNdO8P7krntaduuF9CefGMyjK7TQUT2ezYGn5byj5AP9qymb_yEDjTrrvBlB1Wy6zGxQ3iSsPaZKJVX41Jw5ilA7gGC0jtEGlBuIw3-mRjEOyq/s1600-h/IQR-1.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9ymba-vCdUmX2RRwdI_0fN21EMwI0PuFNdO8P7krntaduuF9CefGMyjK7TQUT2ezYGn5byj5AP9qymb_yEDjTrrvBlB1Wy6zGxQ3iSsPaZKJVX41Jw5ilA7gGC0jtEGlBuIw3-mRjEOyq/s320/IQR-1.png&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5195833054863714514&quot; /&gt;&lt;/a&gt;
&lt;br/&gt; 
Here is how course suggest on finding IQR:
&lt;br/&gt;
&lt;OL&gt;
&lt;LI&gt;First sort the data so that we can easily find the median. As we
know that median divides the dataset in such a way that 50% of data
points are below the median and 50% of data points are above the
median. That is data set would divide in two equal halves; lower and
top halves - first half containing min to median and another from
median to max.

&lt;LI&gt;Find the median of the lower 50% of the data or the first
half. This is called the first quartile of the distribution and is
denoted by Q1. Q1 or median of the fist half is called the first
quartile since one quarter of the data points fall below it.

&lt;LI&gt;Repeat this again for the top 50% of the data. Find the median of
the top 50% of the data. This is called the third quartile of the
distribution and is denoted by Q3. Q3 is called the third quartile
since three quarters of the data points fall below it.

&lt;LI&gt;The middle 50% of data between Q1 and Q3 is IQR and calculated by
following: IQR = Q3 - Q1.
&lt;/OL&gt;

&lt;br/&gt;
Here is another &lt;a href=&quot;
https://oli.web.cmu.edu/repository/webcontent/859044f080020c690045b50e228faf24/_u2_summarizing_data/_m1_examining_distributions/webcontent/spread4.gif&quot;&gt;picture&lt;/a&gt; taken from course website that visually explains how first quartile
and Q1 is found:

&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgleOWfxyZfkYTQtDP_7gI65HlQQz3NCDtLwpatGmZnwP7BmEqHZZQm9t7ZptL08rANr1TYDbXncP1n4SPOGWnFzA5zDlZuHhp4sd1AsEL_c2febdf8mImnXhGzZ8bLgBeeQkXuDgZKQRbh/s1600-h/IQR-2.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgleOWfxyZfkYTQtDP_7gI65HlQQz3NCDtLwpatGmZnwP7BmEqHZZQm9t7ZptL08rANr1TYDbXncP1n4SPOGWnFzA5zDlZuHhp4sd1AsEL_c2febdf8mImnXhGzZ8bLgBeeQkXuDgZKQRbh/s320/IQR-2.png&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5195833785008154850&quot; /&gt;&lt;/a&gt;

&lt;br/&gt;&lt;br/&gt;
Few very important observation that course makes as following:
&lt;UL&gt;

&lt;LI&gt;From the first picture we can see that Q1, M, and Q3 divide the
data into four quarters with 25% of the data points in each, where the
median is essentially the second quartile. The use of IQR=Q3-Q1 as a
measure of spread is therefore particularly appropriate when the
median M is used as a measure of center.

&lt;LI&gt;We can define a bit more precisely what is considered the bottom
or top 50% of the data. The bottom (top) 50% of the data is all the
observations whose position in the ordered list is to the LEFT (RIGHT)
of the location of the overall median M. The following picture will
visually illustrate this for the simple cases of n=7 and n=8.
 &lt;/UL&gt;

&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOVFOsfpqINzibzYh9Ali5ThP1Fl7AH9ZVS1E3nospezHNm4Ub7W5Gyiu_i01XCI3XAb51J5zt9J6tjrC4DzZAaWBlxhQRyO2qAUeL0BLGHeAK4Dw0esqKKXGm_kryKV4OofNZiNqS_E61/s1600-h/IQR-3.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOVFOsfpqINzibzYh9Ali5ThP1Fl7AH9ZVS1E3nospezHNm4Ub7W5Gyiu_i01XCI3XAb51J5zt9J6tjrC4DzZAaWBlxhQRyO2qAUeL0BLGHeAK4Dw0esqKKXGm_kryKV4OofNZiNqS_E61/s320/IQR-3.png&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5195834669771417842&quot; /&gt;&lt;/a&gt;

Note that when n is odd (like in n=7 above), the median is not
included in either the bottom or top half of the data; when n is even
(like in n=8 above), the data are naturally divided into two halves.

&lt;br/&gt;&lt;br/&gt;
Example: Best Actress Oscar Winners:

Course uses stemplot for finding IQR; we use simple R command to find
IQR. Please note that IQR found using R is different from the course
example.
&lt;br/&gt;
&lt;span style=&quot;font-family: trebuchet ms; color:#003300;&quot;&gt;
&lt;pre&gt;
# we have data in &#39;actress&#39; data frame.
&gt; quantile(Age, names=T)
   0%   25%    50%   75%    100%
21.00  32.50  35.00  41.25  80.00 
&gt; IQR(Age)
[1] 8.75
&lt;/pre&gt;&lt;/span&gt;
&lt;br/&gt;
As can be seen in above code, &#39;quantile&#39; R command outputs following for quartile:
&lt;UL&gt;
&lt;LI&gt; Q1 32.50 (shown as 25%; course calculated value is 32)
&lt;LI&gt; Q3 41.25   (shown as 75%; course calculated value is 41.5)
&lt;/UL&gt;
Simple IQR R function calculates 8.75 as IQR; while course calculated value is 9.75.
&lt;/span&gt;</description><link>https://krishnadagli.blogspot.com/2008/05/learning-statistics-using-r-iqr.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9ymba-vCdUmX2RRwdI_0fN21EMwI0PuFNdO8P7krntaduuF9CefGMyjK7TQUT2ezYGn5byj5AP9qymb_yEDjTrrvBlB1Wy6zGxQ3iSsPaZKJVX41Jw5ilA7gGC0jtEGlBuIw3-mRjEOyq/s72-c/IQR-1.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-1262725739844849826</guid><pubDate>Tue, 29 Apr 2008 16:40:00 +0000</pubDate><atom:updated>2008-09-10T23:16:42.204+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Course</category><category domain="http://www.blogger.com/atom/ns#">R</category><category domain="http://www.blogger.com/atom/ns#">Statistics</category><category domain="http://www.blogger.com/atom/ns#">Tutorial</category><title>Learning Statistics using R: Measure of Spread</title><description>&lt;span style=&quot;font-family: verdana;font-size:90%; color:black;&quot;&gt; 
&lt;strong&gt;&lt;em&gt;
Most of the material here is taken from the course website!&lt;/em&gt;&lt;/strong&gt;
&lt;br/&gt;
To describe a distribution along with measure of center we also need
to know spread also known as variability of distribution.  As course
describes there are 3 commonly used measures of spread/variability,
each describing spread differently:
&lt;br/&gt;
&lt;UL&gt;
&lt;LI&gt; Range
&lt;LI&gt; Inter-quartile range (IQR)
&lt;LI&gt; Standard deviation
&lt;/UL&gt;

&lt;br/&gt;

&lt;UL&gt;
&lt;LI&gt;Range:&lt;/LI&gt;
Range is simplest measure of spread and is exactly the distance
(difference) between smallest data point (min) and maximum data point.

We try to find Range of our Best Actress Dataset:

&lt;span style=&quot;font-family: trebuchet ms; color:#003300;&quot;&gt;
&lt;pre&gt;
actress &lt;- read.csv(&quot;actress.csv&quot;, sep=&quot;,&quot;, header=T)
&gt; attach(actress)
&gt; summary(Age)   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.   
21.00   32.50   35.00   38.53   41.25   80.00
&gt; range(Age)
[1] 21 80
&gt; diff(range(Age))
[1] 59
&lt;/pre&gt;
&lt;/span&gt;

Yes, summary command gives us all the details but we try to learn few
more R commands. As can be seen in above example &quot;range&quot; function
gives the minimum and maximum value for the &quot;Age&quot; distribution. If we
subtract min from max we get number of years covered as shown by
&quot;diff&quot; command.
&lt;br/&gt;
80 (max) - 21 (min) = 59 (Range)
&lt;/UL&gt;
&lt;/span&gt;</description><link>https://krishnadagli.blogspot.com/2008/04/learning-statistics-using-r-measure-of.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-996947917721217676</guid><pubDate>Mon, 28 Apr 2008 18:14:00 +0000</pubDate><atom:updated>2008-09-10T23:13:18.189+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Course</category><category domain="http://www.blogger.com/atom/ns#">R</category><category domain="http://www.blogger.com/atom/ns#">Statistics</category><category domain="http://www.blogger.com/atom/ns#">Tutorial</category><title>Learning Statistics using R: Comparing Mean and Median</title><description>&lt;span style=&quot;font-family: verdana;font-size:90%; color:black;&quot;&gt; 
Mean and Median are measure of center, each describing center in a different
way. Mean, is average value of all observations and due to this actual
values of observations makes a difference to its value, while Median
is a middle value in an &lt;b&gt;ordered&lt;/b&gt; data set.
&lt;br/&gt;&lt;br/&gt;

Lets understand this with few simple examples:
&lt;br/&gt;
&lt;UL&gt;
&lt;LI&gt; Assume we have a dataset with these three values: 1, 2, 5. We can
see the median being 2 and mean as (1+2+5) = 8 / 3 = 2.67
&lt;LI&gt; If we just change the last observation value from 5 to 50 then
median is still 2 but mean changes to 17.67.
&lt;/UL&gt;
&lt;br/&gt;&lt;br/&gt;

As course brings out the main point that is &lt;big&gt;&quot;The mean is very
sensitive to outliers (as it factors in their magnitude), while the
median is resistant to outliers.&quot;&lt;/big&gt;
&lt;br/&gt;&lt;br/&gt;

So as course explains: &lt;UL&gt; &lt;LI&gt;For symmetric distributions with no
outliers: &lt;fo:inline text-decoration=&quot;line-through&quot;&gt;X&lt;/fo:inline&gt; is
approximately equal to M.

&lt;LI&gt; For skewed right distributions and/or datasets with high
outliers: &lt;fo:inline text-decoration=&quot;line-over&quot;&gt;X&lt;/fo:inline&gt; &amp;gt; M.

&lt;LI&gt;For skewed left distributions and/or datasets with low outliers:
&lt;fo:inline text-decoration=&quot;line-over&quot;&gt;X&lt;/fo:inline&gt; &amp;lt; M.
&lt;/UL&gt;


Hence mean is used for symmetric distribution with no outliers while
median is used in other case for measure of center.
&lt;/span&gt;</description><link>https://krishnadagli.blogspot.com/2008/04/learning-statistics-using-r-comparing.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-323851765119357329</guid><pubDate>Sat, 26 Apr 2008 18:50:00 +0000</pubDate><atom:updated>2009-01-07T20:36:33.740+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Course</category><category domain="http://www.blogger.com/atom/ns#">R</category><category domain="http://www.blogger.com/atom/ns#">Statistics</category><category domain="http://www.blogger.com/atom/ns#">Tutorial</category><title>Learning Statistics using R: Numerical Measure</title><description>&lt;span style=&quot;font-family: verdana;font-size:90%; color:black;&quot;&gt; 

&lt;OL type=&quot;1&quot;&gt; Numerical Measures: We proceed to numerical measures of
the distribution of a quantitative variable. &lt;BIG&gt;From this point
onward I am including the notes from the course itself. None of
material is mine other than errors!&lt;/BIG&gt; The distribution of a
quantitative variable is described by its shape, center, and
spread. With histogram we can describe the shape of the distribution,
but we can only get a rough estimate for the center and spread. So
along with graphical display we need a more precise numerical
description of the center and spread of the distribution.

&lt;br/&gt;&lt;br/&gt;

In this section we will learn: 
&lt;UL&gt; 
 &lt;LI&gt; how to quantify the center and spread of a distribution with various numerical measures.  
 &lt;LI&gt; some of the properties of these numerical measures, and 
 &lt;LI&gt; how to choose the appropriate numerical measures of center and spread to supplement the histogram. 
&lt;/UL&gt;
&lt;br/&gt;&lt;br/&gt;

&lt;OL&gt;
&lt;LI type=&quot;a&quot;&gt;Measure of Center: The two main numerical measures for
the center of a distribution are the mean and the median. Each one of
these measures is based on a completely different idea of describing
the center of a distribution. We will first present each one of the
measures, and then compare their properties.
&lt;br/&gt;&lt;br/&gt;

&lt;OL&gt;&lt;LI&gt;Measure of Center:
The mean is the sum of the observations divided by the number of
observations. If the n observations are X1, X2, ... Xn, their mean,
which we denote by &lt;span style=&quot;text-decoration:line-over;&quot;&gt;X&lt;/span&gt; (and read X-bar), is
therefore: = &lt;fo:inline text-decoration=&quot;line-through&quot;&gt;X&lt;/fo:inline&gt; =
(X1+X2+..+Xn)/n.

&lt;br/&gt;&lt;br/&gt;
&lt;strong&gt;
Example: Best Actress Oscar Winners: We continue with our
Best Actress Oscar Winners &lt;a
href=&quot;https://oli.web.cmu.edu/jcourse/workbook/activity/page?context=859d4f0980020c69005402d08707e3c0&quot;&gt;
dataset.&lt;/a&gt;&lt;/strong&gt;

&lt;span style=&quot;font-family: trebuchet ms; color:#003300;&quot;&gt;
&lt;pre&gt;
# read the actress.csv file in an actress data frame. [Bug-Fix: Gabriele Righetti]
&gt;actress &lt;- read.csv (&quot;actress.csv&quot;, header=T, sep=&quot;,&quot;)
# with following command we do not have to keep writing actor$Age to refer to Age column of actor.
&gt;attach(actress)
# a single command summary can give us all details, but just to learn few more R commands.
&gt;mean(Age)[1] 38.53125
&lt;/pre&gt;
&lt;/span&gt;


As it can be seen from above example, &quot;mean&quot; is an R command that
gives average of distribution (measure of center). &lt;br/&gt;&lt;br/&gt;

&lt;LI&gt;Median:

The median M is the midpoint of the distribution. It is the number
such that half of the observations fall above and half fall below. To
find the median:
&lt;UL&gt;
&lt;LI&gt; Order the data from smallest to largest. 
&lt;LI&gt;Consider whether n, the number of observations, is even or odd. &lt;br/&gt;
 &lt;UL&gt;&lt;LI&gt;If n is odd, the median M is the center observation in
 the ordered list. This observation is the one &quot;sitting&quot; in the
 (n+1)/2 spot in the ordered list.

 &lt;LI&gt;If n is even, the median M is the mean of the two center
 observations in the ordered list. These two observations are
 the ones &quot;sitting&quot; in the n/2 and n/2 + 1 spots in the ordered
 list.  &lt;/UL&gt;
&lt;br/&gt;
&lt;strong&gt;Finding median using Best Actress data set:&lt;/strong&gt;
&lt;span style=&quot;font-family: trebuchet ms; color:#003300;&quot;&gt;
&lt;pre&gt;
# we already have data read in the actress data frame.
&gt; attach(actress)
&gt; median(Age)
[1] 35
&lt;/pre&gt;
&lt;/span&gt;


As seen in above code we can use &quot;median&quot; command of R to find the
median value of the distribution.

&lt;br/&gt;&lt;br/&gt;


&lt;strong&gt;Example: Finding median.&lt;/strong&gt;
Here are the numbers of hours that 9 students spend on the computer on a typical day: &lt;br/&gt;
1, 6,  7,  5,  5,  8,  11,  12,  15
&lt;span style=&quot;font-family: trebuchet ms; color:#003300;&quot;&gt;
&lt;pre&gt;
# store numbers of hours spent in a hours vector.
hours&lt;-c(1 , 6 , 7 , 5 , 5 , 8 , 11 , 12 , 15)
&gt; median(hours)
[1] 7
&gt; mean(hours)
[1] 7.777778
# as we have total 9 observations, (n+1)/2th observation (in sorted data), i.e. 5th.
&lt;/pre&gt;
&lt;/span&gt;
&lt;/UL&gt;
&lt;/OL&gt;
&lt;/OL&gt;
&lt;/OL&gt;</description><link>https://krishnadagli.blogspot.com/2008/04/learning-statistics-using-r-numerical.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-542053665666511781.post-1020348378106171285</guid><pubDate>Wed, 23 Apr 2008 14:47:00 +0000</pubDate><atom:updated>2008-04-28T00:42:27.041+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Course</category><category domain="http://www.blogger.com/atom/ns#">R</category><category domain="http://www.blogger.com/atom/ns#">Statistics</category><category domain="http://www.blogger.com/atom/ns#">Tutorial</category><title>Learning Statistics using R : One Quantitative Variable:</title><description>&lt;span style=&quot;font-family: verdana;font-size:90%; color:black;&quot;&gt; 
The
course in this section teaches how to explore data collected from a
quantitative variable, and summarize important features of its
distribution. This section starts with graphs and then moves on to
numerical measures of the distribution and 5 number summary.
As course suggest to display data from one quantitative variable
graphically, we can use either the &lt;big&gt;histogram, stem-plot, or
box-plot.&lt;/big&gt; We will try to do course examples using R.

&lt;br/&gt;&lt;br/&gt;
&lt;OL type=&quot;a&quot;&gt;
&lt;LI&gt;Histogram:
For histogram we break range of values into intervals and count how
many observations fall into each interval. The first example
illustrates histogram with the help of exam grades of 15 students.  In
example bins/intervals are created using 10 points wide length,
including first value while excluding last value.
&lt;br/&gt;&lt;br/&gt;
Here are details: 
&lt;br/&gt;
&lt;p&gt;
Exam grades of 15 students: 88, 48, 60, 51, 57, 85, 69, 75, 97, 72, 71, 79, 65, 63, 73.
Bins, intervals that are chosen along with the count of observations:
&lt;/p&gt;
&lt;table style=&quot;align:center&quot;&gt; 
&lt;tr&gt;&lt;td&gt;Score&lt;/td&gt;&lt;td&gt;Count&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;[40-50)&lt;/td&gt;&lt;td&gt; 1&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;[50-60)&lt;/td&gt;&lt;td&gt; 2&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;[60-70)&lt;/td&gt;&lt;td&gt; 4&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;[70-80)&lt;/td&gt;&lt;td&gt; 5&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;[80-90)&lt;/td&gt;&lt;td&gt; 2&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;[90-100]&lt;/td&gt;&lt;td&gt; 1&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
As shown above intervals are closed at one end while open on other
end. Lets try to plot histogram-using R.

&lt;span style=&quot;font-family: trebuchet ms; color:#003300;&quot;&gt;
&lt;pre&gt;
&gt;grades&lt;-c(88, 48, 60, 51, 57, 85, 69, 75, 97, 72, 71, 79, 65, 63, 73)
# Above command we uses R&#39;s &#39;c&#39;  (combine) function to create a vector of grades.
&gt;hist(grades, right=FALSE)
# Just a simple command draws the following histogram.
&lt;/pre&gt;&lt;/span&gt;

&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8feS0gAUA_oBYgpqZ2gAhajPiw0XHkilvZIWzBKeqvTUA9rSkZgOhLDleUZcf_DiSAg6-W-JCwaF0IXp9mBGPXSFjRqGfR3CaJsi5x8sBwW49a1bWADSu-C749WpMXtxQabLxf-wnn7Ws/s1600-h/grades-hist.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8feS0gAUA_oBYgpqZ2gAhajPiw0XHkilvZIWzBKeqvTUA9rSkZgOhLDleUZcf_DiSAg6-W-JCwaF0IXp9mBGPXSFjRqGfR3CaJsi5x8sBwW49a1bWADSu-C749WpMXtxQabLxf-wnn7Ws/s320/grades-hist.png&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5192859322587179138&quot; /&gt;&lt;/a&gt;
&lt;br/&gt;
Note if in the above &quot;hist&quot; command if you do not use &quot;right=FALSE&quot;
argument then the observation with value 60 will be counted in the
[50-60] interval. The R help page says, &quot;right&quot; argument is logical;
if TRUE, the histograms cells are right-closed (left open)
intervals. In our command we used &quot;right=FALSE&quot; that means the
intervals are of the form [a, b); which what we wanted.
&lt;br/&gt;&lt;br/&gt;

&lt;LI&gt;More on histogram: The Center of distribution is its midpoint -
the value that divides the distribution so that approximately half the
observations take smaller values, and approximately half observations
take larger values.

&lt;span style=&quot;font-family: trebuchet ms; color:#003300;&quot;&gt;
&lt;pre&gt;# we use our above &quot;grades&quot;  vector.
&gt;summary(grades)   
Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    
48.0    61.5    71.0    70.2    77.0    97.0
&lt;/pre&gt;
&lt;/span&gt;

As you can see in above example &quot;summary&quot; command displays various
important numbers. The out put displays center of the distribution
along with min and max and other values.
&lt;br/&gt;&lt;br/&gt;
&lt;LI&gt;Best Actor Oscar Winners: Applying histogram to actual data. The
actual data set is 
&lt;a href=&quot;src=859d4a6a80020c69009b0d6efa1ec180&amp;dst=bestactressdataset&quot;&gt;here.&lt;/a&gt;
As usual we save the excel file in a csv (comma separated) file. In
following text we show how to do interesting things with few R
commands.

&lt;span style=&quot;font-family: trebuchet ms; color:#003300;&quot;&gt;
&lt;pre&gt;
# read the actor.csv file in an actor data frame.
&gt;actor &lt;- read.csv (&quot;actor.csv&quot;, header=T, sep=&quot;,&quot;)
# we run summary command, just to see five-point summary.
&gt;summary(actor)
      Age        
Min.    :31.00   
1st Qu. :37.75   
Median  :42.50   
Mean    :44.72   
3rd Qu. :48.75   
Max.    :76.00 
# with following command we do not have to keep writing actor$Age to refer to Age column of actor.
&gt;attach(actor)
# as we have only one column, summary(Age) would also give same output as above.
&lt;/pre&gt;&lt;/span&gt;

As explained in &lt;a
href=&quot;https://oli.web.cmu.edu/jcourse/workbook/activity/page?context=859d4a7580020c69003149349f5f3f16&quot;&gt;here&lt;/a&gt;,
our minimum data point is 31, and our max is 76. We&#39;ll use a bin width
of 5, and make bins from 30 to 80. So we have total 10 bins.
&lt;span style=&quot;font-family: trebuchet ms; color:#003300;&quot;&gt;
&lt;pre&gt;
&gt; hist(Age, breaks=10, xlim=c(30,80))
&lt;/pre&gt;&lt;/span&gt;

In above command we directly refer to &quot;Age&quot; column, the &quot;breaks&quot;
parameters can either specify number of bins or actual breaks.  Also
&quot;xlim&quot; parameter is used to define the range of x values with sensible
defaults. Also help page mentions that &quot;xlim&quot; is not used to define
histogram breaks, but only for plotting.

Here is what final histogram looks like: Play with &quot;xlim&quot; and &quot;ylim&quot;
options and see what happens to the histogram. In our example
Frequency count is only up to 8 on the Y-axis adjust it to 9.
&lt;br/&gt;&lt;br/&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgL1zcOEsOjd-SsV0rrnlt674e4gHj0Y5sr0ISmq8ZdyWK7agoQry_x-vAN_T79wS7pRIzAv0zBB9oiYhY4b1jwKL9y-safu-p94WEzZPASR3v3lbkUvg4HkJh9EA90HjnurjrRzdgAtsQn/s1600-h/actor-hist.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgL1zcOEsOjd-SsV0rrnlt674e4gHj0Y5sr0ISmq8ZdyWK7agoQry_x-vAN_T79wS7pRIzAv0zBB9oiYhY4b1jwKL9y-safu-p94WEzZPASR3v3lbkUvg4HkJh9EA90HjnurjrRzdgAtsQn/s320/actor-hist.png&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5192861663344355490&quot; /&gt;&lt;/a&gt;

&lt;br/&gt;&lt;br/&gt; 
&lt;LI&gt;Stemplot: The stemplot also called stem and leaf plot
is another graphical display of the distribution of quantitative
data. As course suggest for drawing stemplot we separate each data
point into stem and leaf, where &lt;br/&gt;

&lt;UL&gt;&lt;LI&gt;&lt;Big&gt;Leaf - right-most digit.&lt;/BIG&gt;
    &lt;LI&gt;&lt;Big&gt;Stem - anything but the right-most digit.&lt;/Big&gt;
&lt;/UL&gt;
&lt;br/&gt;
So if the data point is 34 then leaf is 4 and stem is 3 but if data
point is 3.41 then leaf is 1 and stem is 3.4

&lt;br/&gt;&lt;br/&gt; &lt;LI&gt;Best Actress Oscar Winners: Stemplot of actual data.
We use now Best Actress data set. The actual data set is here. It also
included in the document at the end.

&lt;span style=&quot;font-family: trebuchet ms; color:#003300;&quot;&gt;
&lt;pre&gt;
# read the actress.csv file in an actress data frame.
&gt;actress &lt;- read.csv (&quot;actress.csv&quot;, header=T, sep=&quot;,&quot;)
# with following command we do not have to keep writing actor$Age to refer to Age column of actor.
&gt;attach(actress)
# as we are interested in &quot;Age&quot; column of the data frame, we will work with it only, but check summary
&gt;stem(Age, scale=2)
&lt;/pre&gt;&lt;/span&gt;

As you can see a simple &quot;stem&quot; R command draws the stemplot. The
&quot;scale&quot; option/argument to the function expands the scale of the
plot. Here is what our stemplot looks like:
&lt;pre&gt;
When we use scale=2
The decimal point is 1 digit(s) to the right of the | 
 2 | 1 
 2 | 56669  
 3 | 013333444  
 3 | 555789
 4 | 11123  
 4 | 599  
 5 |  
 5 |  
 6 | 1 
 6 |  
 7 | 4  
 7 |  
 8 | 0 

When we use scale=1
The decimal point is 1 digit(s) to the right of the |  
2 | 156669  
3 | 013333444555789  
4 | 11123599  
5 |   
6 | 1 
7 | 4  
8 | 0
&lt;/pre&gt;
&lt;/br&gt;
Well, I do not know how to rotate stemplot 90 degree counter clockwise
using R, so it visually resembles histogram; if anybody know please
let me know.

&lt;/OL&gt;
&lt;/span&gt;</description><link>https://krishnadagli.blogspot.com/2008/04/learning-statistics-using-r-one_24.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8feS0gAUA_oBYgpqZ2gAhajPiw0XHkilvZIWzBKeqvTUA9rSkZgOhLDleUZcf_DiSAg6-W-JCwaF0IXp9mBGPXSFjRqGfR3CaJsi5x8sBwW49a1bWADSu-C749WpMXtxQabLxf-wnn7Ws/s72-c/grades-hist.png" height="72" width="72"/><thr:total>2</thr:total></item></channel></rss>