{"id":28,"date":"2015-01-08T13:45:59","date_gmt":"2015-01-08T20:45:59","guid":{"rendered":"https:\/\/blogs.ubc.ca\/wtamagi\/?p=28"},"modified":"2015-01-08T13:45:59","modified_gmt":"2015-01-08T20:45:59","slug":"r-stat-frequency-distribution-example","status":"publish","type":"post","link":"https:\/\/blogs.ubc.ca\/wtamagi\/2015\/01\/08\/r-stat-frequency-distribution-example\/","title":{"rendered":"R &#8211; Stat Frequency distribution example"},"content":{"rendered":"<p>Here&#8217;s an example in R &#8211; Stat you can use to produce a frequency distribution range broken into intervals of 10.<\/p>\n<p>&gt; y<br \/>\n[1] 74 73 71 55 91 68 93 37 78 57 65 58 83 65 72 88 85 73 97 73 75 75 62 41 68<br \/>\n[26] 62 78 83 63 81 56 65 67 81 95 76 81 53 57 67 82 43 69 62 31 87 78 41 98 73<\/p>\n<p>*** I created a column array y with the data values.<\/p>\n<p>&gt; range(y)<br \/>\n[1] 31 98<\/p>\n<p>*** Range outputs the range of values which is [31,98].\u00a0 31 is the minimum value in the range and 98 is the maximum value in the range.<\/p>\n<p>&gt; breaks = seq(30,100,by=10)<\/p>\n<p>*** You can then use the breaks command to break the data into intervals of 10 beginning at 30 and ending at 100.\u00a0 So the intervals are [30,40) [40,50) &#8230;.[90,100)<\/p>\n<p>&gt; breaks<br \/>\n[1]\u00a0 30\u00a0 40\u00a0 50\u00a0 60\u00a0 70\u00a0 80\u00a0 90 100<\/p>\n<p>*** Outputs the break intervals beginning at 30.<\/p>\n<p>&gt; y.cut = cut(y,breaks,right=FALSE)<\/p>\n<p>*** The data is classified using the cut function into the break point intervals &#8220;breaks&#8221; and intervals are closed to the left and open on the right, therefore right=FALSE.<\/p>\n<p>&gt; y.freq = table(y.cut)<\/p>\n<p>*** calculates the frequency of y in each interval using table function.<\/p>\n<p>&gt; y.freq<\/p>\n<p>y.cut<br \/>\n[30,40)\u00a0 [40,50)\u00a0 [50,60)\u00a0 [60,70)\u00a0 [70,80)\u00a0 [80,90) [90,100)<br \/>\n2\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 3\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 6\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 12\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 13\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 9\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 5<\/p>\n<p>*** outputs the table, displaying this break intervals and the frequency of the y range of values for each interval. e.g. There are 2 values that fall in the range of [30 to 40) but less than 40.<\/p>\n<p>&gt; cbind(y.freq)<\/p>\n<p>*** outputs the frequency distribution in a column format.<\/p>\n<p>y.freq<br \/>\n[30,40)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2<br \/>\n[40,50)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 3<br \/>\n[50,60)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 6<br \/>\n[60,70)\u00a0\u00a0\u00a0\u00a0\u00a0 12<br \/>\n[70,80)\u00a0\u00a0\u00a0\u00a0\u00a0 13<br \/>\n[80,90)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 9<br \/>\n[90,100)\u00a0\u00a0\u00a0\u00a0\u00a0 5<\/p>\n<p>&gt; barplot(y.freq,ylim=c(0,15))<\/p>\n<p><a href=\"https:\/\/blogs.ubc.ca\/wtamagi\/files\/2015\/01\/frequency-bar-plot.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-29\" src=\"https:\/\/blogs.ubc.ca\/wtamagi\/files\/2015\/01\/frequency-bar-plot-300x239.png\" alt=\"frequency bar plot\" width=\"300\" height=\"239\" srcset=\"https:\/\/blogs.ubc.ca\/wtamagi\/files\/2015\/01\/frequency-bar-plot-300x239.png 300w, https:\/\/blogs.ubc.ca\/wtamagi\/files\/2015\/01\/frequency-bar-plot-624x498.png 624w, https:\/\/blogs.ubc.ca\/wtamagi\/files\/2015\/01\/frequency-bar-plot.png 819w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>A barplot showing the frequency distribution of values at each interval of 10 beginning at 30 and ending at 100.\u00a0 The y-axis is from 0 to 15.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s an example in R &#8211; Stat you can use to produce a frequency distribution range broken into intervals of 10. &gt; y [1] 74 73 71 55 91 68 93 37 78 57 65 58 83 65 72 88 85 73 97 73 75 75 62 41 68 [26] 62 78 83 63 81 [&hellip;]<\/p>\n","protected":false},"author":25150,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-28","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.ubc.ca\/wtamagi\/wp-json\/wp\/v2\/posts\/28","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.ubc.ca\/wtamagi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.ubc.ca\/wtamagi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.ubc.ca\/wtamagi\/wp-json\/wp\/v2\/users\/25150"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.ubc.ca\/wtamagi\/wp-json\/wp\/v2\/comments?post=28"}],"version-history":[{"count":1,"href":"https:\/\/blogs.ubc.ca\/wtamagi\/wp-json\/wp\/v2\/posts\/28\/revisions"}],"predecessor-version":[{"id":30,"href":"https:\/\/blogs.ubc.ca\/wtamagi\/wp-json\/wp\/v2\/posts\/28\/revisions\/30"}],"wp:attachment":[{"href":"https:\/\/blogs.ubc.ca\/wtamagi\/wp-json\/wp\/v2\/media?parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.ubc.ca\/wtamagi\/wp-json\/wp\/v2\/categories?post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.ubc.ca\/wtamagi\/wp-json\/wp\/v2\/tags?post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}