Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the rank-math domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home1/mbithide/public_html/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the ultimate-addons-for-gutenberg domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home1/mbithide/public_html/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the blogus domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home1/mbithide/public_html/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the blogus domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home1/mbithide/public_html/wp-includes/functions.php on line 6114

Warning: Cannot modify header information - headers already sent by (output started at /home1/mbithide/public_html/wp-includes/functions.php:6114) in /home1/mbithide/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home1/mbithide/public_html/wp-includes/functions.php:6114) in /home1/mbithide/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home1/mbithide/public_html/wp-includes/functions.php:6114) in /home1/mbithide/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home1/mbithide/public_html/wp-includes/functions.php:6114) in /home1/mbithide/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home1/mbithide/public_html/wp-includes/functions.php:6114) in /home1/mbithide/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home1/mbithide/public_html/wp-includes/functions.php:6114) in /home1/mbithide/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home1/mbithide/public_html/wp-includes/functions.php:6114) in /home1/mbithide/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home1/mbithide/public_html/wp-includes/functions.php:6114) in /home1/mbithide/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893
{"id":1792,"date":"2022-10-12T15:15:58","date_gmt":"2022-10-12T15:15:58","guid":{"rendered":"https:\/\/mbithiguide.com\/?p=1792"},"modified":"2022-10-16T06:31:53","modified_gmt":"2022-10-16T06:31:53","slug":"how-to-plot-x-bar-and-r-charts-in-r-with-examples","status":"publish","type":"post","link":"https:\/\/mbithiguide.com\/how-to-plot-x-bar-and-r-charts-in-r-with-examples\/","title":{"rendered":"How to Plot X-bar and R charts in R (with examples)"},"content":{"rendered":"\n

In this article we’ll be looking at how to plot an Xbar and R chart using R programming.<\/a> But before we do that, let us first understand the concept behind it. If you are familiar with the concept, you can just skip ahead and look at an example below.<\/p>\n\n\n\n

Definition<\/strong><\/h2>\n\n\n\n

An xbar chart<\/a> is a graphical representation of the average value of a data set over a period of time. The x-axis of the chart represents time, and the y-axis represents the average value.<\/p>\n\n\n\n

An R chart is a type of statistical chart used to monitor the quality of data over time. It is used to track the variation in the data and to identify any outlying data points.<\/p>\n\n\n\n

Variables and Attributes<\/strong><\/h2>\n\n\n\n

It is important to understand the difference between the two.<\/p>\n\n\n\n

Quality characteristics fall into two broad classes<\/p>\n\n\n\n

  • Variables<\/li>
  • Attributes<\/li><\/ul>\n\n\n\n

    Characteristics that are measurable and are expressed on a numerical scale are called variables like length, width, height, diameter, volume etc.<\/p>\n\n\n\n

    A quality characteristic that cannot be measured on a numerical scale is referred to as an attribute e.g performance, realibilty, appearance, availabilty, safety, usability etc<\/p>\n\n\n\n

    Control Charts for Variables<\/strong><\/h2>\n\n\n\n

    Control charts for variables are powerful tools that can be used when measurements from a process are available. Variable charts explain process data in terms of both spread (piece-to-piece varianility) and location (process average)<\/p>\n\n\n\n

    Control charts for variables are prepared from quantitative data e.g diameter, weight, height etc.<\/p>\n\n\n\n

    Note that control charts for variables are preapred and analyzed in pairs i.e locaion and spread.<\/p>\n\n\n\n

    The most commonly used pair of control charts; x-bar chart and R chart.<\/p>\n\n\n\n

    The X-bar<\/em><\/strong> is the average of the values in small sub-groups, and R is the range of values within each sub-group, and the R chart is the range of values within each sub-group.<\/em><\/strong><\/p>\n\n\n\n

    Control limits for R charts<\/strong><\/h2>\n\n\n\n UCL_R=D_4\\overline{R} <\/span>\n\n\n\n

    and<\/p>\n\n\n\n LCL_R=D_3\\overline{R} <\/span>\n\n\n\n

    where<\/p>\n\n\n\n D_3=1-\\frac{3d_3}{d_2} <\/span>\n\n\n\n D_4=1+\\frac{3d_3}{d_2} <\/span>\n\n\n\n

    where<\/p>\n\n\n\n d_2=\\int_{-\\infty}^{\\infty}\\left[1-\\left(1-\\alpha\\right)^n\\right]dx_l <\/span>\n\n\n\n

    and<\/p>\n\n\n\n d_3=2\\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{x_l}\\left(1-\\alpha_l^n-\\left(1-\\alpha_n\\right)^n+\\left(\\alpha_l-\\alpha_n\\right)^n\\right) <\/span>\n\n\n\n

    and<\/p>\n\n\n\n \\alpha_l=\\frac{1}{\\sqrt{2\\pi}}\\int_{-\\infty}^{x_l}e^{-\\left(\\frac{x^2}{2}\\right)}dx <\/span>\n\n\n\n

    and<\/p>\n\n\n\n \\alpha_n=\\frac{1}{\\sqrt{2\\pi}}\\int_{-\\infty}^{x_n}e^{-\\left(\\frac{x^2}{2}\\right)}dx <\/span>\n\n\n\n

    n is the sample size<\/p>\n\n\n\n

    \\overline{R} <\/span> is the mean of the range of values in each subgroup.<\/p>\n\n\n\n

    Control limits for X-bar Chart<\/strong><\/h2>\n\n\n\n UCL=\\overline{\\overline{R}}+A_2\\overline{R} <\/span>\n\n\n\n

    and<\/p>\n\n\n\n LCL=\\overline{\\overline{X}}-A_2\\overline{R} <\/span>\n\n\n\n

    where<\/p>\n\n\n\n A_2=\\frac{3}{d_2\\left(\\sqrt{n}\\right)} <\/span>\n\n\n\n

    [lat1ex] A_2,\\ D_3\\ and\\ D_4 [\/latex] are factors that depend on subgroup size.<\/p>\n\n\n\n

    A_2 <\/span> is the factor for controlling for averages and D_2\\ and\\ D_4 <\/span> are the factors for controlling for ranges.<\/p>\n\n\n\n

    Table of Constants<\/strong><\/h3>\n\n\n\n
    n<\/strong><\/td>A2<\/strong><\/td>D3<\/strong><\/td>D4<\/strong><\/td><\/tr><\/thead>
    2<\/td>1.880<\/td>0<\/td>3.267<\/td><\/tr>
    3<\/td>1.023<\/td>0<\/td>2.575<\/td><\/tr>
    4<\/td>0.729<\/td>0<\/td>2.282<\/td><\/tr>
    5<\/td>0.577<\/td>0<\/td>2.114<\/td><\/tr>
    6<\/td>0.483<\/td>0<\/td>2.004<\/td><\/tr>
    7<\/td>0.419<\/td>0.076<\/td>1.924<\/td><\/tr>
    8<\/td>0.373<\/td>0.136<\/td>1.864<\/td><\/tr>
    9<\/td>0.337<\/td>0.184<\/td>1.816<\/td><\/tr>
    10<\/td>0.308<\/td>0.223<\/td>1.777<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n

    Example<\/strong><\/h2>\n\n\n\n
    Subgroup<\/strong><\/td>1<\/strong><\/td>2<\/strong><\/td>3<\/strong><\/td>4<\/strong><\/td>mean(x)<\/strong><\/td>R<\/strong><\/td><\/tr><\/thead>
    1<\/td>14<\/td>10<\/td>12<\/td>13<\/td>12.25<\/td>4<\/td><\/tr>
    2<\/td>14<\/td>4<\/td>15<\/td>10<\/td>12.75<\/td>5<\/td><\/tr>
    3<\/td>10<\/td>11<\/td>10<\/td>11.5<\/td>10.63<\/td>1.5<\/td><\/tr>
    4<\/td>12<\/td>15<\/td>17<\/td>14.5<\/td>14.63<\/td>5<\/td><\/tr>
    5<\/td>13<\/td>8<\/td>10<\/td>11.5<\/td>10.63<\/td>5<\/td><\/tr>
    6<\/td>8<\/td>10.5<\/td>9<\/td>11<\/td>9.63<\/td>2<\/td><\/tr>
    7<\/td>11<\/td>12.5<\/td>9<\/td>8<\/td>10.13<\/td>4.5<\/td><\/tr>
    8<\/td>16<\/td>15.5<\/td>13<\/td>15<\/td>14.88<\/td>2.5<\/td><\/tr>
    9<\/td>16<\/td>13<\/td>10<\/td>20<\/td>14.75<\/td>10<\/td><\/tr>
    10<\/td>10<\/td>11<\/td>15<\/td>15<\/td>12.75<\/td>5<\/td><\/tr>
    11<\/td>18<\/td>15<\/td>14.5<\/td>16<\/td>15.88<\/td>3.5<\/td><\/tr>
    12<\/td>15<\/td>13<\/td>13.5<\/td>12<\/td>13.38<\/td>3<\/td><\/tr>
    13<\/td>14<\/td>19<\/td>13<\/td>12<\/td>14.50<\/td>7<\/td><\/tr>
    14<\/td>16<\/td>18<\/td>11<\/td>11<\/td>14.00<\/td>7<\/td><\/tr>
    15<\/td>16<\/td>16<\/td>15<\/td>15<\/td>15.50<\/td>1<\/td><\/tr>
    16<\/td>16<\/td>15.5<\/td>10<\/td>14<\/td>13.88<\/td>6<\/td><\/tr>
    17<\/td>16.5<\/td>18<\/td>18<\/td>20<\/td>18.13<\/td>3.5<\/td><\/tr>
    18<\/td>15<\/td>18<\/td>18<\/td>16.5<\/td>16.88<\/td>3<\/td><\/tr>
    19<\/td>13<\/td>16<\/td>17<\/td>15<\/td>15.25<\/td>4<\/td><\/tr>
    20<\/td>16<\/td>18<\/td>17.5<\/td>19<\/td>17.63<\/td>3<\/td><\/tr>
    21<\/td>18<\/td>17<\/td>13<\/td>14<\/td>15.50<\/td>5<\/td><\/tr>
    22<\/td>16<\/td>10.5<\/td>10<\/td>16<\/td>13.13<\/td>6<\/td><\/tr>
    23<\/td>15<\/td>16<\/td>15<\/td>13<\/td>14.75<\/td>3<\/td><\/tr>
    24<\/td>11.5<\/td>14<\/td>15<\/td>10<\/td>12.63<\/td>5<\/td><\/tr>
    25<\/td>16<\/td>12<\/td>15<\/td>16<\/td>14.75<\/td>4<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n

    Limits for R chart<\/strong><\/h3>\n\n\n\n UCL_R=D_4\\cdot\\overline{R} <\/span>\n\n\n\n

    = 2.28 * 4.34<\/p>\n\n\n\n

    = 9.9<\/p>\n\n\n\n LCL_R=D_3\\cdot\\overline{R} <\/span>\n\n\n\n

    = 0*4.34<\/p>\n\n\n\n

    = 0<\/p>\n\n\n\n

    Limits for X-bar Chart<\/strong><\/h3>\n\n\n\n UCL=\\overline{\\overline{x}}+A_2\\cdot\\overline{R} <\/span>\n\n\n\n

    = 13.96+0.73*4.34<\/p>\n\n\n\n

    = 17.1<\/p>\n\n\n\n LCL=\\overline{x}-A_2\\cdot\\overline{R} <\/span>\n\n\n\n

    = 13.96-0.73*4.34<\/p>\n\n\n\n

    = 10.8<\/p>\n\n\n\n

    Plotting the above data for X-bar and R chart in R<\/strong><\/h3>\n\n\n\n

    Note that if you were to do data entry for the data presented above. You’ll need to input it in this format<\/p>\n\n\n\n

    \"how<\/figure>\n\n\n\n
    library(qcc)\n\ncharts.data <- read.csv(\"SQC.csv\")\ncharts.data\nattach(charts.data)\n\n#To view the last six datasets\ntail(charts.data)\nobs subgroup\n95   15       24\n96   10       24\n97   16       25\n98   12       25\n99   15       25\n100  16       25\n\n\n#creating a qcc object from the data\nmeasurements <- qcc.groups(obs,subgroup)\nhead(measurements)\n[,1] [,2] [,3] [,4]\n1   14 10.0   12 13.0\n2   14  4.0   15 10.0\n3   10 11.0   10 11.5\n4   12 15.0   17 14.5\n5   13  8.0   10 11.5\n6    8 10.5    9 11.0\n\ntail(measurements)\n[,1] [,2] [,3] [,4]\n20 16.0 18.0 17.5   19\n21 18.0 17.0 13.0   14\n22 16.0 10.5 10.0   16\n23 15.0 16.0 15.0   13\n24 11.5 14.0 15.0   10\n25 16.0 12.0 15.0   16\n\n#summary of the data\nsummary(measurements)\nV1              V2              V3              V4       \nMin.   : 8.00   Min.   : 4.00   Min.   : 9.00   Min.   : 8.00  \n1st Qu.:13.00   1st Qu.:11.00   1st Qu.:10.00   1st Qu.:11.50  \nMedian :15.00   Median :15.00   Median :13.50   Median :14.00  \nMean   :14.24   Mean   :13.86   Mean   :13.42   Mean   :13.96  \n3rd Qu.:16.00   3rd Qu.:16.00   3rd Qu.:15.00   3rd Qu.:16.00  \nMax.   :18.00   Max.   :19.00   Max.   :18.00   Max.   :20.00  <\/pre>\n\n\n\n
    #R charts\nqcc(measurements,type=\"R\")<\/pre>\n\n\n\n
    \"how<\/figure>\n\n\n\n
    #X-bar chart\nqcc(measurements,type=\"xbar\")<\/pre>\n\n\n\n
    \"\"<\/figure>\n","protected":false},"excerpt":{"rendered":"

    In this article we’ll be looking at how to plot an Xbar and R chart using R programming. But before we do that, let us first understand the concept behind it. If you are familiar with the concept, you can just skip ahead and look at an example below. Definition An xbar chart is a […]<\/p>\n","protected":false},"author":1,"featured_media":1804,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"_uag_custom_page_level_css":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[4,15],"tags":[],"class_list":["post-1792","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r-programming","category-statistics"],"uagb_featured_image_src":{"full":["https:\/\/mbithiguide.com\/wp-content\/uploads\/2022\/10\/diogo-ascenso-o7j_dfkFMYw-unsplash.jpg",0,0,false],"thumbnail":["https:\/\/mbithiguide.com\/wp-content\/uploads\/2022\/10\/diogo-ascenso-o7j_dfkFMYw-unsplash.jpg",1,1,false],"medium":["https:\/\/mbithiguide.com\/wp-content\/uploads\/2022\/10\/diogo-ascenso-o7j_dfkFMYw-unsplash.jpg",1,1,false],"medium_large":["https:\/\/mbithiguide.com\/wp-content\/uploads\/2022\/10\/diogo-ascenso-o7j_dfkFMYw-unsplash.jpg",1,1,false],"large":["https:\/\/mbithiguide.com\/wp-content\/uploads\/2022\/10\/diogo-ascenso-o7j_dfkFMYw-unsplash.jpg",1,1,false],"1536x1536":["https:\/\/mbithiguide.com\/wp-content\/uploads\/2022\/10\/diogo-ascenso-o7j_dfkFMYw-unsplash.jpg",1,1,false],"2048x2048":["https:\/\/mbithiguide.com\/wp-content\/uploads\/2022\/10\/diogo-ascenso-o7j_dfkFMYw-unsplash.jpg",1,1,false],"blogus-slider-full":["https:\/\/mbithiguide.com\/wp-content\/uploads\/2022\/10\/diogo-ascenso-o7j_dfkFMYw-unsplash.jpg",1,1,false],"blogus-featured":["https:\/\/mbithiguide.com\/wp-content\/uploads\/2022\/10\/diogo-ascenso-o7j_dfkFMYw-unsplash.jpg",1,1,false],"blogus-medium":["https:\/\/mbithiguide.com\/wp-content\/uploads\/2022\/10\/diogo-ascenso-o7j_dfkFMYw-unsplash.jpg",1,1,false]},"uagb_author_info":{"display_name":"Benard Mbithi","author_link":"https:\/\/mbithiguide.com\/author\/benard-mbithi\/"},"uagb_comment_info":0,"uagb_excerpt":"In this article we’ll be looking at how to plot an Xbar and R chart using R programming. But before we do that, let us first understand the concept behind it. If you are familiar with the concept, you can just skip ahead and look at an example below. Definition An xbar chart is a…","_links":{"self":[{"href":"https:\/\/mbithiguide.com\/wp-json\/wp\/v2\/posts\/1792","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mbithiguide.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mbithiguide.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mbithiguide.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mbithiguide.com\/wp-json\/wp\/v2\/comments?post=1792"}],"version-history":[{"count":10,"href":"https:\/\/mbithiguide.com\/wp-json\/wp\/v2\/posts\/1792\/revisions"}],"predecessor-version":[{"id":1806,"href":"https:\/\/mbithiguide.com\/wp-json\/wp\/v2\/posts\/1792\/revisions\/1806"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mbithiguide.com\/wp-json\/wp\/v2\/media\/1804"}],"wp:attachment":[{"href":"https:\/\/mbithiguide.com\/wp-json\/wp\/v2\/media?parent=1792"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mbithiguide.com\/wp-json\/wp\/v2\/categories?post=1792"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mbithiguide.com\/wp-json\/wp\/v2\/tags?post=1792"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}