{"id":2017,"date":"2018-02-22T13:44:09","date_gmt":"2018-02-22T08:14:09","guid":{"rendered":"http:\/\/stepbystepschools.net\/?p=2017"},"modified":"2018-02-22T13:52:51","modified_gmt":"2018-02-22T08:22:51","slug":"data-science-training-in-mumbai-chi-squared-test","status":"publish","type":"post","link":"https:\/\/www.stepbystepschools.net\/?p=2017","title":{"rendered":"Data Science Training in Mumbai :- Chi-squared Test."},"content":{"rendered":"<p>A Chi-squared test which can also be written as <b>&#967;2<\/b> test can be any statistical hypothesis test where the sampling distribution of the test statistic is a chi-squared distribution where the null-hypothesis is true.<\/p>\n<p>Chi-squared test also known as Pearson\u2019s chi-squared test.<\/p>\n<p>Chi-squared test is commonly used to determine whether there is great difference between observed frequencies and expected frequencies in one or more categories that we need to judge<\/p>\n<p>This is the formula for Chi-square statistics in chi-square test:<\/p>\n<p><a href=\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2018\/02\/1.png\" rel=\"attachment wp-att-2018\"><img loading=\"lazy\" src=\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2018\/02\/1.png\" alt=\"1\" width=\"507\" height=\"196\" class=\"aligncenter size-full wp-image-2018\" srcset=\"https:\/\/www.stepbystepschools.net\/wp-content\/uploads\/2018\/02\/1.png 507w, https:\/\/www.stepbystepschools.net\/wp-content\/uploads\/2018\/02\/1-300x116.png 300w\" sizes=\"(max-width: 507px) 100vw, 507px\" \/><\/a><\/p>\n<p>A lower value for Chi-square test means a higher the accuracy of the predicted data.<\/p>\n<p>So if Observed and expected values were equal to each other hence chi-square would be zero.<\/p>\n<p>This event that is unlikely to happen in real life.<\/p>\n<p><a href=\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2018\/02\/2.png\" rel=\"attachment wp-att-2019\"><img loading=\"lazy\" src=\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2018\/02\/2.png\" alt=\"2\" width=\"643\" height=\"108\" class=\"aligncenter size-full wp-image-2019\" srcset=\"https:\/\/www.stepbystepschools.net\/wp-content\/uploads\/2018\/02\/2.png 643w, https:\/\/www.stepbystepschools.net\/wp-content\/uploads\/2018\/02\/2-300x50.png 300w\" sizes=\"(max-width: 643px) 100vw, 643px\" \/><\/a><\/p>\n<h2>What is the Use of Chi-Squared Test?<\/h2>\n<p><a href=\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2018\/02\/3.png\" rel=\"attachment wp-att-2020\"><img loading=\"lazy\" src=\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2018\/02\/3.png\" alt=\"3\" width=\"612\" height=\"467\" class=\"aligncenter size-full wp-image-2020\" srcset=\"https:\/\/www.stepbystepschools.net\/wp-content\/uploads\/2018\/02\/3.png 612w, https:\/\/www.stepbystepschools.net\/wp-content\/uploads\/2018\/02\/3-300x229.png 300w\" sizes=\"(max-width: 612px) 100vw, 612px\" \/><\/a><\/p>\n<p>Chi-squared test is used to test goodness of fit and used to decide whether there is any difference between the observed (experimental) value and the expected (theoretical) value.<\/p>\n<p>The Value of Chi-square test should typically be lower than 0.05 of it to be acceptable as a test for data analysis and later on representation in a more visual basis.<\/p>\n<p>In the following demonstration we will use R programming to perform this test<\/p>\n<p><b>Initial Environment Setup<\/b><\/p>\n<p>But before we get into creating a program let\u2019s just first set up a proper environment for R programming.<\/p>\n<p>To install R programming tool go to the following link and download the software and install it.<\/p>\n<p>For Windows Users:<\/p>\n<p><a target=\"_blank\" href=\" https:\/\/ftp.iitm.ac.in\/cran\/\"> https:\/\/ftp.iitm.ac.in\/cran\/<\/a><\/p>\n<p><a href=\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2018\/02\/4.png\" rel=\"attachment wp-att-2021\"><img loading=\"lazy\" src=\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2018\/02\/4.png\" alt=\"4\" width=\"602\" height=\"118\" class=\"aligncenter size-full wp-image-2021\" srcset=\"https:\/\/www.stepbystepschools.net\/wp-content\/uploads\/2018\/02\/4.png 602w, https:\/\/www.stepbystepschools.net\/wp-content\/uploads\/2018\/02\/4-300x59.png 300w\" sizes=\"(max-width: 602px) 100vw, 602px\" \/><\/a><\/p>\n<p> And Type and Run the following code RGui<br \/>\n<span style=\"background-color: #C0C0C0\">install.packages(&#8220;ggplot2&#8221;)<\/span><\/p>\n<p>For Linux Users:<\/p>\n<p>If you are on Linux platform then you can use this fast and easy command used in Linux which can be used to install R. The yum command is used for installing like this:<br \/>\n<span style=\"background-color: #C0C0C0\">$ yum install R<\/span><\/p>\n<p>For Ubuntu Linux or other Debian-related OSs, a more direct method is:<br \/>\n<span style=\"background-color: #C0C0C0\">$ apt-get install r-base<\/span><\/p>\n<p>The function that is used to perform Chi-Squared Test is <b>chisq.test ()<\/b><\/p>\n<p>It can be expressed as <span style=\"background-color: #C0C0C0\">chisq.test (data)<\/span> where data is the object which contains the dataframe which is in the form of a table containing the count value of the variables in the observation.<\/p>\n<p>Now in the demo below let us first import the library called as \u201cMass\u201d which contains data for different models of car in the year 1993.<br \/>\n<span style=\"background-color: #C0C0C0\">library(&#8220;MASS&#8221;)<\/span><\/p>\n<p>We can observe the data from the <span style=\"background-color: #C0C0C0\">Car93<\/span> in <span style=\"background-color: #C0C0C0\">Mass<\/span> Library using the following command<br \/> <span style=\"background-color: #C0C0C0\">print(str(Cars93))<\/span><\/p>\n<p>The Output generated should look something like this.<\/p>\n<p><a href=\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2018\/02\/5.png\" rel=\"attachment wp-att-2022\"><img loading=\"lazy\" src=\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2018\/02\/5.png\" alt=\"5\" width=\"602\" height=\"441\" class=\"aligncenter size-full wp-image-2022\" srcset=\"https:\/\/www.stepbystepschools.net\/wp-content\/uploads\/2018\/02\/5.png 602w, https:\/\/www.stepbystepschools.net\/wp-content\/uploads\/2018\/02\/5-300x220.png 300w\" sizes=\"(max-width: 602px) 100vw, 602px\" \/><\/a><\/p>\n<p>In the above result we see that the dataset has many Factor variables which can be considered as categorical variables.<\/p>\n<p>In this model let us consider the variables &#8220;AirBags&#8221; and &#8220;Type&#8221;. <\/p>\n<p>Through this test we aim to find out any significant correlation between the types of car sold and the type of Air bags it is fitted with.<\/p>\n<p>With this correlation we can observe and estimate which types of cars can sell better with what types of air bags.<\/p>\n<p><span style=\"background-color: #C0C0C0\"># Load the library.<br \/>\n<\/span><span style=\"background-color: #C0C0C0\">library(&#8220;MASS&#8221;)<\/span>\n<\/p>\n<p><span style=\"background-color: #C0C0C0\"># Create a data frame from the main data set.<br \/>\n<\/span><span style=\"background-color: #C0C0C0\">car.data <- data.frame(Cars93$AirBags, Cars93$Type)<\/span>\n<\/p>\n<p><span style=\"background-color: #C0C0C0\"># Create a table with the needed variables.<br \/>\n<\/span><span style=\"background-color: #C0C0C0\">car.data = table(Cars93$AirBags, Cars93$Type)<br \/>\n<\/span><span style=\"background-color: #C0C0C0\">print(car.data)<\/span><\/p>\n<p><span style=\"background-color: #C0C0C0\"># Perform the Chi-Square test.<br \/>\n<\/span><span style=\"background-color: #C0C0C0\">print(chisq.test(car.data))<br \/>\n<\/span>\n<\/p>\n<p>On execution of this code in RGui software that is installed in our Computer we should receive the following Output:<\/p>\n<p><a href=\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2018\/02\/6.png\" rel=\"attachment wp-att-2023\"><img loading=\"lazy\" src=\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2018\/02\/6.png\" alt=\"6\" width=\"602\" height=\"276\" class=\"aligncenter size-full wp-image-2023\" srcset=\"https:\/\/www.stepbystepschools.net\/wp-content\/uploads\/2018\/02\/6.png 602w, https:\/\/www.stepbystepschools.net\/wp-content\/uploads\/2018\/02\/6-300x138.png 300w\" sizes=\"(max-width: 602px) 100vw, 602px\" \/><\/a><\/p>\n<p>If result shows the p-value to have value less than 0.05 then this indicates a significant correlation.<\/p>\n<p><a target=\"_blank\" href=\"http:\/\/stepbystepschools.net\/?page_id=1842\">Syllabus of Data Science training in Mumbai<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A Chi-squared test which can also be written as &#967;2 test can be any statistical hypothesis test where the sampling distribution of the test statistic is a chi-squared distribution where the null-hypothesis is true. Chi-squared test also known as Pearson\u2019s &hellip; <a href=\"https:\/\/www.stepbystepschools.net\/?p=2017\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":40,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[1],"tags":[207,205,198,199],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v18.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Data Science Training in Mumbai :- Chi-squared Test. - Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.stepbystepschools.net\/?p=2017\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Data Science Training in Mumbai :- Chi-squared Test. - Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai\" \/>\n<meta property=\"og:description\" content=\"A Chi-squared test which can also be written as &#967;2 test can be any statistical hypothesis test where the sampling distribution of the test statistic is a chi-squared distribution where the null-hypothesis is true. Chi-squared test also known as Pearson\u2019s &hellip; Continue reading &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.stepbystepschools.net\/?p=2017\" \/>\n<meta property=\"og:site_name\" content=\"Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai\" \/>\n<meta property=\"article:published_time\" content=\"2018-02-22T08:14:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-02-22T08:22:51+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2018\/02\/1.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"StepByStepSchoolsSupport\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.stepbystepschools.net\/#website\",\"url\":\"https:\/\/www.stepbystepschools.net\/\",\"name\":\"Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai\",\"description\":\"MVC 5\/Core, AngularJS 1.x, 2.0, 4.0, Design Pattern, Architecture, SSIS, SSAS, SSRS, Data Science, Big data, Hadoop classroom training\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.stepbystepschools.net\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.stepbystepschools.net\/?p=2017#primaryimage\",\"url\":\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2018\/02\/1.png\",\"contentUrl\":\"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2018\/02\/1.png\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.stepbystepschools.net\/?p=2017#webpage\",\"url\":\"https:\/\/www.stepbystepschools.net\/?p=2017\",\"name\":\"Data Science Training in Mumbai :- Chi-squared Test. - Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai\",\"isPartOf\":{\"@id\":\"https:\/\/www.stepbystepschools.net\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.stepbystepschools.net\/?p=2017#primaryimage\"},\"datePublished\":\"2018-02-22T08:14:09+00:00\",\"dateModified\":\"2018-02-22T08:22:51+00:00\",\"author\":{\"@id\":\"https:\/\/www.stepbystepschools.net\/#\/schema\/person\/7131e4ee1c5673879e6029d14ec2f655\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.stepbystepschools.net\/?p=2017#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.stepbystepschools.net\/?p=2017\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.stepbystepschools.net\/?p=2017#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.stepbystepschools.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Data Science Training in Mumbai :- Chi-squared Test.\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.stepbystepschools.net\/#\/schema\/person\/7131e4ee1c5673879e6029d14ec2f655\",\"name\":\"StepByStepSchoolsSupport\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.stepbystepschools.net\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cecaf2a0ee369391127b0159c266979d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cecaf2a0ee369391127b0159c266979d?s=96&d=mm&r=g\",\"caption\":\"StepByStepSchoolsSupport\"},\"url\":\"https:\/\/www.stepbystepschools.net\/?author=40\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Data Science Training in Mumbai :- Chi-squared Test. - Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.stepbystepschools.net\/?p=2017","og_locale":"en_US","og_type":"article","og_title":"Data Science Training in Mumbai :- Chi-squared Test. - Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai","og_description":"A Chi-squared test which can also be written as &#967;2 test can be any statistical hypothesis test where the sampling distribution of the test statistic is a chi-squared distribution where the null-hypothesis is true. Chi-squared test also known as Pearson\u2019s &hellip; Continue reading &rarr;","og_url":"https:\/\/www.stepbystepschools.net\/?p=2017","og_site_name":"Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai","article_published_time":"2018-02-22T08:14:09+00:00","article_modified_time":"2018-02-22T08:22:51+00:00","og_image":[{"url":"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2018\/02\/1.png"}],"twitter_card":"summary_large_image","twitter_misc":{"Written by":"StepByStepSchoolsSupport","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/www.stepbystepschools.net\/#website","url":"https:\/\/www.stepbystepschools.net\/","name":"Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai","description":"MVC 5\/Core, AngularJS 1.x, 2.0, 4.0, Design Pattern, Architecture, SSIS, SSAS, SSRS, Data Science, Big data, Hadoop classroom training","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.stepbystepschools.net\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.stepbystepschools.net\/?p=2017#primaryimage","url":"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2018\/02\/1.png","contentUrl":"http:\/\/stepbystepschools.net\/wp-content\/uploads\/2018\/02\/1.png"},{"@type":"WebPage","@id":"https:\/\/www.stepbystepschools.net\/?p=2017#webpage","url":"https:\/\/www.stepbystepschools.net\/?p=2017","name":"Data Science Training in Mumbai :- Chi-squared Test. - Learn MVC, Angular, Architecture, MSBI, Data Science in Mumbai","isPartOf":{"@id":"https:\/\/www.stepbystepschools.net\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.stepbystepschools.net\/?p=2017#primaryimage"},"datePublished":"2018-02-22T08:14:09+00:00","dateModified":"2018-02-22T08:22:51+00:00","author":{"@id":"https:\/\/www.stepbystepschools.net\/#\/schema\/person\/7131e4ee1c5673879e6029d14ec2f655"},"breadcrumb":{"@id":"https:\/\/www.stepbystepschools.net\/?p=2017#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.stepbystepschools.net\/?p=2017"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.stepbystepschools.net\/?p=2017#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.stepbystepschools.net\/"},{"@type":"ListItem","position":2,"name":"Data Science Training in Mumbai :- Chi-squared Test."}]},{"@type":"Person","@id":"https:\/\/www.stepbystepschools.net\/#\/schema\/person\/7131e4ee1c5673879e6029d14ec2f655","name":"StepByStepSchoolsSupport","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.stepbystepschools.net\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cecaf2a0ee369391127b0159c266979d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cecaf2a0ee369391127b0159c266979d?s=96&d=mm&r=g","caption":"StepByStepSchoolsSupport"},"url":"https:\/\/www.stepbystepschools.net\/?author=40"}]}},"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"_links":{"self":[{"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=\/wp\/v2\/posts\/2017"}],"collection":[{"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=\/wp\/v2\/users\/40"}],"replies":[{"embeddable":true,"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2017"}],"version-history":[{"count":2,"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=\/wp\/v2\/posts\/2017\/revisions"}],"predecessor-version":[{"id":2025,"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=\/wp\/v2\/posts\/2017\/revisions\/2025"}],"wp:attachment":[{"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2017"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2017"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.stepbystepschools.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2017"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}