{"id":38197,"date":"2022-03-04T13:09:06","date_gmt":"2022-03-04T13:09:06","guid":{"rendered":"https:\/\/assignmenttutors.net\/blog\/exploring-data-using-graphics-and-visualization\/"},"modified":"2022-03-04T13:09:06","modified_gmt":"2022-03-04T13:09:06","slug":"exploring-data-using-graphics-and-visualization","status":"publish","type":"post","link":"https:\/\/assignmenttutors.net\/blog\/exploring-data-using-graphics-and-visualization\/","title":{"rendered":"Exploring data using graphics and visualization"},"content":{"rendered":"<div>\n<p>\u00a0<\/p>\n<p>In this you will be using the <em>churn<\/em> data:\u00a0 <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/myleoonline.tamuc.edu\/d2l\/common\/dialogs\/quickLink\/quickLink.d2l?ou=33580&amp;type=coursefile&amp;fileId=data%2fchurn_data.txt\">churn_data.txt<\/a><\/p>\n<p>Read data into a data frame using the function read.csv() with the following options:<\/p>\n<p>header=T, stringsAsFactors=F<\/p>\n<p>Assume that you saved the file churn_data.txt in C:\/Datasets folder. Then you can read file into a data frame as follows:<\/p>\n<p>file=&#8221;C:\/Datasets\/churn_data.txt&#8221;<br \/>churnData=read.csv(file, stringsAsFactors = FALSE,header = TRUE)<\/p>\n<p>A) Print the name of the columns.<\/p>\n<p>Hint: colnames() function.<\/p>\n<p>B) Print the number of rows and columns<\/p>\n<p>Hint: dim()<\/p>\n<p>C)\u00a0\u00a0Count the number calls per state.<\/p>\n<p>Hint: table() function.<\/p>\n<p>D) Find mean, median,standard deviation, and variance of nightly charges, the column Night.Charge in the data.<br \/>The R functions to be used are mean(), median(), sd(), var().<\/p>\n<p>E) Find maximum and minimum values of international charges (Intl.Charge), customer service calls (CustServ.Calls), and daily charges(Day.Charge).<\/p>\n<p>F) Use summary() function to print information about the distribution of the following features:<\/p>\n<pre><code>\"Eve.Charge\" \u00a0\u00a0\u00a0\u00a0\"Night.Mins\" \u00a0\u00a0\u00a0\u00a0\"Night.Calls\" \u00a0\u00a0\u00a0\"Night.Charge\" \u00a0\u00a0\"Intl.Mins\" \u00a0\u00a0\u00a0\u00a0\u00a0\"Intl.Calls\"<\/code><\/pre>\n<p>What are the min and max values printed by the summary() function for these features?<\/p>\n<p>Check textbook page 34 for a sample.<\/p>\n<p>G)\u00a0Use\u00a0unique() function to print the distinct values of the following columns:<\/p>\n<p>State, Area.Code, and Churn.<\/p>\n<p>H)\u00a0\u00a0Extract the subset of\u00a0 data for the churned customers(i.e., Churn=True). How many rows are in the subset?<br \/>Hint: Use subset() function. Check lecture notes and textbook for samples.<\/p>\n<p>I)\u00a0\u00a0Extract the subset of data for customers that made more than 3 customer service calls(CustServ.Calls). How many rows are in the subset?<\/p>\n<p>J) Extract the subset of churned customers with no international plan (Int.l,Plan) and no voice mail plan (VMail.Plan). How many rows are in the subset?<\/p>\n<p>K) Extract the data for customers from California (i.e., State is CA)\u00a0 who did not churn but made more than 2 customer service calls.<\/p>\n<p>L) What is the mean of customer service calls for the customers that did not churn (i.e., Churn=False)?<\/p>\n<p><strong>question2 related to above\u00a0<\/strong><\/p>\n<p>\u00a0<\/p>\n<p>In this ,we will explore the <em>churn<\/em> data using graphics and visualization. One of the primary reasons for performing <em>exploratory data analysis<\/em> (EDA) is to investigate the variables, examine the distributions of the categorical variables, look at the histograms of the numeric variables, and explore the relationships among sets of variables.<\/p>\n<p>Although we are not going to develop any models for this project, in a real-world project our task is to identify patterns in the data that will help to reduce the proportion of churners.<\/p>\n<p>We will use the same data set we had in Week 2 assignment:<\/p>\n<p>Data file: <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/myleoonline.tamuc.edu\/d2l\/common\/dialogs\/quickLink\/quickLink.d2l?ou=33580&amp;type=coursefile&amp;fileId=data%2fchurn_data.txt\">churn_data.txt<\/a><\/p>\n<p>All graphics in this assignment have to be plotted using ggplot2 library. So, you need to install ggplot2 library for graphs:<\/p>\n<p>install.packages(&#8220;ggplot2&#8221;)<\/p>\n<p>Before using any methods from the libraries, you need to load these libraries into the R code using<\/p>\n<p>library(ggplot2)<\/p>\n<p>Here is how you can read data into a data frame named churnData:<\/p>\n<p>churnData &lt;- read.csv(filePath, stringsAsFactors = FALSE,header = TRUE)<\/p>\n<p>where filePath is the location of the churn_data.txt file. For example, if you saved file in C:\/tmp, then you should use C:\/tmp\/churn_data.txt<\/p>\n<p>The variables in the file churn_data.txt are<\/p>\n<p><em><strong>State<\/strong><\/em>: Categorical, for the 50 states and the District of Columbia.<br \/><em><strong>Account length<\/strong><\/em>: Integer-valued, how long account has been active.<br \/><em><strong>Area code<\/strong><\/em>: Categorical<br \/><em><strong>Phone number<\/strong><\/em>: Essentially a surrogate for customer ID.<br \/><em><strong>International plan<\/strong><\/em>: Dichotomous categorical, yes or no.<br \/><em><strong>Voice mail plan<\/strong><\/em>: Dichotomous categorical, yes or no.<br \/><em><strong>Number of voice mail messages<\/strong><\/em>: Integer-valued.<br \/><em><strong>Total day minutes<\/strong><\/em>: Continuous, minutes customer used service during the day.<br \/><em><strong>Total day calls<\/strong><\/em>: Integer-valued.<br \/><em><strong>Total day charge<\/strong><\/em>: Continuous, perhaps based on above two variables.<br \/><em><strong>Total eve minutes<\/strong><\/em>: Continuous, minutes customer used service during the evening.<br \/><em><strong>Total eve calls<\/strong><\/em>: Integer-valued.<br \/><em><strong>Total eve charge<\/strong><\/em>: Continuous, perhaps based on above two variables.<br \/><em><strong>Total night minutes<\/strong><\/em>: Continuous, minutes customer used service during the night.<br \/><em><strong>Total night calls<\/strong><\/em>: Integer-valued.<br \/><em><strong>Total night charge<\/strong><\/em>: Continuous, perhaps based on above two variables.<br \/><em><strong>Total international minutes<\/strong><\/em>: Continuous, minutes customer used service to make<br \/>international calls.<br \/><em><strong>Total international calls<\/strong><\/em>: Integer-valued.<br \/><em><strong>Total international charge<\/strong><\/em>: Continuous, perhaps based on above two variables.<br \/><em><strong>Number of calls to customer service<\/strong><\/em>: Integer-valued.<br \/><em><strong>Churn<\/strong><\/em>: Target. Indicator of whether the customer has left the company (true or false).<\/p>\n<p><strong>Part 1. Bar Charts<\/strong><\/p>\n<p>A <em>bar chart<\/em> is a histogram for discrete data: it records the frequency of every value of a categorical variable.<\/p>\n<p>1.) <strong>Vertical Bar Charts<\/strong><\/p>\n<p>Plot the bar charts of State, Area.Code, Int.l.Plan, VMail.Plan, CustServ.Calls, and Churn.<\/p>\n<p>Use the theme() function to change the text size, location, color, etc.. (An example is given in the textbook on page 61)<\/p>\n<p>The following is the bar chart for State. As an example, the x-axis labels are bold, and rotated 90 degrees which can be set in the theme() function using\u00a0<\/p>\n<p>axis.text.x = element_text(face=&#8221;bold&#8221;,angle=90,vjust=0.5, size=11).<\/p>\n<p>Similarly, the parameter colour=&#8221;#990000&#8243; is used for the color of the x-axis title. So, the following options for axis.title.x and axis.text.x\u00a0 in theme() function display the title and text of x-axis as shown in the figure below:<\/p>\n<p>axis.title.x = element_text(face=&#8221;bold&#8221;, colour=&#8221;#990000&#8243;, size=12), axis.text.x = element_text(face=&#8221;bold&#8221;,angle=90,vjust=0.5, size=11)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"stat_barchart\" src=\"https:\/\/myleoonline.tamuc.edu\/content\/enforced\/33580-201980CSCI-556-01W\/images\/week3\/fall2019\/fall2019_state_barchart.GIF?_&amp;d2lSessionVal=lRXH9QHk7fkksG6VMpAoamLsA\" width=\"788\" height=\"592\"\/><\/p>\n<p>2.) <strong>Horizontal Bar Charts<\/strong><\/p>\n<p>Create the horizontal bar chart of CustServ.Calls.<\/p>\n<p>Hint: Textbook page 49.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"fall2019_int_call_horiz_bar\" src=\"https:\/\/myleoonline.tamuc.edu\/content\/enforced\/33580-201980CSCI-556-01W\/images\/week3\/fall2019\/fall2019_int_call_horiz_bar.GIF?_&amp;d2lSessionVal=lRXH9QHk7fkksG6VMpAoamLsA\" width=\"634\" height=\"529\"\/><\/p>\n<p>3.) <strong>Horizontal Bar Charts with Sorted Categories<\/strong><\/p>\n<p>Create horizontal bar chart where the number of calls are sorted for CustServ.Calls.<\/p>\n<p>Hint: Textbook pages 50-51<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"fall2019_int_call_sorted_horiz_bar\" src=\"https:\/\/myleoonline.tamuc.edu\/content\/enforced\/33580-201980CSCI-556-01W\/images\/week3\/fall2019\/fall2019_int_call_sorted_horiz_bar.GIF?_&amp;d2lSessionVal=lRXH9QHk7fkksG6VMpAoamLsA\" width=\"633\" height=\"524\"\/><\/p>\n<p><strong>Part 2: Histograms and Density Plots<\/strong><\/p>\n<p>The histogram and the density plot are two visualizations that help you quickly examine the distribution of a numerical variable.<\/p>\n<p>A basic histogram bins a variable into fixed-width buckets and returns the number of data points that falls into each bucket. You can think of a <em>density plot<\/em> as a \u201ccontinuous histogram\u201d of a variable, except the area under the density plot is equal to 1.<\/p>\n<p>1.) Plot the histograms of Account.Length, VMail.Message, Day.Mins, Intl.Calls, and VMail.Message.<\/p>\n<p>Based on the histograms, comment on whether any of them have outliers, close to the Normal Distribution, multi-modal, or skewed.<\/p>\n<p>The histogram for Account.Length is shown below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"acc_length_bar\" src=\"https:\/\/myleoonline.tamuc.edu\/content\/enforced\/33580-201980CSCI-556-01W\/images\/week3\/fall2019\/fall2019_acc_length_bar.GIF?_&amp;d2lSessionVal=lRXH9QHk7fkksG6VMpAoamLsA\" width=\"485\" height=\"455\"\/><\/p>\n<p>2.) Plot the density plots of Account.Length, VMail.Message, Day.Mins, Intl.Calls, and VMail.Message.<\/p>\n<p>Based on the density plots, comment on whether any of them have outliers, close to the Normal Distribution, multi-modal, or skewed.<\/p>\n<p>As a sample, the density plot for VMail.Message is shown below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"density_plot1\" src=\"https:\/\/myleoonline.tamuc.edu\/content\/enforced\/33580-201980CSCI-556-01W\/images\/week3\/fall2019\/fall2019_density_plot1.GIF?_&amp;d2lSessionVal=lRXH9QHk7fkksG6VMpAoamLsA\" width=\"520\" height=\"340\"\/><\/p>\n<p><strong>Part 3. Scatter Plots<\/strong><\/p>\n<p>In addition to examining variables in isolation, you\u2019ll often want to look at the relationship between two variables.<\/p>\n<p><strong>Part A)<\/strong><\/p>\n<p>Plot the scatter plots for pairs Eve.Mins &#8211; Day.Mins, Day.Mins-Day.Charge, Eve.Mins-Eve.Charge, Day.Mins-Day.Calls.<\/p>\n<p>Based on the plots, are there any relationships between the pair of features plotted?<\/p>\n<p>The scatter plot of Eve.Mins vs Day.Mins is given below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"scatter_plot2\" src=\"https:\/\/myleoonline.tamuc.edu\/content\/enforced\/33580-201980CSCI-556-01W\/images\/week3\/fall2019\/fall2019_scatter_plot2.GIF?_&amp;d2lSessionVal=lRXH9QHk7fkksG6VMpAoamLsA\" width=\"465\" height=\"341\"\/><\/p>\n<p><strong>Part B)<\/strong><\/p>\n<p>For the scatter plots in part A, add color\u00a0 to display churn and no-churn data points. Simply add\u00a0 aes(color=Churn) to the geom_point() function as shown below:<\/p>\n<p>geom_point(aes(color=Churn))<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"scatter_plot1\" src=\"https:\/\/myleoonline.tamuc.edu\/content\/enforced\/33580-201980CSCI-556-01W\/images\/week3\/fall2019\/fall2019_scatter_plot1.GIF?_&amp;d2lSessionVal=lRXH9QHk7fkksG6VMpAoamLsA\" width=\"514\" height=\"344\"\/><\/p>\n<p><strong>Part 4. Box Plots<\/strong><\/p>\n<p>A <em>box-and-whiskers<\/em> plot describes the distribution of a continuous variable by\u00a0 plotting its five-number summary: the minimum, lower quartile (25th\u00a0 percentile), median (50th percentile), upper quartile (75th percentile), and maximum.<\/p>\n<p>Plot the box plots of CustServ.Calls, Night.Calls, and Intl.Charge by Churn.<\/p>\n<p>Which of the features have outliers? (can you spot them in the box plot?)<\/p>\n<p>What is the median of Night.Calls for customers that did not churn? (from the box plot)<\/p>\n<p>The following is the box plot of CustServ.Calls.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"box_plot2\" src=\"https:\/\/myleoonline.tamuc.edu\/content\/enforced\/33580-201980CSCI-556-01W\/images\/week3\/fall2019\/fall2019_box_plot2.GIF?_&amp;d2lSessionVal=lRXH9QHk7fkksG6VMpAoamLsA\" width=\"465\" height=\"339\"\/><\/p>\n<p><strong>Hint<\/strong>:You can find detailed information and samples of box plot at\u00a0<\/p>\n<p><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/ggplot2.tidyverse.org\/reference\/geom_boxplot.html\">https:\/\/ggplot2.tidyverse.org\/reference\/geom_boxplot.html<\/a><\/p>\n<p><strong>Part 5. Dodged and Stacked Bar Charts<\/strong><\/p>\n<p>A) Display a dodged bar chart of <em>Int.l.Plan<\/em> by <em>Churn<\/em>.<\/p>\n<p>Hint: Textbook pages 60-61.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"dodge_chart1\" src=\"https:\/\/myleoonline.tamuc.edu\/content\/enforced\/33580-201980CSCI-556-01W\/images\/week3\/fall2019\/fall2019_dodge_chart1.GIF?_&amp;d2lSessionVal=lRXH9QHk7fkksG6VMpAoamLsA\" width=\"461\" height=\"342\"\/><\/p>\n<p>B) Display a stacked bar chart of <em>CustServ.Calls<\/em> <em>and<\/em> <em>Churn<\/em>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"stack_chart1\" src=\"https:\/\/myleoonline.tamuc.edu\/content\/enforced\/33580-201980CSCI-556-01W\/images\/week3\/fall2019\/fall2019_stack_chart1.GIF?_&amp;d2lSessionVal=lRXH9QHk7fkksG6VMpAoamLsA\" width=\"461\" height=\"337\"\/><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 In this you will be using the churn data:\u00a0 churn_data.txt Read data into a data frame using the function read.csv() with the following options: header=T, stringsAsFactors=F Assume that you saved the file churn_data.txt in C:\/Datasets folder. Then you can read file into a data frame as follows: file=&#8221;C:\/Datasets\/churn_data.txt&#8221;churnData=read.csv(file, stringsAsFactors = FALSE,header = TRUE) A) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-38197","post","type-post","status-publish","format-standard","hentry","category-education"],"_links":{"self":[{"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/posts\/38197","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/comments?post=38197"}],"version-history":[{"count":0,"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/posts\/38197\/revisions"}],"wp:attachment":[{"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/media?parent=38197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/categories?post=38197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/tags?post=38197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}