Docsity

Appunti Statistical Data Analysis - ESIR, Appunti di Statistica

Toggle sidebar
bg1
Camilla Sala – Statistical Data Analysis
1
STATISTICAL DATA ANALYSIS – Silvia Facchinetti
TEXTBOOK→ Newbold, Carlson, Thorne - Statistics for business and economics → Ch. 1, 2, 11, 12
11/09/2020
INTRODUCTION TO EXCEL
Microsoft Excel → a spreadsheet program used to record, analyse and store numerical data. A
worksheet is a collection of columns and rows that form a table.
• Alphabetical letters → for columns
• Numbers → for rows
• Cell → a point where a column and a row meet → each cell has its own letter and number
that correspond to the column and row
• Workbook → a collection of worksheets
You can enter 3 types of data into the cells
• Labels → text, descriptive information, usually include alphabetical characters → ex. “bye”
• Values→ generally row numbers / data → ex. “234”
• Formulas → equations that can perform calculations, return info, manipulate the content of
other cells, etc… →
HOW TO CREATE A FORMULA → select a cell → a formula always starts with an = sign
• ex. “= 1 + 2 enter” → it will appear the result, which is 3
• ex. “=6/3 enter” → it will appear the result, that is 2
In these simple examples the values are fixed, this means the results won’t change if you don’t edit
the formula again and change the value manually → this is considered a bad form because it makes
harder to maintain a spreadsheet → instead we can use CELL REFERENCE → in this way values can
be changed at any time
HOW TO USE A CELL REFERENCE → ex. write the numbers 1, 3, 5 in the same column starting from
the cell F3→ in G3 write “= F3 + F4 + F5 enter” → the result is 9 → Note that:
• If you double click on the cell, you’ll obtain the formula inserted
• The references are color-coded
• If you change a number in a cell, the result will change automatically
The words FORMULA and FUNCTION are closely related, but they’re not the same
• Formula→ an expression that begins with an equal sign
• Function → a formula with a specific name and purpose → in most cases functions are
named to reflect their use
HOW TO USE A FUNCTION → select a cell
• If you know the name of the function write → ex. “=SUM”, then select the cells F3, F4, F5 →
the results will be the sum of the numbers written in these cells, that is 9
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33

Anteprima parziale del testo

Scarica Appunti Statistical Data Analysis - ESIR e più Appunti in PDF di Statistica solo su Docsity!

STATISTICAL DATA ANALYSIS – Silvia Facchinetti

