Docsity
Top Seller

Statistical Data Analysis - ESIR, Appunti di Analisi Statistica

Anteprima parziale del testo

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

STATISTICAL

DATA ANALYSIS

COURSE NOTES – PROFESSOR RICCARDO BRAMANTE

MAURIZIO NAVA ESIR 1ST YEAR Catholic University of the Sacred Heart, Milan

STATISTICAL DATA ANALYSIS

08 th^ FEBRUARY 20 23 Text is left-aligned, while numbers are usually right-aligned. Usually, the dot represents the decimal separator and the comma represents the thousands separator. 15 th^ FEBRUARY 2023 The main distinction between variables is quantitative and qualitative. Qualitative variables can also be called categorical variables, we can distinguish between nominal and ordinal variables:

  • Nominal : categories with no ordering
  • Ordinal : categories which can be ordered Quantitative variables can also be called numerical variables. Here, we distinguish between discrete and continuous:
  • Discrete : a countable number of possible values
  • Continuous : values of continuous scale Data in raw form are usually not easy to be used for decision making and therefore we use some type of organization. In particular, we use tables and graphs. The kind of graph we use depends on the variable we are analyzing. Frequency tables can be univariate, when you consider only one kind of variable or bivariate if we consider two variables at the same time. They may also be trivariate or multivariate. In the frequency table we have absolute frequency, thus the count of a certain variable within our data. We can also compute the so-called relative frequency which is the ratio of the absolute frequency over the total. This is usually expressed as a percentage. In a multivariate analysis we may have two qualitative variables, in this case it is called contingency table. When we have quantitative variables, we call the table cross table. When we work with two variables, we have frequencies which represent when the two variables apply together in our data set. If I have three categories of one variable and three of the other, I will have 9 absolute joint frequencies, and 9 relative joint frequencies. The sum of all absolute joint frequencies will be equal to the total of data for each category and the sum of relative joint frequencies will be equal to 1. In order to analyze the income of people, it is useful to group them. In order to do so, we click on an income with the right button and click on group, there we choose the maximum difference inside the group. 01 ST^ MARCH 2023 Absolute joint frequency is the absolute frequency of two joint variables, such as for example the number of divorced people who have primary education. The last row or column are marginal

We may have modal intervals, such as in the case of income, where it is useful to make groupings. The median is the middle observation when the data are ranked in increasing order. This can be computed for either numerical or ordinal data, but not for nominal ones. The interpretation is that 50% of the observations has an income which is below or equal the median value, the other 50% has an income which is above. We can use the function “median”, or we can sort the values from smallest to largest. In order to find the median value of education level, which is categorical, we use the pivot table, compute the cumulative frequency of relative frequency and thus we check the first cumulative frequency which is greater or equal to 50%. Percentiles indicate the position of a value relative to the set of data ranked in increasing order. The Pth percentile is a value such that, approximately, P% of the observations are at above or below that number, i.e., the percentiles separate data sets into 100ths:

  • the 25th percentile is the first quartile: P% = 25%
  • the 50th percentile is the second quartile (median): P% = 50%
  • the 75th percentile is the third quartile: P% = 75% We have 99 percentiles. 15 TH^ MARCH 2023 How can we find quartiles or percentiles? We can work by means of the distribution function. For the quartiles we search for the first cumulative frequency which is greater or equal to 25%. We need to calculate also the mean value. It is a number which is usually analyzed. The average can be a number which represents the distribution because the observations are all more or less around the average. If, on the other hand, we have outliers, then the average does not represent all numbers in the table. We can calculate it by means of frequency distribution or by means of the function. We can evaluate the average by means of the sum of the products of each value and its percentage divided by the total number of observations. We can understand whether we have a symmetric or a skewed distribution. The usual distribution are skewed ones, either left- or right-skewed. If the mean is lower than the median, then the distribution is left-skewed, while in case the mean is higher than the median, then the distribution is right-skewed. The symmetric distribution can be witnessed if the three measures of location have the same value, it may be the case we do not have the mode. 29 th^ MARCH 2023 MEASURES OF DISPERSION Variability is when we try to replace the original raw data by means of a certain indicator. We need something which shows us how the initial distribution was spread. The quantities are quantities which can be used to give the reader an insight on how the distribution is spread and comment the values. We thus look at the range, interquartile range, variance, standard deviation and coefficient of variation. Range is the maximum minus the minimum.

