<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4274823366855967619</id><updated>2011-10-02T14:20:33.982+02:00</updated><category term='P-value'/><category term='Independent groups'/><category term='Polynomial regression'/><category term='Image'/><category term='Fligner-Killeen test'/><category term='Chi-square'/><category term='Probability'/><category term='Import data in R'/><category term='Regression'/><category term='Correlation'/><category term='Fisher'/><category term='Benford'/><category term='Matrix multiplication'/><category term='R functions'/><category term='Plot'/><category term='Multiple comparison'/><category term='Two sample'/><category term='IEEE-754'/><category term='Kendall correlation test'/><category term='Two-way ANOVA'/><category term='Bartlett test'/><category term='Negative binomial distribution'/><category term='ANOVA'/><category term='Welch-Satterthwaite formula'/><category term='T-test'/><category term='One sample'/><category term='OR'/><category term='Spearman correlation test'/><category term='Binomial distribution'/><category term='Homoskedasticity test'/><category term='Wilcoxon-Mann-Whitney'/><category term='U-test'/><category term='Dixon-Massey formula'/><category term='Trend analysis'/><category term='Graphs'/><category term='Bhapkar V test'/><category term='Latin square design'/><category term='Pearson&apos;s Chi-squared test'/><category term='Simple linear regression'/><category term='Independent data-set'/><category term='Cox-Stuart test'/><category term='Editor'/><category term='Pearson product-moment correlation test'/><category term='Z-test'/><category term='Three-way ANOVA'/><category term='Alternative hypothesis'/><category term='Google Analytics'/><category term='Paired groups'/><category term='Logit'/><category term='Sound'/><category term='Logistic regression'/><category term='Contingency table'/><category term='Kruskal-Wallis test'/><category term='Wilcoxon'/><category term='Sign test'/><category term='F-test'/><category term='Residuals'/><category term='Bernoulli'/><category term='CDC'/><category term='Proportions comparison'/><category term='Strassen Algorithm'/><title type='text'>Statistic on aiR</title><subtitle type='html'>&lt;img src="http://img694.imageshack.us/img694/1906/front2s.jpg"&gt;&lt;br&gt;Solved problems of statistic with R</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>37</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-6844495299583994926</id><published>2011-09-17T22:44:00.008+02:00</published><updated>2011-09-17T23:25:30.238+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='R functions'/><category scheme='http://www.blogger.com/atom/ns#' term='Graphs'/><category scheme='http://www.blogger.com/atom/ns#' term='CDC'/><title type='text'>Implementation of the CDC Growth Charts in R</title><content type='html'>I implemented in R a function to re-create the &lt;a href="http://www.cdc.gov/growthcharts/clinical_charts.htm" target="_blank"&gt;CDC Growth Chart&lt;/a&gt;, according to the &lt;a href="http://www.cdc.gov/growthcharts/data_tables.htm" target="_blank"&gt;data provided by the CDC&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;In order to use this function, you need to download the .rar file available at this &lt;a href="http://www.megaupload.com/?d=A2DYUNQ4" target="_blank"&gt;megaupload link&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Then unrar the file, and put the &lt;b&gt;Growth&lt;/b&gt; folder in your main directory, as selected in R. You are now able to use the two functions i'm going to illustrate.&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width=50%&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;big&gt;growthFun.R&lt;/big&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;script src="https://gist.github.com/1224344.js?file=growthFun.R"&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;The function &lt;code style="color: rgb(153, 0, 0);"&gt;growthFun&lt;/code&gt; allows you to draw 8 different growth chart, which are different for Male and Female (sixteen in total).&lt;br /&gt;The only parameters you need to input are:&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt; sex = c("m", "f")&lt;/code&gt;&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt; type = c("wac36", "lac36", "wlc", "hac", "wsc", "wac20", "lac20", "bac")&lt;/code&gt;&lt;br /&gt;The explanation for the type's parameters code are in the first part of the function code.&lt;br /&gt;Eventually you can modify the &lt;code style="color: rgb(153, 0, 0);"&gt;pat&lt;/code&gt; variable, if you want to put the &lt;b&gt;Growth&lt;/b&gt; folder in another place (not in the main directory of R).&lt;br /&gt;&lt;br /&gt;I reccomend to use the &lt;code style="color: rgb(153, 0, 0);"&gt;pdf()&lt;/code&gt; graphic device for best resolution.&lt;br /&gt;&lt;br /&gt;Hese is an example of the output you can obtain, with the following code:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;pdf("hac_example.pdf", paper="a4", width=0, height=0)&lt;br /&gt;growthFun("m", "hac")&lt;br /&gt;dev.off()&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;iframe width=100% height=560px frameborder=0 src=https://docs.google.com/gview?a=v&amp;pid=explorer&amp;chrome=false&amp;api=true&amp;embedded=true&amp;srcid=0B5Soe5lALqepYzlhN2FjYTgtY2Q2ZS00MjRmLThkMGUtMGM5MjU2ZTg0M2Iz&amp;hl=en&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width=50%&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;big&gt;MygrowthFun.R&lt;/big&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;script src="https://gist.github.com/1224345.js?file=MygrowthFun.R"&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;The function &lt;code style="color: rgb(153, 0, 0);"&gt;MygrowthFun&lt;/code&gt; allows you to personalize the output of the previous function, with specific patient's data.&lt;br /&gt;The parameters you can modify are:&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt; sex=c("m", "f")&lt;br /&gt; type=c("wac36", "lac36", "wlc", "hac", "wsc", "wac20", "lac20", "bac", "bmi.adv")&lt;br /&gt; path="./Growth/"&lt;br /&gt; name = NULL&lt;br /&gt; surname = NULL&lt;br /&gt; birth_date = NULL&lt;br /&gt; mydataAA = NULL&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The three parameter &lt;code style="color: rgb(153, 0, 0);"&gt;sex&lt;/code&gt;, &lt;code style="color: rgb(153, 0, 0);"&gt;type&lt;/code&gt; and &lt;code style="color: rgb(153, 0, 0);"&gt;path&lt;/code&gt; are the same of the &lt;code style="color: rgb(153, 0, 0);"&gt;growthFun&lt;/code&gt; function. The three parameters &lt;code style="color: rgb(153, 0, 0);"&gt;name&lt;/code&gt;, &lt;code style="color: rgb(153, 0, 0);"&gt;surname&lt;/code&gt; and &lt;code style="color: rgb(153, 0, 0);"&gt;birth_date&lt;/code&gt; refer to the patient's data; you can add this data in form of &lt;code style="color: rgb(153, 0, 0);"&gt;character()&lt;/code&gt;.&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;mydataAA&lt;/code&gt; is an optional parameters with the values measured on your patients during the time you follow up him. Generally you need to input this data in form of a &lt;code style="color: rgb(153, 0, 0);"&gt;data.frame()&lt;/code&gt;.&lt;br /&gt;In the &lt;code style="color: rgb(153, 0, 0);"&gt;type&lt;/code&gt; parameter there is an additional choice: &lt;code style="color: rgb(153, 0, 0);"&gt;bmi.adv&lt;/code&gt; allows you to obtain three chart (&lt;code style="color: rgb(153, 0, 0);"&gt;wac20, lac20, bac&lt;/code&gt; - see the explanation codes), if your &lt;code style="color: rgb(153, 0, 0);"&gt;mydataAA&lt;/code&gt; dataframe contains data about Stature and Weight during the time of follow up.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;big&gt;Details.&lt;/big&gt;&lt;/b&gt;&lt;br /&gt;Let's see the format of &lt;code style="color: rgb(153, 0, 0);"&gt;mydataAA&lt;/code&gt;, according to the &lt;code style="color: rgb(153, 0, 0);"&gt;type&lt;/code&gt; of chart you want to graph.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;b&gt;type = wac36&lt;/b&gt;&lt;br /&gt;&lt;b&gt;mydataAA: &lt;/b&gt;&lt;br /&gt;first column = months of measurement, from 0 to 36&lt;br /&gt;second column = weight (in kg)&lt;br /&gt;&lt;br /&gt;&lt;b&gt;type = lac36&lt;/b&gt;&lt;br /&gt;&lt;b&gt;mydataAA: &lt;/b&gt;&lt;br /&gt;first column = months of measurement, from 0 to 36&lt;br /&gt;second column = length (in cm)&lt;br /&gt;&lt;br /&gt;&lt;b&gt;type = hac&lt;/b&gt;&lt;br /&gt;&lt;b&gt;mydataAA: &lt;/b&gt;&lt;br /&gt;first column = months of measurement, from 0 to 36&lt;br /&gt;second column = head circumference (in cm)&lt;br /&gt;&lt;br /&gt;&lt;b&gt;type = wac20&lt;/b&gt;&lt;br /&gt;&lt;b&gt;mydataAA: &lt;/b&gt;&lt;br /&gt;first column = months of measurement, from 24 to 240 (from 2 to 20 years)&lt;br /&gt;second column = weight (in kg)&lt;br /&gt;&lt;br /&gt;&lt;b&gt;type = lac20&lt;/b&gt;&lt;br /&gt;&lt;b&gt;mydataAA: &lt;/b&gt;&lt;br /&gt;first column = months of measurement, from 24 to 240 (from 2 to 20 years)&lt;br /&gt;second column = stature (in cm)&lt;br /&gt;&lt;br /&gt;&lt;b&gt;type = bmi.adv&lt;/b&gt;&lt;br /&gt;&lt;b&gt;mydataAA: &lt;/b&gt;&lt;br /&gt;first column (&lt;b&gt;months&lt;/b&gt;) = months of measurement, from 24 to 240 (from 2 to 20 years)&lt;br /&gt;second column (&lt;b&gt;stature&lt;/b&gt;) = stature (in cm)&lt;br /&gt;third column (&lt;b&gt;weight&lt;/b&gt;)= weight (in kg)&lt;/pre&gt;&lt;br /&gt;In the last type it's not importat the order of the columns, but here are important their names.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;big&gt;Examples.&lt;/big&gt;&lt;/b&gt;&lt;br /&gt;Let's see some example. Suppose that you are following the growth of a new born (her name is Alyssa Gigave, born on 07/08/2009), and you collect the following data:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Months  Length&lt;br /&gt;0       50&lt;br /&gt;2       55&lt;br /&gt;3       56&lt;br /&gt;5       61&lt;br /&gt;8       71&lt;br /&gt;9       72&lt;br /&gt;12      75&lt;br /&gt;15      75&lt;br /&gt;18      81&lt;br /&gt;21      89&lt;br /&gt;26      91&lt;br /&gt;27      94&lt;br /&gt;30      95&lt;br /&gt;35      98&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So you can create your personalized graph in this way:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;alyssa_data &lt;- data.frame(&lt;br /&gt;  months=c(0, 2, 3, 5, 8, 9, 12, 15, 18, 21, 26, 27, 30, 35),&lt;br /&gt;  length=c(50, 55, 56, 61, 71, 72, 75, 75, 81, 89, 91, 94, 95, 98))&lt;br /&gt;&lt;br /&gt;pdf("alyssa_growth_chart.pdf", paper="a4", width=0, height=0)&lt;br /&gt;&lt;br /&gt;MygrowthFun(sex="f", type="lac36", name="Alyssa", surname="Gigave", birth_date="july 08, 2009", mydataAA=alyssa_data)&lt;br /&gt;&lt;br /&gt;dev.off()&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The output is the following pdf file:&lt;br /&gt;&lt;br /&gt;&lt;iframe width=100% height=560px frameborder=0 src=https://docs.google.com/gview?a=v&amp;pid=explorer&amp;chrome=false&amp;api=true&amp;embedded=true&amp;srcid=0B5Soe5lALqepOWRiZWYyYjItNGVhMi00OWY4LThlZDEtZTE1NjY5MTVjZjQw&amp;hl=en&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;Now suppose that you're a pediatric doctor, and that you follow a boy (Tommy Cigalino, born on 07/08/1980). Whenever he has come to you, you collect his weight and stature, and the months from his birth he was. So you have the following data:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;   months stature weight&lt;br /&gt;      25      98     17&lt;br /&gt;      31     100     21&lt;br /&gt;      34     102     27&lt;br /&gt;      35     104     29&lt;br /&gt;      58     106     30&lt;br /&gt;      60     109     32&lt;br /&gt;      70     111     33&lt;br /&gt;      85     118     34&lt;br /&gt;      88     119     36&lt;br /&gt;      89     120     39&lt;br /&gt;      91     121     42&lt;br /&gt;     102     126     45&lt;br /&gt;     107     128     47&lt;br /&gt;     108     135     49&lt;br /&gt;     120     144     51&lt;br /&gt;     134     145     52&lt;br /&gt;     154     148     54&lt;br /&gt;     166     152     55&lt;br /&gt;     169     157     62&lt;br /&gt;     170     158     63&lt;br /&gt;     178     163     64&lt;br /&gt;     179     167     68&lt;br /&gt;     181     168     71&lt;br /&gt;     219     169     74&lt;br /&gt;     234     176     76&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So you can create three graphs (&lt;code style="color: rgb(153, 0, 0);"&gt;wac20, lac20, bac&lt;/code&gt;), using the &lt;code style="color: rgb(153, 0, 0);"&gt;bmi.adv&lt;/code&gt; type:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;tommy_data &lt;- data.frame(&lt;br /&gt; months = c( 25, 31, 34, 35, 58, 60, &lt;br /&gt;             70, 85, 88, 89, 91, 102, &lt;br /&gt;             107, 108, 120, 134, 154, &lt;br /&gt;             166, 169, 170, 178, 179, &lt;br /&gt;             181, 219, 234),&lt;br /&gt;&lt;br /&gt; stature = c( 98, 100, 102, 104, 106, &lt;br /&gt;             109, 111, 118, 119, 120, &lt;br /&gt;             121, 126, 128, 135, 144, &lt;br /&gt;             145, 148, 152, 157, 158, &lt;br /&gt;             163, 167, 168, 169, 176),&lt;br /&gt;&lt;br /&gt; weight = c( 17, 21, 27, 29, 30, 32, &lt;br /&gt;             33, 34, 36, 39, 42, 45, &lt;br /&gt;             47, 49, 51, 52, 54, 55, &lt;br /&gt;             62, 63, 64, 68, 71, 74, &lt;br /&gt;             76))&lt;br /&gt;&lt;br /&gt;pdf("tommy_growth_chart.pdf", paper="a4", width=0, height=0)&lt;br /&gt;&lt;br /&gt;MygrowthFun(sex="m", type="bmi.adv", name="Tommy", surname="Cigalino", birth_date="july 08, 1980", mydataAA=tommy_data)&lt;br /&gt;&lt;br /&gt;dev.off()&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;iframe width=100% height=560px frameborder=0 src=https://docs.google.com/gview?a=v&amp;pid=explorer&amp;chrome=false&amp;api=true&amp;embedded=true&amp;srcid=0B5Soe5lALqepMjljMjhiZGQtNTkxNi00Zjg2LWJkYWMtMzkxMDlhMDNjZjM4&amp;hl=en&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;Tommaso MARTINO&lt;/b&gt;, 17/09/2011&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;REFERENCES&lt;/b&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;http://www.cdc.gov/growthcharts/cdc_charts.htm&lt;/li&gt;&lt;br /&gt;&lt;li&gt;http://www.cdc.gov/growthcharts/clinical_charts.htm&lt;/li&gt;&lt;br /&gt;&lt;li&gt;http://www.cdc.gov/growthcharts/percentile_data_files.htm&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Kuczmarski RJ, Ogden CL, Guo, SS, et al. CDC growth charts for the United States: Methods and Development. Vital Health Stat; 11 (246) National Center for Health Statistics. 2002.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-6844495299583994926?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/6844495299583994926/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2011/09/implementation-of-cdc-growth-charts-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/6844495299583994926'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/6844495299583994926'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2011/09/implementation-of-cdc-growth-charts-in.html' title='Implementation of the CDC Growth Charts in R'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-8984142002635654896</id><published>2011-09-07T16:43:00.007+02:00</published><updated>2011-09-07T17:07:17.623+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='R functions'/><category scheme='http://www.blogger.com/atom/ns#' term='Sound'/><title type='text'>R is a cool sound editor!</title><content type='html'>Capabilities of R are definitely unless! After my previous posts about some easy image editing in R (they are &lt;a href="http://statistic-on-air.blogspot.com/2010/11/r-is-cool-image-editor.html"&gt;here&lt;/a&gt;, and &lt;a href="http://statistic-on-air.blogspot.com/2011/08/r-is-cool-image-editor-2-dithering.html"&gt;here&lt;/a&gt;), now is the time to explore if R is capable of sound editing!&lt;br /&gt;&lt;br /&gt;Just for fun, here I created a function that receives a phone number (or another sequence of numbers), and returns the equivalent melody you can listen if you press that sequence on your house' phone... =D&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;br /&gt;It requires the &lt;code style="color: rgb(255, 0, 0);"&gt;sound&lt;/code&gt; library, and here's the code.&lt;br /&gt;&lt;br /&gt;&lt;script src="https://gist.github.com/1200780.js?file=PlayTel.R"&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;Now you can simply create your phone melody =)&lt;br /&gt;&lt;br /&gt;&lt;code style="color: rgb(255, 0, 0);"&gt;s2 &amp;lt;- PlayTel("556c885a4623#")&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;You can listen to it with the command:&lt;br /&gt;&lt;br /&gt;&lt;code style="color: rgb(255, 0, 0);"&gt;play(s2)&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;(&lt;span style="font-style:italic;"&gt;NOTE&lt;/span&gt;: in Windows 7 I was unable to find a wave player that works on batch mode - i.e. mplay32.exe. So this command doesn't work on Windows 7. It works on Windows XP)&lt;br /&gt;&lt;br /&gt;You can save the output using the command:&lt;br /&gt;&lt;br /&gt;&lt;code style="color: rgb(255, 0, 0);"&gt;saveSample(s2, "tel.wav")&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;(This command works on Windows 7)&lt;br /&gt;&lt;br /&gt;Here is an example of the output:&lt;br /&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;var zippywww="www28";var zippyfile="67433758";var zippydown="ffffff";var zippyfront="000000";var zippyback="ffffff";var zippylight="000000";var zippywidth=300;var zippyauto=false;var zippyvol=60;&lt;/script&gt;&lt;script type="text/javascript" src="http://api.zippyshare.com/api/embed.js"&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;Have fun!! =)&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-8984142002635654896?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/8984142002635654896/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2011/09/r-is-cool-sound-editor.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/8984142002635654896'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/8984142002635654896'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2011/09/r-is-cool-sound-editor.html' title='R is a cool sound editor!'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-4921874882651831320</id><published>2011-08-29T11:11:00.002+02:00</published><updated>2011-08-29T11:20:07.883+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Editor'/><category scheme='http://www.blogger.com/atom/ns#' term='R functions'/><category scheme='http://www.blogger.com/atom/ns#' term='Image'/><title type='text'>R is a cool image editor #2: Dithering algorithms</title><content type='html'>Here I implemented in R some dithering algorithms:&lt;br /&gt;- &lt;b&gt;Floyd-Steinberg dithering&lt;/b&gt;&lt;br /&gt;- &lt;b&gt;Bill Atkinson dithering&lt;/b&gt;&lt;br /&gt;- &lt;b&gt;Jarvis-Judice-Ninke dithering&lt;/b&gt;&lt;br /&gt;- &lt;b&gt;Sierra 2-4a dithering&lt;/b&gt;&lt;br /&gt;- &lt;b&gt;Stucki dithering&lt;/b&gt;&lt;br /&gt;- &lt;b&gt;Burkes dithering&lt;/b&gt;&lt;br /&gt;- &lt;b&gt;Sierra2 dithering&lt;/b&gt;&lt;br /&gt;- &lt;b&gt;Sierra3 dithering&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;For each algorithm, I wrote a 2-dimensional convolution function (a matrix passing over a matrix); it is &lt;i&gt;slow&lt;/i&gt; because I didn't implemented any fasting tricks. It can be easily implemented in C, then used in R for a faster solution.&lt;br /&gt;Then, a function to transform a grey image in a grey-dithered image is provided, with an example. The library &lt;b&gt;rimage&lt;/b&gt; was used for loading and displaying images (see the other post &lt;a href="http://statistic-on-air.blogspot.com/2010/11/r-is-cool-image-editor.html"&gt;R is a cool image editor&lt;/a&gt;).&lt;br /&gt;These function can be easily re-coded for a RGB image.&lt;br /&gt;Only the first code is commented, 'cause they're all very similar.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;library(rimage)&lt;br /&gt;y &lt;- read.jpeg("valve.jpg")&lt;br /&gt;plot(y)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;center&gt;&lt;a target='_blank' href='http://img695.imageshack.us/img695/9885/originalys.jpg'&gt;&lt;img src='http://img695.imageshack.us/img695/9885/originalys.th.jpg' border='0'/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width=50%&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;big&gt;&lt;u&gt;Floyd-Steinberg dithering&lt;/u&gt;&lt;/big&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;script src="https://gist.github.com/1178029.js?file=Floyd-Steinberg%20dithering"&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;plot(normalize(grey2FSdith(rgb2grey(y))))&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a target='_blank' href='http://img190.imageshack.us/img190/5848/fsdith.jpg'&gt;&lt;img src='http://img190.imageshack.us/img190/5848/fsdith.th.jpg' border='0'/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width=50%&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;big&gt;&lt;u&gt;Bill Atkinson dithering&lt;/u&gt;&lt;/big&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;script src="https://gist.github.com/1178030.js?file=Bill%20Atkinson%20dithering"&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;plot(normalize(grey2ATKdith(rgb2grey(y))))&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a target='_blank' href='http://img855.imageshack.us/img855/8114/atkdith.jpg'&gt;&lt;img src='http://img855.imageshack.us/img855/8114/atkdith.th.jpg' border='0'/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width=50%&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;big&gt;&lt;u&gt;Jarvis-Judice-Ninke dithering&lt;/u&gt;&lt;/big&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;script src="https://gist.github.com/1178033.js?file=Jarvis-Judice-Ninke%20dithering"&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;plot(normalize(grey2JJNdith(rgb2grey(y))))&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a target='_blank' href='http://img717.imageshack.us/img717/1548/jjndith.jpg'&gt;&lt;img src='http://img717.imageshack.us/img717/1548/jjndith.th.jpg' border='0'/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width=50%&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;big&gt;&lt;u&gt;Sierra 2-4a dithering filter&lt;/u&gt;&lt;/big&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;script src="https://gist.github.com/1178034.js?file=Sierra%202-4a%20dithering"&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;plot(normalize(grey2S24adith(rgb2grey(y))))&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a target='_blank' href='http://img535.imageshack.us/img535/8584/s24adith.jpg'&gt;&lt;img src='http://img535.imageshack.us/img535/8584/s24adith.th.jpg' border='0'/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width=50%&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;big&gt;&lt;u&gt;Stucki dithering&lt;/u&gt;&lt;/big&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;script src="https://gist.github.com/1178036.js?file=Stucki%20dithering"&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;plot(normalize(grey2Stucki(rgb2grey(y))))&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a target='_blank' href='http://img714.imageshack.us/img714/108/stuckidith.jpg'&gt;&lt;img src='http://img714.imageshack.us/img714/108/stuckidith.th.jpg' border='0'/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width=50%&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;big&gt;&lt;u&gt;Burkes dithering&lt;/u&gt;&lt;/big&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;script src="https://gist.github.com/1178037.js?file=Burkes%20dithering"&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;plot(normalize(grey2Burkes(rgb2grey(y))))&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a target='_blank' href='http://img153.imageshack.us/img153/3861/burkesdith.jpg'&gt;&lt;img src='http://img153.imageshack.us/img153/3861/burkesdith.th.jpg' border='0'/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width=50%&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;big&gt;&lt;u&gt;Sierra2 dithering&lt;/u&gt;&lt;/big&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;script src="https://gist.github.com/1178039.js?file=Sierra2%20dithering"&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;plot(normalize(grey2Sierra2(rgb2grey(y))))&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a target='_blank' href='http://img97.imageshack.us/img97/9585/sierra2dith.jpg'&gt;&lt;img src='http://img97.imageshack.us/img97/9585/sierra2dith.th.jpg' border='0'/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width=50%&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;big&gt;&lt;u&gt;Sierra3 dithering&lt;/u&gt;&lt;/big&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;script src="https://gist.github.com/1178040.js?file=Sierra3%20dithering"&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;plot(normalize(grey2Sierra3(rgb2grey(y))))&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a target='_blank' href='http://img692.imageshack.us/img692/4319/sierra3dith.jpg'&gt;&lt;img src='http://img692.imageshack.us/img692/4319/sierra3dith.th.jpg' border='0'/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-4921874882651831320?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/4921874882651831320/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2011/08/r-is-cool-image-editor-2-dithering.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/4921874882651831320'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/4921874882651831320'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2011/08/r-is-cool-image-editor-2-dithering.html' title='R is a cool image editor #2: Dithering algorithms'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-1034194000703020571</id><published>2011-08-25T23:30:00.007+02:00</published><updated>2011-08-25T23:46:16.169+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Plot'/><category scheme='http://www.blogger.com/atom/ns#' term='R functions'/><category scheme='http://www.blogger.com/atom/ns#' term='Benford'/><title type='text'>Benford's law, or the First-digit law</title><content type='html'>&lt;b&gt;Benford's law&lt;/b&gt;, also called the &lt;i&gt;first-digit law&lt;/i&gt;, states that in lists of numbers from many (but not all) real-life sources of data, the leading digit is distributed in a specific, non-uniform way. According to this law, the first digit is 1 about 30% of the time, and larger digits occur as the leading digit with lower and lower frequency, to the point where 9 as a first digit occurs less than 5% of the time.&lt;br /&gt;&lt;span style="font-style:italic;"&gt;Wikipedia, retrieved 08/25/2011&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;iframe width="500" height="345" src="http://www.youtube.com/embed/6KmeGpjeLZ0" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;iframe width="500" height="345" src="http://www.youtube.com/embed/SZUDoEdjTzg" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;R simulation:&lt;/span&gt;&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;&lt;br /&gt;library(MASS)&lt;br /&gt;benford &lt;- function(m, n){&lt;br /&gt;list &lt;- c()&lt;br /&gt;&lt;br /&gt;# compute all m^n, for n= 1, 2, ..., i, ..., n&lt;br /&gt;for(i in 1:n){&lt;br /&gt;list[i] &lt;- m^i&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;# a function to extract the first digit from a number&lt;br /&gt;bben &lt;- function(k){&lt;br /&gt;as.numeric(head(strsplit(as.character(k),'')[[1]],n=1))&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;# extract the first digit from all numbers computed&lt;br /&gt;first.digit &lt;- sapply(list, bben)&lt;br /&gt;&lt;br /&gt;# plot frequency of first digits&lt;br /&gt;truehist(first.digit, nbins=10, main=m)&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;par(mfrow=c(2,2))&lt;br /&gt;benford(2,1000)&lt;br /&gt;benford(3,640) # if n is greater, it returns "inf" (on my pc)&lt;br /&gt;benford(4,500)&lt;br /&gt;benford(5,440)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;a target='_blank' href='http://img840.imageshack.us/img840/2315/benford.jpg'&gt;&lt;img src='http://img840.imageshack.us/img840/2315/benford.th.jpg' border='0'/&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-1034194000703020571?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/1034194000703020571/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2011/08/benfords-law-or-first-digit-law.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/1034194000703020571'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/1034194000703020571'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2011/08/benfords-law-or-first-digit-law.html' title='Benford&apos;s law, or the First-digit law'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://img.youtube.com/vi/6KmeGpjeLZ0/default.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-3068193343216860499</id><published>2011-06-16T09:52:00.002+02:00</published><updated>2011-06-16T09:56:08.428+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Residuals'/><category scheme='http://www.blogger.com/atom/ns#' term='Graphs'/><category scheme='http://www.blogger.com/atom/ns#' term='Regression'/><title type='text'>How to plot points, regression line and residuals</title><content type='html'>&lt;code style="color: rgb(153, 0, 0);"&gt;&lt;br /&gt;x &lt;- c(173, 169, 176, 166, 161, 164, 160, 158, 180, 187)&lt;br /&gt;y &lt;- c(80, 68, 72, 75, 70, 65, 62, 60, 85, 92)&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;# plot scatterplot and the regression line&lt;/span&gt;&lt;br /&gt;mod1 &lt;- lm(y ~ x)&lt;br /&gt;plot(x, y, xlim=c(min(x)-5, max(x)+5), ylim=c(min(y)-10, max(y)+10))&lt;br /&gt;abline(mod1, lwd=2)&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;# calculate residuals and predicted values&lt;/span&gt;&lt;br /&gt;res &lt;- signif(residuals(mod1), 5)&lt;br /&gt;pre &lt;- predict(mod1)&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;# plot distances between points and the regression line&lt;/span&gt;&lt;br /&gt;segments(x, y, x, pre, col="red")&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;# add labels (res values) to points&lt;/span&gt;&lt;br /&gt;library(calibrate)&lt;br /&gt;textxy(x, y, res, cx=0.7)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;a target='_blank' href='http://img851.imageshack.us/img851/1310/plotres.jpg'&gt;&lt;img src='http://img851.imageshack.us/img851/1310/plotres.th.jpg' border='0'/&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-3068193343216860499?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/3068193343216860499/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2011/06/how-to-plot-points-regression-line-and.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/3068193343216860499'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/3068193343216860499'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2011/06/how-to-plot-points-regression-line-and.html' title='How to plot points, regression line and residuals'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-4147084687440995836</id><published>2010-11-07T11:40:00.003+01:00</published><updated>2010-11-07T12:24:41.971+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Editor'/><category scheme='http://www.blogger.com/atom/ns#' term='R functions'/><category scheme='http://www.blogger.com/atom/ns#' term='Image'/><title type='text'>R is a cool image editor!</title><content type='html'>Here I present some functions I wrote to recreate some of the most common image effect available in all image editor.&lt;br /&gt;They require the library &lt;span style="font-weight:bold;"&gt;rimage&lt;/span&gt;.&lt;br /&gt;To load the image, use:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;y &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; read.jpeg&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;quot;path&amp;quot;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;To display the image, use:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;plot&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;y&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width=50%&gt;&lt;/center&gt;&lt;br /&gt;&lt;center&gt;&lt;big&gt;&lt;u&gt;Original image&lt;/u&gt;&lt;/big&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a target='_blank' href='http://img89.imageshack.us/img89/7343/dandg.jpg'&gt;&lt;img src='http://img89.imageshack.us/img89/7343/dandg.th.jpg' border='0'/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width=50%&gt;&lt;/center&gt;&lt;br /&gt;&lt;center&gt;&lt;big&gt;&lt;u&gt;Sepia tone&lt;/u&gt;&lt;/big&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;rgb2sepia &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;function&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;img&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt; iRed &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;*&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;br /&gt; iGreen &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;*&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;br /&gt; iBlue &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;3&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;*&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; oRed &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; iRed &lt;span style=""&gt;*&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;.393&lt;/span&gt; &lt;span style=""&gt;+&lt;/span&gt; iGreen &lt;span style=""&gt;*&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;.769&lt;/span&gt; &lt;span style=""&gt;+&lt;/span&gt; iBlue &lt;span style=""&gt;*&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;.189&lt;/span&gt;&lt;br /&gt; oGreen &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; iRed &lt;span style=""&gt;*&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;.349&lt;/span&gt; &lt;span style=""&gt;+&lt;/span&gt; iGreen &lt;span style=""&gt;*&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;.686&lt;/span&gt; &lt;span style=""&gt;+&lt;/span&gt; iBlue &lt;span style=""&gt;*&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;.168&lt;/span&gt;&lt;br /&gt; oBlue &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; iRed &lt;span style=""&gt;*&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;.272&lt;/span&gt; &lt;span style=""&gt;+&lt;/span&gt; iGreen &lt;span style=""&gt;*&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;.534&lt;/span&gt; &lt;span style=""&gt;+&lt;/span&gt; iBlue &lt;span style=""&gt;*&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;.131&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; qw &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;array&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;oRed&lt;span style=""&gt;/&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt; &lt;span style="color: #339933;"&gt;,&lt;/span&gt; oGreen&lt;span style=""&gt;/&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt; &lt;span style="color: #339933;"&gt;,&lt;/span&gt; oBlue&lt;span style=""&gt;/&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;=&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;dim(iRed)[1]&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;dim(iRed)[2]&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;3&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; imagematrix&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;qw&lt;span style="color: #339933;"&gt;,&lt;/span&gt; type=&lt;span style="color: #0000ff;"&gt;&amp;quot;rgb&amp;quot;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;plot&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;rgb2sepia&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;y&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a target='_blank' href='http://img600.imageshack.us/img600/9976/sepia.png'&gt;&lt;img src='http://img600.imageshack.us/img600/9976/sepia.th.png' border='0'/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width=50%&gt;&lt;/center&gt;&lt;br /&gt;&lt;center&gt;&lt;big&gt;&lt;u&gt;Negative&lt;/u&gt;&lt;/big&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;rgb2neg &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;function&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;img&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt; iRed &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt; iGreen &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt; iBlue &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;3&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; oRed &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt; &lt;span style=""&gt;-&lt;/span&gt; iRed&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt; oGreen &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt; &lt;span style=""&gt;-&lt;/span&gt; iGreen&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt; oBlue &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt; &lt;span style=""&gt;-&lt;/span&gt; iBlue&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; qw &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;array&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;oRed&lt;span style="color: #339933;"&gt;,&lt;/span&gt; oGreen&lt;span style="color: #339933;"&gt;,&lt;/span&gt; oBlue&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;=&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;dim(iRed)[1]&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;dim(iRed)[2]&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;3&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; imagematrix&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;qw&lt;span style="color: #339933;"&gt;,&lt;/span&gt; type=&lt;span style="color: #0000ff;"&gt;&amp;quot;rgb&amp;quot;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;plot&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;rgb2neg&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;y&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a target='_blank' href='http://img269.imageshack.us/img269/6540/negn.png'&gt;&lt;img src='http://img269.imageshack.us/img269/6540/negn.th.png' border='0'/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width=50%&gt;&lt;/center&gt;&lt;br /&gt;&lt;center&gt;&lt;big&gt;&lt;u&gt;Pixelation&lt;/u&gt;&lt;/big&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;pixmatr &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;function&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;a&lt;span style="color: #339933;"&gt;,&lt;/span&gt; n&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt; aa &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;seq&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;a&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;n&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt; ll &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;seq&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;a&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;n&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; &lt;span style="color: #000000; font-weight: bold;"&gt;for&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;i &lt;span style="color: #000000; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;length&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;aa&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style=""&gt;-&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: #000000; font-weight: bold;"&gt;for&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;j &lt;span style="color: #000000; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;length&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;ll&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style=""&gt;-&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;   sub1 &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; a&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;aa&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;i&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;aa&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;i&lt;span style=""&gt;+&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;-&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;ll&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;j&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;ll&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;j&lt;span style=""&gt;+&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;-&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;   k &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;mean&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;sub1&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;   sub1m &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;matrix&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;rep&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;k&lt;span style="color: #339933;"&gt;,&lt;/span&gt; n&lt;span style=""&gt;*&lt;/span&gt;n&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; n&lt;span style="color: #339933;"&gt;,&lt;/span&gt; n&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;   a&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;aa&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;i&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;aa&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;i&lt;span style=""&gt;+&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;-&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;ll&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;j&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;ll&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;j&lt;span style=""&gt;+&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;-&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt; &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; sub1m&lt;br /&gt;   &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; &lt;span style="color: #000000; font-weight: bold;"&gt;for&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;j &lt;span style="color: #000000; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;length&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;ll&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style=""&gt;-&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;  sub1 &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; a&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;max&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;aa&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;a&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;ll&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;j&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;ll&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;j&lt;span style=""&gt;+&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;-&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;  k &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;mean&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;sub1&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;  sub1m &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;matrix&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;rep&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;k&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;nrow&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;sub1&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style=""&gt;*&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;ncol&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;sub1&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;nrow&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;sub1&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;ncol&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;sub1&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;  a&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;max&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;aa&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;a&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;ll&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;j&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;ll&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;j&lt;span style=""&gt;+&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;-&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt; &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; sub1m&lt;br /&gt; &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; &lt;span style="color: #000000; font-weight: bold;"&gt;for&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;i &lt;span style="color: #000000; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;length&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;aa&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style=""&gt;-&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;  sub1 &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; a&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;aa&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;i&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;aa&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;i&lt;span style=""&gt;+&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;-&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;max&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;ll&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;a&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;  k &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;mean&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;sub1&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;  sub1m &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;matrix&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;rep&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;k&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;nrow&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;sub1&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style=""&gt;*&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;ncol&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;sub1&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;nrow&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;sub1&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;ncol&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;sub1&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;  a&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;aa&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;i&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;aa&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;i&lt;span style=""&gt;+&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;-&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;max&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;ll&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;a&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt; &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; sub1m&lt;br /&gt; &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; sub1 &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; a&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;max&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;aa&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;a&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;max&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;ll&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;a&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt; k &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;mean&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;sub1&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt; sub1m &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;matrix&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;rep&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;k&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;nrow&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;sub1&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style=""&gt;*&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;ncol&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;sub1&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;nrow&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;sub1&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;ncol&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;sub1&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt; a&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;max&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;aa&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;a&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;max&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;ll&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;a&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt; &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; sub1m&lt;br /&gt;&amp;nbsp;&lt;br /&gt;a&lt;br /&gt;&lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;rgb2pix &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;function&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;img&lt;span style="color: #339933;"&gt;,&lt;/span&gt;n&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt; iRed &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;*&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;br /&gt; iGreen &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;*&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;br /&gt; iBlue &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;3&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;*&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; oRed &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; pixmatr&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iRed&lt;span style="color: #339933;"&gt;,&lt;/span&gt;n&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt; oGreen &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; pixmatr&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iGreen&lt;span style="color: #339933;"&gt;,&lt;/span&gt;n&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt; oBlue &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; pixmatr&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iBlue&lt;span style="color: #339933;"&gt;,&lt;/span&gt;n&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; qw &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;array&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;oRed&lt;span style=""&gt;/&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt; &lt;span style="color: #339933;"&gt;,&lt;/span&gt; oGreen&lt;span style=""&gt;/&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt; &lt;span style="color: #339933;"&gt;,&lt;/span&gt; oBlue&lt;span style=""&gt;/&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;=&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;dim(iRed)[1]&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;dim(iRed)[2]&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;3&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; imagematrix&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;qw&lt;span style="color: #339933;"&gt;,&lt;/span&gt; type=&lt;span style="color: #0000ff;"&gt;&amp;quot;rgb&amp;quot;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;plot&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;rgb2pix&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;y&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;6&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;plot&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;rgb2pix&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;y&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;10&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a href="http://img29.imageshack.us/img29/9105/pix1h.png" target="_blank"&gt;&lt;img src="http://img29.imageshack.us/img29/9105/pix1h.th.png" border="0"/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;center&gt;&lt;a href="http://img530.imageshack.us/img530/3725/pix2.png" target="_blank"&gt;&lt;img src="http://img530.imageshack.us/img530/3725/pix2.th.png" border="0"/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width=50%&gt;&lt;/center&gt;&lt;br /&gt;&lt;center&gt;&lt;big&gt;&lt;u&gt;Remove red&lt;/u&gt;&lt;/big&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;rgb2blu &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;function&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;img&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt; iRed &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt; iGreen &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt; iBlue &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;3&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; oRed &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;matrix&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iRed&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iRed&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt; oGreen &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; iGreen&lt;br /&gt; oBlue &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; iBlue&lt;br /&gt;&amp;nbsp;&lt;br /&gt; qw &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;array&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;oRed&lt;span style="color: #339933;"&gt;,&lt;/span&gt; oGreen&lt;span style="color: #339933;"&gt;,&lt;/span&gt; oBlue&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;=&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;dim(iRed)[1]&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;dim(iRed)[2]&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;3&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; imagematrix&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;qw&lt;span style="color: #339933;"&gt;,&lt;/span&gt; type=&lt;span style="color: #0000ff;"&gt;&amp;quot;rgb&amp;quot;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;plot&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;rgb2blu&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;y&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a target='_blank' href='http://img44.imageshack.us/img44/3697/blupa.png'&gt;&lt;img src='http://img44.imageshack.us/img44/3697/blupa.th.png' border='0'/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width=50%&gt;&lt;/center&gt;&lt;br /&gt;&lt;center&gt;&lt;big&gt;&lt;u&gt;Remove green&lt;/u&gt;&lt;/big&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;rgb2vio &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;function&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;img&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt; iRed &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt; iGreen &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt; iBlue &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;3&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; oRed &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; iRed&lt;br /&gt; oGreen &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;matrix&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iRed&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iRed&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt; oBlue &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; iBlue&lt;br /&gt;&amp;nbsp;&lt;br /&gt; qw &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;array&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;oRed&lt;span style="color: #339933;"&gt;,&lt;/span&gt; oGreen&lt;span style="color: #339933;"&gt;,&lt;/span&gt; oBlue&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;=&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;dim(iRed)[1]&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;dim(iRed)[2]&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;3&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; imagematrix&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;qw&lt;span style="color: #339933;"&gt;,&lt;/span&gt; type=&lt;span style="color: #0000ff;"&gt;&amp;quot;rgb&amp;quot;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;plot&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;rgb2vio&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;y&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a target='_blank' href='http://img801.imageshack.us/img801/9264/vios.png'&gt;&lt;img src='http://img801.imageshack.us/img801/9264/vios.th.png' border='0'/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width=50%&gt;&lt;/center&gt;&lt;br /&gt;&lt;center&gt;&lt;big&gt;&lt;u&gt;Remove blue&lt;/u&gt;&lt;/big&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;rgb2yel &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;function&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;img&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt; iRed &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt; iGreen &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt; iBlue &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;3&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; oRed &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; iRed&lt;br /&gt; oGreen &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; iGreen&lt;br /&gt; oBlue &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;matrix&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iRed&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iRed&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; qw &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;array&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;oRed&lt;span style="color: #339933;"&gt;,&lt;/span&gt; oGreen&lt;span style="color: #339933;"&gt;,&lt;/span&gt; oBlue&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;=&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;dim(iRed)[1]&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;dim(iRed)[2]&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;3&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; imagematrix&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;qw&lt;span style="color: #339933;"&gt;,&lt;/span&gt; type=&lt;span style="color: #0000ff;"&gt;&amp;quot;rgb&amp;quot;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;plot&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;rgb2yel&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;y&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a href="http://img59.imageshack.us/img59/4473/yel.png" target="_blank"&gt;&lt;img src="http://img59.imageshack.us/img59/4473/yel.th.png" border="0"/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width=50%&gt;&lt;/center&gt;&lt;br /&gt;&lt;center&gt;&lt;big&gt;&lt;u&gt;Adjust brightness&lt;/u&gt;&lt;/big&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;rgb2bri &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;function&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;img&lt;span style="color: #339933;"&gt;,&lt;/span&gt; n&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt; iRed &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt; iGreen &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt; iBlue &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;3&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; oRed &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; iRed &lt;span style=""&gt;+&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iRed &lt;span style=""&gt;*&lt;/span&gt; n&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt; oGreen &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; iGreen &lt;span style=""&gt;+&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iGreen &lt;span style=""&gt;*&lt;/span&gt; n&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt; oBlue &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; iBlue &lt;span style=""&gt;+&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iBlue &lt;span style=""&gt;*&lt;/span&gt; n&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; qw &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;array&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;oRed&lt;span style="color: #339933;"&gt;,&lt;/span&gt; oGreen&lt;span style="color: #339933;"&gt;,&lt;/span&gt; oBlue&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;=&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;dim(iRed)[1]&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;dim(iRed)[2]&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;3&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; imagematrix&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;qw&lt;span style="color: #339933;"&gt;,&lt;/span&gt; type=&lt;span style="color: #0000ff;"&gt;&amp;quot;rgb&amp;quot;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;plot&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;rgb2bri&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;y&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style=""&gt;+&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;0.5&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;plot&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;rgb2bri&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;y&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style=""&gt;-&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;0.5&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a href="http://img408.imageshack.us/img408/9818/bri1.png" target="_blank"&gt;&lt;img src="http://img408.imageshack.us/img408/9818/bri1.th.png" border="0"/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;center&gt;&lt;a href="http://img683.imageshack.us/img683/5796/bri2.png" target="_blank"&gt;&lt;img src="http://img683.imageshack.us/img683/5796/bri2.th.png" border="0"/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width=50%&gt;&lt;/center&gt;&lt;br /&gt;&lt;center&gt;&lt;big&gt;&lt;u&gt;Truncate colors into bands (posterize)&lt;/u&gt;&lt;/big&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;rgb2ban &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;function&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;img&lt;span style="color: #339933;"&gt;,&lt;/span&gt; n&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt; iRed &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;*&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;br /&gt; iGreen &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;*&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;br /&gt; iBlue &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;3&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;*&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; band_size &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;trunc&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;span style=""&gt;/&lt;/span&gt;n&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; oRed &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; band_size &lt;span style=""&gt;*&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;trunc&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iRed &lt;span style=""&gt;/&lt;/span&gt; band_size&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt; oGreen &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; band_size &lt;span style=""&gt;*&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;trunc&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iGreen &lt;span style=""&gt;/&lt;/span&gt; band_size&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt; oBlue &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; band_size &lt;span style=""&gt;*&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;trunc&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iBlue &lt;span style=""&gt;/&lt;/span&gt; band_size&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; qw &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;array&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;oRed&lt;span style=""&gt;/&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; oGreen&lt;span style=""&gt;/&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; oBlue&lt;span style=""&gt;/&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;=&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;dim(iRed)[1]&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;dim(iRed)[2]&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;3&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; imagematrix&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;qw&lt;span style="color: #339933;"&gt;,&lt;/span&gt; type=&lt;span style="color: #0000ff;"&gt;&amp;quot;rgb&amp;quot;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;plot&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;rgb2ban&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;y&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;5&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;plot&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;rgb2ban&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;y&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;10&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a href="http://img263.imageshack.us/img263/2084/ban1b.png/" target="_blank"&gt;&lt;img src="http://img263.imageshack.us/img263/2084/ban1b.th.png" border="0"/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;center&gt;&lt;a href="http://img574.imageshack.us/img574/4012/ban2.png" target="_blank"&gt;&lt;img src="http://img574.imageshack.us/img574/4012/ban2.th.png" border="0"/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width=50%&gt;&lt;/center&gt;&lt;br /&gt;&lt;center&gt;&lt;big&gt;&lt;u&gt;Solarize&lt;/u&gt;&lt;/big&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;rgb2sol &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;function&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;img&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt; iRed &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;*&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;br /&gt; iGreen &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;*&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;br /&gt; iBlue &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; img&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;3&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;*&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; &lt;span style="color: #000000; font-weight: bold;"&gt;for&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;i &lt;span style="color: #000000; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iRed&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: #000000; font-weight: bold;"&gt;for&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;j &lt;span style="color: #000000; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iRed&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;   &lt;span style="color: #000000; font-weight: bold;"&gt;if&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iRed&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;i&lt;span style="color: #339933;"&gt;,&lt;/span&gt;j&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;128&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; iRed&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;i&lt;span style="color: #339933;"&gt;,&lt;/span&gt;j&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt; &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;span style=""&gt;-&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style=""&gt;*&lt;/span&gt;iRed&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;i&lt;span style="color: #339933;"&gt;,&lt;/span&gt;j&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;   &lt;span style="color: #000000; font-weight: bold;"&gt;else&lt;/span&gt; iRed&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;i&lt;span style="color: #339933;"&gt;,&lt;/span&gt;j&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt; &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style=""&gt;*&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iRed&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;i&lt;span style="color: #339933;"&gt;,&lt;/span&gt;j&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;-&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;128&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt; &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; &lt;span style="color: #000000; font-weight: bold;"&gt;for&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;i &lt;span style="color: #000000; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iGreen&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: #000000; font-weight: bold;"&gt;for&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;j &lt;span style="color: #000000; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iGreen&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;   &lt;span style="color: #000000; font-weight: bold;"&gt;if&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iGreen&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;i&lt;span style="color: #339933;"&gt;,&lt;/span&gt;j&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;128&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; iGreen&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;i&lt;span style="color: #339933;"&gt;,&lt;/span&gt;j&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt; &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;span style=""&gt;-&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style=""&gt;*&lt;/span&gt;iGreen&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;i&lt;span style="color: #339933;"&gt;,&lt;/span&gt;j&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;   &lt;span style="color: #000000; font-weight: bold;"&gt;else&lt;/span&gt; iGreen&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;i&lt;span style="color: #339933;"&gt;,&lt;/span&gt;j&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt; &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style=""&gt;*&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iGreen&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;i&lt;span style="color: #339933;"&gt;,&lt;/span&gt;j&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;-&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;128&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt; &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; &lt;span style="color: #000000; font-weight: bold;"&gt;for&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;i &lt;span style="color: #000000; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iBlue&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: #000000; font-weight: bold;"&gt;for&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;j &lt;span style="color: #000000; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style=""&gt;:&lt;/span&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iBlue&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;   &lt;span style="color: #000000; font-weight: bold;"&gt;if&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iBlue&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;i&lt;span style="color: #339933;"&gt;,&lt;/span&gt;j&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;128&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; iBlue&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;i&lt;span style="color: #339933;"&gt;,&lt;/span&gt;j&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt; &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;span style=""&gt;-&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style=""&gt;*&lt;/span&gt;iBlue&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;i&lt;span style="color: #339933;"&gt;,&lt;/span&gt;j&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;   &lt;span style="color: #000000; font-weight: bold;"&gt;else&lt;/span&gt; iBlue&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;i&lt;span style="color: #339933;"&gt;,&lt;/span&gt;j&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt; &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style=""&gt;*&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iBlue&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;i&lt;span style="color: #339933;"&gt;,&lt;/span&gt;j&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style=""&gt;-&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;128&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt; &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; qw &lt;span style=""&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;array&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;iRed&lt;span style=""&gt;/&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; iGreen&lt;span style=""&gt;/&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; iBlue&lt;span style=""&gt;/&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;255&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #003399; font-weight: bold;"&gt;dim&lt;/span&gt;=&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;dim(iRed)[1]&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;dim(iRed)[2]&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;3&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt; imagematrix&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;qw&lt;span style="color: #339933;"&gt;,&lt;/span&gt; type=&lt;span style="color: #0000ff;"&gt;&amp;quot;rgb&amp;quot;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;plot&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;rgb2sol&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;y&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a href="http://img602.imageshack.us/img602/5332/sol.png" target="_blank"&gt;&lt;img src="http://img602.imageshack.us/img602/5332/sol.th.png" border="0"/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-4147084687440995836?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/4147084687440995836/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2010/11/r-is-cool-image-editor.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/4147084687440995836'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/4147084687440995836'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2010/11/r-is-cool-image-editor.html' title='R is a cool image editor!'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-5722342236610944441</id><published>2010-10-19T20:13:00.002+02:00</published><updated>2010-10-19T20:18:35.622+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Strassen Algorithm'/><category scheme='http://www.blogger.com/atom/ns#' term='R functions'/><category scheme='http://www.blogger.com/atom/ns#' term='Matrix multiplication'/><title type='text'>Fast matrix inversion</title><content type='html'>Very similar to what has been done to create a function to perform fast multiplication of large matrices using the Strassen algorithm (see &lt;a href="http://statistic-on-air.blogspot.com/2010/10/fast-matrix-multiplication-in-r.html"&gt;previous post&lt;/a&gt;), now we write the functions to quickly calculate the &lt;a href="http://en.wikipedia.org/wiki/Invertible_matrix" target="_blank"&gt;inverse of a matrix&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;To avoid rewriting pages and pages of comments and formulas, as I did for matrix multiplication, this time I'll show you directly the code of the function (the reasoning behind it is quite similar). Please, copy and paste all the code in an external editor to see it properly.&lt;br /&gt;&lt;br /&gt;    &lt;div style="margin-bottom: 2px;"&gt;Function &lt;code style="color: rgb(0, 0, 0);"&gt;strassenInv(A)&lt;/code&gt;&lt;br /&gt;    &lt;div style="margin-top: 5px; text-align: center;"&gt;&lt;input value="Show" style="margin-top: 5px; width: 60px; font-size: 10px;" onclick="if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = ''; this.innerText = ''; this.value = 'Hide'; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerText = ''; this.value = 'Show'; }" type="button"&gt; &lt;/div&gt;&lt;br /&gt;    &lt;div style="border: 1px inset ; margi : 0px; padding: 6px;"&gt;&lt;div style="display: none;"&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;strassenInv &lt;- function(A){&lt;br /&gt;&lt;br /&gt; div4 &lt;- function(A, r){&lt;br /&gt;  A &lt;- list(A)&lt;br /&gt;  A11 &lt;- A[[1]][1:(r/2),1:(r/2)]&lt;br /&gt;  A12 &lt;- A[[1]][1:(r/2),(r/2+1):r]&lt;br /&gt;  A21 &lt;- A[[1]][(r/2+1):r,1:(r/2)]&lt;br /&gt;  A22 &lt;- A[[1]][(r/2+1):r,(r/2+1):r]&lt;br /&gt;  A &lt;- list(X11=A11, X12=A12, X21=A21, X22=A22)&lt;br /&gt;  return(A)&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;        if (nrow(A) != ncol(A)) &lt;br /&gt;          { stop("only square matrices can be inverted") }&lt;br /&gt;&lt;br /&gt; is.wholenumber &lt;-&lt;br /&gt;     function(x, tol = .Machine$double.eps^0.5)  abs(x - round(x)) &lt; tol&lt;br /&gt;&lt;br /&gt; if ( (is.wholenumber(log(nrow(A), 2)) != TRUE) || (is.wholenumber(log(ncol(A), 2)) != TRUE) )&lt;br /&gt;   { stop("only square matrices of dimension 2^k * 2^k can be inverted with Strassen method") }&lt;br /&gt;&lt;br /&gt; A &lt;- div4(A, dim(A)[1])&lt;br /&gt;&lt;br /&gt; R1 &lt;- solve(A$X11)&lt;br /&gt; R2 &lt;- A$X21 %*% R1&lt;br /&gt; R3 &lt;- R1 %*% A$X12&lt;br /&gt; R4 &lt;- A$X21 %*% R3&lt;br /&gt; R5 &lt;- R4 - A$X22&lt;br /&gt; R6 &lt;- solve(R5)&lt;br /&gt; C12 &lt;- R3 %*% R6&lt;br /&gt; C21 &lt;- R6 %*% R2&lt;br /&gt; R7 &lt;- R3 %*% C21&lt;br /&gt; C11 &lt;- R1 - R7&lt;br /&gt; C22 &lt;- -R6&lt;br /&gt; &lt;br /&gt; C &lt;- rbind(cbind(C11,C12), cbind(C21,C22))&lt;br /&gt;&lt;br /&gt; return(C)&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;    &lt;div style="margin-bottom: 2px;"&gt;Function &lt;code style="color: rgb(0, 0, 0);"&gt;strassenInv2(A)&lt;/code&gt;&lt;br /&gt;    &lt;div style="margin-top: 5px; text-align: center;"&gt;&lt;input value="Show" style="margin-top: 5px; width: 60px; font-size: 10px;" onclick="if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = ''; this.innerText = ''; this.value = 'Hide'; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerText = ''; this.value = 'Show'; }" type="button"&gt; &lt;/div&gt;&lt;br /&gt;    &lt;div style="border: 1px inset ; margi : 0px; padding: 6px;"&gt;&lt;div style="display: none;"&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;strassenInv2 &lt;- function(A){&lt;br /&gt;&lt;br /&gt; div4 &lt;- function(A, r){&lt;br /&gt;  A &lt;- list(A)&lt;br /&gt;  A11 &lt;- A[[1]][1:(r/2),1:(r/2)]&lt;br /&gt;  A12 &lt;- A[[1]][1:(r/2),(r/2+1):r]&lt;br /&gt;  A21 &lt;- A[[1]][(r/2+1):r,1:(r/2)]&lt;br /&gt;  A22 &lt;- A[[1]][(r/2+1):r,(r/2+1):r]&lt;br /&gt;  A &lt;- list(X11=A11, X12=A12, X21=A21, X22=A22)&lt;br /&gt;  return(A)&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; strassen &lt;- function(A, B){&lt;br /&gt;  A &lt;- div4(A, dim(A)[1])&lt;br /&gt;  B &lt;- div4(B, dim(B)[1])&lt;br /&gt;  M1 &lt;- (A$X11+A$X22) %*% (B$X11+B$X22)&lt;br /&gt;  M2 &lt;- (A$X21+A$X22) %*% B$X11&lt;br /&gt;  M3 &lt;- A$X11 %*% (B$X12-B$X22)&lt;br /&gt;  M4 &lt;- A$X22 %*% (B$X21-B$X11)&lt;br /&gt;  M5 &lt;- (A$X11+A$X12) %*% B$X22&lt;br /&gt;  M6 &lt;- (A$X21-A$X11) %*% (B$X11+B$X12)&lt;br /&gt;  M7 &lt;- (A$X12-A$X22) %*% (B$X21+B$X22)&lt;br /&gt;&lt;br /&gt;  C11 &lt;- M1+M4-M5+M7&lt;br /&gt;  C12 &lt;- M3+M5&lt;br /&gt;  C21 &lt;- M2+M4&lt;br /&gt;  C22 &lt;- M1-M2+M3+M6&lt;br /&gt; &lt;br /&gt;  C &lt;- rbind(cbind(C11,C12), cbind(C21,C22))&lt;br /&gt;  return(C)&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;        if (nrow(A) != ncol(A)) &lt;br /&gt;          { stop("only square matrices can be inverted") }&lt;br /&gt;&lt;br /&gt; is.wholenumber &lt;-&lt;br /&gt;     function(x, tol = .Machine$double.eps^0.5)  abs(x - round(x)) &lt; tol&lt;br /&gt;&lt;br /&gt; if ( (is.wholenumber(log(nrow(A), 2)) != TRUE) || (is.wholenumber(log(ncol(A), 2)) != TRUE) )&lt;br /&gt;   { stop("only square matrices of dimension 2^k * 2^k can be inverted with Strassen method") }&lt;br /&gt;&lt;br /&gt; A &lt;- div4(A, dim(A)[1])&lt;br /&gt;&lt;br /&gt; R1 &lt;- strassenInv(A$X11)&lt;br /&gt; R2 &lt;- strassen(A$X21 , R1)&lt;br /&gt; R3 &lt;- strassen(R1 , A$X12)&lt;br /&gt; R4 &lt;- strassen(A$X21 , R3)&lt;br /&gt; R5 &lt;- R4 - A$X22&lt;br /&gt; R6 &lt;- strassenInv(R5)&lt;br /&gt; C12 &lt;- strassen(R3 , R6)&lt;br /&gt; C21 &lt;- strassen(R6 , R2)&lt;br /&gt; R7 &lt;- strassen(R3 , C21)&lt;br /&gt; C11 &lt;- R1 - R7&lt;br /&gt; C22 &lt;- -R6&lt;br /&gt; &lt;br /&gt; C &lt;- rbind(cbind(C11,C12), cbind(C21,C22))&lt;br /&gt;&lt;br /&gt; return(C)&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;    &lt;div style="margin-bottom: 2px;"&gt;Function &lt;code style="color: rgb(0, 0, 0);"&gt;strassenInv3(A)&lt;/code&gt;&lt;br /&gt;    &lt;div style="margin-top: 5px; text-align: center;"&gt;&lt;input value="Show" style="margin-top: 5px; width: 60px; font-size: 10px;" onclick="if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = ''; this.innerText = ''; this.value = 'Hide'; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerText = ''; this.value = 'Show'; }" type="button"&gt; &lt;/div&gt;&lt;br /&gt;    &lt;div style="border: 1px inset ; margi : 0px; padding: 6px;"&gt;&lt;div style="display: none;"&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;strassenInv3 &lt;- function(A){&lt;br /&gt;&lt;br /&gt; div4 &lt;- function(A, r){&lt;br /&gt;  A &lt;- list(A)&lt;br /&gt;  A11 &lt;- A[[1]][1:(r/2),1:(r/2)]&lt;br /&gt;  A12 &lt;- A[[1]][1:(r/2),(r/2+1):r]&lt;br /&gt;  A21 &lt;- A[[1]][(r/2+1):r,1:(r/2)]&lt;br /&gt;  A22 &lt;- A[[1]][(r/2+1):r,(r/2+1):r]&lt;br /&gt;  A &lt;- list(X11=A11, X12=A12, X21=A21, X22=A22)&lt;br /&gt;  return(A)&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; strassen &lt;- function(A, B){&lt;br /&gt;  A &lt;- div4(A, dim(A)[1])&lt;br /&gt;  B &lt;- div4(B, dim(B)[1])&lt;br /&gt;  M1 &lt;- (A$X11+A$X22) %*% (B$X11+B$X22)&lt;br /&gt;  M2 &lt;- (A$X21+A$X22) %*% B$X11&lt;br /&gt;  M3 &lt;- A$X11 %*% (B$X12-B$X22)&lt;br /&gt;  M4 &lt;- A$X22 %*% (B$X21-B$X11)&lt;br /&gt;  M5 &lt;- (A$X11+A$X12) %*% B$X22&lt;br /&gt;  M6 &lt;- (A$X21-A$X11) %*% (B$X11+B$X12)&lt;br /&gt;  M7 &lt;- (A$X12-A$X22) %*% (B$X21+B$X22)&lt;br /&gt;&lt;br /&gt;  C11 &lt;- M1+M4-M5+M7&lt;br /&gt;  C12 &lt;- M3+M5&lt;br /&gt;  C21 &lt;- M2+M4&lt;br /&gt;  C22 &lt;- M1-M2+M3+M6&lt;br /&gt; &lt;br /&gt;  C &lt;- rbind(cbind(C11,C12), cbind(C21,C22))&lt;br /&gt;  return(C)&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; strassen2 &lt;- function(A, B){&lt;br /&gt;  A &lt;- div4(A, dim(A)[1])&lt;br /&gt;  B &lt;- div4(B, dim(B)[1])&lt;br /&gt;  M1 &lt;- strassen((A$X11+A$X22) , (B$X11+B$X22))&lt;br /&gt;  M2 &lt;- strassen((A$X21+A$X22) , B$X11)&lt;br /&gt;  M3 &lt;- strassen(A$X11 , (B$X12-B$X22))&lt;br /&gt;  M4 &lt;- strassen(A$X22 , (B$X21-B$X11))&lt;br /&gt;  M5 &lt;- strassen((A$X11+A$X12) , B$X22)&lt;br /&gt;  M6 &lt;- strassen((A$X21-A$X11) , (B$X11+B$X12))&lt;br /&gt;  M7 &lt;- strassen((A$X12-A$X22) , (B$X21+B$X22))&lt;br /&gt;&lt;br /&gt;  C11 &lt;- M1+M4-M5+M7&lt;br /&gt;  C12 &lt;- M3+M5&lt;br /&gt;  C21 &lt;- M2+M4&lt;br /&gt;  C22 &lt;- M1-M2+M3+M6&lt;br /&gt;&lt;br /&gt;  C &lt;- rbind(cbind(C11,C12), cbind(C21,C22))&lt;br /&gt;  return(C)&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;        if (nrow(A) != ncol(A)) &lt;br /&gt;          { stop("only square matrices can be inverted") }&lt;br /&gt;&lt;br /&gt; is.wholenumber &lt;-&lt;br /&gt;     function(x, tol = .Machine$double.eps^0.5)  abs(x - round(x)) &lt; tol&lt;br /&gt;&lt;br /&gt; if ( (is.wholenumber(log(nrow(A), 2)) != TRUE) || (is.wholenumber(log(ncol(A), 2)) != TRUE) )&lt;br /&gt;   { stop("only square matrices of dimension 2^k * 2^k can be inverted with Strassen method") }&lt;br /&gt;&lt;br /&gt; A &lt;- div4(A, dim(A)[1])&lt;br /&gt;&lt;br /&gt; R1 &lt;- strassenInv2(A$X11)&lt;br /&gt; R2 &lt;- strassen2(A$X21 , R1)&lt;br /&gt; R3 &lt;- strassen2(R1 , A$X12)&lt;br /&gt; R4 &lt;- strassen2(A$X21 , R3)&lt;br /&gt; R5 &lt;- R4 - A$X22&lt;br /&gt; R6 &lt;- strassenInv2(R5)&lt;br /&gt; C12 &lt;- strassen2(R3 , R6)&lt;br /&gt; C21 &lt;- strassen2(R6 , R2)&lt;br /&gt; R7 &lt;- strassen2(R3 , C21)&lt;br /&gt; C11 &lt;- R1 - R7&lt;br /&gt; C22 &lt;- -R6&lt;br /&gt; &lt;br /&gt; C &lt;- rbind(cbind(C11,C12), cbind(C21,C22))&lt;br /&gt;&lt;br /&gt; return(C)&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;We run now some test. First check if the function successfully invert the matrix and compare them with the results of the standard R function (Function &lt;code style="color: rgb(0, 0, 0);"&gt;solve()&lt;/code&gt;):&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;A &lt;- matrix(trunc(rnorm(512*512)*100), 512,512)&lt;br /&gt;&lt;br /&gt;all( round(solve(A),8) == round(strassenInv(A),8) )&lt;br /&gt;[1] TRUE&lt;br /&gt;&lt;br /&gt;all( round(solve(A),8) == round(strassenInv2(A),8) )&lt;br /&gt;[1] TRUE&lt;br /&gt;&lt;br /&gt;all( round(solve(A),6) == round(strassenInv3(A),6) )&lt;br /&gt;[1] TRUE&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The function performs the operations correctly. But there is a problem of approximation: in fact the first two functions are accurate to the eighth decimal place, while the third through sixth. Probably not an issue of calculus, but it is a problem of expression of numbers in binary format and 32-bit, which causes these errors.&lt;br /&gt;&lt;br /&gt;Now we analyze the computation time. See in the table the result, obtained by running the following code:&lt;br /&gt;&lt;br /&gt;    &lt;div style="margin-bottom: 2px;"&gt;Time computation&lt;br /&gt;    &lt;div style="margin-top: 5px; text-align: center;"&gt;&lt;input value="Show" style="margin-top: 5px; width: 60px; font-size: 10px;" onclick="if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = ''; this.innerText = ''; this.value = 'Hide'; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerText = ''; this.value = 'Show'; }" type="button"&gt; &lt;/div&gt;&lt;br /&gt;    &lt;div style="border: 1px inset ; margi : 0px; padding: 6px;"&gt;&lt;div style="display: none;"&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;A &lt;- matrix(trunc(rnorm(512*512)*100), 512,512)&lt;br /&gt;system.time(solve(A))&lt;br /&gt;system.time(strassenInv(A))&lt;br /&gt;system.time(strassenInv2(A))&lt;br /&gt;system.time(strassenInv3(A))&lt;br /&gt;&lt;br /&gt;A &lt;- matrix(trunc(rnorm(1024*1024)*100), 1024,1024)&lt;br /&gt;system.time(solve(A))&lt;br /&gt;system.time(strassenInv(A))&lt;br /&gt;system.time(strassenInv2(A))&lt;br /&gt;system.time(strassenInv3(A))&lt;br /&gt;&lt;br /&gt;A &lt;- matrix(trunc(rnorm(2048*2048)*100), 2048,2048)&lt;br /&gt;system.time(solve(A))&lt;br /&gt;system.time(strassenInv(A))&lt;br /&gt;system.time(strassenInv2(A))&lt;br /&gt;system.time(strassenInv3(A))&lt;br /&gt;&lt;br /&gt;A &lt;- matrix(trunc(rnorm(4096*4096)*100), 4096,4096)&lt;br /&gt;system.time(solve(A))&lt;br /&gt;system.time(strassenInv(A))&lt;br /&gt;system.time(strassenInv2(A))&lt;br /&gt;system.time(strassenInv3(A))&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a target='_blank' href='http://img148.imageshack.us/img148/2208/tabella.jpg'&gt;&lt;img src='http://img148.imageshack.us/img148/2208/tabella.th.jpg' border='0'/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;The results are quite obvious, and using a modification of Strassen algorithm for matrix inversion, there is a real time saving.&lt;br /&gt;&lt;br /&gt;Please, remember these two recommendations already made:&lt;br /&gt;- The code is to be improved, and if anyone wants to help me, I will be happy to update my code&lt;br /&gt;- If you consider it useful to use these function for any work, a citation is always welcome (contact me at my e-mail for details)&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-5722342236610944441?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/5722342236610944441/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2010/10/fast-matrix-inversion.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/5722342236610944441'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/5722342236610944441'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2010/10/fast-matrix-inversion.html' title='Fast matrix inversion'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-8832299279899776655</id><published>2010-10-18T15:31:00.005+02:00</published><updated>2010-10-18T22:09:24.626+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Strassen Algorithm'/><category scheme='http://www.blogger.com/atom/ns#' term='R functions'/><category scheme='http://www.blogger.com/atom/ns#' term='Matrix multiplication'/><title type='text'>Fast matrix multiplication in R: Strassen's algorithm</title><content type='html'>I tried to implement the Strassen's algorithm for big matrices multiplication in R.&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;Here I present a pdf with some theory element, some example and a possible solution in R.&lt;br /&gt;I'm not a programmer, so the function is not optimize, but it works.&lt;br /&gt;&lt;br /&gt;I want to thank &lt;a href="http://stackoverflow.com/users/382907/g-grothendieck" target="_blank"&gt;G. Grothendieck&lt;/a&gt;: suggested me a very nice way on &lt;a href="http://stackoverflow.com/questions/3948497/create-a-bigger-matrix-from-smaller-one/3948621#3948621" target="_blank"&gt;StackOverFlow&lt;/a&gt; to create a bigger square matrix starting from small one.&lt;br /&gt;&lt;br /&gt;This is just a first version of the function; it needs more work on it. If someone want to collaborate, I'll be very happy.&lt;br /&gt;Finally if you find my code useful for your work, I'd love to be cited (ask me via e-mail how to cite me: &lt;span style="font-weight:bold;"&gt;todoslogos &lt;span style="font-style:italic;"&gt;-at-&lt;/span&gt; gmail . com&lt;/span&gt;).&lt;br /&gt;&lt;br /&gt;&lt;iframe width=100% height=560px frameborder=0 src=https://docs.google.com/gview?a=v&amp;pid=explorer&amp;chrome=false&amp;api=true&amp;embedded=true&amp;srcid=0B5Soe5lALqepMmJjY2JiYjQtOTlhZi00ZTc2LThjODEtNzc0OTg0MjA0YzA3&amp;hl=en&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-8832299279899776655?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/8832299279899776655/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2010/10/fast-matrix-multiplication-in-r.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/8832299279899776655'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/8832299279899776655'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2010/10/fast-matrix-multiplication-in-r.html' title='Fast matrix multiplication in R: Strassen&apos;s algorithm'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-2361246015824566013</id><published>2010-10-06T12:47:00.003+02:00</published><updated>2010-10-06T12:51:01.200+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='IEEE-754'/><title type='text'>Convert decimal to IEEE-754 in R</title><content type='html'>For some theory on the standard IEEE-754, you can read the &lt;a href="http://en.wikipedia.org/wiki/IEEE_754-2008" target="_blank"&gt;Wikipedia&lt;/a&gt; page. Here I will post only the code of the function to make the conversion in R.&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;First we write some functions to convert decimal numbers to binary numbers:&lt;br /&gt;&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;&lt;br /&gt;decInt_to_8bit &lt;- function(x, precs) {&lt;br /&gt;q &lt;- c()&lt;br /&gt;r &lt;- c()&lt;br /&gt;xx &lt;- c()&lt;br /&gt;for(i in 1:precs){&lt;br /&gt;xx[1] &lt;- x&lt;br /&gt;q[i] &lt;- xx[i] %/% 2&lt;br /&gt;r[i] &lt;- xx[i] %% 2&lt;br /&gt;xx[i+1] &lt;- q[i]&lt;br /&gt;}&lt;br /&gt;rr &lt;- rev(r)&lt;br /&gt;return(rr)&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;devDec_to_8bit &lt;- function(x, precs) {&lt;br /&gt;nas &lt;- c()&lt;br /&gt;nbs &lt;- c()&lt;br /&gt;xxs &lt;- c()&lt;br /&gt;for(i in 1:precs)&lt;br /&gt;{&lt;br /&gt;xxs[1] &lt;- x*2&lt;br /&gt;nas[i] &lt;- (xxs[i]) - floor(xxs[i])&lt;br /&gt;nbs[i] &lt;- trunc(xxs[i], 1)&lt;br /&gt;xxs[i+1] &lt;- nas[i]*2&lt;br /&gt;}&lt;br /&gt;return(nbs)&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;For example, in 8-bit:&lt;br /&gt;&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;&lt;br /&gt;decInt_to_8bit(11, 8)&lt;br /&gt;[1] 0 0 0 0 1 0 1 1&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;&lt;br /&gt;devDec_to_8bit(0.625, 8)&lt;br /&gt;[1] 1 0 1 0 0 0 0 0&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;&lt;br /&gt;devDec_to_8bit(0.3, 8)&lt;br /&gt;[1] 0 1 0 0 1 1 0 0&lt;br /&gt;devDec_to_8bit(0.3, 16)&lt;br /&gt;[1] 0 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;We can delete the extra-zeros from the vectors, using these functions:&lt;br /&gt;&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;&lt;br /&gt;remove.zero.aft &lt;- function(a) {&lt;br /&gt;n &lt;- length(a)&lt;br /&gt;for(i in n:1){&lt;br /&gt;if (a[n]==0) a &lt;- a[-n]&lt;br /&gt;else return(a)&lt;br /&gt;n &lt;- n-1&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;remove.zero.bef &lt;- function(a) {&lt;br /&gt;n &lt;- length(a)&lt;br /&gt;for(i in 1:n){&lt;br /&gt;if (a[1]==0) a &lt;- a[-1]&lt;br /&gt;else return(a)&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;So we have:&lt;br /&gt;&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;&lt;br /&gt;remove.zero.bef(decInt_to_8bit(11, 8))&lt;br /&gt;[1] 1 0 1 1&lt;br /&gt;&lt;br /&gt;remove.zero.aft(devDec_to_8bit(0.625, 8))&lt;br /&gt;[1] 1 0 1&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Binding these functions, we have:&lt;br /&gt;&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;&lt;br /&gt;dec.to.nbit &lt;- function(x,n) {&lt;br /&gt;aa &lt;- abs(trunc(x, 1))&lt;br /&gt;bb &lt;- abs(x) - abs(trunc(x))&lt;br /&gt;&lt;br /&gt;q &lt;- c()&lt;br /&gt;r &lt;- c()&lt;br /&gt;xx &lt;- c()&lt;br /&gt;for(i in 1:n){&lt;br /&gt;xx[1] &lt;- aa&lt;br /&gt;q[i] &lt;- xx[i] %/% 2&lt;br /&gt;r[i] &lt;- xx[i] %% 2&lt;br /&gt;xx[i+1] &lt;- q[i]&lt;br /&gt;}&lt;br /&gt;rr &lt;- rev(r)&lt;br /&gt;&lt;br /&gt;nas &lt;- c()&lt;br /&gt;nbs &lt;- c()&lt;br /&gt;xxs &lt;- c()&lt;br /&gt;for(i in 1:n)&lt;br /&gt;{&lt;br /&gt;xxs[1] &lt;- bb*2&lt;br /&gt;nas[i] &lt;- (xxs[i]) - floor(xxs[i])&lt;br /&gt;nbs[i] &lt;- trunc(xxs[i], 1)&lt;br /&gt;xxs[i+1] &lt;- nas[i]*2&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;bef &lt;- paste(remove.zero.bef(rr), collapse="")&lt;br /&gt;aft &lt;- paste(remove.zero.aft(nbs), collapse="")&lt;br /&gt;bef.aft &lt;- c(bef, aft)&lt;br /&gt;strings &lt;- paste(bef.aft, collapse=".")&lt;br /&gt;return(strings)&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;&lt;br /&gt;dec.to.nbit(11.625,8)&lt;br /&gt;[1] "1011.101"&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width="50%"&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;Now we can write the code for the decimal to IEEE-754 single float conversion in R:&lt;br /&gt;&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;&lt;br /&gt;dec.to.ieee754 &lt;- function(x) {&lt;br /&gt;aa &lt;- abs(trunc(x, 1))&lt;br /&gt;bb &lt;- abs(x) - abs(trunc(x))&lt;br /&gt;&lt;br /&gt;rr &lt;- decInt_to_8bit(aa, 32)&lt;br /&gt;&lt;br /&gt;ppc &lt;- 24 - length(remove.zero.bef(rr))&lt;br /&gt;&lt;br /&gt;nbs &lt;- devDec_to_8bit(bb, ppc)&lt;br /&gt;&lt;br /&gt;bef &lt;- remove.zero.bef(rr)&lt;br /&gt;aft &lt;- remove.zero.aft(nbs)&lt;br /&gt;&lt;br /&gt;exp &lt;- length(bef) - 1&lt;br /&gt;mantissa &lt;- c(bef[-1], aft)&lt;br /&gt;&lt;br /&gt;exp.bin &lt;- decInt_to_8bit(exp + 127, 16)&lt;br /&gt;exp.bin &lt;- remove.zero.bef(exp.bin)&lt;br /&gt;&lt;br /&gt;first &lt;- c()&lt;br /&gt;if (sign(x)==1) first=c(0)&lt;br /&gt;if (sign(x)==-1) first=c(1)&lt;br /&gt;&lt;br /&gt;ieee754 &lt;- c(first, exp.bin, mantissa, rep(0, 23-length(mantissa)))&lt;br /&gt;ieee754 &lt;- paste(ieee754, collapse="")&lt;br /&gt;&lt;br /&gt;return(ieee754)&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The numbers 11.625 and 11.33 in IEEE-754 are:&lt;br /&gt;&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;&lt;br /&gt;dec.to.ieee754(11.625)&lt;br /&gt;[1] "01000001001110100000000000000000"&lt;br /&gt;&lt;br /&gt;dec.to.ieee754(11.33)&lt;br /&gt;[1] "01000001001101010100011110101110"&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;You can verify the output with this &lt;a href="http://www.binaryconvert.com/index.html" target="_blank"&gt;Online Binary-Decimal Converter&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-2361246015824566013?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/2361246015824566013/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2010/10/convert-decimal-to-ieee-754-in-r.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/2361246015824566013'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/2361246015824566013'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2010/10/convert-decimal-to-ieee-754-in-r.html' title='Convert decimal to IEEE-754 in R'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-1342624649124163298</id><published>2010-04-28T18:22:00.004+02:00</published><updated>2010-04-28T18:29:42.811+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Bhapkar V test'/><title type='text'>Bhapkar V test</title><content type='html'>This is the code to perform the Bhapkar V test. I've rapidly wrote it, in 2 hours. The code is then quite &lt;i&gt;brutal&lt;/i&gt; and it could be done better. As soon as possible, I will correct it.&lt;br /&gt;&lt;br /&gt;WARNING: it works *ONLY* with 3 groups, for now!&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;bhapkar.test.3g &lt;- function(data1=list){&lt;br /&gt;&lt;br /&gt;sample &lt;- c()&lt;br /&gt;for(i in 1:length(data1)){&lt;br /&gt;sample &lt;- c(sample, rep(i, length(data1[[i]])))&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;obs &lt;- c()&lt;br /&gt;for(i in 1:length(data1)){&lt;br /&gt;obs &lt;- c(obs, data1[[i]])&lt;br /&gt;}&lt;br /&gt;rank &lt;- rank(obs)&lt;br /&gt;&lt;br /&gt;cplets &lt;- list()&lt;br /&gt;vec &lt;- c()&lt;br /&gt;for(i in 1:length(data1[[1]])){&lt;br /&gt;vec &lt;- c(vec, (length(data1[[2]][data1[[2]]&gt;data1[[1]][i]]) * length(data1[[3]][data1[[3]]&gt;data1[[1]][i]])))&lt;br /&gt;}&lt;br /&gt;cplets[[1]] &lt;- vec&lt;br /&gt;&lt;br /&gt;vec &lt;- c()&lt;br /&gt;for(i in 1:length(data1[[2]])){&lt;br /&gt;vec &lt;- c(vec, (length(data1[[1]][data1[[1]]&gt;data1[[2]][i]]) * length(data1[[3]][data1[[3]]&gt;data1[[2]][i]])))&lt;br /&gt;}&lt;br /&gt;cplets[[2]] &lt;- vec&lt;br /&gt;&lt;br /&gt;vec &lt;- c()&lt;br /&gt;for(i in 1:length(data1[[3]])){&lt;br /&gt;vec &lt;- c(vec, (length(data1[[2]][data1[[2]]&gt;data1[[3]][i]]) * length(data1[[1]][data1[[1]]&gt;data1[[3]][i]])))&lt;br /&gt;}&lt;br /&gt;cplets[[3]] &lt;- vec&lt;br /&gt;&lt;br /&gt;cplets1 &lt;- c(cplets[[1]], cplets[[2]], cplets[[3]])&lt;br /&gt;mydata &lt;- data.frame(obs=obs, sample=sample, rank=rank, cplets=cplets1)&lt;br /&gt;&lt;br /&gt;v1 &lt;- sum(cplets[[1]])&lt;br /&gt;v2 &lt;- sum(cplets[[2]])&lt;br /&gt;v3 &lt;- sum(cplets[[3]])&lt;br /&gt;&lt;br /&gt;vtot &lt;- v1+v2+v3&lt;br /&gt;u1 &lt;- v1/vtot&lt;br /&gt;u2 &lt;- v2/vtot&lt;br /&gt;u3 &lt;- v3/vtot&lt;br /&gt;u &lt;- c(u1,u2,u3)&lt;br /&gt;&lt;br /&gt;lengths &lt;- c(length(data1[[1]]), length(data1[[2]]), length(data1[[3]]))&lt;br /&gt;N &lt;- sum(lengths)&lt;br /&gt;P &lt;- c(lengths / N)&lt;br /&gt;ngroup &lt;- length(data1)&lt;br /&gt;&lt;br /&gt;V &lt;- N * (2*length(data1)-1)* (sum(P*((u-1/ngroup)^2)) - (sum(P*((u-1/ngroup))))^2)&lt;br /&gt;&lt;br /&gt;prop &lt;- pchisq(V, df=length(data1)-1)&lt;br /&gt;names(V) = "V = "&lt;br /&gt;method = "Bhapkar V-test"&lt;br /&gt;rval &lt;- list(method = method, statistic = V, p.value = prop)&lt;br /&gt;class(rval) = "htest"&lt;br /&gt;return(rval)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;An example:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;a &lt;- c(42, 46, 48.5, 49, 68, 51)&lt;br /&gt;b &lt;- c(70.5, 54, 60,72)&lt;br /&gt;c &lt;- c(66, 54, 43, 105, 94)&lt;br /&gt;&lt;br /&gt;mydata &lt;- list(a,b,c)&lt;br /&gt;&lt;br /&gt;bhapkar.test.3g(mydata)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        Bhapkar V-test&lt;br /&gt;&lt;br /&gt;data:  &lt;br /&gt;V = 6.7713, p-value = 0.9661&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;REFERENCES&lt;/b&gt;:&lt;br /&gt;&lt;i&gt;Statistical analysis of nonnormal data&lt;/i&gt;&lt;br /&gt;By J. V. Deshpande, A. P. Gore, A. Shanubhogue&lt;br /&gt;pag. 61&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-1342624649124163298?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/1342624649124163298/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2010/04/bhapkar-v-test.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/1342624649124163298'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/1342624649124163298'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2010/04/bhapkar-v-test.html' title='Bhapkar V test'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-4069483112031982717</id><published>2010-01-06T13:21:00.003+01:00</published><updated>2010-01-06T13:29:12.803+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Latin square design'/><category scheme='http://www.blogger.com/atom/ns#' term='ANOVA'/><category scheme='http://www.blogger.com/atom/ns#' term='Three-way ANOVA'/><title type='text'>Latin squares design in R</title><content type='html'>The Latin square design is used where the researcher desires to control the variation in an experiment that is related to rows and columns in the field.&lt;br /&gt;Remember that:&lt;br /&gt;    * Treatments are assigned at random within rows and columns, with each treatment once per row and once per column.&lt;br /&gt;    * There are equal numbers of rows, columns, and treatments.&lt;br /&gt;    * Useful where the experimenter desires to control variation in two different directions&lt;br /&gt;&lt;br /&gt;The formula used for this kind of three-way ANOVA are:&lt;br /&gt;&lt;br /&gt;&lt;table border=1 cellspacing="0" cellpadding="5"&gt;&lt;tr align="right" valign="top" bgcolor="cccccc"&gt;  &lt;td align="left"&gt;&lt;b&gt;Source of&lt;br&gt;variation&lt;/b&gt;&lt;/td&gt;  &lt;td align="center"&gt;&lt;b&gt;Degrees of&lt;br&gt;freedom&lt;sup&gt;a&lt;/sup&gt;&lt;/b&gt;&lt;/td&gt;  &lt;td align="center"&gt;&lt;b&gt;Sums of&lt;br&gt;squares (SSQ)&lt;/b&gt;&lt;/td&gt;  &lt;td align="center"&gt;&lt;b&gt;Mean&lt;br&gt;square (MS)&lt;/b&gt;&lt;/td&gt;  &lt;td align="center"&gt;&lt;b&gt;F&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr align="right" valign="center"&gt;  &lt;td align="left"&gt;Rows (&lt;i&gt;R&lt;/i&gt;)&lt;/td&gt;  &lt;td align="center"&gt;r-1&lt;/td&gt;  &lt;td align="center"&gt;SSQ&lt;sub&gt;&lt;i&gt;R&lt;/i&gt;&lt;/sub&gt;&lt;/td&gt;  &lt;td align="center"&gt;SSQ&lt;sub&gt;&lt;i&gt;R&lt;/i&gt;&lt;/sub&gt;/(r-1)&lt;/td&gt;  &lt;td align="center"&gt;MS&lt;sub&gt;&lt;i&gt;R&lt;/i&gt;&lt;/sub&gt;/MS&lt;sub&gt;&lt;i&gt;E&lt;/i&gt;&lt;/sub&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr align="right" valign="center"&gt;  &lt;td align="left"&gt;Columns (&lt;i&gt;C&lt;/i&gt;)&lt;/td&gt;  &lt;td align="center"&gt;r-1&lt;/td&gt;  &lt;td align="center"&gt;SSQ&lt;sub&gt;&lt;i&gt;C&lt;/i&gt;&lt;/sub&gt;&lt;/td&gt;  &lt;td align="center"&gt;SSQ&lt;sub&gt;&lt;i&gt;C&lt;/i&gt;&lt;/sub&gt;/(r-1)&lt;/td&gt;  &lt;td align="center"&gt;MS&lt;sub&gt;&lt;i&gt;C&lt;/i&gt;&lt;/sub&gt;/MS&lt;sub&gt;&lt;i&gt;E&lt;/i&gt;&lt;/sub&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr align="right" valign="center"&gt;  &lt;td align="left"&gt;Treatments (&lt;i&gt;Tr&lt;/i&gt;)&lt;/td&gt; &lt;td align="center"&gt;r-1&lt;/td&gt;  &lt;td align="center"&gt;SSQ&lt;sub&gt;&lt;i&gt;Tr&lt;/i&gt;&lt;/sub&gt;&lt;/td&gt;  &lt;td align="center"&gt;SSQ&lt;sub&gt;&lt;i&gt;Tr&lt;/i&gt;&lt;/sub&gt;/(r-1)&lt;/td&gt;  &lt;td align="center"&gt;MS&lt;sub&gt;&lt;i&gt;Tr&lt;/i&gt;&lt;/sub&gt;/MS&lt;sub&gt;&lt;i&gt;E&lt;/i&gt;&lt;/sub&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr align="right" valign="center"&gt;  &lt;td align="left"&gt;Error (&lt;i&gt;E&lt;/i&gt;)&lt;/td&gt;  &lt;td align="center"&gt;(r-1)(r-2)&lt;/td&gt;  &lt;td align="center"&gt;SSQ&lt;sub&gt;&lt;i&gt;E&lt;/i&gt;&lt;/sub&gt;&lt;/td&gt;  &lt;td align="center"&gt;SSQ&lt;sub&gt;&lt;i&gt;E&lt;/i&gt;&lt;/sub&gt;/((r-1)(r-2))&lt;/td&gt;  &lt;td align="center"&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;&lt;tr align="right" valign="center"&gt;  &lt;td align="left"&gt;Total (&lt;i&gt;Tot&lt;/i&gt;)&lt;/td&gt;  &lt;td align="center"&gt;r&lt;sup&gt;2&lt;/sup&gt;-1&lt;/td&gt;  &lt;td align="center"&gt;SSQ&lt;sub&gt;&lt;i&gt;Tot&lt;/i&gt;&lt;/sub&gt;&lt;/td&gt;  &lt;td align="center"&gt;&amp;nbsp;&lt;/td&gt;  &lt;td align="center"&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=5&gt;&lt;sup&gt;a&lt;/sup&gt;where r = number of (treatments=rows=columns).&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;Suppose you want to analyse the productivity of 5 kind on fertilizer, 5 kind of tillage, and 5 kind of seed. The data are organized in a latin square design, as follow:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;             treatA  treatB  treatC  treatD  treatE&lt;br /&gt;fertilizer1  "A42"   "C47"   "B55"   "D51"   "E44"         &lt;br /&gt;fertilizer2  "E45"   "B54"   "C52"   "A44"   "D50"         &lt;br /&gt;fertilizer3  "C41"   "A46"   "D57"   "E47"   "B48"         &lt;br /&gt;fertilizer4  "B56"   "D52"   "E49"   "C50"   "A43"         &lt;br /&gt;fertilizer5  "D47"   "E49"   "A45"   "B54"   "C46"  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The three factors are: fertilizer (fertilizer1:5), tillage (treatA:E), seed (A:E). The numbers are the productivity in cwt / year.&lt;br /&gt;&lt;br /&gt;Now create a dataframe in R with these data:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;fertil &lt;- c(rep("fertil1",1), rep("fertil2",1), rep("fertil3",1), rep("fertil4",1), rep("fertil5",1))&lt;br /&gt;treat &lt;- c(rep("treatA",5), rep("treatB",5), rep("treatC",5), rep("treatD",5), rep("treatE",5))&lt;br /&gt;seed &lt;- c("A","E","C","B","D", "C","B","A","D","E", "B","C","D","E","A", "D","A","E","C","B", "E","D","B","A","C")&lt;br /&gt;freq &lt;- c(42,45,41,56,47, 47,54,46,52,49, 55,52,57,49,45, 51,44,47,50,54, 44,50,48,43,46)&lt;br /&gt; &lt;br /&gt;mydata &lt;- data.frame(treat, fertil, seed, freq)&lt;br /&gt;&lt;br /&gt;mydata&lt;br /&gt;&lt;br /&gt;    treat  fertil seed freq&lt;br /&gt;1  treatA fertil1    A   42&lt;br /&gt;2  treatA fertil2    E   45&lt;br /&gt;3  treatA fertil3    C   41&lt;br /&gt;4  treatA fertil4    B   56&lt;br /&gt;5  treatA fertil5    D   47&lt;br /&gt;6  treatB fertil1    C   47&lt;br /&gt;7  treatB fertil2    B   54&lt;br /&gt;8  treatB fertil3    A   46&lt;br /&gt;9  treatB fertil4    D   52&lt;br /&gt;10 treatB fertil5    E   49&lt;br /&gt;11 treatC fertil1    B   55&lt;br /&gt;12 treatC fertil2    C   52&lt;br /&gt;13 treatC fertil3    D   57&lt;br /&gt;14 treatC fertil4    E   49&lt;br /&gt;15 treatC fertil5    A   45&lt;br /&gt;16 treatD fertil1    D   51&lt;br /&gt;17 treatD fertil2    A   44&lt;br /&gt;18 treatD fertil3    E   47&lt;br /&gt;19 treatD fertil4    C   50&lt;br /&gt;20 treatD fertil5    B   54&lt;br /&gt;21 treatE fertil1    E   44&lt;br /&gt;22 treatE fertil2    D   50&lt;br /&gt;23 treatE fertil3    B   48&lt;br /&gt;24 treatE fertil4    A   43&lt;br /&gt;25 treatE fertil5    C   46&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We can re-create the original table, using the matrix function:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;matrix(mydata$seed, 5,5)&lt;br /&gt;&lt;br /&gt;     [,1] [,2] [,3] [,4] [,5]&lt;br /&gt;[1,] "A"  "C"  "B"  "D"  "E" &lt;br /&gt;[2,] "E"  "B"  "C"  "A"  "D" &lt;br /&gt;[3,] "C"  "A"  "D"  "E"  "B" &lt;br /&gt;[4,] "B"  "D"  "E"  "C"  "A" &lt;br /&gt;[5,] "D"  "E"  "A"  "B"  "C" &lt;br /&gt;&lt;br /&gt;matrix(mydata$freq, 5,5)&lt;br /&gt;&lt;br /&gt;     [,1] [,2] [,3] [,4] [,5]&lt;br /&gt;[1,]   42   47   55   51   44&lt;br /&gt;[2,]   45   54   52   44   50&lt;br /&gt;[3,]   41   46   57   47   48&lt;br /&gt;[4,]   56   52   49   50   43&lt;br /&gt;[5,]   47   49   45   54   46&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Before proceeding with the analysis of variance of this Latin square design, you should perform a Boxplot, aimed to have an idea of what we expect:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;par(mfrow=c(2,2))&lt;br /&gt;plot(freq ~ fertil+treat+seed, mydata)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a href="http://img684.imageshack.us/img684/1954/lsd1.jpg" target="_blank"&gt;&lt;img src="http://img684.imageshack.us/img684/1954/lsd1.th.jpg" border="0" /&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;Note that the differences considering the fertilizer is low; it is medium considering the tillage, and is very high considering the seed.&lt;br /&gt;Now confirm these graphics observations, with the ANOVA table:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;myfit &lt;- lm(freq ~ fertil+treat+seed, mydata)&lt;br /&gt;anova(myfit)&lt;br /&gt;&lt;br /&gt;Analysis of Variance Table&lt;br /&gt;&lt;br /&gt;Response: freq&lt;br /&gt;          Df  Sum Sq Mean Sq F value   Pr(&gt;F)    &lt;br /&gt;fertil     4  17.760   4.440  0.7967 0.549839    &lt;br /&gt;treat      4 109.360  27.340  4.9055 0.014105 *  &lt;br /&gt;seed       4 286.160  71.540 12.8361 0.000271 ***&lt;br /&gt;Residuals 12  66.880   5.573                     &lt;br /&gt;---&lt;br /&gt;Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Well, the boxplot was useful. Look at the significance of the F-test.&lt;br /&gt;- The difference between group considering the fertilizer is not significant (p-value &gt; 0.1);&lt;br /&gt;- The difference between group considering the tillage is quite significant (p-value &lt; 0.05);&lt;br /&gt;- The difference between group considering the seed is very significant (p-value &lt; 0.001);&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-4069483112031982717?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/4069483112031982717/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2010/01/latin-squares-design-in-r.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/4069483112031982717'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/4069483112031982717'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2010/01/latin-squares-design-in-r.html' title='Latin squares design in R'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-2907645859162343907</id><published>2009-09-05T20:26:00.000+02:00</published><updated>2009-09-05T20:27:46.892+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Polynomial regression'/><category scheme='http://www.blogger.com/atom/ns#' term='Regression'/><title type='text'>Polynomial regression techniques</title><content type='html'>Suppose we want to create a polynomial that can approximate better the following dataset on the population of a certain Italian city over 10 years. The table summarizes the data:&lt;br /&gt;&lt;br /&gt;$$\begin{tabular}{|1|1|}\hline Year &amp; Population\\ \hline 1959&amp;4835\\ 1960&amp;4970\\ 1961&amp;5085\\ 1962&amp;5160\\ 1963&amp;5310\\ 1964&amp;5260\\ 1965&amp;5235\\ 1966&amp;5255\\ 1967&amp;5235\\ 1968&amp;5210\\ 1969&amp;5175\\ \hline \end{tabular}$$&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;First we import the data into R:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;Year &lt;- c(1959, 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969)&lt;br /&gt;Population &lt;- c(4835, 4970, 5085, 5160, 5310, 5260, 5235, 5255, 5235, 5210, 5175)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now we create the dataframe named sample1:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;sample1 &lt;- data.frame(Year, Population)&lt;br /&gt;sample1&lt;br /&gt;&lt;br /&gt;   Year Population&lt;br /&gt;1  1959       4835&lt;br /&gt;2  1960       4970&lt;br /&gt;3  1961       5085&lt;br /&gt;4  1962       5160&lt;br /&gt;5  1963       5310&lt;br /&gt;6  1964       5260&lt;br /&gt;7  1965       5235&lt;br /&gt;8  1966       5255&lt;br /&gt;9  1967       5235&lt;br /&gt;10 1968       5210&lt;br /&gt;11 1969       5175&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;At this point may be useful to chart these values, to observe the trend and take an idea of the final polynomial function. For convenience we modify the column &lt;code style="color: rgb(153, 0, 0);"&gt;Year&lt;/code&gt;, creating a neighborhood of zero, thus:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;sample1$Year &lt;- sample1$Year - 1964&lt;br /&gt;sample1&lt;br /&gt;&lt;br /&gt;   Year Population&lt;br /&gt;1    -5       4835&lt;br /&gt;2    -4       4970&lt;br /&gt;3    -3       5085&lt;br /&gt;4    -2       5160&lt;br /&gt;5    -1       5310&lt;br /&gt;6     0       5260&lt;br /&gt;7     1       5235&lt;br /&gt;8     2       5255&lt;br /&gt;9     3       5235&lt;br /&gt;10    4       5210&lt;br /&gt;11    5       5175&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Put the values on a chart&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;plot(sample1$Year, sample1$Population, type="b")&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a href="http://img137.imageshack.us/img137/7946/pol1.jpg" target="_blank"&gt;&lt;img src="http://img137.imageshack.us/img137/7946/pol1.th.jpg" border="0"/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;At this point we can start with the search for a polynomial model that adequately approximates our data. First, we specify that we want a polynomial function of X, ie a &lt;em&gt;raw polynomial&lt;/em&gt; , is different from the &lt;em&gt;orthogonal polynomial&lt;/em&gt;. This is an important addition because the controls and the results will change in the two cases R. So we want a function of X like:&lt;br /&gt;&lt;br /&gt;$$f(x)=\beta_0+\beta_1x+\beta_2x^2+\beta_3x^3+ ... +\beta_nx^n$$&lt;br /&gt;&lt;br /&gt;At what degree of the polynomial stop? Depends on the degree of precision that we seek. The greater the degree of the polynomial, the greater the accuracy of the model, but the greater the difficulty in calculating; we must also verify the significance of coefficients that are found. But let's get straight to the point.&lt;br /&gt;&lt;br /&gt;In R for &lt;b&gt;fitting a polynomial regression model&lt;/b&gt; (not orthogonal), there are two methods, among them identical. Suppose we seek the values of beta coefficients for a polynomial of degree 1, then 2nd degree, and 3rd degree:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;fit1 &lt;- lm(sample1$Population ~ sample1$Year)&lt;br /&gt;fit2 &lt;- lm(sample1$Population ~ sample1$Year + I(sample1$Year^2))&lt;br /&gt;fit3 &lt;- lm(sample1$Population ~ sample1$Year + I(sample1$Year^2) + I(sample1$Year^3))&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Or we can write more quickly, for polynomials of degree 2 and 3:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;fit2b &lt;- lm(sample1$Population ~ poly(sample1$Year, 2, raw=TRUE))&lt;br /&gt;fit3b &lt;- lm(sample1$Population ~ poly(sample1$Year, 3, raw=TRUE))&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The function &lt;code style="color: rgb(153, 0, 0);"&gt;poly&lt;/code&gt; is useful if you want to get a polynomial of high degree, because it avoids explicitly write the formula. If we specify &lt;code style="color: rgb(153, 0, 0);"&gt;raw=TRUE&lt;/code&gt;, the two methods provide the same output, but if we do not specify &lt;code style="color: rgb(153, 0, 0);"&gt;raw=TRUE&lt;/code&gt; (or rgb(153, 0, 0);"&gt;raw=F&lt;/code&gt;), the function &lt;code style="color: rgb(153, 0, 0);"&gt;poly&lt;/code&gt; give us the values of the beta parameters of an orthogonal polynomials, which is different from the general formula I wrote above, although the models are both effective.&lt;br /&gt;&lt;br /&gt;Let's look at the output. &lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;summary(fit2)&lt;br /&gt;## or summary(fit2b)&lt;br /&gt;&lt;br /&gt;Call:&lt;br /&gt;lm(formula = sample1$Population ~ sample1$Year + I(sample1$Year^2))&lt;br /&gt;&lt;br /&gt;Residuals:&lt;br /&gt;    Min      1Q  Median      3Q     Max &lt;br /&gt;-46.888 -18.834  -3.159   2.040  86.748 &lt;br /&gt;&lt;br /&gt;Coefficients:&lt;br /&gt;                  Estimate Std. Error t value Pr(&gt;|t|)    &lt;br /&gt;(Intercept)       5263.159     17.655 298.110  &lt; 2e-16 ***&lt;br /&gt;sample1$Year        29.318      3.696   7.933 4.64e-05 ***&lt;br /&gt;I(sample1$Year^2)  -10.589      1.323  -8.002 4.36e-05 ***&lt;br /&gt;---&lt;br /&gt;Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 &lt;br /&gt;&lt;br /&gt;Residual standard error: 38.76 on 8 degrees of freedom&lt;br /&gt;Multiple R-squared: 0.9407,     Adjusted R-squared: 0.9259 &lt;br /&gt;F-statistic: 63.48 on 2 and 8 DF,  p-value: 1.235e-05 &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The output of &lt;code style="color: rgb(153, 0, 0);"&gt;summary(fit2b)&lt;/code&gt; is the same. We obtained the values of beta0 (5263,159), beta1 (29,318) and beta2 (-10,589), which appear to be significant AII 3. The equation of polynomial of degree 2 of our model is:&lt;br /&gt;&lt;br /&gt;$$f(x)=5263.1597+29.318x-10.589x^2$$&lt;br /&gt;&lt;br /&gt;If we want a polynomial of 3rd degree, we have:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;summary(fit3)&lt;br /&gt;## of summary(fit3b)&lt;br /&gt;&lt;br /&gt;Call:&lt;br /&gt;lm(formula = sample1$Population ~ sample1$Year + I(sample1$Year^2) + &lt;br /&gt;    I(sample1$Year^3))&lt;br /&gt;&lt;br /&gt;Residuals:&lt;br /&gt;    Min      1Q  Median      3Q     Max &lt;br /&gt;-32.774 -14.802  -1.253   3.199  72.634 &lt;br /&gt;&lt;br /&gt;Coefficients:&lt;br /&gt;                   Estimate Std. Error t value Pr(&gt;|t|)    &lt;br /&gt;(Intercept)       5263.1585    15.0667 349.324 4.16e-16 ***&lt;br /&gt;sample1$Year        14.3638     8.1282   1.767   0.1205    &lt;br /&gt;I(sample1$Year^2)  -10.5886     1.1293  -9.376 3.27e-05 ***&lt;br /&gt;I(sample1$Year^3)    0.8401     0.4209   1.996   0.0861 .  &lt;br /&gt;---&lt;br /&gt;Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 &lt;br /&gt;&lt;br /&gt;Residual standard error: 33.08 on 7 degrees of freedom&lt;br /&gt;Multiple R-squared: 0.9622,     Adjusted R-squared: 0.946 &lt;br /&gt;F-statistic: 59.44 on 3 and 7 DF,  p-value: 2.403e-05 &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The equation is:&lt;br /&gt;&lt;br /&gt;$$f(x)=5263.1585+14.3638x-10.5886x^2+0.8401x^3$$&lt;br /&gt;&lt;br /&gt;In the latter case, however, the coefficients beta1 and beta3 are not significant, then the best model is the polynomial of 2nd degree. Furthermore look at the Multiple R-squared: in the 2nd degree model it is 94.07%, while in the 3rd degree model it is 96.22%. It seems that there has been an increase in accuracy of the model, but it is a significant increase? We can compare the two model with an ANOVA table:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;anova(fit2, fit3)&lt;br /&gt;&lt;br /&gt;Analysis of Variance Table&lt;br /&gt;&lt;br /&gt;Model 1: sample1$Population ~ sample1$Year + I(sample1$Year^2)&lt;br /&gt;Model 2: sample1$Population ~ sample1$Year + I(sample1$Year^2) + I(sample1$Year^3)&lt;br /&gt;  Res.Df     RSS Df Sum of Sq      F Pr(&gt;F)  &lt;br /&gt;1      8 12019.8                             &lt;br /&gt;2      7  7659.5  1    4360.3 3.9848 0.0861 .&lt;br /&gt;---&lt;br /&gt;Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Since the p-value is greater than 0.05, we accept the null hypothesis: there wasn't a significant improvement of the model.&lt;br /&gt;&lt;br /&gt;The biggest problem now is to represent graphically the result. In fact, R does not exist (as far as I know) a function for plotting polynomials found. We must therefore proceed with graphic artifacts still valid, but somewhat laborious.&lt;br /&gt;&lt;br /&gt;First, we plotted the values, with the command seen before. This time only display the lines and not points, for convenience graphics:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;plot(sample1$Year, sample1$Population, type="l", lwd=3)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now add to this chart the progress of the 2nd degree polynomial, in this way:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;points(sample1$Year, predict(fit2), type="l", col="red", lwd=2)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The function &lt;code style="color: rgb(153, 0, 0);"&gt;predict()&lt;/code&gt; compute the Y values given the X values. The the coordinates are linked with lines. Is not plotted the continuous, but the discrete. With a few values, this method is highly debilitating.&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a href="http://img245.imageshack.us/img245/9274/pol2d.jpg" target="_blank"&gt;&lt;img src="http://img245.imageshack.us/img245/9274/pol2d.th.jpg" border="0"/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;Let's add the graph of the polynomial of 3rd degree:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;points(sample1&amp;Year, predict(fit3), type="l", col="blue", lwd=2)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a href="http://img269.imageshack.us/img269/6797/pol3k.jpg" target="_blank"&gt;&lt;img src="http://img269.imageshack.us/img269/6797/pol3k.th.jpg" border="0"/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;As you can see the two models have very similar trends.&lt;br /&gt;&lt;br /&gt;If we would instead obtain the graph of continuous functions obtained, we proceed in this manner. First you create the polynomial equation we previously found:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;pol2 &lt;- function(x) fit2$coefficient[3]*x^2 + fit2$coefficient[2]*x + fit2$coefficient[1]&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Remember that:&lt;br /&gt;- coefficient[1] = beta0&lt;br /&gt;- coefficient[2] = beta1&lt;br /&gt;- coefficient[3] = beta2&lt;br /&gt;and so on.&lt;br /&gt;&lt;br /&gt;At this point we plotted the coordinates of sample1 and then the created curve with &lt;code style="color: rgb(153, 0, 0);"&gt;curve(x)&lt;/code&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;plot(sample1$Year, sample1$Population, type="p", lwd=3)&lt;br /&gt;pol2 &lt;- function(x) fit2$coefficient[3]*x^2 + fit2$coefficient[2]*x + fit2$coefficient[1]&lt;br /&gt;curve(pol2, col="red", lwd=2)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The point, however, disappear, but we can replace them with the command &lt;code style="color: rgb(153, 0, 0);"&gt;points&lt;/code&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;points(sample1$Year, sample1$Population, type="p", lwd=3)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;A note: you must follow the order of commands as I have described, otherwise the function &lt;code style="color: rgb(153, 0, 0);"&gt;curve&lt;/code&gt; creates a wrong graph. So summarizing the commands to get the continuous function, and the experimental points on the same graph are the following:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;plot(sample1$Year, sample1$Population, type="p", lwd=3)&lt;br /&gt;pol2 &lt;- function(x) fit2$coefficient[3]*x^2 + fit2$coefficient[2]*x + fit2$coefficient[1]&lt;br /&gt;curve(pol2, col="red", lwd=2)&lt;br /&gt;points(sample1$Year, sample1$Population, type="p", lwd=3)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The graph we get is the following:&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a href="http://img245.imageshack.us/img245/4396/pol4.jpg" target="_blank"&gt;&lt;img src="http://img245.imageshack.us/img245/4396/pol4.th.jpg" border="0"/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;Now draw the graph of the polynomial of 3rd degree:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;plot(sample1$Year, sample1$Population, type="p", lwd=3)&lt;br /&gt;pol3 &lt;- function(x) fit3$coefficient[4]*x^3 + fit3$coefficient[3]*x^2 + fit3$coefficient[2]*x + fit3$coefficient[1]&lt;br /&gt;curve(pol3, col="red", lwd=2)&lt;br /&gt;points(sample1$Year, sample1$Population, type="p", lwd=3)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a href="http://img269.imageshack.us/img269/261/pol5e.jpg" target="_blank"&gt;&lt;img src="http://img269.imageshack.us/img269/261/pol5e.th.jpg" border="0"/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-2907645859162343907?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/2907645859162343907/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/09/polynomial-regression-techniques.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/2907645859162343907'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/2907645859162343907'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/09/polynomial-regression-techniques.html' title='Polynomial regression techniques'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-2379097929919335020</id><published>2009-08-25T20:44:00.004+02:00</published><updated>2009-08-27T17:18:06.304+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Cox-Stuart test'/><category scheme='http://www.blogger.com/atom/ns#' term='Google Analytics'/><category scheme='http://www.blogger.com/atom/ns#' term='Trend analysis'/><category scheme='http://www.blogger.com/atom/ns#' term='Simple linear regression'/><category scheme='http://www.blogger.com/atom/ns#' term='Import data in R'/><title type='text'>Web-site trend analysis with data from Google Analytics</title><content type='html'>This post is a summary of my two previous posts on the &lt;b&gt;trend analysis&lt;/b&gt; with the &lt;a href="http://statistic-on-air.blogspot.com/2009/08/trend-analysis-with-cox-stuart-test-in.html"&gt;Cox-Stuart test&lt;/a&gt; and on &lt;a href="http://statistic-on-air.blogspot.com/2009/08/simple-linear-regression.html"&gt;simple linear regression&lt;/a&gt;. The goal that we propose is to assess the trend in the number of visits received from a site over a long time. I use &lt;em&gt;Google Analytics&lt;/em&gt;, because this tool allows us to save the various reports in &lt;em&gt;Excel CSV format&lt;/em&gt;. Let's see, step by step, how to save the reportage, and then &lt;b&gt;how to import data from Excel to R&lt;/b&gt;, and finally how to estimate if the number of daily visitors follows an increasing or decreasing trend.&lt;br /&gt;&lt;br /&gt;Let's start by creating an ad hoc report in Google Analytics. Once you have logged in, select the date range that we want to analyze. Then click on&lt;i&gt;Visits&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;center&gt;&lt;a target='_blank' href='hhttp://img25.imageshack.us/img25/5784/62278291.jpg'&gt;&lt;img src='http://img25.imageshack.us/img25/5784/62278291.th.jpg' border='0'/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;At this point we can save the report, clicking on &lt;i&gt;Export&lt;/i&gt; and then clicking on &lt;b&gt;CSV for Excel&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a target='_blank' href='http://img253.imageshack.us/img253/9418/38168132.jpg'&gt;&lt;img src='http://img253.imageshack.us/img253/9418/38168132.th.jpg' border='0'/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;Save the CSV file, and open it with Excel. Here's how it seems:&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a target='_blank' href='http://img443.imageshack.us/img443/1205/83377368.jpg'&gt;&lt;img src='http://img443.imageshack.us/img443/1205/83377368.th.jpg' border='0'/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;Now import the data into R. Import data from Excel to R is very simple. Simply select the column (or columns) of our interest (in our case the column &lt;code style="color: rgb(153, 0, 0);"&gt;Visits&lt;/code&gt;) and copy in the clipboard with CTRL + C (remember to select the cell &lt;code style="color: rgb(153, 0, 0);"&gt;Visits&lt;/code&gt;, because it will be useful):&lt;br /&gt;&lt;br /&gt;Then open R and type the following command:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;myvisit &lt;- read.delim("clipboard")&lt;br /&gt;&lt;br /&gt;myvisit&lt;br /&gt;&lt;br /&gt;   Visits&lt;br /&gt;1      33&lt;br /&gt;2      41&lt;br /&gt;3      34&lt;br /&gt;4      45&lt;br /&gt;5      46&lt;br /&gt;6      37&lt;br /&gt;7      31&lt;br /&gt;8      37&lt;br /&gt;9      34&lt;br /&gt;10     34&lt;br /&gt;11     48&lt;br /&gt;12     39&lt;br /&gt;13     33&lt;br /&gt;...&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;It is a one column dataframe; the name of the column is Visits (so it is importat to select the header from Excel).&lt;br /&gt;&lt;br /&gt;Now we can proceed with the analysis of trends in the two proposed ways: through a &lt;b&gt;Cox-Stuart test&lt;/b&gt; e through the &lt;b&gt;analysis of the simple linear regression&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;The function to perform the Cox-Stuart test is available &lt;a href="http://statistic-on-air.blogspot.com/2009/08/trend-analysis-with-cox-stuart-test-in.html"&gt;here&lt;/a&gt;. First we must convert the dataframe in a format that can be read by the function cox.stuart.test, like this:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;visits &lt;- c(myvisit$Visits)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;I have created in this way, a vector (visits) that contains all data that were ordered in the column Visits of the dataframe myvisit. Now we provide a test of Cox-Stuart:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;cox.stuart.test(visits)&lt;br /&gt;&lt;br /&gt;        Cox-Stuart test for trend analysis&lt;br /&gt;&lt;br /&gt;data:  &lt;br /&gt;Increasing trend, p-value = 0.0012&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The output is very clear: We have detected an increasing trend of visits, highly significant (since &lt;i&gt;p-value &lt; 0.5&lt;/i&gt;). &lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width=50%&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;If we are not satisfied or sure of this result, we can take into account the slope of the regression line. Firstly may want to show the results. The vector contains the hits daily visits to the site. Now we create a sorted array of the days in question, the same length of the carrier hits:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;days &lt;- c(1 : length(visits))&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Create a plot:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;plot(days, visits, type="b")&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Choosing &lt;code style="color: rgb(153, 0, 0);"&gt;type="b"&lt;/code&gt; I see dots and lines, as shown in figure:&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a target='_blank' href='http://img145.imageshack.us/img145/2041/88334099.jpg'&gt;&lt;img src='http://img145.imageshack.us/img145/2041/88334099.th.jpg' border='0'/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;From this plot is not easy to observe a possible trend of the progress of visits. We can still do a regression analysis. Evaluating the sign of the slope of the line, we can estimate whether the trend is increasing or decreasing:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;fit &lt;- lm(visits ~ days)&lt;br /&gt;summary(fit)&lt;br /&gt;&lt;br /&gt;Call:&lt;br /&gt;lm(formula = visits ~ days)&lt;br /&gt;&lt;br /&gt;Residuals:&lt;br /&gt;    Min      1Q  Median      3Q     Max &lt;br /&gt;-22.714  -6.197  -1.313   5.648  31.153 &lt;br /&gt;&lt;br /&gt;Coefficients:&lt;br /&gt;            Estimate Std. Error t value Pr(&gt;|t|)    &lt;br /&gt;(Intercept) 31.79694    2.27151  13.998  &lt; 2e-16 ***&lt;br /&gt;days         0.19815    0.04242   4.671 1.04e-05 ***&lt;br /&gt;---&lt;br /&gt;Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 &lt;br /&gt;&lt;br /&gt;Residual standard error: 10.81 on 90 degrees of freedom&lt;br /&gt;Multiple R-squared: 0.1951,     Adjusted R-squared: 0.1862 &lt;br /&gt;F-statistic: 21.82 on 1 and 90 DF,  p-value: 1.043e-05 &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The slope coefficient has a value of: &lt;code style="color: rgb(153, 0, 0);"&gt;b = 0.06251&lt;/code&gt;. It therefore has a positive sign, then one may think of an increasing trend. The value of the statistical t-test on the slope, and its relative p-value, indicate either that it is significant. We can therefore say that there is an increasing trend.&lt;br /&gt;&lt;br /&gt;Finally, we can see the regression line directly on the plot previously obtained in this way:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;plot(days, visits, type="b")&lt;br /&gt;abline(fit, col="red", lwd=3)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The command abline allows us to add a line defined by the equation given, directly on the chart shown; the parameter "col" specifies the color and the "lwd" parameter specifies the thickness of the line. Observe now the graph:&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a target='_blank' href='http://img294.imageshack.us/img294/9043/36017503.jpg'&gt;&lt;img src='http://img294.imageshack.us/img294/9043/36017503.th.jpg' border='0'/&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;It's obvious that there is an increasing trend, as said by the Cox-Stuart test.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-2379097929919335020?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/2379097929919335020/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/08/web-site-trend-analysis-with-data-from.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/2379097929919335020'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/2379097929919335020'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/08/web-site-trend-analysis-with-data-from.html' title='Web-site trend analysis with data from Google Analytics'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-8237856403387792533</id><published>2009-08-20T12:43:00.009+02:00</published><updated>2009-08-20T13:05:32.095+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Contingency table'/><category scheme='http://www.blogger.com/atom/ns#' term='Logit'/><category scheme='http://www.blogger.com/atom/ns#' term='Logistic regression'/><category scheme='http://www.blogger.com/atom/ns#' term='OR'/><category scheme='http://www.blogger.com/atom/ns#' term='Regression'/><title type='text'>Simple logistic regression on qualitative dichotomic variables</title><content type='html'>In this post we will see briefly how to implement a logistic regression model if you have categorical variables, or qualitative, organized in double entry contingency tables. In this model the dependent variable (Y) and independent variable (X) are both dichotomies (or Bernoullian).&lt;br /&gt;&lt;br /&gt;In general, the probability that Y = 1 as a function of &lt;b&gt;predictors&lt;/b&gt; is:&lt;br /&gt;&lt;br /&gt;$$P(Y=1|X=x)=\pi(x)=\frac{exp(\beta_0+\beta_1x_1+\cdots +\beta_kx_k)}{1+exp(\beta_0+\beta_1x_1+\cdots +\beta_kx_k)}$$&lt;br /&gt;&lt;br /&gt;Our goal is to estimate the value of the beta parameters (&lt;b&gt;regressors&lt;/b&gt;).&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;We begin to examine a &lt;b&gt;model of simple logistic regression&lt;/b&gt; (with &lt;i&gt;only one predictor&lt;/i&gt;).&lt;br /&gt;&lt;br /&gt;Consider the following example. The table below shows the results of a study on gastroesophageal reflux. You want to evaluate how the presence of a stress factor can influence the onset of this disease.&lt;br /&gt;&lt;br /&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 244px; height: 141px;" src="http://1.bp.blogspot.com/_0yqjfYQXaSw/So0ra9uO28I/AAAAAAAAAF4/syOtm6rOq7Q/s400/refl.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5371997672767937474" /&gt;&lt;br /&gt;&lt;br /&gt;First we import the values in R. We must create a table with double entry; proceed as follows:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;reflux &lt;- matrix(c(251,131,4,33), nrow=2)&lt;br /&gt;colnames(reflux) &lt;- c("reflNO", "reflYES")&lt;br /&gt;rownames(reflux) &lt;- c("stressNO", "stressYES")&lt;br /&gt;table &lt;- as.table(reflux)&lt;br /&gt;&lt;br /&gt;table&lt;br /&gt;&lt;br /&gt;          reflNO reflYES&lt;br /&gt;stressNO     251       4&lt;br /&gt;stressYES    131      33&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now adjust the data for the logistic regression. We must create a data frame:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;dft &lt;- as.data.frame(table)&lt;br /&gt;dft&lt;br /&gt;&lt;br /&gt;       Var1    Var2 Freq&lt;br /&gt;1  stressNO  reflNO  251&lt;br /&gt;2 stressYES  reflNO  131&lt;br /&gt;3  stressNO reflYES    4&lt;br /&gt;4 stressYES reflYES   33&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We can now fit the model, and then perform the logistic regression in R:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;fit &lt;- glm(Var2 ~ Var1, weights = Freq, data = dft, family = binomial(logit))&lt;br /&gt;summary(fit)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Call:&lt;br /&gt;glm(formula = Var2 ~ Var1, family = binomial(logit), data = dft, &lt;br /&gt;    weights = Freq)&lt;br /&gt;&lt;br /&gt;Deviance Residuals: &lt;br /&gt;     1       2       3       4  &lt;br /&gt;-2.817  -7.672   5.765  10.287  &lt;br /&gt;&lt;br /&gt;Coefficients:&lt;br /&gt;              Estimate Std. Error z value Pr(&gt;|z|)    &lt;br /&gt;(Intercept)    -4.1392     0.5040  -8.213  &lt; 2e-16 ***&lt;br /&gt;Var1stressYES   2.7605     0.5403   5.109 3.23e-07 ***&lt;br /&gt;---&lt;br /&gt;Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 &lt;br /&gt;&lt;br /&gt;(Dispersion parameter for binomial family taken to be 1)&lt;br /&gt;&lt;br /&gt;    Null deviance: 250.23  on 3  degrees of freedom&lt;br /&gt;Residual deviance: 205.86  on 2  degrees of freedom&lt;br /&gt;AIC: 209.86&lt;br /&gt;&lt;br /&gt;Number of Fisher Scoring iterations: 6&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;First we comment the code to perform the regression. The logistic regression is called imposing the family: &lt;code style="color: rgb(153, 0, 0);"&gt;family = binomial(logit)&lt;/code&gt;. The code &lt;code style="color: rgb(153, 0, 0);"&gt;Var2 ~ Var1&lt;/code&gt; means that we want to create a model that will explain the variable var2 (presence or absence of reflux) as a function of the variable var1 (presence or absence of stressful events). In practice var2 is the independent variable Y, and Var1 is the dependent variable X (the regressors). Provided the formula to be analyzed, you specify the weight of each variable, data in column &lt;code style="color: rgb(153, 0, 0);"&gt;Freq&lt;/code&gt; of the dataframe &lt;code style="color: rgb(153, 0, 0);"&gt;dft&lt;/code&gt; (so we write &lt;code style="color: rgb(153, 0, 0);"&gt;weights = Freq&lt;/code&gt; and &lt;code style="color: rgb(153, 0, 0);"&gt;data = dft&lt;/code&gt; to specify the location where the values are contained).&lt;br /&gt;&lt;br /&gt;The values of the parameters $\beta_0$ and $\beta_1$ are respectively the values &lt;code style="color: rgb(153, 0, 0);"&gt;(intercept)&lt;/code&gt; and &lt;code style="color: rgb(153, 0, 0);"&gt;Var1stress1&lt;/code&gt;. We can then write our empirical model:&lt;br /&gt;&lt;br /&gt;$$\pi(x)=\frac{exp(-4.139+2.760x)}{1+exp(-4.139+2.760x)}$$&lt;br /&gt;&lt;br /&gt;The independent variable x can be zero or one. If you assume value 0 (ie in the absence of stressful events), then the probability of having reflux is:&lt;br /&gt;&lt;br /&gt;$$\pi(x=0)=\frac{exp(\beta_0)}{1+exp(\beta_0)}=0.016=1.6\%$$&lt;br /&gt;&lt;br /&gt;If there are stressful events (x = 1), the probability of having reflux is:&lt;br /&gt;&lt;br /&gt;$$\pi(x=1)=\frac{exp(\beta_0+\beta_1)}{1+exp(\beta_0+\beta_1)}=0.20=20\%$$&lt;br /&gt;&lt;br /&gt;The odds are:&lt;br /&gt;&lt;br /&gt;$$odds(x=1)=\frac{\pi(1)}{1-\pi(1)}=exp(\beta_0+\beta_1)$$&lt;br /&gt;&lt;br /&gt;$$odds(x=0)=\frac{\pi(0)}{1-\pi(0)}=exp(\beta_0)$$&lt;br /&gt;&lt;br /&gt;We can finally calculate the odd ratio OR:&lt;br /&gt;&lt;br /&gt;$$OR=\frac{odds(x=1)}{odds(x=0)}=15.807$$&lt;br /&gt;&lt;br /&gt;A person who has experienced a stressful event has a propensity to develop gastroesophageal reflux 15.807 times larger than the person who has not undergone stressful events.&lt;br /&gt;&lt;br /&gt;The probabilities and the odds can be readily calculated in R recalling that:&lt;br /&gt;&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;fit$coefficient[1]&lt;/code&gt; = $\beta_0$ (intercept)&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;fit$coefficient[2]&lt;/code&gt; = $\beta_1$&lt;br /&gt;&lt;br /&gt;Furthermore:&lt;br /&gt;&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;summary(fit)$coefficient[1,2]&lt;/code&gt; = standard error of $\beta_0$&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;summary(fit)$coefficient[2,2]&lt;/code&gt; = standard error of $\beta_1$&lt;br /&gt;&lt;br /&gt;And so we have:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;pi0 &lt;- exp(fit$coefficient[1]) / (1 + exp(fit$coefficient[1]))&lt;br /&gt;pi1 &lt;- exp(fit$coefficient[1] + fit$coefficient[2]) / (1 + exp(fit$coefficient[1]+fit$coefficient[2]))&lt;br /&gt;&lt;br /&gt;odds0 &lt;- pi0 / (1 - pi0)&lt;br /&gt;odds1 &lt;- pi1 / (1 - pi1)&lt;br /&gt;&lt;br /&gt;OR &lt;- odds1 / odds0&lt;br /&gt;&lt;br /&gt;#the same result with:&lt;br /&gt;OR &lt;- exp(fit$coefficient[2])&lt;br /&gt;&lt;br /&gt;#the confidence interval for OR is:&lt;br /&gt;ORmin &lt;- exp( fit$coefficient[2] - qnorm(.975) * summary(fit)$coefficient[2,2] )&lt;br /&gt;&lt;br /&gt;ORmax &lt;- exp( fit$coefficient[2] + qnorm(.975) * summary(fit)$coefficient[2,2] )&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We can obtain the same result for the odd-ratio, using the simplify formula:&lt;br /&gt;&lt;br /&gt;$$OR=\frac{ad}{bc}=\frac{251\cdot33}{4\cdot131}=15.807$$&lt;br /&gt;&lt;br /&gt;that in R is:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;OR &lt;- (table[1,1]*table[2,2]) / (table[1,2]*table[2,1])&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The acronym AIC stands for &lt;b&gt;Akaike's information criterion&lt;/b&gt;. This parameter does not provide any data on the model just created. It&lt;br /&gt;may be useful in comparing this model with other possibly taken into account (the model with lowest AIC is the better).&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-8237856403387792533?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/8237856403387792533/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/08/simple-logistic-regression-on.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/8237856403387792533'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/8237856403387792533'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/08/simple-logistic-regression-on.html' title='Simple logistic regression on qualitative dichotomic variables'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_0yqjfYQXaSw/So0ra9uO28I/AAAAAAAAAF4/syOtm6rOq7Q/s72-c/refl.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-805117350524899768</id><published>2009-08-08T09:59:00.004+02:00</published><updated>2010-10-17T18:47:58.958+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Cox-Stuart test'/><category scheme='http://www.blogger.com/atom/ns#' term='Trend analysis'/><title type='text'>Trend Analysis with the Cox-Stuart test in R</title><content type='html'>The &lt;b&gt;Cox-Stuart test&lt;/b&gt; is defined as a little powerful test (power equal to 0.78), but very robust for the &lt;b&gt;trend analysis&lt;/b&gt;. It is therefore applicable to a wide variety of situations, to get an idea of the evolution of values obtained. The proposed method is based on the &lt;em&gt;binomial distribution&lt;/em&gt;. In R there is no function to perform a test of Cox-Stuart, so now we see the logical steps that are the basis of test and finally we can write the function ourself.&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;You want to assess whether there is an &lt;em&gt;increasing or decreasing trend&lt;/em&gt; of the number of daily customers of a restaurant. We have the number of customers in 15 days:&lt;br /&gt;&lt;div style="text-align: center;"&gt;Customers: 5, 9, 12, 18, 17, 16, 19, 20, 4, 3, 18, 16, 17, 15, 14&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;To perform the test of Cox-Stuart, the number of observations must be even. In our case we have 15 observations. Delete, therefore, the observation at position (N+1)/2 (here the observation with value = 20):&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;customers = c(5, 9, 12, 18, 17, 16, 19, 20, 4, 3, 18, 16, 17, 15, 14)&lt;br /&gt;&lt;br /&gt;length(customers)&lt;br /&gt;[1] 15&lt;br /&gt;&lt;br /&gt;cust_even = customers[ -(length(customers)+1)/2 ]&lt;br /&gt;length(cust_even)&lt;br /&gt;[1] 14&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now we have 14 observations, and we can then proceed. Divide the observations into two vectors, the first containing the first half of the measures, and the second the second half:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;fHalf = cust_even[1:7]&lt;br /&gt;sHalf = cust_even[8:14]&lt;br /&gt;&lt;br /&gt;fHalf&lt;br /&gt;[1]  5  9 12 18 17 16 19&lt;br /&gt;&lt;br /&gt;sHalf&lt;br /&gt;[1]  4  3 18 16 17 15 14&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now subtract, value by value, the content of the two vectors:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;difference = fHalf - sHalf&lt;br /&gt;&lt;br /&gt;difference&lt;br /&gt;[1]  1  6 -6  2  0  1  5&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now consider only the signs of the contents of the vector difference&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;signs = sign(difference)&lt;br /&gt;&lt;br /&gt;signs&lt;br /&gt;[1]  1  1 -1  1  0  1  1&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;A difference has value 0 and therefore also in the vector with the signs there is a value equal to 0. This must be eliminated:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;signs = signs[ signs != 0 ]&lt;br /&gt;&lt;br /&gt;signs&lt;br /&gt;[1]  1  1 -1  1  1  1&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We obtained six differences, and then six signs. Now we have to count the number of positive-signs and the number of negative-signs:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;pos = signs[signs &gt; 0]&lt;br /&gt;neg = signs[signs &lt; 0]&lt;br /&gt;&lt;br /&gt;length(pos)&lt;br /&gt;[1] 5&lt;br /&gt;&lt;br /&gt;length(neg)&lt;br /&gt;[1] 1&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now we choose the number of signs that is smaller. In this case we choose the number of negative signs (1). We compute the probability to obtain x = 1 successes on N = 6 experiments, each of which yields success with probability p = 0.5 (binomial distribution):&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;pbinom(1, 6, 0.5)&lt;br /&gt;[1] 0.109375&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The value so calculated is higher than 0.05 (we choose a significance level of 95%). Therefore there is no significant trend (which would have been in decline since the number of negative signs is minor).&lt;br /&gt;If the value was less than 0.05, we accepted the hypothesis of a significant trend.&lt;br /&gt;&lt;br /&gt;Now try to fit a regression model, and observe the p-value of the slope: the coefficient b is not significant.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;customers = c(5, 9, 12, 18, 17, 16, 19, 20, 4, 3, 18, 16, 17, 15, 14)&lt;br /&gt;days &lt;- c(1:length(customers))&lt;br /&gt;model &lt;- lm(customers ~ days)&lt;br /&gt;summary(model)&lt;br /&gt;&lt;br /&gt;Call:&lt;br /&gt;lm(formula = customers ~ days)&lt;br /&gt;&lt;br /&gt;Residuals:&lt;br /&gt;    Min      1Q  Median      3Q     Max &lt;br /&gt;-11.090  -2.173   1.352   3.967   6.467 &lt;br /&gt;&lt;br /&gt;Coefficients:&lt;br /&gt;            Estimate Std. Error t value Pr(&gt;|t|)   &lt;br /&gt;(Intercept)  11.3048     3.1104   3.634  0.00303 **&lt;br /&gt;days          0.2786     0.3421   0.814  0.43014   &lt;br /&gt;---&lt;br /&gt;Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 &lt;br /&gt;&lt;br /&gt;Residual standard error: 5.724 on 13 degrees of freedom&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here is the code to perform a Cos-Stuart test, written by me.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;cox.stuart.test =&lt;br /&gt;function (x)&lt;br /&gt;{&lt;br /&gt;  method = "Cox-Stuart test for trend analysis"&lt;br /&gt;  leng = length(x)&lt;br /&gt;  apross = round(leng) %% 2&lt;br /&gt;  if (apross == 1) {&lt;br /&gt;    delete = (length(x)+1)/2&lt;br /&gt;    x = x[ -delete ] &lt;br /&gt;  }&lt;br /&gt;  half = length(x)/2&lt;br /&gt;  x1 = x[1:half]&lt;br /&gt;  x2 = x[(half+1):(length(x))]&lt;br /&gt;  difference = x1-x2&lt;br /&gt;  signs = sign(difference)&lt;br /&gt;  signcorr = signs[signs != 0]&lt;br /&gt;  pos = signs[signs&gt;0]&lt;br /&gt;  neg = signs[signs&lt;0]&lt;br /&gt;  if (length(pos) &lt; length(neg)) {&lt;br /&gt;    prop = pbinom(length(pos), length(signcorr), 0.5)&lt;br /&gt;    names(prop) = "Increasing trend, p-value"&lt;br /&gt;    rval &lt;- list(method = method, statistic = prop)&lt;br /&gt;    class(rval) = "htest"&lt;br /&gt;    return(rval)&lt;br /&gt;  }&lt;br /&gt;  else {&lt;br /&gt;    prop = pbinom(length(neg), length(signcorr), 0.5)&lt;br /&gt;    names(prop) = "Decreasing trend, p-value"&lt;br /&gt;    rval &lt;- list(method = method, statistic = prop)&lt;br /&gt;    class(rval) = "htest"&lt;br /&gt;    return(rval)&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We can now use the function just created:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;customers = c(5, 9, 12, 18, 17, 16, 19, 20, 4, 3, 18, 16, 17, 15, 14)&lt;br /&gt;cox.stuart.test(customers)&lt;br /&gt;&lt;br /&gt;        Cox-Stuart test for trend analysis&lt;br /&gt;&lt;br /&gt;data:  &lt;br /&gt;Decreasing trend, p-value = 0.1094&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-805117350524899768?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/805117350524899768/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/08/trend-analysis-with-cox-stuart-test-in.html#comment-form' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/805117350524899768'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/805117350524899768'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/08/trend-analysis-with-cox-stuart-test-in.html' title='Trend Analysis with the Cox-Stuart test in R'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-2982820506675129947</id><published>2009-08-07T20:28:00.002+02:00</published><updated>2009-08-07T20:34:53.813+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Two-way ANOVA'/><category scheme='http://www.blogger.com/atom/ns#' term='ANOVA'/><category scheme='http://www.blogger.com/atom/ns#' term='F-test'/><title type='text'>Two-way analysis of variance: two-way ANOVA in R</title><content type='html'>The &lt;b&gt;&lt;a href="http://statistic-on-air.blogspot.com/2009/07/analysis-of-variance-anova-for-multiple.html"&gt;one-way analysis of variance&lt;/a&gt;&lt;/b&gt; is a useful technique to verify if the means of more groups are equals. But this analysis may not be very useful for more complex problems. For example, it may be necessary to take into account two factors of variability to determine if the averages between the groups depend on the group classification ( "zone") or the second variable that is to consider ("block"). In this case should be used the &lt;b&gt;two-way analysis of variance&lt;/b&gt; (&lt;b&gt;two-way ANOVA&lt;/b&gt;).&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;We begin immediately with an example so as to facilitate the understanding of this statistical method. The data collected are organized into &lt;b&gt; double entry tables&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;The director of a company has collected revenue (thousand dollars) for 5 years and under per month. You want to see if the revenue depends on the year and/or month, or if they are independent of these two factors.&lt;br /&gt;&lt;br /&gt;Conceptually, the problem may be solved by an &lt;em&gt;horizontal ANOVA&lt;/em&gt; and a &lt;em&gt;vertical ANOVA&lt;/em&gt;, in order to verify if the average revenues per year are the same, and if they are equal to the average revenue computed by month. This would require many calculations, and so we prefer to use the two-way ANOVA, which provides the result instantly.&lt;br /&gt;This is the table of revenue classified by year and month:&lt;br /&gt;&lt;br /&gt;$$\begin{tabular}{|c||ccccc||r|}\hline Months &amp; Year 1 &amp; Year 2 &amp; Year 3 &amp; Year 4 &amp; Year 5\\\hline January&amp;15&amp;18&amp;22&amp;23&amp;24\\ February&amp;22&amp;25&amp;15&amp;15&amp;14\\ March&amp;18&amp;22&amp;15&amp;19&amp;21\\ April&amp;23&amp;15&amp;14&amp;17&amp;18\\ May&amp;23&amp;15&amp;26&amp;18&amp;14\\ June&amp;12&amp;15&amp;11&amp;10&amp;8\\ July&amp;26&amp;12&amp;23&amp;15&amp;18\\ August&amp;19&amp;17&amp;15&amp;20&amp;10\\ September&amp;15&amp;14&amp;18&amp;19&amp;20\\ October&amp;14&amp;18&amp;10&amp;12&amp;23\\ November&amp;14&amp;22&amp;19&amp;17&amp;11\\ December&amp;21&amp;23&amp;11&amp;18&amp;14\\ \hline \end{tabular}$$&lt;br /&gt;&lt;br /&gt;As with the one-way ANOVA, even here the aim is to structure a &lt;b&gt;Fisher's F-test&lt;/b&gt; to assess the significance of the variable "month" and of the variable "year", determine if the revenues are dependent on one (or both) the criteria for classification.&lt;br /&gt;&lt;em&gt;How to perform the two-way ANOVA in R&lt;/em&gt;? First creates an array containing all the values tabulated, transcribed by rows:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;revenue = c(15,18,22,23,24, 22,25,15,15,14, 18,22,15,19,21, &lt;br /&gt;         23,15,14,17,18, 23,15,26,18,14, 12,15,11,10,8, 26,12,23,15,18, &lt;br /&gt;         19,17,15,20,10, 15,14,18,19,20, 14,18,10,12,23, 14,22,19,17,11, &lt;br /&gt;         21,23,11,18,14)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;According to the months, you create a factor of 12 levels (the number of rows) with 5 repetitions (the number columns) in this manner:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;months = gl(12,5)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;According to the years you create a factor with 5 levels (the number of column) and 1 recurrence, declaring the total number of observations (the length of the vector revenue):&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;years = gl(5, 1, length(entrate))&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now you can fit the linear model and produce the ANOVA table: &lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;fit = aov(revenue ~ months + years)&lt;br /&gt;&lt;br /&gt;anova(fit)&lt;br /&gt;&lt;br /&gt;Analysis of Variance Table&lt;br /&gt;&lt;br /&gt;Response: revenue&lt;br /&gt;          Df Sum Sq Mean Sq F value Pr(&gt;F)&lt;br /&gt;months    11 308.45   28.04  1.4998 0.1660&lt;br /&gt;years      4  44.17   11.04  0.5906 0.6712&lt;br /&gt;Residuals 44 822.63   18.70  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now interpret the results.&lt;br /&gt;The significance of the difference between months is: &lt;i&gt;F = 1.4998&lt;/i&gt;. This value is lower than the value tabulated and indeed &lt;i&gt;p-value &gt; 0.05&lt;/i&gt;. So we accept the null hypothesis: the means of revenue evaluated according to the months are equal, then the variable "months" has no effect on revenue.&lt;br /&gt;&lt;br /&gt;The significance of the difference between years is: &lt;i&gt;F = 0.5906&lt;/i&gt;. This value is lower than the value tabulated and indeed &lt;i&gt;p-value &gt; 0.05&lt;/i&gt;. So we accept the null hypothesis: the means of revenue evaluated according to the years are equal, then the variable "years" has no effect on revenue.&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-2982820506675129947?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/2982820506675129947/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/08/two-way-analysis-of-variance-two-way.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/2982820506675129947'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/2982820506675129947'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/08/two-way-analysis-of-variance-two-way.html' title='Two-way analysis of variance: two-way ANOVA in R'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-4610375755145548145</id><published>2009-08-06T07:30:00.003+02:00</published><updated>2009-08-06T10:53:25.695+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ANOVA'/><category scheme='http://www.blogger.com/atom/ns#' term='Simple linear regression'/><category scheme='http://www.blogger.com/atom/ns#' term='F-test'/><category scheme='http://www.blogger.com/atom/ns#' term='Regression'/><category scheme='http://www.blogger.com/atom/ns#' term='T-test'/><title type='text'>Simple linear regression</title><content type='html'>We use the &lt;b&gt;regression analysis&lt;/b&gt; when, from the data sample, we want to derive a statistical model that predicts the values of a variable (Y, &lt;em&gt;dependent&lt;/em&gt;) from the values of another variable (X, &lt;em&gt;independent&lt;/em&gt;). The &lt;b&gt;linear regression&lt;/b&gt;, which is the simplest and most frequent relationship between two quantitative variables, can be &lt;em&gt;positive&lt;/em&gt; (when X increase, Y increase too) or &lt;em&gt;negative&lt;/em&gt; (when X increase, Y decrease): this is indicated by the sign of the coefficient &lt;code style="color: rgb(153, 0, 0);"&gt;b&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;To build the line that describes the distribution of points, we might refer to different principles. The most common is the &lt;b&gt;least squares method&lt;/b&gt; (or &lt;em&gt;Model I&lt;/em&gt;), and this is the method used by the statistical software R.&lt;br /&gt;&lt;br /&gt;Suppose you want to obtain a linear relationship between weight (kg) and height (cm) of 10 subjects.&lt;br /&gt;&lt;div style="text-align: center;"&gt;Height: 175, 168, 170, 171, 169, 165, 165, 160, 180, 186&lt;br /&gt;Weight: 80, 68, 72, 75, 70, 65, 62, 60, 85, 90&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;The first problem is to decide what is the dependent variable Y and waht is the independent variable X. In general, the independent variable is not affected by an error during the measurement (or affected by random error), while the dependent variable is affected by error. In our case we can assume that the variable weight is the independent variable (X), and the dependent variable height (Y).&lt;br /&gt;So our problem is to find a linear relationship (formula) that allows us to calculate the height, known as the weight of an individual. The simplest formula is that of a broad line of type &lt;code style="color: rgb(153, 0, 0);"&gt;Y = a + bX&lt;/code&gt;. The simple regression line in R is calculated as follows:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;height = c(175, 168, 170, 171, 169, 165, 165, 160, 180, 186)&lt;br /&gt;weight = c(80, 68, 72, 75, 70, 65, 62, 60, 85, 90)&lt;br /&gt; &lt;br /&gt;model = lm(formula = height ~ weight, x=TRUE, y=TRUE)&lt;br /&gt;model&lt;br /&gt;&lt;br /&gt;Call:&lt;br /&gt;lm(formula = height ~ weight, x = TRUE, y = TRUE)&lt;br /&gt;&lt;br /&gt;Coefficients:&lt;br /&gt;(Intercept)       weight  &lt;br /&gt;   115.2002       0.7662 &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The correct syntax of the formula stated in lm is: Y ~ X, then you declare first the dependent variable, and after the independent variable (or variables).&lt;br /&gt;The output of the function is represented by two parameters &lt;b&gt;a&lt;/b&gt; and &lt;b&gt;b&lt;/b&gt;: &lt;code style="color: rgb(153, 0, 0);"&gt;a=115.2002&lt;/code&gt; (intercept), &lt;code style="color: rgb(153, 0, 0);"&gt;b=0.7662&lt;/code&gt; (the slope).&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width="50%"&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;The simple calculation of the line is not enough. We must assess the significance of the line, ie if the slope&lt;code style="color: rgb(153, 0, 0);"&gt;b&lt;/code&gt; differs from zero significantly. This may be done with a &lt;b&gt;Student's t.test&lt;/b&gt; or with a &lt;b&gt;Fisher's F-test&lt;/b&gt;.&lt;br /&gt;In R both can be retrieved very quickly, with the function summary(). Here's how:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;model &lt;- lm(height ~ weight)&lt;br /&gt;summary(model)&lt;br /&gt;&lt;br /&gt;Call:&lt;br /&gt;lm(formula = height ~ weight)&lt;br /&gt;&lt;br /&gt;Residuals:&lt;br /&gt;    Min      1Q  Median      3Q     Max &lt;br /&gt;-1.6622 -0.9683 -0.1622  0.5679  2.2979 &lt;br /&gt;&lt;br /&gt;Coefficients:&lt;br /&gt;             Estimate Std. Error t value Pr(&gt;|t|)    &lt;br /&gt;(Intercept) 115.20021    3.48450   33.06 7.64e-10 ***&lt;br /&gt;weight        0.76616    0.04754   16.12 2.21e-07 ***&lt;br /&gt;---&lt;br /&gt;Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 &lt;br /&gt;&lt;br /&gt;Residual standard error: 1.405 on 8 degrees of freedom&lt;br /&gt;Multiple R-squared: 0.9701,     Adjusted R-squared: 0.9664 &lt;br /&gt;F-statistic: 259.7 on 1 and 8 DF,  p-value: 2.206e-07 &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here too there are the values of the parameters &lt;b&gt;a&lt;/b&gt; and &lt;b&gt;b&lt;/b&gt;.&lt;br /&gt;The &lt;b&gt;Student's t-test&lt;/b&gt; on the slope in this case has the value 16.12; the &lt;b&gt;Student's t-test&lt;/b&gt; on the intercept has value 16.12; the value of the &lt;b&gt;Fisher's F test&lt;/b&gt; is 259.7 (is the same value would be achieved by performing an &lt;a href="http://statistic-on-air.blogspot.com/2009/07/analysis-of-variance-anova-for-multiple.html"&gt;ANOVA&lt;/a&gt; on the same data: &lt;code style="color: rgb(153, 0, 0);"&gt;anova(model)&lt;/code&gt;). The p-values of the t-tests and the F-test are less then 0.05, so the model we found is significant.&lt;br /&gt;The &lt;b&gt;Multiple R-squared&lt;/b&gt; is the &lt;b&gt;coefficient of determination&lt;/b&gt;. It provides a measure of how well future outcomes are likely to be predicted by the model. In this case, the 97.01% of the data are well predicted (with 95% of significance) by our model.&lt;br /&gt;&lt;br /&gt;We can plot on a graph the data points and the regression line, in this way:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;plot(weight, height)&lt;br /&gt;abline(model)&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-4610375755145548145?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/4610375755145548145/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/08/simple-linear-regression.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/4610375755145548145'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/4610375755145548145'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/08/simple-linear-regression.html' title='Simple linear regression'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-3609971637564506194</id><published>2009-08-05T07:30:00.001+02:00</published><updated>2009-08-05T10:38:39.596+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Correlation'/><category scheme='http://www.blogger.com/atom/ns#' term='Contingency table'/><category scheme='http://www.blogger.com/atom/ns#' term='Pearson&apos;s Chi-squared test'/><title type='text'>Contingency table and the study of the correlation between qualitative variables: Pearson's Chi-squared test</title><content type='html'>If you have &lt;em&gt;qualitative variable&lt;/em&gt;, it is possible to verify the correlation by studying a &lt;b&gt;contingency table R by C&lt;/b&gt;, using the &lt;b&gt;Pearson's Chi-squared test&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;A casino wants to study the correlation between the modes of play and the number of winners by age group, to see if the number of winners depends on the type of game that you chose to do, in light of experience. It has the following data (number of winners / 100 player for game and age-group):&lt;br /&gt;&lt;br /&gt;&lt;center&gt;$$\begin{tabular}{c|ccc}&amp;Age\\\hline Game&amp;20-30&amp;31-40&amp;41-50\\ \hline Roulette&amp;44&amp;56&amp;55\\ Black-jack&amp; 66&amp; 88&amp; 23\\Poker&amp; 15&amp; 29&amp; 45 \end{tabular}$$&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;In R, we must first build a matrix with the data collected:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;table &lt;- matrix(c(44,56,55, 66,88,23, 15,29,45), nrow=3, byrow=TRUE)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now we can compute the chi-squared correlation coefficient:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;chisq.test(table)&lt;br /&gt;&lt;br /&gt;        Pearson's Chi-squared test&lt;br /&gt;&lt;br /&gt;data:  table &lt;br /&gt;X-squared = 46.0767, df = 4, p-value = 2.374e-09&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;I reject the null hypothesis H0 in favor of the alternative hypothesis (&lt;i&gt;p-value &lt; 0.05&lt;/i&gt;): there is a strong correlation between the age of the player and his probability to win.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-3609971637564506194?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/3609971637564506194/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/08/contingency-table-and-study-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/3609971637564506194'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/3609971637564506194'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/08/contingency-table-and-study-of.html' title='Contingency table and the study of the correlation between qualitative variables: Pearson&apos;s Chi-squared test'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-9025558253464520073</id><published>2009-08-04T07:30:00.001+02:00</published><updated>2009-08-05T10:37:15.533+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Correlation'/><category scheme='http://www.blogger.com/atom/ns#' term='Spearman correlation test'/><category scheme='http://www.blogger.com/atom/ns#' term='Kendall correlation test'/><title type='text'>Non-parametric methods for the study of the correlation: Spearman's rank correlation coefficient and Kendall tau rank correlation coefficient</title><content type='html'>We saw in the previous post, how to study the correlation between variables that follow a Gaussian distribution with the &lt;a href="http://statistic-on-air.blogspot.com/2009/08/parametric-method-for-study-of.html"&gt; Pearson product-moment correlation coefficient&lt;/a&gt;. If it is not possible to assume that the values follow gaussian distributions, we have two non-parametric methods: the &lt;b&gt;Spearman's rho test&lt;/b&gt; and &lt;b&gt;Kendall's tau test&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;For example, you want to study the productivity of various types of machinery and the satisfaction of operators in their use (as with a number from 1 to 10). These are the values:&lt;br /&gt;&lt;div style="text-align: center;"&gt;Productivity: 5, 7, 9, 9, 8, 6, 4, 8, 7, 7&lt;br /&gt;Satisfaction: 6, 7, 4, 4, 8, 7, 3, 9, 5, 8&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Begin to use first the &lt;b&gt;&lt;u&gt;Spearman's rank correlation coefficient&lt;/b&gt;&lt;/u&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;a &lt;- c(5, 7, 9, 9, 8, 6, 4, 8, 7, 7)&lt;br /&gt;b &lt;- c(6, 7, 4, 4, 8, 7, 3, 9, 5, 8)&lt;br /&gt;&lt;br /&gt;cor.test(a, b, method="spearman")&lt;br /&gt;&lt;br /&gt;        Spearman's rank correlation rho&lt;br /&gt;&lt;br /&gt;data:  a and b &lt;br /&gt;S = 145.9805, p-value = 0.7512&lt;br /&gt;alternative hypothesis: true rho is not equal to 0 &lt;br /&gt;sample estimates:&lt;br /&gt;      rho &lt;br /&gt;0.1152698 &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The statistical test gives us as a result &lt;i&gt;rho = 0.115&lt;/i&gt;, which indicates a low correlation (not parametric) between the two sets of values.&lt;br /&gt;The &lt;i&gt;p-value &gt; 0.05&lt;/i&gt; allows us to accept the value of rho calculated, being statistically significant.&lt;br /&gt;&lt;br /&gt;Now we check the same data with the &lt;b&gt;&lt;u&gt;Kendall tau rank correlation coefficient&lt;/b&gt;&lt;/u&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;a &lt;- c(5, 7, 9, 9, 8, 6, 4, 8, 7, 7)&lt;br /&gt;b &lt;- c(6, 7, 4, 4, 8, 7, 3, 9, 5, 8)&lt;br /&gt; &lt;br /&gt;cor.test(a, b, method="kendall")&lt;br /&gt;&lt;br /&gt;        Kendall's rank correlation tau&lt;br /&gt;&lt;br /&gt;data:  a and b &lt;br /&gt;z = 0.5555, p-value = 0.5786&lt;br /&gt;alternative hypothesis: true tau is not equal to 0 &lt;br /&gt;sample estimates:&lt;br /&gt;     tau &lt;br /&gt;0.146385&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Even with the Kendall test, the correlation is very low (&lt;i&gt;tau = 0.146&lt;/i&gt;), and significant (&lt;i&gt;p-value &gt; 0.05&lt;/i&gt;).&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-9025558253464520073?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/9025558253464520073/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/08/non-parametric-methods-for-study-of.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/9025558253464520073'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/9025558253464520073'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/08/non-parametric-methods-for-study-of.html' title='Non-parametric methods for the study of the correlation: Spearman&apos;s rank correlation coefficient and Kendall tau rank correlation coefficient'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-7461519838314344388</id><published>2009-08-03T09:33:00.003+02:00</published><updated>2009-08-05T10:35:18.234+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Correlation'/><category scheme='http://www.blogger.com/atom/ns#' term='Pearson product-moment correlation test'/><title type='text'>Parametric method for the study of the correlation: the Pearson r-test</title><content type='html'>Suppose you want to study whether there is a correlation between 2 sets of data. To do this we compute the &lt;b&gt;Pearson product-moment correlation coefficient&lt;/b&gt;, which is a measure of the correlation (linear dependence) between two variables X and Y; then we compute the value of a t-test to study the significance of the &lt;b&gt;Pearson coefficient R&lt;/b&gt;. We can use this test when the data follow a Gaussian distribution.&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;A new test to measure IQ is subjected to 10 volunteers. You want to see if there is a correlation between the new experimental test and the classical test, in order to replace the old test with the new test. These the values:&lt;br /&gt;&lt;div style="text-align: center;"&gt;Old test: 15, 21, 25, 26, 30, 30, 22, 29, 19, 16&lt;br /&gt;New test: 55, 56, 89, 67, 84, 89, 99, 62, 83, 88&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;The software R has a single function, easily recalled, which gives us directly the value of the Pearson coefficient and the t-statistical test for checking the significance of the coefficient:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;a = c(15, 21, 25, 26, 30, 30, 22, 29, 19, 16)&lt;br /&gt;b = c(55, 56, 89, 67, 84, 89, 99, 62, 83, 88)&lt;br /&gt;&lt;br /&gt;cor.test(a, b)&lt;br /&gt;&lt;br /&gt;        Pearson's product-moment correlation&lt;br /&gt;&lt;br /&gt;data:  a and b &lt;br /&gt;t = 0.4772, df = 8, p-value = 0.646&lt;br /&gt;alternative hypothesis: true correlation is not equal to 0 &lt;br /&gt;95 percent confidence interval:&lt;br /&gt; -0.5174766  0.7205107 &lt;br /&gt;sample estimates:&lt;br /&gt;     cor &lt;br /&gt;0.166349&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The value of the coefficient of Pearson is 0.166: it is a very low value, which indicates a poor correlation between the variables. &lt;br /&gt;Furthermore, the p-value is greater than 0.05; so we reject the null hypothesis: then the Pearson coefficient is significant.&lt;br /&gt;So we can say that there is no correlation between the results of both tests.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-7461519838314344388?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/7461519838314344388/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/08/parametric-method-for-study-of.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/7461519838314344388'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/7461519838314344388'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/08/parametric-method-for-study-of.html' title='Parametric method for the study of the correlation: the Pearson r-test'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-1429117192957268556</id><published>2009-07-31T10:46:00.001+02:00</published><updated>2009-08-05T10:29:46.028+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Multiple comparison'/><category scheme='http://www.blogger.com/atom/ns#' term='Kruskal-Wallis test'/><title type='text'>Kruskal-Wallis one-way analysis of variance</title><content type='html'>If you have to perform the comparison between multiple groups, but you can not run a &lt;a href="http://statisticaconr.blogspot.com/2009/07/confronto-tra-piu-gruppi-metodo.html"&gt;ANOVA for multiple comparisons&lt;/a&gt; because the groups do not follow a normal distribution, you can use the &lt;b&gt;Kruskal-Wallis test&lt;/b&gt;, which can be applied when you can not make the assumption that the groups follow a gaussian distribution.&lt;br /&gt;This test is similar to the Wilcoxon test for 2 samples.&lt;br /&gt;&lt;br /&gt;Suppose you want to see if the means of the following 4 sets of values are statistically similar:&lt;br /&gt;&lt;div style="text-align: center;"&gt;Group A: 1, 5, 8, 17, 16&lt;br /&gt;Group B: 2, 16, 5, 7, 4&lt;br /&gt;Group C: 1, 1, 3, 7, 9&lt;br /&gt;Group D: 2, 15, 2, 9, 7&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;To use the test of Kruskal-Wallis simply enter the data, and then organize them into a list:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;a = c(1, 5, 8, 17, 16)&lt;br /&gt;b = c(2, 16, 5, 7, 4)&lt;br /&gt;c = c(1, 1, 3, 7, 9)&lt;br /&gt;d = c(2, 15, 2, 9, 7)&lt;br /&gt;&lt;br /&gt;dati = list(g1=a, g2=b, g3=c, g4=d)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now we can apply the &lt;code style="color: rgb(153, 0, 0);"&gt;kruskal.test()&lt;/code&gt; function:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;kruskal.test(dati)&lt;br /&gt;&lt;br /&gt;        Kruskal-Wallis rank sum test&lt;br /&gt;&lt;br /&gt;data:  dati &lt;br /&gt;Kruskal-Wallis chi-squared = 1.9217, df = 3, p-value = 0.5888&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The value of the test statistic is 1.9217. This value already contains the fix when there are ties (repetitions). The p-value is greater than 0.05; also the value of the test statistic is lower than the chi-square-tabulation:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;qchisq(0.950, 3)&lt;br /&gt;[1] 7.814728&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The conclusion is therefore that I accept the null hypothesis H0: the means of the 4 groups are statistically equal.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-1429117192957268556?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/1429117192957268556/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/kruskal-wallis-one-way-analysis-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/1429117192957268556'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/1429117192957268556'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/kruskal-wallis-one-way-analysis-of.html' title='Kruskal-Wallis one-way analysis of variance'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-3347153346897537413</id><published>2009-07-30T09:32:00.002+02:00</published><updated>2009-08-05T10:27:53.533+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ANOVA'/><category scheme='http://www.blogger.com/atom/ns#' term='Fligner-Killeen test'/><category scheme='http://www.blogger.com/atom/ns#' term='Multiple comparison'/><category scheme='http://www.blogger.com/atom/ns#' term='F-test'/><category scheme='http://www.blogger.com/atom/ns#' term='Bartlett test'/><title type='text'>Analysis of variance: ANOVA, for multiple comparisons</title><content type='html'>&lt;span style="font-weight: bold;"&gt;Analysis of variance: ANOVA, for multiple comparisons&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The ANOVA model can be used to compare the mean of several groups with each other, using a parametric method (assuming that the groups follow a Gaussian distribution).&lt;br /&gt;Proceed with the following example:&lt;br /&gt;&lt;br /&gt;The manager of a supermarket chain wants to see if the consumption in kilowatts of 4 stores between them are equal. He collects data at the end of each month for 6 months. The results are:&lt;br /&gt;&lt;div style="text-align: center;"&gt;Store A: 65, 48, 66, 75, 70, 55&lt;br /&gt;Store B: 64, 44, 70, 70, 68, 59&lt;br /&gt;Store C: 60, 50, 65, 69, 69, 57&lt;br /&gt;Store D: 62, 46, 68, 72, 67, 56&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;To proceed with the verification ANOVA, we must first verify the homoskedasticity (ie test for homogeneity of variances). The software R provides two tests: the Bartlett test, and the Fligner-Killeen test.&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width="50%"&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;We begin with the &lt;b&gt;Bartlett test&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;First we create the 4 vectors:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;a = c(65, 48, 66, 75, 70, 55)&lt;br /&gt;b = c(64, 44, 70, 70, 68, 59)&lt;br /&gt;c = c(60, 50, 65, 69, 69, 57)&lt;br /&gt;d = c(62, 46, 68, 72, 67, 56)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now we combine the 4 vectors in a single vector:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;dati = c(a, b, c, d)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now, on this vector in which are stored all the data, we create the 4 levels:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;groups = factor(rep(letters[1:4], each = 6))&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We can observe the contents of the vector &lt;code style="color: rgb(153, 0, 0);"&gt;groups&lt;/code&gt; simply by typing &lt;code style="color: rgb(153, 0, 0);"&gt;groups + [enter]&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;At this point we start the Bartlett test:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;bartlett.test(dati, groups)&lt;br /&gt;&lt;br /&gt;        Bartlett test of homogeneity of variances&lt;br /&gt;&lt;br /&gt;data:  dati and groups &lt;br /&gt;Bartlett's K-squared = 0.4822, df = 3, p-value = 0.9228&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The function gave us the value of the statistical tests (&lt;b&gt;K squared&lt;/b&gt;), and the p-value. Can be argued that the variances are homogeneous since &lt;i&gt;p-value &gt; 0.05&lt;/i&gt;. Alternatively, we can compare the Bartlett's K-squared with the value of chi-square-tables; we compute that value, assigning the value of alpha and degrees of freedom at the &lt;code style="color: rgb(153, 0, 0);"&gt;qchisq&lt;/code&gt; function:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;qchisq(0.950, 3)&lt;br /&gt;[1] 7.814728&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Chi-squared &gt; Bartlett's K-squared: we accept the null hypothesis H0 (variances homogeneity)&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width="50%"&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;We try now to check the homoskedasticity, with the &lt;b&gt;Fligner-Killeen test&lt;/b&gt;.&lt;br /&gt;The syntax is quite similar, and then proceed quickly.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;a = c(65, 48, 66, 75, 70, 55)&lt;br /&gt;b = c(64, 44, 70, 70, 68, 59)&lt;br /&gt;c = c(60, 50, 65, 69, 69, 57)&lt;br /&gt;d = c(62, 46, 68, 72, 67, 56)&lt;br /&gt;&lt;br /&gt;dati = c(a, b, c, d)&lt;br /&gt;&lt;br /&gt;groups = factor(rep(letters[1:4], each = 6))&lt;br /&gt;&lt;br /&gt;fligner.test(dati, groups)&lt;br /&gt;&lt;br /&gt;        Fligner-Killeen test of homogeneity of variances&lt;br /&gt;&lt;br /&gt;data:  dati and groups &lt;br /&gt;Fligner-Killeen:med chi-squared = 0.1316, df = 3, p-value = 0.9878&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The conclusions are similar to those for the test of Bartlett.&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width="50%"&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;Having verified the homoskedasticity of the 4 groups, we can proceed with the &lt;b&gt;ANOVA model&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;First organize the values, fitting the model:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;fit = lm(formula = dati ~ groups)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Then we analyze the ANOVA model:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;anova (fit)&lt;br /&gt;&lt;br /&gt;Analysis of Variance Table&lt;br /&gt;&lt;br /&gt;Response: dati&lt;br /&gt;          Df  Sum Sq Mean Sq F value Pr(&gt;F)&lt;br /&gt;groups     3    8.46    2.82  0.0327 0.9918&lt;br /&gt;Residuals 20 1726.50   86.33  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The output of the function is a classical ANOVA table with the following data:&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;Df&lt;/code&gt; = degree of freedom&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;Sum Sq&lt;/code&gt; = deviance (within groups, and residual)&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;Mean Sq&lt;/code&gt; = variance (within groups, and residual)&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;F value&lt;/code&gt; = the value of the Fisher statistic test, so computed (variance within groups) / (variance residual)&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;Pr(&gt;F)&lt;/code&gt; = p-value&lt;br /&gt;&lt;br /&gt;Since &lt;i&gt;p-value &gt; 0.05&lt;/i&gt;, we accept the null hypothesis H0: the four means are statistically equal. We can also compare the computed F-value with the tabulated F-value:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;qf(0.950, 20, 3)&lt;br /&gt;[1] 8.66019&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Tabulated F-value &gt; computed F-value: we accept the null hyptohesis.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-3347153346897537413?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/3347153346897537413/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/analysis-of-variance-anova-for-multiple.html#comment-form' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/3347153346897537413'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/3347153346897537413'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/analysis-of-variance-anova-for-multiple.html' title='Analysis of variance: ANOVA, for multiple comparisons'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-3212733558169947294</id><published>2009-07-29T10:24:00.004+02:00</published><updated>2009-08-05T10:22:51.220+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Contingency table'/><category scheme='http://www.blogger.com/atom/ns#' term='Proportions comparison'/><category scheme='http://www.blogger.com/atom/ns#' term='Chi-square'/><category scheme='http://www.blogger.com/atom/ns#' term='Z-test'/><title type='text'>Comparison of two proportions: parametric (Z-test) and non-parametric (chi-squared) methods</title><content type='html'>Consider for example the following problem.&lt;br /&gt;The owner of a betting company wants to verify whether a customer is cheating or not. To do this want to compare the number of successes of one player with the number of successes of one of his employees, of which he is certain that he is not cheating. In a month's time, the player performs 74 bets and wins 30; the player in the same period of time making 103 bets, wins 65. Your client is a cheat or not?&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;A problem of this kind can be solved in two different ways: using a parametric and a non-parametric method.&lt;br /&gt;&lt;br /&gt;       &lt;span style="font-weight: bold;"&gt;* Solution with the parametric method: Z-test.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You can use a Z-test if you can do the following two assumptions: the probability of common success is approximate 0.5, and the number of games is very high (under these assumption, a binomial distribution is approximate a gaussian distribution). Suppose that this is the case. In R there is no function to calculate the value of Z, so we remember the mathematical formula, and we write our function:&lt;br /&gt;&lt;br /&gt;$$Z=\frac{\frac{x_1}{n_1}-\frac{x_2}{n_s}}{\sqrt{\widehat{p}(1-\widehat{p})(\frac{1}{n_1}+\frac{1}{n_2})}}$$&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;z.prop = function(x1,x2,n1,n2){&lt;br /&gt;  numerator = (x1/n1) - (x2/n2)&lt;br /&gt;  p.common = (x1+x2) / (n1+n2)&lt;br /&gt;  denominator = sqrt(p.common * (1-p.common) * (1/n1 + 1/n2))&lt;br /&gt;  z.prop.ris = numerator / denominator&lt;br /&gt;  return(z.prop.ris)&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;Z.prop&lt;/code&gt; function calculates the value of Z, receiving input the number of successes (x1 and x2), and the total number of games (n1 and n2). We apply the function just written with the data of our problem:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;z.prop(30, 65, 74, 103)&lt;br /&gt;[1] -2.969695&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We obtained a value of z greater than the value of z-tabulated (1.96), which leads us to conclude that the player that the director was looking at is actually a cheat, since its probability of success is higher than a non-cheat user.&lt;br /&gt;&lt;br /&gt;       &lt;span style="font-weight: bold;"&gt;* Solution with the non-parametric method: Chi-squared test.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Suppose now that it can not make any assumption on the data of the problem, so that it can not approximate the binomial with a Gauss. We solve the problem with the test of chi-square applied to a 2x2 &lt;b&gt;contingency table&lt;/b&gt;. In R there is the function prop.test.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;prop.test(x = c(30, 65), n = c(74, 103), correct = FALSE)&lt;br /&gt;&lt;br /&gt;    2-sample test for equality of proportions without continuity correction&lt;br /&gt;&lt;br /&gt;data: c(30, 65) out of c(74, 103)&lt;br /&gt;X-squared = 8.8191, df = 1, p-value = 0.002981&lt;br /&gt;alternative hypothesis: two.sided&lt;br /&gt;95 percent confidence interval:&lt;br /&gt;  -0.37125315 -0.08007196&lt;br /&gt;sample estimates:&lt;br /&gt;prop 1     prop 2&lt;br /&gt;0.4054054  0.6310680&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;Prop.test&lt;/code&gt; function calculates the value of chi-square, given the values of success (in the vector &lt;code style="color: rgb(153, 0, 0);"&gt;x&lt;/code&gt;) and total attempts (in the vector &lt;code style="color: rgb(153, 0, 0);"&gt;n&lt;/code&gt;). The vectors x and n can also be previously declared, and then be retrieved as usual: &lt;code style="color: rgb(153, 0, 0);"&gt;prop.test (x, n, correct = FALSE)&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;In the case of small samples (low value of n), you must specify &lt;code style="color: rgb(153, 0, 0);"&gt;correct = TRUE&lt;/code&gt;, so as to change the computation of chi-square based on the &lt;b&gt;continuity of Yates&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;prop.test(x = c(30, 65), n = c(74, 103), correct=TRUE)&lt;br /&gt;&lt;br /&gt;    2-sample test for equality of proportions with continuity correction&lt;br /&gt;&lt;br /&gt;data: c(30, 65) out of c(74, 103)&lt;br /&gt;X-squared = 7.9349, df = 1, p-value = 0.004849&lt;br /&gt;alternative hypothesis: two.sided&lt;br /&gt;95 percent confidence interval:&lt;br /&gt;  -0.38286428 -0.06846083&lt;br /&gt;sample estimates:&lt;br /&gt;prop 1     prop 2&lt;br /&gt;0.4054054  0.6310680&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In both cases, we obtained p-value less than 0.05, which leads us to reject the hypothesis of equal probability. In conclusion, the customer is a cheat. For confirmation we compare the value chi-square-value calculated with the chi-square-tabulation, which we calculate in this way:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;qchisq(0.950, 1)&lt;br /&gt;[1] 3.841459&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;code style="color: rgb(153, 0, 0);"&gt;qchisq&lt;/code&gt; function calculates the value of chi-square as a function of alpha and degrees of freedom. Since chi-square-calculated is greater than chi-square-tabulation, we conclude by rejecting the hypothesis H0 (as stated by the p-value, and the parametric test).&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-3212733558169947294?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/3212733558169947294/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/comparison-of-two-proportions.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/3212733558169947294'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/3212733558169947294'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/comparison-of-two-proportions.html' title='Comparison of two proportions: parametric (Z-test) and non-parametric (chi-squared) methods'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-1810558224724195990</id><published>2009-07-29T10:22:00.001+02:00</published><updated>2009-08-05T10:19:25.287+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Paired groups'/><category scheme='http://www.blogger.com/atom/ns#' term='Sign test'/><category scheme='http://www.blogger.com/atom/ns#' term='Wilcoxon'/><title type='text'>Wilcoxon signed rank test</title><content type='html'>&lt;span style="font-weight: bold;"&gt;Non-parametric statistical hypothesis test, for the comparison of the means between 2 paired samples&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The mayor of a city wants to see if pollution levels are reduced by closing the streets to the car traffic. This is measured by the rate of pollution every 60 minutes (8am 22pm: total of 15 measurements) in a day when traffic is open, and in a day of closure to traffic. Here the values of air pollution:&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;With traffic: 214, 159, 169, 202, 103, 119, 200, 109, 132, 142, 194, 104, 219, 119, 234&lt;br /&gt;Without traffic: 159, 135, 141, 101, 102, 168, 62, 167, 174, 159, 66, 118, 181, 171, 112&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;It is clear that the two groups are paired, because there is a bond between the readings, consisting in the fact that we are considering the same city (with its peculiarities weather, ventilation, etc.) albeit in two different days. Not being able to assume a Gaussian distribution for the values recorded, we must proceed with a non-parametric test, the &lt;b&gt;Wilcoxon signed rank test&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;a &lt;- c(214, 159, 169, 202, 103, 119, 200, 109, 132, 142, 194, 104, 219, 119, 234)&lt;br /&gt;b &lt;- c(159, 135, 141, 101, 102, 168, 62, 167, 174, 159, 66, 118, 181, 171, 112)&lt;br /&gt;&lt;br /&gt;wilcox.test(a,b, paired=TRUE)&lt;br /&gt;&lt;br /&gt;Wilcoxon signed rank test&lt;br /&gt;&lt;br /&gt;data: a and b&lt;br /&gt;V = 80, p-value = 0.2769&lt;br /&gt;alternative hypothesis: true location shift is not equal to 0&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;Since the p-value is greater than 0.05, we conclude that the means have remained essentially unchanged (we accept the null hypothesis H0), then blocking traffic for a single day did not lead to any improvement in terms of pollution of the city.&lt;br /&gt;The value &lt;code style="color: rgb(153, 0, 0);"&gt;V = 80&lt;/code&gt; corresponds to the sum of ranks assigned to the differences with positive sign. We can manually calculate the sum of ranks assigned to the differences with positive sign, and the sum of ranks assigned to the differences with negative sign, to compare this interval with the interval tabulated on the tables of Wilcoxon for paired samples, and confirm our statistic decision. Here's how to calculate the two sums.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;a &lt;- c(214, 159, 169, 202, 103, 119, 200, 109, 132, 142, 194, 104, 219, 119, 234)&lt;br /&gt;b &lt;- c(159, 135, 141, 101, 102, 168, 62, 167, 174, 159, 66, 118, 181, 171, 112)&lt;br /&gt;&lt;br /&gt; diff &lt;- c(a - b) #calculating the vector containing the differences&lt;br /&gt; diff &lt;- diff[ diff!=0 ] #delete all differences equal to zero&lt;br /&gt; diff.rank &lt;- rank(abs(diff)) #check the ranks of the differences, taken in absolute&lt;br /&gt; diff.rank.sign &lt;- diff.rank * sign(diff) #check the sign to the ranks, recalling the signs of the values of the differences&lt;br /&gt; ranks.pos &lt;- sum(diff.rank.sign[diff.rank.sign &gt; 0]) #calculating the sum of ranks assigned to the differences as a positive, ie greater than zero&lt;br /&gt; ranks.neg &lt;- -sum(diff.rank.sign[diff.rank.sign &lt; 0]) #calculating the sum of ranks assigned to the differences as a negative, ie less than zero&lt;br /&gt; ranks.pos #it is the value V of the wilcoxon signed rank test&lt;br /&gt;[1] 80&lt;br /&gt; ranks.neg&lt;br /&gt;[1] 40&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The computed interval is (40, 80). The tabulated interval on Wilcoxon paired samples tables, with 15 differences, is (25, 95). Since the calculated interval is contained in the tabulated, we accept the null hypothesis H0 of equality of the means. As predicted by the p-value, closing roads to traffic did not bring any improvement in terms of rate of pollution.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-1810558224724195990?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/1810558224724195990/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/wilcoxon-signed-rank-test.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/1810558224724195990'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/1810558224724195990'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/wilcoxon-signed-rank-test.html' title='Wilcoxon signed rank test'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-1803156460568383811</id><published>2009-07-28T07:30:00.001+02:00</published><updated>2009-08-05T10:17:26.625+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='U-test'/><category scheme='http://www.blogger.com/atom/ns#' term='Wilcoxon-Mann-Whitney'/><category scheme='http://www.blogger.com/atom/ns#' term='Independent groups'/><category scheme='http://www.blogger.com/atom/ns#' term='Wilcoxon'/><title type='text'>Wilcoxon-Mann-Whitney rank sum test (or test U)</title><content type='html'>&lt;span style="font-weight: bold;"&gt;Comparison of the averages of two independent groups of samples, of which we can not assume a distribution of Gaussian type; is also known as Mann-Whitney U-test.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You want to see if the mean of goals suffered by two football teams over the years is the same. Are below the number of goals suffered by each team in 6 games for each year.&lt;br /&gt;&lt;div style="text-align: center;"&gt;Team A: 6, 8, 2, 4, 4, 5&lt;br /&gt;Team B: 7, 10, 4, 3, 5, 6&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;The &lt;b&gt;Wilcoxon-Matt-Whitney test&lt;/b&gt; (or &lt;b&gt;Wilcoxon rank sum test&lt;/b&gt;, or &lt;b&gt;Mann-Whitney U-test&lt;/b&gt;) is used when is asked to compare the means of two groups that do not follow a normal distribution: it is a non-parametrical test. It is the equivalent of the t test, applied for independent samples.&lt;br /&gt;&lt;span class="fullpost"&gt;Let's see how to solve the problem with R:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;a = c(6, 8, 2, 4, 4, 5)&lt;br /&gt;b = c(7, 10, 4, 3, 5, 6)&lt;br /&gt;&lt;br /&gt;wilcox.test(a,b, correct=FALSE)&lt;br /&gt;&lt;br /&gt;Wilcoxon rank sum test&lt;br /&gt;&lt;br /&gt;data: a and b&lt;br /&gt;W = 14, p-value = 0.5174&lt;br /&gt;alternative hypothesis: true location shift is not equal to 0&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The p-value is greater than 0.05, then we can accept the hypothesis H0 of statistical equality of the means of two groups.&lt;br /&gt;If you run &lt;code style="color: rgb(153, 0, 0);"&gt;wilcox.test(b, a, correct = FALSE)&lt;/code&gt;, the p-value would be logically the same:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;a = c(6, 8, 2, 4, 4, 5)&lt;br /&gt;b = c(7, 10, 4, 3, 5, 6)&lt;br /&gt;&lt;br /&gt;wilcox.test(b,a, correct=FALSE)&lt;br /&gt;&lt;br /&gt;Wilcoxon rank sum test&lt;br /&gt;&lt;br /&gt;data: b and a&lt;br /&gt;W = 22, p-value = 0.5174&lt;br /&gt;alternative hypothesis: true location shift is not equal to 0&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The value W is so computed:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;sum.rank.a = sum(rank(c(a,b))[1:6]) #sum of ranks assigned to the group a&lt;br /&gt; W = sum.rank.a – (length(a)*(length(a)+1)) / 2&lt;br /&gt; W&lt;br /&gt;[1] 14&lt;br /&gt;&lt;br /&gt;sum.rank.b = sum(rank(c(a,b))[7:12]) #sum of ranks assigned to the group b&lt;br /&gt; W = sum.rank.b – (length(b)*(length(b)+1)) / 2 &lt;br /&gt; W&lt;br /&gt;[1] 22&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We can finally compare the intervals tabulated on the tables of Wilcoxon for independent samples. The tabulated interval for two groups of 6 samples each is (26, 52), while the interval of our samples is:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;sum(rank(c(a,b))[1:6]) #sum of ranks assigned to the group a&lt;br /&gt;[1] 35&lt;br /&gt;sum(rank(c(a,b))[7:12]) #sum of ranks assigned to the group b&lt;br /&gt;[1] 43&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Since the computed interval (35, 43), is contained within the tabulated interval (26, 52), we conclude by accepting the hypothesis H0 of equality of means.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-1803156460568383811?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/1803156460568383811/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/wilcoxon-mann-whitney-rank-sum-test-or.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/1803156460568383811'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/1803156460568383811'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/wilcoxon-mann-whitney-rank-sum-test-or.html' title='Wilcoxon-Mann-Whitney rank sum test (or test U)'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-4475129104783384918</id><published>2009-07-27T07:30:00.002+02:00</published><updated>2009-08-05T10:14:42.424+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Paired groups'/><category scheme='http://www.blogger.com/atom/ns#' term='Alternative hypothesis'/><category scheme='http://www.blogger.com/atom/ns#' term='T-test'/><title type='text'>Paired Student's t-test</title><content type='html'>&lt;span style="font-weight: bold;"&gt;Comparison of the means of two sets of paired samples, taken from two populations with unknown variance.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A school athletics has taken a new instructor, and want to test the effectiveness of the new type of training proposed by comparing the average times of 10 runners in the 100 meters. Are below the time in seconds before and after training for each athlete.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;Before training: 12.9, 13.5, 12.8, 15.6, 17.2, 19.2, 12.6, 15.3, 14.4, 11.3&lt;br /&gt;After training: 12.7, 13.6, 12.0, 15.2, 16.8, 20.0, 12.0, 15.9, 16.0, 11.1&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;In this case we have two sets of paired samples, since the measurements were made on the same athletes before and after the workout. To see if there was an improvement, deterioration, or if the means of times have remained substantially the same (hypothesis H0), we need to make a &lt;b&gt;Student's t-test for paired samples&lt;/b&gt;, proceeding in this way: &lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;a = c(12.9, 13.5, 12.8, 15.6, 17.2, 19.2, 12.6, 15.3, 14.4, 11.3)&lt;br /&gt;b = c(12.7, 13.6, 12.0, 15.2, 16.8, 20.0, 12.0, 15.9, 16.0, 11.1)&lt;br /&gt;&lt;br /&gt;t.test(a,b, paired=TRUE)&lt;br /&gt;&lt;br /&gt;    Paired t-test&lt;br /&gt;&lt;br /&gt;data: a and b&lt;br /&gt;t = -0.2133, df = 9, p-value = 0.8358&lt;br /&gt;alternative hypothesis: true difference in means is not equal to 0&lt;br /&gt;95 percent confidence interval:&lt;br /&gt;    -0.5802549 0.4802549&lt;br /&gt;sample estimates:&lt;br /&gt;mean of the differences&lt;br /&gt;    -0.05&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The p-value is greater than 0.05, then we can accept the hypothesis H0 of equality of the averages. In conclusion, the new training has not made any significant improvement (or deterioration) to the team of athletes.&lt;br /&gt;Similarly, we calculate the t-tabulated value:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;qt(0.975, 9)&lt;br /&gt;[1] 2.262157&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;t-computed &lt; t-tabulated&lt;/em&gt;, so we accept the null hypothesis H0.&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;hr width="50%"&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;Suppose now that the manager of the team (given the results obtained) fired the coach who has not made any improvement, and take another, more promising. We report the times of athletes after the second training:&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;Before training: 12.9, 13.5, 12.8, 15.6, 17.2, 19.2, 12.6, 15.3, 14.4, 11.3&lt;br /&gt;After the second training: 12.0, 12.2, 11.2, 13.0, 15.0, 15.8, 12.2, 13.4, 12.9, 11.0&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Now we check if there was actually an improvement, ie perform a &lt;b&gt;t-test for paired data&lt;/b&gt;, specifying in R to test the &lt;b&gt;alternative hypothesis H1&lt;/b&gt; of improvement in times. To do this simply add the syntax &lt;code style="color: rgb(153, 0, 0);"&gt;alt = "less"&lt;/code&gt; when you call the t-test:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;a = c(12.9, 13.5, 12.8, 15.6, 17.2, 19.2, 12.6, 15.3, 14.4, 11.3)&lt;br /&gt;b = c(12.0, 12.2, 11.2, 13.0, 15.0, 15.8, 12.2, 13.4, 12.9, 11.0)&lt;br /&gt;&lt;br /&gt;t.test(a,b, paired=TRUE, alt="less")&lt;br /&gt;&lt;br /&gt;    Paired t-test&lt;br /&gt;&lt;br /&gt;data: a and b&lt;br /&gt;t = 5.2671, df = 9, p-value = 0.9997&lt;br /&gt;alternative hypothesis: true difference in means is less than 0&lt;br /&gt;95 percent confidence interval:&lt;br /&gt;    -Inf 2.170325&lt;br /&gt;sample estimates:&lt;br /&gt;mean of the differences&lt;br /&gt;     1.61&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;With this syntax we asked R to check whether the mean of the values contained in the vector &lt;code style="color: rgb(153, 0, 0);"&gt;a&lt;/code&gt; is less of the mean of the values contained in the vector &lt;code style="color: rgb(153, 0, 0);"&gt;b&lt;/code&gt;. In response, we obtained a p-value well above 0.05, which leads us to conclude that we can reject the null hypothesis H0 in favor of the alternative hypothesis H1: the new training has made substantial improvements to the team.&lt;br /&gt;&lt;br /&gt;If we had written: &lt;code style="color: rgb(153, 0, 0);"&gt;t.test (a, b, paired = TRUE, alt = "greater")&lt;/code&gt;, we asked R to check whether the mean of the values contained in the vector &lt;code style="color: rgb(153, 0, 0);"&gt;a&lt;/code&gt; is greater than the mean of the values contained in the vector &lt;code style="color: rgb(153, 0, 0);"&gt;b&lt;/code&gt;. In light of the previous result, we can suspect that the p-value will be much smaller than 0.05, and in fact:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;a = c(12.9, 13.5, 12.8, 15.6, 17.2, 19.2, 12.6, 15.3, 14.4, 11.3)&lt;br /&gt;b = c(12.0, 12.2, 11.2, 13.0, 15.0, 15.8, 12.2, 13.4, 12.9, 11.0)&lt;br /&gt;&lt;br /&gt;t.test(a,b, paired=TRUE, alt="greater")&lt;br /&gt;&lt;br /&gt;    Paired t-test&lt;br /&gt;&lt;br /&gt;data: a and b&lt;br /&gt;t = 5.2671, df = 9, p-value = 0.0002579&lt;br /&gt;alternative hypothesis: true difference in means is greater than 0&lt;br /&gt;95 percent confidence interval:&lt;br /&gt;    1.049675 Inf&lt;br /&gt;sample estimates:&lt;br /&gt;mean of the differences&lt;br /&gt;    1.61&lt;/pre&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-4475129104783384918?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/4475129104783384918/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/paired-students-t-test.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/4475129104783384918'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/4475129104783384918'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/paired-students-t-test.html' title='Paired Student&apos;s t-test'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-1559568043931290152</id><published>2009-07-26T07:30:00.007+02:00</published><updated>2010-10-17T18:41:53.596+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Two sample'/><category scheme='http://www.blogger.com/atom/ns#' term='Homoskedasticity test'/><category scheme='http://www.blogger.com/atom/ns#' term='Welch-Satterthwaite formula'/><category scheme='http://www.blogger.com/atom/ns#' term='Dixon-Massey formula'/><category scheme='http://www.blogger.com/atom/ns#' term='T-test'/><title type='text'>Two sample Student's t-test #2</title><content type='html'>&lt;span style="font-weight: bold;"&gt;Comparison of the averages of two independent groups, extracted from two populations at variance unknown; sample variances are not homogeneous.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We want to compare the heights in inches of two groups of individuals. Here the measurements:&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;A: 175, 168, 168, 190, 156, 181, 182, 175, 174, 179&lt;br /&gt;B: 120, 180, 125, 188, 130, 190, 110, 185, 112, 188&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;As we have seen in a &lt;a href="http://statistic-on-air.blogspot.com/2009/07/two-sample-students-t-test-1.html"&gt;previous exercise&lt;/a&gt;, we must first check whether the variances are homogeneous (homoskedasticity) with a &lt;b&gt;F-test of Fisher&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;a = c(175, 168, 168, 190, 156, 181, 182, 175, 174, 179)&lt;br /&gt; b = c(120, 180, 125, 188, 130, 190, 110, 185, 112, 188)&lt;br /&gt;&lt;br /&gt;var.test(b,a)&lt;br /&gt;&lt;br /&gt;    F test to compare two variances&lt;br /&gt;&lt;br /&gt;data: b and a&lt;br /&gt;F = 14.6431, num df = 9, denom df = 9, p-value = 0.0004636&lt;br /&gt;alternative hypothesis: true ratio of variances is not equal to 1&lt;br /&gt;95 percent confidence interval:&lt;br /&gt;   3.637133 58.952936&lt;br /&gt;sample estimates:&lt;br /&gt; ratio of variances&lt;br /&gt;   14.64308&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We obtained p-value less than 0.05, then the two variances are not homogeneous. Indeed we can compare the value of F computed with the tabulated value of F for &lt;i&gt;alpha = 0.05&lt;/i&gt;, &lt;i&gt;degrees of freedom at numerator = 9&lt;/i&gt;, and &lt;i&gt;degrees of freedom of denominator = 9&lt;/i&gt;, using the function &lt;code style="color: rgb(153, 0, 0);"&gt;qf(p, df.num, df.den)&lt;/code&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;qf(0.95, 9, 9)&lt;br /&gt;[1] 3.178893&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;F-computed is greater than F-tabulated, so we can reject the &lt;b&gt;null hypothesis H0 of homogeneity of variances&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;To make the comparison between the two groups, we use the function &lt;code style="color: rgb(153, 0, 0);"&gt;t.test&lt;/code&gt; with not homogeneous variances (&lt;code style="color: rgb(153, 0, 0);"&gt;var.equal = FALSE&lt;/code&gt;, which can also be omitted, because the function works on non-homogeneous variance by default) and independent samples (&lt;code style="color: rgb(153, 0, 0);"&gt;paired = FALSE&lt;/code&gt;, which can also be omitted, because by default the function works on independent samples) in this way:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;t.test(a,b, var.equal=FALSE, paired=FALSE)&lt;br /&gt;&lt;br /&gt;    Welch Two Sample t-test&lt;br /&gt;&lt;br /&gt;data: a and b&lt;br /&gt;t = 1.8827, df = 10.224, p-value = 0.08848&lt;br /&gt;alternative hypothesis: true difference in means is not equal to 0&lt;br /&gt;95 percent confidence interval:&lt;br /&gt;    -3.95955 47.95955&lt;br /&gt;sample estimates:&lt;br /&gt;mean of x mean of y&lt;br /&gt;    174.8     152.8&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;As we see in the headline, you made a t-test on two samples with the calculation of degrees of freedom using the &lt;b&gt;formula of Welch-Satterthwaite&lt;/b&gt; (the result of the formula is &lt;i&gt;df = 10,224&lt;/i&gt;), which is used in cases where the variances are not homogeneous. Welch-Satterthwaite equation is also called &lt;b&gt;Dixon-Massey formula&lt;/b&gt; when you make the comparison between two groups, as in this case.&lt;br /&gt;We obtained p-value greater than 0.05, then we can conclude that the means of the two groups are significantly similar (albeit p-value is very close to the threshold 0.05). Indeed the value of t is less than the tabulated t-value for 10,224 degrees of freedom, which in R we can calculate:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;qt(0.975, 10.224)&lt;br /&gt;[1] 2.221539&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We can accept the hypothesis H0 of equality of means.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Welch-Satterthwaite formula&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;$$df=\frac{\sum deviance(X)}{\sum df(X)}=\frac{\sum_{i=1}^{k} (\sum_{j=1}^{n} (X_{ij} - \bar{X_i})^2}{\sum_{i=1}^{k}(n_i-1)}$$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Dixon-Massey formula&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;$$df=\frac{\left(\frac{\displaystyle S_1^2}{\displaystyle n_1}+\frac{\displaystyle S_2^2}{\displaystyle n_2}\right)^2}{\frac{\displaystyle\left(\frac{\displaystyle S_1^2}{\displaystyle n_1}\right)^2}{\displaystyle n_1-1}+\frac{\displaystyle\left(\frac{\displaystyle S_2^2}{\displaystyle n_2}\right)^2}{\displaystyle n_2-1}}$$&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-1559568043931290152?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/1559568043931290152/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/two-sample-students-t-test-2.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/1559568043931290152'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/1559568043931290152'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/two-sample-students-t-test-2.html' title='Two sample Student&apos;s t-test #2'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-6747735063462448430</id><published>2009-07-25T07:30:00.002+02:00</published><updated>2009-08-05T10:07:56.495+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Two sample'/><category scheme='http://www.blogger.com/atom/ns#' term='Homoskedasticity test'/><category scheme='http://www.blogger.com/atom/ns#' term='Fisher'/><category scheme='http://www.blogger.com/atom/ns#' term='Independent data-set'/><category scheme='http://www.blogger.com/atom/ns#' term='F-test'/><category scheme='http://www.blogger.com/atom/ns#' term='T-test'/><title type='text'>Two sample Student's t-test #1</title><content type='html'>&lt;span style="font-weight: bold;"&gt;t-Test to compare the means of two groups under the assumption that both samples are random, independent, and come from normally distributed population with unknow but equal variances&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Here I will use the same data just seen in a &lt;a href="http://statistic-on-air.blogspot.com/2009/07/two-sample-z-test.html"&gt;previous post&lt;/a&gt;. The data are given below:&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;A: 175, 168, 168, 190, 156, 181, 182, 175, 174, 179&lt;br /&gt;B: 185, 169, 173, 173, 188, 186, 175, 174, 179, 180&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;To solve this problem we must use to a Student's t-test with two samples, assuming that the two samples are taken from populations that follow a Gaussian distribution (if we cannot assume that, we must solve this problem using the non-parametric test called &lt;b&gt;Wilcoxon-Mann-Whitney test&lt;/b&gt;; we will see this test in a future post). Before proceeding with the &lt;em&gt;t-test&lt;/em&gt;, it is necessary to evaluate the sample variances of the two groups, using a &lt;b&gt;Fisher's F-test&lt;/b&gt; to verify the &lt;em&gt;homoskedasticity&lt;/em&gt; (&lt;em&gt;homogeneity of variances&lt;/em&gt;). In R you can do this in this way:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;a = c(175, 168, 168, 190, 156, 181, 182, 175, 174, 179)&lt;br /&gt;b = c(185, 169, 173, 173, 188, 186, 175, 174, 179, 180)&lt;br /&gt;&lt;br /&gt;var.test(a,b)&lt;br /&gt;&lt;br /&gt;     F test to compare two variances&lt;br /&gt;&lt;br /&gt;data: a and b&lt;br /&gt;F = 2.1028, num df = 9, denom df = 9, p-value = 0.2834&lt;br /&gt;alternative hypothesis: true ratio of variances is not equal to 1&lt;br /&gt;95 percent confidence interval:&lt;br /&gt;   0.5223017 8.4657950&lt;br /&gt;sample estimates:&lt;br /&gt; ratio of variances&lt;br /&gt;2.102784&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We obtained p-value greater than 0.05, then we can assume that the two variances are homogeneous. Indeed we can compare the value of F obtained with the tabulated value of F for alpha = 0.05, degrees of freedom of numerator = 9, and degrees of freedom of denominator = 9, using the function &lt;code style="color: rgb(153, 0, 0);"&gt;qf(p, df.num, df.den)&lt;/code&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;qf(0.95, 9, 9)&lt;br /&gt;[1] 3.178893&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Note that the value of F computed is less than the tabulated value of F, which leads us to accept the null hypothesis of homogeneity of variances.&lt;br /&gt;&lt;b&gt;NOTE:&lt;/b&gt; The F distribution has only one tail, so with a confidence level of 95%, &lt;code style="color: rgb(153, 0, 0);"&gt;p = 0.95&lt;/code&gt;. Conversely, the &lt;em&gt;t-distribution&lt;/em&gt; has two tails, and in the R's function &lt;code style="color: rgb(153, 0, 0);"&gt;qt(p, df)&lt;/code&gt; we insert a value &lt;code style="color: rgb(153, 0, 0);"&gt;p = 0975&lt;/code&gt; when you're testing a two-tailed alternative hypothesis.&lt;br /&gt;&lt;br /&gt;Then call the function t.test for homogeneous variances (&lt;code style="color: rgb(153, 0, 0);"&gt;var.equal = TRUE&lt;/code&gt;) and independent samples (&lt;code style="color: rgb(153, 0, 0);"&gt;paired = FALSE&lt;/code&gt;: you can omit this because the function works on independent samples by default) in this way:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;t.test(a,b, var.equal=TRUE, paired=FALSE)&lt;br /&gt;&lt;br /&gt;Two Sample t-test&lt;br /&gt;&lt;br /&gt;data: a and b&lt;br /&gt;t = -0.9474, df = 18, p-value = 0.356&lt;br /&gt;alternative hypothesis: true difference in means is not equal to 0&lt;br /&gt;95 percent confidence interval:&lt;br /&gt;  -10.93994 4.13994&lt;br /&gt;sample estimates:&lt;br /&gt;mean of x mean of y&lt;br /&gt;    174.8     178.2&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We obtained p-value greater than 0.05, then we can conclude that the averages of two groups are significantly similar. Indeed the value of t-computed is less than the tabulated t-value for 18 degrees of freedom, which in R we can calculate:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;qt(0.975, 18)&lt;br /&gt;[1] 2.100922&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This confirms that we can accept the null hypothesis H0 of equality of the means.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-6747735063462448430?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/6747735063462448430/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/two-sample-students-t-test-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/6747735063462448430'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/6747735063462448430'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/two-sample-students-t-test-1.html' title='Two sample Student&apos;s t-test #1'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-8459704097425421932</id><published>2009-07-24T07:30:00.004+02:00</published><updated>2009-08-05T10:05:15.823+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='One sample'/><category scheme='http://www.blogger.com/atom/ns#' term='P-value'/><category scheme='http://www.blogger.com/atom/ns#' term='T-test'/><title type='text'>One sample Student's t-test</title><content type='html'>&lt;span style="font-weight: bold;"&gt;Comparison of the sample mean with a known value, when the variance of the population is not known.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Consider the exercise we have just seen before.&lt;br /&gt;It was made an intelligence test in 10 subjects, and here are the results obtained. The average result of the population whici received the same test, is equal to 75. You want to check if the sample mean is significantly similar (when the significance level is 95%) to the average population, assuming that the variance of the population is not known.&lt;br /&gt;&lt;div style="text-align: center;"&gt;65, 78, 88, 55, 48, 95, 66, 57, 79, 81&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Contrary to the &lt;a href="http://statistic-on-air.blogspot.com/2009/07/one-sample-z-test.html"&gt;one sample Z-test&lt;/a&gt;, the &lt;b&gt;Student's t-test&lt;/b&gt; for a &lt;b&gt;single sample&lt;/b&gt; have a pre-set function in R we can apply immediately.&lt;br /&gt;&lt;span class="fullpost"&gt;It is the &lt;code style="color: rgb(153, 0, 0);"&gt;t.test (a, mu)&lt;/code&gt;, we can see below applied.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;a = c(65, 78, 88, 55, 48, 95, 66, 57, 79, 81)&lt;br /&gt;&lt;br /&gt;t.test (a, mu=75)&lt;br /&gt;&lt;br /&gt;One Sample t-test&lt;br /&gt;&lt;br /&gt;data: a&lt;br /&gt;t = -0.783, df = 9, p-value = 0.4537&lt;br /&gt;alternative hypothesis: true mean is not equal to 75&lt;br /&gt;95 percent confidence interval:&lt;br /&gt;  60.22187 82.17813&lt;br /&gt;sample estimates:&lt;br /&gt; mean of x&lt;br /&gt;71.2&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The function &lt;code style="color: rgb(153, 0, 0);"&gt;t.test&lt;/code&gt; on one sample provides in output the value of t calculated; also gives us degrees of freedom, the confidence interval and the average (mean of x).&lt;br /&gt;In order to take your statistic decision, you can proceed in two ways. We can compare the value of t with the value of the tabulated student t with 9 degrees of freedom. If we do not have tables, we can calculate the value t-tabulated in the following way:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;qt(0.975, 9)&lt;br /&gt;[1] 2.262157&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;The function &lt;code style="color: rgb(153, 0, 0);"&gt;qt (p, df)&lt;/code&gt; returns the value of t computed considering the significance level (we chose a significance level equal to 95%, which means that each tail is the 2.5% which corresponds to the value of &lt;em&gt;p = 1 - 0.025&lt;/em&gt;), and the degrees of freedom. By comparing the value of t-tabulated with t-computed, t-computed appears smaller, which means that we accept the null hypothesis of equality of the averages: our sample mean is significantly similar to the mean of the population.&lt;br /&gt;&lt;br /&gt;Alternatively we could consider the p-value. With a significance level of 95%, remember this rule: If &lt;b&gt;p-value is greater than 0.05&lt;/b&gt; then &lt;b&gt;we accept the null hypothesis H0&lt;/b&gt;; if &lt;b&gt;p-value is less than 0.05&lt;/b&gt; then &lt;b&gt;we reject the null hypothesis H0&lt;/b&gt; in favor of the alternative hypothesis H1.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-8459704097425421932?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/8459704097425421932/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/one-sample-students-t-test.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/8459704097425421932'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/8459704097425421932'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/one-sample-students-t-test.html' title='One sample Student&apos;s t-test'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-5911292142891504709</id><published>2009-07-23T07:30:00.002+02:00</published><updated>2009-08-05T10:03:10.071+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Two sample'/><category scheme='http://www.blogger.com/atom/ns#' term='Independent data-set'/><category scheme='http://www.blogger.com/atom/ns#' term='Z-test'/><title type='text'>Two sample Z-test</title><content type='html'>&lt;span style="font-weight: bold;"&gt;Comparison of the means of two independent groups of samples, taken from two populations with known variance.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Is asked to compare the average heights of two groups. The first group (A) consists of individuals of Italian nationality (the variance of the Italian population is 5); the second group is taken from individuals of German nationality (the variance of German population variance is 8.5). The data are given below:&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;A: 175, 168, 168, 190, 156, 181, 182, 175, 174, 179&lt;br /&gt;B: 185, 169, 173, 173, 188, 186, 175, 174, 179, 180&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;Since we have the variance of the population, we must proceed with a &lt;b&gt;two sample Z-test&lt;/b&gt;. Even in this case is not avalilable in R a function to solve the problem, but we can easily create it ourselves.&lt;br /&gt;&lt;br /&gt;$$Z=\frac{(\overline{x}_1-\overline{x}_2)-(\mu_1-\mu_2)}{\sqrt{\frac{\sigma_1^2}{n_1}+\frac{\sigma_2^2}{n_2}}}$$&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;z.test2sam = function(a, b, var.a, var.b){&lt;br /&gt;   n.a = length(a)&lt;br /&gt;   n.b = length(b)&lt;br /&gt;   zeta = (mean(a) - mean(b)) / (sqrt(var.a/n.a + var.b/n.b))&lt;br /&gt;   return(zeta)&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The function &lt;code style="color: rgb(153, 0, 0);"&gt;z.test2sam&lt;/code&gt; provides in output the value of zeta, after receiving in input two vectors (&lt;code style="color: rgb(153, 0, 0);"&gt;a&lt;/code&gt; and &lt;code style="color: rgb(153, 0, 0);"&gt;b&lt;/code&gt;), the variance of the first population (&lt;code style="color: rgb(153, 0, 0);"&gt;var.a&lt;/code&gt;) and the variance of the second population (&lt;code style="color: rgb(153, 0, 0);"&gt;var.b&lt;/code&gt;).&lt;br /&gt;Using this function we obtain: &lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;a = c(175, 168, 168, 190, 156, 181, 182, 175, 174, 179)&lt;br /&gt;b = c(185, 169, 173, 173, 188, 186, 175, 174, 179, 180)&lt;br /&gt;&lt;br /&gt;z.test2sam(a, b, 5, 8.5)&lt;br /&gt;[1] -2.926254&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The value of zeta is greater than the value of the critical value zeta tabulated for alpha equal to 0.05 (&lt;b&gt;z-tabulated = 1.96&lt;/b&gt; for a two-tailed test): then we reject the null hypothesis in favor of the alternative hypothesis. We conclude that the two means are significantly different.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-5911292142891504709?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/5911292142891504709/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/two-sample-z-test.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/5911292142891504709'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/5911292142891504709'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/two-sample-z-test.html' title='Two sample Z-test'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-3231164487489995643</id><published>2009-07-22T07:30:00.001+02:00</published><updated>2009-08-05T10:00:57.994+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='One sample'/><category scheme='http://www.blogger.com/atom/ns#' term='Z-test'/><title type='text'>One sample Z-test</title><content type='html'>&lt;span style="font-weight: bold;"&gt;Comparison of the sample mean with know population mean and standard deviation.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Suppose that 10 volunteers have done an intelligence test; here are the results obtained. The mean obtained at the same test, from the entire population is 75. You want to check if there is a statistically significant difference (with a significance level of 95%) between the means of the sample and the population, assuming that the sample variance is known and equal to 18.&lt;br /&gt;&lt;div style="text-align: center;"&gt;65, 78, 88, 55, 48, 95, 66, 57, 79, 81&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;To solve this problem it is necessary to develop a &lt;b&gt;one sample Z-test&lt;/b&gt;. In R there isn't a similar function, so we can create our function.&lt;br /&gt;&lt;span class="fullpost"&gt;Recalling the formula for calculating the value of z, we will write this function: &lt;br /&gt;&lt;br /&gt;$$Z=\frac{\overline{x}-\mu_0}{\frac{\sigma}{\sqrt{n}}}$$&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;z.test = function(a, mu, var){&lt;br /&gt;   zeta = (mean(a) - mu) / (sqrt(var / length(a)))&lt;br /&gt;   return(zeta)&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We have built so the function &lt;code style="color: rgb(153, 0, 0);"&gt;z.test&lt;/code&gt;; it receives in input a vector of values (a), the mean of the population to perform the comparison (mu), and the population variance (var); it returns the value of zeta. Now apply the function to our problem.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;a = c(65, 78, 88, 55, 48, 95, 66, 57, 79, 81)&lt;br /&gt;&lt;br /&gt;z.test(a, 75, 18)&lt;br /&gt;[1] -2.832353&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The value of zeta is equal to -2.83, which is higher than the critical value &lt;code style="color: rgb(153, 0, 0);"&gt;Zcv = 1.96&lt;/code&gt;, with &lt;code style="color: rgb(153, 0, 0);"&gt;alpha = 0.05&lt;/code&gt; (&lt;b&gt;2-tailed test&lt;/b&gt;). We conclude therefore that the mean of our sample is significantly different from the mean of the population.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-3231164487489995643?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/3231164487489995643/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/one-sample-z-test.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/3231164487489995643'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/3231164487489995643'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/one-sample-z-test.html' title='One sample Z-test'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-893417314670513279</id><published>2009-07-21T07:30:00.001+02:00</published><updated>2009-08-05T09:59:01.617+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='R functions'/><title type='text'>Geometric and harmonic means in R</title><content type='html'>Compute the &lt;b&gt;geometric mean&lt;/b&gt; and &lt;b&gt;harmonic mean&lt;/b&gt; in R of this sequence.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;10, 2, 19, 24, 6, 23, 47, 24, 54, 77&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;These features are not present in the standard package of R, although they are easily available in some packets. &lt;br /&gt;&lt;span class="fullpost"&gt;However, it is easy to calculate these values simply by remembering the mathematical formulas, and applying them in R.&lt;br /&gt;&lt;br /&gt;$$H = \frac{n}{\frac{1}{x_1} + \frac{1}{x_2} + \cdots + \frac{1}{x_n}} = \frac{n}{\sum_{i=1}^n \frac{1}{x_i}}, \qquad x_i &gt; 0 \text{ for all } i.$$&lt;br /&gt;&lt;br /&gt;In R language:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;a = c(10, 2, 19, 24, 6, 23, 47, 24, 54, 77)&lt;br /&gt;&lt;br /&gt;1/mean(1/a) #compute the harmonic mean&lt;br /&gt;[1] 10.01109&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;$$\overline{a}_{geom}=\bigg(\prod_{i=1}^n a_i \bigg)^{1/n} = \sqrt[n]{a_1 \cdot a_2 \cdots a_n}$$&lt;br /&gt;&lt;br /&gt;In R language&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;a = c(10, 2, 19, 24, 6, 23, 47, 24, 54, 77)&lt;br /&gt;&lt;br /&gt;n = length(a) #now n is equal to the number of elements in a&lt;br /&gt;&lt;br /&gt;prod(a)^(1/n) #compute the geometric mean&lt;br /&gt;[1] 18.92809&lt;/pre&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-893417314670513279?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/893417314670513279/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/geometric-and-harmonic-means-in-r.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/893417314670513279'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/893417314670513279'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/geometric-and-harmonic-means-in-r.html' title='Geometric and harmonic means in R'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-4125226614947505357</id><published>2009-07-20T07:30:00.002+02:00</published><updated>2009-08-05T09:56:59.581+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Negative binomial distribution'/><category scheme='http://www.blogger.com/atom/ns#' term='R functions'/><category scheme='http://www.blogger.com/atom/ns#' term='Probability'/><title type='text'>Probability exercise: negative binomial distribution</title><content type='html'>What is the probability you get the 4th cross before the 3rd head, flipping a coin?&lt;br /&gt;&lt;br /&gt;The mathematical formula for solving this exercise, which follows a &lt;b&gt;negative binomial distribution&lt;/b&gt;, is:&lt;br /&gt;&lt;br /&gt;$$f(x)=P(X=x)=\begin{pmatrix} x+y-1\\ y-1 \end{pmatrix} \cdot p^x \cdot (1-p)^y$$&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;To solve a problem like this, the number of experiments is not significant, since it is sufficient to know the probability of individual shots that are done and you want to combine, to obtain the required probability. To solve this problem in R, we can use the function &lt;code style="color: rgb(153, 0, 0);"&gt;dnbinom(x, y, p)&lt;/code&gt;. This distribution allows to calculate the probability that a number of &lt;em&gt;failures x&lt;/em&gt; occurs before &lt;em&gt;y-th success&lt;/em&gt;, in a &lt;b&gt;sequence of Bernoulli trials&lt;/b&gt;, for which the probability of individual success is &lt;em&gt;p&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;dnbinom(4,3,0.5)&lt;br /&gt;[1] 0.1171875&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The probability of obtaining the fourth cross before the third head (and then after two head) is equal to 11,72%.&lt;br /&gt;&lt;br /&gt;It may seem a strange result, but to convince us about the accuracy of this function of R, let us consider this other problem: what are the chances of leaving the first, second, third, ... the 25th head before the second cross?&lt;br /&gt;We can obtain a histogram in R, which shows what is required, in this manner: &lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;barplot(dnbinom(1:25,2,0.5), col="grey", names.arg=1:25)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Observe that the probability to get the first head before the second cross is 0.25, which is the product &lt;code style="color: rgb(153, 0, 0);"&gt;0.5 x 0.5&lt;/code&gt; (probability to get H after T). As the number of flips have been going on, the probability falls more and more.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-4125226614947505357?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/4125226614947505357/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/probability-exercise-negative-binomial.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/4125226614947505357'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/4125226614947505357'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/probability-exercise-negative-binomial.html' title='Probability exercise: negative binomial distribution'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-6793908630797585579</id><published>2009-07-19T07:29:00.003+02:00</published><updated>2009-08-05T09:54:56.706+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Binomial distribution'/><category scheme='http://www.blogger.com/atom/ns#' term='R functions'/><category scheme='http://www.blogger.com/atom/ns#' term='Probability'/><category scheme='http://www.blogger.com/atom/ns#' term='Bernoulli'/><title type='text'>A probability exercise on the Bernoulli distribution</title><content type='html'>What is the probability, flipping a coin 8 times, to obtain the sequence HHTTTHTT? (H = head; T= tail)&lt;br /&gt;&lt;br /&gt;The theory teaches us that to solve this question, we can simply use the following formula:&lt;br /&gt;&lt;br /&gt;$$f(x)=P(X=x)=B(n,p)=\begin{pmatrix}n\\ x \end{pmatrix} \cdot p^x \cdot q^{n-x}=\frac{n!}{x!(n-x)!}$$&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;To solve a problem like this, we can use in R the function &lt;code style="color: rgb(153, 0, 0);"&gt;dbinom(x, n, p)&lt;/code&gt;. The coin flipping follow a  binomial distribution, in which every event can be H or T. Suppose that T is the number of successes &lt;code style="color: rgb(153, 0, 0);"&gt;x&lt;/code&gt; (in this case &lt;code style="color: rgb(153, 0, 0);"&gt;x = 5&lt;/code&gt;), while &lt;code style="color: rgb(153, 0, 0);"&gt;n&lt;/code&gt; is the number independet experiments (in this case &lt;code style="color: rgb(153, 0, 0);"&gt;n = 8&lt;/code&gt;). The probability of success is &lt;code style="color: rgb(153, 0, 0);"&gt;p = 0.5&lt;/code&gt;. Put these data into R and get the answer:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;dbinom(5, 8, 0.5)&lt;br /&gt;[1] 0.21875&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The probability of obtaining that particular sequence is equal to 21,875%.&lt;br /&gt;What probability we would have obtained if we had chosen H as the success (ie by imposing &lt;code style="color: rgb(153, 0, 0);"&gt;x = 3&lt;/code&gt;)?&lt;/code&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-6793908630797585579?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/6793908630797585579/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/probability-exercise-on-bernoulli.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/6793908630797585579'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/6793908630797585579'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/probability-exercise-on-bernoulli.html' title='A probability exercise on the Bernoulli distribution'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-946669744997424783</id><published>2009-07-19T07:16:00.004+02:00</published><updated>2009-08-05T09:53:01.443+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='R functions'/><title type='text'>Let us practice with some functions of R</title><content type='html'>Given the following data set, compute the arithmetic mean, median, variance, standard deviation; find the greatest and the smaller value, the sum of all values, the square of the sum of all values, the sum of the square of all values; assigne the ranks and add them, assigning the ranks to the first 6 values and add those.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;10, 2, 19, 24, 6, 23, 47, 24, 54, 77&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;Extremely simple to perform in R, deliberately created to familiarize with some statistical functions that can serve us in the future. Not carry over mathematical formulas, which you can find in any book of mathematics, or Wikipedia.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;a = c(10, 2, 19, 24, 6, 23, 47, 24, 54, 77)&lt;br /&gt;&lt;br /&gt;mean(a) #calculate the arithmetic mean&lt;br /&gt;[1] 28.6&lt;br /&gt;&lt;br /&gt;median(a) #calculate the median&lt;br /&gt;[1] 23.5&lt;br /&gt;&lt;br /&gt;var(a) #calculate the variance&lt;br /&gt;[1] 561.8222&lt;br /&gt;&lt;br /&gt;sd(a) #calculate the standard deviation&lt;br /&gt;[1] 23.70279&lt;br /&gt;&lt;br /&gt;max(a) #shows the larger value of the sequence&lt;br /&gt;[1] 77&lt;br /&gt;&lt;br /&gt;min(a) #shows the smallest value of the sequence&lt;br /&gt;[1] 2&lt;br /&gt;&lt;br /&gt;sum(a) #sum all the values&lt;br /&gt;[1] 286&lt;br /&gt;&lt;br /&gt;sum(a)*sum(a) #calculates the square of the sum of all values&lt;br /&gt;[1] 81796&lt;br /&gt;&lt;br /&gt;sum(a*a) #calculates the sum of the squares of all values&lt;br /&gt;[1] 13236&lt;br /&gt;&lt;br /&gt;sum(rank(a)) #sum of ranks assigned to the variables contained in a&lt;br /&gt;[1] 55&lt;br /&gt;&lt;br /&gt;sum(rank(a)[1:6]) #sum of ranks assigned to the first 6 values of a&lt;br /&gt;[1] 21.5&lt;/pre&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-946669744997424783?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/946669744997424783/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/let-us-practice-with-some-functions-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/946669744997424783'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/946669744997424783'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/let-us-practice-with-some-functions-of.html' title='Let us practice with some functions of R'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-6915256079358550790</id><published>2009-07-10T07:59:00.005+02:00</published><updated>2010-11-07T22:03:40.689+01:00</updated><title type='text'>Useful Links</title><content type='html'>&lt;ul&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Category:Statistics" target="_blank"&gt;Statistic on WikiPedia&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.r-project.org/"&gt;R homepage&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://cran.r-project.org/mirrors.html"&gt;R download&lt;/a&gt; (first select the mirror)&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Blogs on R:&lt;/b&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;a href='http://blog.revolution-computing.com/' target="_blank"&gt;Revolutions R Blog&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href='http://www.r-bloggers.com/' target="_blank"&gt;R bloggers&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href='http://planetr.stderr.org/' target="_blank"&gt;Planet R&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href='http://www.statmethods.net/index.html' target="_blank"&gt;Quick-R&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://onertipaday.blogspot.com/" target="_blank"&gt;One R tip a day&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href='http://datamining.togaware.com/survivor/index.html' target="_blank"&gt;Data Mining With Rattle and R&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href='http://animation.yihui.name/' target="_blank"&gt;AniWiki&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href='http://addictedtor.free.fr/graphiques' target="_blank"&gt;R Graph Gallery&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href='http://pj.freefaculty.org/R/Rtips.html' target="_blank"&gt;R Tips / StatsRus&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href='http://romainfrancois.blog.free.fr/' target="_blank"&gt;Romain Francois blog&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href='http://ryouready.wordpress.com/' target="_blank"&gt;"R" you ready?&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href='http://learnr.wordpress.com/' target="_blank"&gt;Learning R&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href='http://weitaiyun.blogspot.com/' target="_blank"&gt;Taiyun Wei blog&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href='http://blog.moertel.com/' target="_blank"&gt;Tom Moertel's Weblog&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href='http://www.r-ohjelmointi.org' target="_blank"&gt;r-ohjelmointi&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-6915256079358550790?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/6915256079358550790/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/useful-links.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/6915256079358550790'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/6915256079358550790'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/useful-links.html' title='Useful Links'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4274823366855967619.post-2448862640156238497</id><published>2009-07-10T07:54:00.016+02:00</published><updated>2010-01-06T13:26:56.345+01:00</updated><title type='text'>Exercise Index</title><content type='html'>&lt;h1&gt;Chapter 0: Basic Exercises with R and probability&lt;/h1&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://statistic-on-air.blogspot.com/2009/07/let-us-practice-with-some-functions-of.html"&gt;Some practice with R&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://statistic-on-air.blogspot.com/2009/07/probability-exercise-on-bernoulli.html"&gt;Exercise on probability: the distribution of Bernoulli&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://statistic-on-air.blogspot.com/2009/07/probability-exercise-negative-binomial.html"&gt;Exercise on probability: the negative binomial distribution&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://statistic-on-air.blogspot.com/2009/07/geometric-and-harmonic-means-in-r.html"&gt;Geometric mean and harmonic mean in R&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;h1&gt;Chapter 1: Statistical inference: statistical hypothesis testing&lt;/h1&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://statistic-on-air.blogspot.com/2009/07/one-sample-z-test.html"&gt;Comparison between the sample mean and the population mean, with known variance: one sample Z-test&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://statistic-on-air.blogspot.com/2009/07/two-sample-z-test.html"&gt;Comparison between two independent data-set, with know standard deviation: two sample Z-test&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://statistic-on-air.blogspot.com/2009/07/one-sample-students-t-test.html"&gt;Comparison between the sample mean with the population mean, with unknown standard deviation: one sample Student's t-test&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://statistic-on-air.blogspot.com/2009/07/two-sample-students-t-test-1.html"&gt;Comparison of the means of two independent groups, taken from two populations with unknown variance: two samples Student's t-test #1&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://statistic-on-air.blogspot.com/2009/07/two-sample-students-t-test-2.html"&gt;Comparison of the means of two independent group; calculation of the number of degree of freedom using the Welch-Satterthwaite formula: two sample Student's t-test #2&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://statistic-on-air.blogspot.com/2009/07/paired-students-t-test.html"&gt;Comparison of the means of two paired samples: Paired Student's t-test&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Non-parametric test:&lt;/li&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://statistic-on-air.blogspot.com/2009/07/wilcoxon-mann-whitney-rank-sum-test-or.html"&gt;Wilcoxon-Mann-Whitney rank sum test (or test U)&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://statistic-on-air.blogspot.com/2009/07/wilcoxon-signed-rank-test.html"&gt;Wilcoxon signed rank test&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;li&gt;&lt;a href="http://statistic-on-air.blogspot.com/2009/07/comparison-of-two-proportions.html"&gt;Comparison of two proportions: parametric (Z-test) and non-parametric (chi-squared) methods&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://statistic-on-air.blogspot.com/2009/07/analysis-of-variance-anova-for-multiple.html"&gt;Analysis of variance: one-way ANOVA, for multiple comparisons&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://statistic-on-air.blogspot.com/2009/08/two-way-analysis-of-variance-two-way.html"&gt;Two-way analysis of variance: two-way ANOVA in R&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://statistic-on-air.blogspot.com/2010/01/latin-squares-design-in-r.html"&gt;Latin squares design in R&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Non-parametric test:&lt;/li&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://statistic-on-air.blogspot.com/2009/07/kruskal-wallis-one-way-analysis-of.html"&gt;Kruskal-Wallis one-way analysis of variance, for multiple comparisons&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;br /&gt;&lt;h1&gt;Chapter 2: Study of correlation and regression&lt;/h1&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://statistic-on-air.blogspot.com/2009/08/parametric-method-for-study-of.html"&gt;Parametric method for the study of the correlation: the Pearson r-test&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://statistic-on-air.blogspot.com/2009/08/non-parametric-methods-for-study-of.html"&gt;Non-parametric methods for the study of the correlation: Spearman's rank correlation coefficient and Kendall tau rank correlation coefficient&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://statistic-on-air.blogspot.com/2009/08/contingency-table-and-study-of.html"&gt;Contingency table and the study of the correlation between qualitative variables: Pearson's Chi-squared test&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://statistic-on-air.blogspot.com/2009/08/simple-linear-regression.html"&gt;Simple linear regression&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4274823366855967619-2448862640156238497?l=statistic-on-air.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://statistic-on-air.blogspot.com/feeds/2448862640156238497/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/exercise-index.html#comment-form' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/2448862640156238497'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4274823366855967619/posts/default/2448862640156238497'/><link rel='alternate' type='text/html' href='http://statistic-on-air.blogspot.com/2009/07/exercise-index.html' title='Exercise Index'/><author><name>Todos Logos</name><uri>http://www.blogger.com/profile/09881188152777475558</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_0yqjfYQXaSw/Slja2zxaT7I/AAAAAAAAAFM/n3sn-WHktl4/s1600-R/1228321236hmKk20.jpg'/></author><thr:total>7</thr:total></entry></feed>