TEXTBOOK→ Newbold, Carlson, Thorne - Statistics for business and economics → Ch. 1, 2, 11, 12 11/09/ INTRODUCTION TO EXCEL Microsoft Excel → a spreadsheet program used to record, analyse and store numerical data. A worksheet is a collection of columns and rows that form a table.

  • Alphabetical letters → for columns
  • Numbers → for rows
  • Cell → a point where a column and a row meet → each cell has its own letter and number that correspond to the column and row
  • Workbook → a collection of worksheets You can enter 3 types of data into the cells
  • Labels → text, descriptive information, usually include alphabetical characters → ex. “bye”
  • Values→ generally row numbers / data → ex. “234”
  • Formulas → equations that can perform calculations, return info, manipulate the content of other cells, etc… → HOW TO CREATE A FORMULA → select a cell → a formula always starts with an = sign
  • ex. “= 1 + 2 enter” → it will appear the result, which is 3
  • ex. “=6/3 enter” → it will appear the result, that is 2 In these simple examples the values are fixed, this means the results won’t change if you don’t edit the formula again and change the value manually → this is considered a bad form because it makes harder to maintain a spreadsheet → instead we can use CELL REFERENCE → in this way values can be changed at any time HOW TO USE A CELL REFERENCE → ex. write the numbers 1, 3, 5 in the same column starting from the cell F3→ in G3 write “= F3 + F4 + F5 enter” → the result is 9 → Note that:
  • If you double click on the cell, you’ll obtain the formula inserted
  • The references are color-coded
  • If you change a number in a cell, the result will change automatically The words FORMULA and FUNCTION are closely related, but they’re not the same
  • Formula→ an expression that begins with an equal sign
  • Function → a formula with a specific name and purpose → in most cases functions are named to reflect their use HOW TO USE A FUNCTION → select a cell
  • If you know the name of the function write → ex. “=SUM”, then select the cells F3, F4, F5 → the results will be the sum of the numbers written in these cells, that is 9
  • If you don’t know the name of the function → go to Formulas → Insert Function → select the category All → select the desired function → select the desired cells CHART → is a visual representation of data
  • The graphical form of the chart makes it easy to understand large quantities of data and the relationship btw different series of data
  • The chart can also show a bigger picture, so that you can analyse your date and look for important trends HOW TO CREATE A CHART
  • Write the data in the cells
  • Select all the cells you want to insert
  • Go to Insert → select the arrow that says “See All Charts” → All Charts → select the type of chart desired → OK DATA ANALYSIS COMMAND Go to Data → Data Analysis Lecture 1 Outline of the course
  • Introduction to Statistics (chapter 1)
  • Graphs to describe data (chapter 1) o Categorical variables o Numerical variables o Time-series
  • Numerical measures to describe data (chapter 2) o Measures of location o Measures of dispersion
  • Measures of relationships between variables (chapter 2)
  • Regression analysis (chapters 11-12) Decision making in an uncertain environment
  • Who will win the next political elections?
  • What will the price of a stock be in six months from now based on company performance measures and other economic factors?
  • Is new grain seed or fertilizer more productive?
  • What is the right amount of dosage of drug to treatment?
  • What are the effects of atmospheric pollution on our health?
  • Does it typically rain more in the United States or in Brazil? To figure out the desired information and answer different questions, you need to analyse data STATISTICS → is the science of data → may be broadly described as the techniques to collect, clarify, summarize, analyse and interpret data. Statistics provides methods for
  • Planning and carrying out research studies
  • Summarizing and exploring data
  • Making predictions and generalizing about phenomena represented by the data

The variables are:

  • Customer ID: number that identify the bank client (numeric)
  • Marital: marital status (nominal) Single or married
  • Children: number of children (numeric)
  • Education: education level (ordinal) e.g. primary, secondary, etc…
  • Month: last contact month of year (ordinal) e.g. January, February, etc…
  • Age: age of the client (numeric) is a continuous variable
  • House: number of owned houses (numeric) is a discreet variable, the number of owned houses
  • Income: average yearly income, in euros (numeric) Graphical presentation of data
  • Data in raw form are usually not easy to use for decision making
  • Some type of organization is needed o Table o Graph
  • The type of graph to use depends on the variable being summarized FREQUENCY TABLES → UNIVARIATE VARIABLES The frequency distribution is a table used to organize data→ it contains all possible responses of the categorical variable and the number of observations or frequency fi% for each category. There are different types of frequencies: ABSOLUTE FREQUENCIES → number of observations for each modality → ni RELATIVE FREQUANCIES → are obtained by dividing each absolute frequency by the number of observations n → fi

PERCENT FREQUENCIES → are obtained by multiplying the relative frequency by 100 → fi%=ni/n × 100 CONTINGENCY TABLES → MULTIVARIATE VARIABLES

  • A cross table, or contingency table, lists the number of observations for every combination of values for two categorical variables
  • If there are r categories for the first variable (rows) and categories for the second variable (columns), the table is called an R X C CROSS TABLE Example: 3 x 3 Cross Table for marital status by education In this course we’ll use Excel to perform a descriptive analysis of a data set→ we have:
  • The bank data set
  • The frequency distribution
  • The contingency table PIVOT TABLE → used to extract frequency distribution from a data set:
  • Univariate distribution
  • Contingency table HOW TO CREATE A PIVOT TABLE
  • Click any single cell inside the data set
  • Go to Insert → Pivot Table → Excel already selects the data set → we need to choose where the Pivot table report will be placed→ the default place is New Worksheet →OK
  • The Pivot Table Fields appears on the right
  • To get the FREQUANCY TABLE for “Marital status”, drag the following fields to the different areas: o Marital field to the Rows area o Marital field to the Values area
  • Finally, the Pivot table is created FREQUENCY DISTRIBUTION
  • Discrete variable: distinct values and corresponding frequencies, similar to categorical variable
  • Continuous variable: intervals or class groupings (within which the data is included) and the corresponding frequencies → the classes are not easily identifiable