Interquartile range is similar to the range, it is Q 3 - Q1. It is the central 50% of given data. Variance is the average of squared differences between values and mean. Variance (S) differs from variance (P), in the first one the denominator is the number of observations minus one, while in the second the denominator is the number of observations. Variance increases as the distance of the observations from the mean increases and vice versa. The standard deviation is the square root of the variance. If each data in the sample is further from the mean, then there is a higher deviation within the sample. Coefficient of variation is the ratio between standard deviation and the average. This can be shown also as a percentage. To set up a variability scheme related to a specific variable we usually use the standard deviation, when we want to compare some types of distribution we need to work with the coefficient of variation. It is zero when all values are the same. There may be the case where we do not have raw data but a frequency table. Suppose we need to evaluate the above measures. We take the square of the differences between values and average, multiply each by the relative frequency. 19 TH^ APRIL 2023 When variables are quantitative, we can set up an analysis that enables us to deepen the analysis having numbers which explain how strong the relation is. Covariance is variance in common, it is a measure of linear dependence between two variables. Since the variance can be evaluated both on population and on a sample, also covariance has the same structure. The structure of covariance is the average of the product of the differences between each variable and the corresponding average. If we compute the covariance of x and x, we get the variance of x. The covariance of the same variable is the variance of this variable. Covariance is symmetric, if we switch x and y, the value we have is the same. 𝑠𝑥𝑦 =

𝑛 𝑖= 1

When covariance is equal to zero , the two variables are independent. When covariance is positive , then it means that the two variables tend to move in the same direction, as one increases, also the other one tends to increase. It may also be the case that the two variables decrease. When covariance is negative the two variables tend to move in opposite directions, thus as one increases, the other one tends to decrease. Correlation coefficient is the ratio between covariance and the product of standard deviation. It is a measure of the direction and strength of the linear relationship between two variables.

  • The closer to - 1 the stronger is the negative linear relationship.
  • The closer to 1, the stronger is the positive linear relationship.
  • The closer to 0, then there is no linear relationship.

The minimum of the square of the error is equal to the minimization of the variance of the error term. This means that all the other models we can imagine have a variance of the error term that is at least equal to the variance of the model least squares criterion. SCATTERPLOT We use age and income => hide column of house Select the 2 columns, insert the scatter plot, with the right click on the graph we add the trend line. 3 ways to evaluate the 2 parameters of the model:

  1. Directly on the chart : we can select the model, click the line, format trend line and introduce the equation of the chart, by selecting “display equation on chart”. So that we can see the parameters The meaning of the slope : value of the income I have when I become older (when my age increases). When you become older than 1 year, you should get b1 (468,76) more.
  2. Use formulas related to statistical indicators : Slope: beta 1 = ratio of covariance and variance or correlation coefficient r * ratio of standard deviations (slide 8) Intercept: b0 = difference between the average of y – beta 1 * average of x Simple Regression Compute average, std dev, covariance, correlation. If we use the formula .P for std dev, we need to use it also for covariance and correlation. Compute the slope beta 1 and compare with the equation we have in the chart: 1 - Covariance/variance of the independent variable. Variance = square of std dev 2 - Correlation * std dependent variable/std independent variable. Intercept beta 0 : average income – slope * average age The increase of 1 in age is the slope. The increase of 3 in age is the slope * 3. The rule to choose the (only one) x is based on the maximum correlation coefficient (in absolute value) that you have in your dataset. 3 rd^ way: compute regression through data analysis