➔ now the grand total is wrong

  • Click any cell inside the Sum of income column
  • Right click → Value Field Settings
  • Choose Count → OK
  • Next, click one cell inside the column with Row labels
  • Right click → Group → it opens a new window called Grouping → change it or leave it as it is and then click OK ➔ Now the grand total is correct We obtained a table containing:
  • class groupings (categories or ranges within which the data fall)
  • the corresponding frequencies with which data fall within each class or category
  • the left boundary is included in the class → e.g. 2987 is included in the first class, 12986 is included too, but for e.g. the value 12986,7 is included in the first class, NOT in the 2nd^ one
  • to include all data the classes must be defined as: [2897, 12987); [12987, 22987),…, [52987,
  • Most clients of the bank have an income between these values [22987, 32987) CONTINGENCY TABLE → multivariate variable → describes the relationship btw two variables If you drag a field to the Rows area and Columns area, you can create a two-dimensional pivot table. To get the cross table for marital status by education, drag the following fields to the different areas:
  • marital field to the Rows area
  • education field to the Columns area
  • marital (or education) field to the Values area Below you can find the two-dimensional pivot table. Married/secondary is the main marital/education status of the bank clients. 18/09/

We want to represent the data with GRAPHS → It’s possible to use different graphs according to the type of variable considered

  • Categorical/qualitative variables: o Nominal → pie chart o Ordinal → bar graph
  • Numerical/quantitative variables: o Discrete → bar graph o Continuous → histogram
  • Time series → line chart HOW TO CREATE GRAPHS IN EXCEL → In Excel, you have plenty of choices for charts and graphs to create. This includes column/bar graphs, line graphs, pie graphs, scatter plot, etc... To make a graph, you must
  • Highlight/select the data without the totals
  • Insert → Charts section → click the arrow “See All Graphs”
  • All Charts → Click the icon corresponding to the desired graph and choose the graph you wish If you want to choose the style of your graph, you must
  • Click on the area of the graph
  • Design → select the design desired HOW TO OBTAIN RELATIVE/PERCENT FREQUENCIES IN EXCEL → there are two ways
  • With the Pivot Table → click on the pivot table → drag “Marital” to the Values field → you obtain the column Count of Marital → right click on a cell of this column → Show Value As → % of Grand Total → in this way you obtain the percent frequencies fi%
  • Another way is to calculate the relative frequencies with an excel formula o write = in the first cell of the fi column → then you select the correspondent absolute frequency ni → write / → select the total → enter o the sum of all the relative frequencies must be 1 → to sum them up select the data → select Σ from Home → Editing GRAPHS FOR NOMINAL QUALITATIVE VARIABLES → PIE CHART A pie chart is a circular chart used to compare parts of the whole. It is divided into sectors; the size of the sectors is proportional to the frequency of each category. We draw attention to the proportion of frequency of each category. The circle represents the total and the pieces of the pie cut from its centre represents the categories. GRAPHS FOR ORDINAL QUALITATIVE VARIABLES → BAR/COLUMN CHART A bar graph is composed of bars that represent different categories of data. The height of the bar represents the frequency for each category. The bars must be separated GRAPHING MULTIVARIATE CATEGORICAL/QUALITATIVE DATA
  • Above each interval a bar of the appropriate heights is used to represent the number of observations within each class
  • NB → No gaps between bars, otherwise you’ll get a column chart HOW TO CREATE AN HISTOGRAM IN EXCEL
  • Select the date without the totals
  • Insert → See All Charts → Clustered Column
  • Then in order to eliminate the gaps you must → right click on one bar of the graph → Format Data Series o Series Overlap → 100 o Gap width → 0
  • Now you have a histogram HOW TO CREATE HISTOGRAMS IN EXCEL WITH THE DATA ANALYSIS COMMAND → Histograms in Excel can be computed also by Data Analysis command. Once the add-in has been successfully installed you will see data analysis when you click on the Data tab.
  • Input data range → is the data we want to represent. With the chart tools we consider the frequency distribution, but with the data analysis tool we have to consider the original not grouped data
  • Bin range→ is a cell range containing the upper interval endpoints for each class Click on Data → Data Analysis → Histogram → it appears a table that has to be completed. In order to compete the table, you have to: First, create the bin range→ excel requires the UPPER/RIGHT CLASS ENDPOINTS → first write 12987 → 12987 is the upper endpoint of the first class (2987; 12987] NB → ]a, b] = (a, b] → Excel automatically counts the number of observations from the first observed value to 12987 → 22987 is the upper endpoint of the second class (12987; 22987] → Excel automatically counts the number of observations from the endpoint of the first class to 22987 → and so on… Then, select the whole column of the Income → Input Range Then, select the bin column that you created before → Bin Range
  • Select the field Labels
  • Output Range → select a random cell where the histogram will be placed
  • Select Chart Output → OK

QUESTIONS ABOUT GROUPING DATA INTO INTERVALS

How wide should each interval be? How many classes should be used? → The goal is to create a distribution that is neither too "jagged" nor too "blocky” to show the pattern of variation in the data SHAPE OF DISTRIBUTION It is possible to describe graphically the shape of the distribution using a histogram

  • Symmetric distribution → a distribution is symmetric if the observations are balanced around its centre. A symmetric distribution is a type of distribution where the left side of the distribution mirrors the right side.
  • Skewed right distribution, also called positively skewed distribution → most data falls to the right, or positive side, of the graph's peak. Thus, the histogram skews in such a way that its right side or tail is longer than its left side.
  • Skewed left distribution → has a long-left tail. Left-skewed distributions are also called negatively skewed distributions. That is because there is a long tail in the negative direction on the number line. Most data falls to the left, or negative side, of the graph's peak. GRAPHS FOR NUMERICAL VARIABLES → SCATTER DIAGRAMS Scatter Diagrams are used for paired observations taken from two numerical variables → one variable is measured on the vertical axis and the other variable is measured on the horizontal axis → The scatter plot provides a picture of the data that includes
  • The range of each variable
  • The pattern of the value of a range
  • Suggestion of possible relation between variables
  • Indication of outliers

Tables and graphs are not sufficient to describe statistical variables → we study numerical measures to describe data

  • Measures of location
  • Measures of dispersion → let’s start with measures of location, also called measures of central tendency MEASURES OF LOCATION / OF CENTRAL TENDENCY → usually are computed from sample data rather than population data Mode → most frequently observed value (if one exists) Median → midpoint of ranked values Mean → arithmetic value MODE → The mode is the most frequently occurring value
  • This is the only measure of location for categorical nominal variables, but it can be used also for quantitative variables
  • Used for either numerical or categorical data
  • There may be no mode
  • A distribution with one mode is called UNIMODAL
  • A distribution with two modes is called BIMODAL
  • A distribution with several/more than two modes is called MULTIMODAL
  • Not affected by extreme values, also called OUTLIERS → these are observations unusually small or big compared to the rest of the data FINDING THE MODE → the mode can be easily found using a table or a graph → in the following example the highest bar corresponds to “secondary” The Excel MODE function exists, but you can use it only for numeric values and not for categorical ones → this function returns the most frequently occurring number in a numeric data set → N.B. in order to compute the mode you cannot use the frequency tables → the input of MODE function is the column containing the original data EXCEL MODE FUNCTION SYNTAX → =MODE(C2:C4522) where C2:C4522 are cell references that contain “children” numeric values. You do not need to select the name of the column → The result is 2 FINDING THE MODE FOR QUANTITATIVE CONTINUOUS VARIABLES → e.g. income

For quantitative variables in classes, you can find the most frequent class with the frequency distribution → you don’t find the exact value of the mode → instead, you find the interval that contains the mode → usually, the central value of the mode class, is considered a good approximation of the mode Let’s consider the income example

The mode class/interval is 22987 |- 32987 → mode = (Linf + Lsup) / 2