Go to the dataset, select data analysis, select regression, Select Y and X without label. “constant is 0” → remove the intercept (usually we don’t have it). Set the result in a new sheet. ANOVA = analysis of variance Second column SS stands for SUM OF SQUARES and this numbers are related to the structure of the model. SS of the residual is the number to minimize by the least squares criterion. Residual = error. R = correlation coefficient evaluated by means of the model → it is the square of the correlation coefficient. 67% is the percentage of the variance of the income that is evaluated by means of the linear model. 33% is related to the error. 3 RD^ MAY 2023 We have three correlation coefficients, since we know that the minimum value of the variance of the error corresponds to correlation coefficient, which is the highest one. The variance of the dependent variable is split into two parts, the first one is the variance of the model and the second one is the variance of the error. If SSR increases - such as changing the independent variable - and increases, then SSE decreases. Otherwise, if the variable we use is poorer than the previous one - thus SSE increases - then SSR decreases. If this is the situation, we can use r^2. It is the portion of the total variation in the dependent variable that is explained by variation in the independent variable. When we have only one independent variable, r^2 can be calculated as sum of the squares of the correlation coefficient. It is the ratio between the regression sum of squares over the total sum of squares. It can also be computed as 1 minus SSE over SST. R^2 less than 0.6 means the model is poor, we cannot give an insight of y by means of the x. From 0.6 and 0.8 it works well, but not so well. If it is greater than 0.8, then the model is top. Standard errors are measures of variability, if they increase, we have a problem, the number that identifies the coefficients can change a lot if the former changes even a bit. We want to evaluate T-stat and P-value. We want to check if the parameters can be zero, mainly the slope, if it can be zero, then it means the relation between x and y is going to be similar to a non-linear relationship. T-stat is the ratio of the parameter coefficient and the corresponding standard deviation. The rule of thumb, if the absolute value of t-test is greater than two, we infer that the parameters are different from zero. Otherwise, if the absolute value of t-test is lower than two then the parameters can be zero.

=countifs(selectcolumn;selectdivorced;selectsecondcolumn;selectprimary) → it can be applied with more than one criteria =quartile.exc(selectcolumn;decidewhichquartile)→ extremes are excluded =concat(…) Statistics may be broadly described as the techniques to collect, clarify, summarize, analyze and interpret data. Descriptive and inferential statistics. The range is the first and most simple measure of dispersion. It is the difference between the largest and the smallest value. It is strongly influenced by the presence of outliers and in addition ignores the way in which data are distributed. The Interquartile range (IQR) measures the distribution of the observations in the 50% of data in the middle, thus it is computed as Q3-Q1. This allows to find outliers - which are taken into account by the range - and thus eliminates their effects. Variance is computed as the average of squared deviations of values from the mean. This, hence, tells us how far each number of a certain variable is from the mean computed for that variable. It measures the degree of dispersion of data around the sample’s mean. The Standard Deviation measures the dispersion of the data of a variable in relation to the mean. If each data in the sample is further from the mean, then there is a higher deviation within the sample. (square of distance of each observation from the mean, sum all of them and divide by n-1, then square root) The Coefficient of Variation expresses the standard deviation as a percentage of the mean. The higher it is, the bigger is the level of dispersion around the mean. A lower co-efficient of variation is usually more desirable, since it suggests a lower spread of the value in relation to the mean. It can be used to compare the degree of variation of data from different variables, even if with completely different means and values. 𝐶𝑉 =

× 100%

Covariance is a measure of linear dependence between two variables, it indicates the relationship between the two when one of them changes. It evaluates how the mean values of the two variables move together.

Correlation coefficient expresses the direction and strength of the linear relationship between two variables. The possible values it can get are from - 1 to 1. If the value is negative, it means the linear relationship is negative, and it is stronger the closer the value is to - 1. If the value is positive, it means the linear relationship is positive, and it is stronger the closer is to 1. If the value is 0, then the two variables are independent one from the other. (Covariance divided product of the standard deviations) 𝑟 =

R^2 is a measure of how strong the linear relationship between the two variables is. If it is less than 0.6 the model is poor. Y= b0 + b1x. b0 (estimate of regression intercept) and b1 (estimate of regression slope) are obtained by finding the values of b0 and b1 that minimize the sum of the squared residuals (errors), SSE. b 1 = r sy/sx. b1 is the estimated change in y as a result of a one-unit change in x. b 0 = Y_bar – b1x_bar. b0 is the estimated value of y when the value of x is zero. Total variation is made up of two parts. SST = SSR (regression)+SSE. SSE is the part of variation which cannot be explained. se is the standard error of the estimate. se is a measure of the variation of observed y values from the regression line. The magnitude of se should always be judged relative to the size of the y values in the sample data. The variance of the regression slope coefficient (b1) is estimated by: t-test shows if a specific independent variable is conditionally important: Null and alternative hypotheses. β 1 is the value of the slope coefficient. H 0 : β 1 = 0 (no linear relationship) H 1 : β 1 =/ 0 (linear relationship does exist) → p-value lower than 0.05 to reject H 0