→ mode = (22987 + 32987) / 2 = 27987 EXCEL MODE FUNCTION WITH A MODE CLASS SYNTAX → =MODE(H2:H4522) where H2:H4522 are cell references that contain “income” numeric values → you obtain the exact mode value is 28,027.00 € 18/09/ MEDIAN → is the middle observation when the data are ranked in increasing order → x(1), x(2),…, x(n) → 50% above, 50% below

  • Used for either numerical or ordinal data, but it cannot be used for nominal data
  • Not affected by extreme values → e.g. 0,1,2,3,4,10 → 10 is an outlier PERCENTILES → indicate the position of a value relative to the set of data ranked in increasing order → cannot be calculated for qualitative nominal variables (the only location index for this kind of variable is the mode) The Pth percentile is a value such that, approximately, P% of the observations are at, above or below that number → the percentiles separate data sets into 100 parts:
  • the 25th percentile is the first quartile: P% = 25% → FIRST QUARTILE → 25% of the observation are smaller than Q 1 and 75% of the observations are larger
  • the 50th percentile is the second quartile (median): P% = 50% → MEDIAN OR SECOND QUARTILE → 50% of the observation are smaller than Q 2 and 50% of the observations are larger
  • the 75th percentile is the third quartile: P = 75% → THIRD QUARTILE → 75% of the observation are smaller than Q 3 and 2 5% of the observations are larger

The hight of each step is equal to each percent/relative frequency → You cannot do a scatter plot with qualitative data, so in the education example you have to write a column with 1,2,3 that corresponds to primary, secondary, tertiary → then copy the Fi% next to the 1,2,3 column → select the two columns → Insert → See All Charts → X Y (Scatter) → OK Then, in order to insert the steps → Insert → Illustrations → Shapes → insert a line equal to zero before the first observation → then continue drawing horizontal lines following the points, until you reach the last point, here the line is equal to 1 HOW TO FIND QUARTILES WITH THE STEP GRAPH

  • If you want to find the median → draw a horizontal line in correspondence to 50% on the y axis → consider where this horizontal line meets the vertical lines (heights) of each step → in this case the line meets the projection of the 2 point, that is secondary
  • If you want to find the first quartile → draw a horizontal line in correspondence to 25% on the y axis → in this case the line meets the projection of the 2 point, that is secondary
  • If you want to find the third quartile → draw a horizontal line in correspondence to 75% on the y axis → in this case the line meets the projection of the 3 point, that is tertiary FINDING THE QUARTILES FOR QUALITATIVE CONTINUOUS VARIABLES Qualitative continuous variables are grouped in classes → e.g. income → so when you are searching for the quartiles, first you find the class in which the quartile is contained → then, an approximated value of the quartile is equal to the central value of the quartile class → central value = (lower endpoint + upper endpoint) / 2 QUARTILES IN EXCEL → THE FIVE-NUMBER SUMMARY The Excel QUARTILE.INC function exists, but you can use it only for numeric values and not for categorical ones. → the Excel QUARTILE.INC function returns the quartile for a given set of numeric data → this function can provide→ x(1), Q(1), Me, Q(3) and x(n) SYNTAX → =QUARTILE.INC(Array; Quart) Where:
  • Array → are cell references that contain numeric values for which you want the quartile value → select only the numbers, not the label
  • Quart is: o 0 for minimum value x(1) → 0 children o 1 for first quartile Q(1) → 1 child o 2 for Median Me → 2 children

o 3 for third quartile Q(3) → 3 children o 4 for maximum value x(n) → 4 children NB you cannot use frequency table data or grouped data, you must use the original data set HOW TO SELECT THE WHOLE COLUMN → Ctrl + Shift + Down arrow ARITMETIC MEAN / AVARAGE → is the most informative/representative location measure → if it can be calculated, then it should be calculated The arithmetic mean Is the sum of the values divided by the number of observations

  • If the data set is the colums population → 𝜇 = 1 𝑁
  • If the data set is a sample→ 𝑥̅ = 1 𝑛

Where N is the population size, and n is the sample size. The mean is:

  • Used for discrete data, tabulated in a frequency table, where outcomes x1,…,xk occurring with frequencies f 1 ,…, fk the sample mean is 𝑥̅ = ∑ 𝑘 𝑖= 1 𝑥𝑖 × 𝑓𝑖→ where k is the number of different modalities
  • Used only for numerical data , and not for qualitative data
  • The most common measure of central tendency
  • Affected by extreme values (outliers) HOW TO CALCULATE THE MEAN → e.g. children
  • Let’s consider the sample mean → 𝑥̅ = 1 𝑛 ∑ 𝑛 𝑖= 1 𝑥𝑖→ you have to sum the number of children and divide it by the total number of bank clients → 𝑥̅ = ( 0 + 1 + 0 + 2 + 4 +⋯+ 3 ) 4521

8039 4521

  • Let’s consider the frequency table → you have to multiply the values of the modalities by the corresponding frequencies xi × fi → (fi=ni/n)→ 0 ×0,191=0; 1×0,221=0,221; 2 ×0,325=0,651; … → sum all the results → 𝑥̅ = ∑ 𝑥𝑖 × 𝑓𝑖 𝑘 𝑖= 1

The values obtained with the two formulas are equal → observe that n=4521, while k= HOW TO CALCULATE THE MEAN WITH CLASSES → e.g. income

  • Let’s consider the sample mean and the data of the original data set → 𝑥̅ = 1 𝑛

( 2987 +⋯+ 58654 ) 4521 =^ 115270762 4521 =^25496 ,^74

  • Standard Deviation
  • Coefficient of Variation The measures of variation give information about the variability of the data → used only for numerical data RANGE → is the difference between the largest and smallest observation → the greater the spread of the data from the centre, the larger the range will be → range = x(n) – x(1)
  • The simplest measure of variation
  • Strongly influenced by outliers, even if they don’t represent the distribution because they’re extreme values → this problem can be solved by ordering the data in ascending or descending order and then discarding the lowest 25% of the data and the highest 25% of the data → see Interquartile Range below
  • Ignores the way in which data are distributed → it considers only the minimum and the maximum values → that’s why it’s susceptible to distortion if there’s an unusually extreme observation INTERQUARTILE RANGE/DIFFERENCE → is the difference between the observations at the third quartile and the first quartile:
  • It measures the spread in the middle 50% of the data/observations
  • Can eliminate some outlier problems by using the interquartile range, it eliminates high and low valued observations E.g.
  • Range(children) = 4 - 0 = 4 → IQR (children) = Q3 - Q1 = 3 - 1 = 2
  • Range(income) = 58654 - 2987 = 55667 → IQR (income) = 29521-21228 = 8293 BOX-AND-WHISKER PLOT → is a graph that describes the shape of a distribution, in terms of the five- numbers summary, and describes also the spreading of the data.
  • Created from the five-number summary: → x(1), Q(1), Me, Q(3) and x(n)
  • Can be vertically or horizontally drawn
  • The inner box shows the range from Q 1 to Q 3 , the line in the middle represents the median
  • Two “whiskers” extend from the box: o One whisker is the line from Q 1 to the Min → NB Min≠x(1) → Min=max(x(1); Q1 1 , 5 ×IQR) o The other is the line from Q 3 to the Max → NB Max≠x(n) → Max=min(x(n); Q3+1, 5 ×IQR) gff
  • The distribution 1 is left-skewed because the median in on the left/higher part of the box
  • The distribution 2 is symmetric because the median in in the centre of the box
  • The distribution 1 is left-skewed because the median in on the left/higher part of the box
  • The distribution 1 is right-skewed because the median in on the right/lower part of the box BOX-AND-WHISKER PLOT IN EXCEL To make a box-and-whisker plot in Excel:
  • Select the original data from the data set, not from the frequency table (when you insert graphs you can select also the label)
  • Go to Insert → All Charts → Box & Whisker → OK E.g. Children X → corresponds to the mean NB excel automatically calculate Min and Max to provide the whiskers → if I want to do it manually:
  • Min = max(x(1); Q1-1.5×IQR) → IQR=Q 3 - Q 1 → Min = max[0; 1-1.5 × (3-1)] → Min = max[0, - 2] = 0
  • Max = min(x(n); Q3+1.5×IQR) → IQR=Q 3 - Q 1 → Max = min[4; 3+1.5 × (3-1)] → Max = min[4, 6] = 4 There are no points larger than the max or lower than the min → so there are no outliers Is this distribution symmetric? The length of the whiskers is equal, and the mean is exactly in the center of the box → so it is symmetric E.g. Income