Docsity

Business Statistics (BUS 101)- Understanding Random Variable.pdf, Esercizi di Statistica

Anteprima parziale del testo

Scarica Business Statistics (BUS 101)- Understanding Random Variable.pdf e più Esercizi in PDF di Statistica solo su Docsity!

Business Statisti 20/02/2023 Random variable: A random variable is a variable whose value is unknown or a function that assigns values to each of an experiment's outcomes. A random variable can be either discrete (having specific values) or continuous (any value in a continuous range). The idea is to take a real phenomenon and describe it through a random variable, a mathematical value. Discrete data is a numerical type of data that includes whole, concrete numbers with specific and fixed data values determined by counting. Continuous data includes complex numbers and varying data values measured over a particular time interval. Descriptive statistics VS Inference: Descriptive statistics is used to describe a set of units through a set of values, with the objective of synthesizing our data set through a single value, e.g. average. Inference doesn't allow us to do this. With millions of subjects, we cannot observe all of them, so we'll have to observe a sub-sample of units. “Statistical inference is the process of drawing conclusions about an underlying population based on a sample or subset of the data. In most cases, it is not practical to obtain all the measurements in a given population.” Expected Value Example: (Cars by cylinder capacity — Italy 2010 Discrete R.V.) (emjce cars (% x PON) 01000) <300 1500 4% A 800-120 8200. 22% 2 02 1201-1600 15300 42% Probability of i si Probability 1601-1800 2100 6% | MPNSISNRNNES i distribution 1801-2000 5800 19% with a given CC A ofrv. 2001-2500 1600 4% in italy g 2501-3000 800 se >3000 300 + Total 36600 _100% LA Expected value = 1-0.04 + 2-0.22 + 3-0.42 + 4-0.06 + 5-0.19 + 6-0.04 + 7-0.02 + 8-0.01 = 3.39 Variability: Variability refers to the difference being exhibited by data points within a data set, as related to each other or as related to the mean. This can be expressed through the range, variance, or standard deviation of a data set. Random Variable (r.v.) P(X=x) x P(X=x) = 1 0.04 2° 022 È 3 04 |[px=x)=0 | 4 | Ù 7 006 || pl on |Ere=szi| » Î i 004 ox 1 [n] Mm _ 0.02 8 001 Sa: dj Propertiesofa p.d. If drawn randomly, the cylinder capacity range we're likeliest to get is 1201-1600, at 42%. Observing the graph however we can see it isn't symmetrical, rather it's skewed to the left, with two “peaks”. There's two clusters of cars, one with a low engine capacity (2 & 3), and the other with a much higher power (5 & 6). What is Big Data? Big Data is a term used to indicate extremely large data sets that may be analysed computationally to reveal patterns, trends, and associations, especially relating to human behaviour and interactions. It's composed by three dimensions: Volume (amount of information used and at our disposal), Velocity, and Variety (the different types of data we're dealing with). This is known as the “Triple V” definition. Most data found on the Internet is qualitative, rather than quantitative. Recall that quantitative data is all the information which can be quantified (counted or measured), meaning reported through numbers, while qualitative data is descriptive, and expressed in terms if language rather than numbers. Dependent & Independent variables: / Y=continuous Y=dummy Dependence Linear regressione model —Logit model ANOVA = Analysis (N; xy Kay 7) ANOVA model Probit model È AR(1) of Variance Between Variables Between Units Interdependence Principal Component Cluster Analysis (A Xag K) Analysis Ye 52,8 Turnover +—— #employees, Activity Sector, Innovation, IT investiment <= x Educational level + Income ‘“Y” is our dependent variable, while “X” is our independent/explanatory/predictor/input variable. ‘“Y” depends on “X”, and is often represented as “Y&-X”, meaning there's some sort of relationship between them. Unfortunately, there/s also several issues: 1. ‘“Y” may be influenced by many different variables (Xs); which are the explanatory variables best suited to describe it? 2. Suppose l’ve successfully identified the best explanatory variables; which (mathematical) function links the dependent and the independent variables? 3. Interdependence + How and to what extent do the different independent variables (Xs) relate/interact with each other? In this regard, the correlation index/covariance allows us to measure the linear relationship between two variables. As we get more variables, we'll need more complex instruments. Continuous VS Discrete variables: A discrete variable is a variable that takes on distinct, countable values (e.g. number of art pieces in a collection). A continuous variable on the other hand takes on any value within a range, and the number of possible values within that range is infinite. Statistical model: =f(x)+8; y; is the response (dependent) variable for observation i x; isthe value of the explanatory variable for observation i f(x;) is the regression function €, is a rv. capturing the effect of non measurable factors that are not attributable to the x;'s, in some sense, and affect the response variable. Expenditure=f(income,}+ £, £ includes Age, Education, Job).. We'll have several independent variables (Xs) which'Il influence our dependent variable (Y). However, we'll have to distinguish between large and small “ variables are included as part of the random variable “e”, with the “f(X)” function giving us the relationship between “Y” and “X”. influencers”. The smaller, irrelevant Steps in formulating a statistical model: There's several steps we should follow when developing a model: 1. Choice of variables Data collection Selecting the type of model + Defining the F(x) function. Parameter estimation Goodness of fit of the model + How accurate is my model? Does it effectively describe my values? 6. Purpose of use: 1. Explanatory analysis, to analyse the relationships between variables. 2. Forecasting > Using my model to forecast new values of “Y”. The more complex the forecast, the more complex the model required. 3. Simulate SGARON Different ways of collecting sample data: Sample data can be collected in different ways: 1. Variables Y and X are measured on N different units, in a certain instant. 2. Variables Y and X are measured in T different times. 3. Variables Y and X are measured in T different times, always on the same N units. For each different method we'll have a respective model: 1. Cross section: Cross-sectional data refer to observations of many different individuals (subjects, objects) at a given point in time, each observation belonging to a different individual. We'll have “n” different units, each with a couple of values. 2. Fortime series: A time series is a collection of observations of well-defined data items obtained through repeated measurements over time. The variables/observations are all different. “n” Here we'll still observe “n” different units, however the second and third samples we'll have different units. The units are different throughout all three samples. 3. For panel data: Panel data is a collection of quantities obtained across multiple individuals, that are assembled over even intervals in time and ordered chronologically. It's collected by observing particular variables over a period of time at a regular frequency. This data can help experts establish trends, make correlations, and guide further analysis of the variables included in the panel data. The variables/observations are allthe same. 21/02/2023 Simple linear regression model: y=P+Bx +5; where: y; = dependent variable; x, = explanatory variable; Bo B1= parameters(intercept and regression coefficient); €, = error term (noise). * Nature of random disturbance €, : — Ele; |x;)=0 — Varle; |x,)=02 is costant (omoschedasticity) — &; i=1,....n are incorrelated — eis a Normal rv. ‘“Y” îs a quantitative variable, while “X” can be either quantitative or qualitative. Either way, the idea is to study the relationship between the two, trying to understand how the first depends on the second, through a Y=f(X)+e equation. By defining f(X) and the nature of e we'll have our Simple Linear Regression model. It's “simple” because well have only one explanatory variable (X), and Simple linear regression model continued: Vi= Bo+ PX + £; Recall the example “Y” as expenditure and “X” as family income. Imagine we have 100 families with the same income (X, now fixed); well still see 100 different values of “Y”, all generated by differing values of £. The second hypothesis listed above states that this random variable (£) has a variance. Small values of variance entail overall values closer to the average value, however we're supposing this variability is constant, without depending on the values of X. Look at the brackets below; they're supposed to be all the same (ignore X,). r EXPENDITUNE S INCOME Suppose we have 40 families, each with one of four levels of income. We'll observe similar groupings, each with 10 different values for each class, due to the effect of our random variable (€). We're assuming that increasing income (Y) also increases expenditure (X), which is why each cluster is higher than the previous one. We can observe as X changes, the variability in Y remains constant. This is called “homogeneity” or “homoscedasticity” of the variance. It's a particular assumption which states the variability of e remains constant when changing the values of X; a sequence of random variables all have the same finite variance. Homoscedasticity Heteroscedasticity Is this always the case? No; in this particular case increasing income will cause our variability to increase (the diagonal line in the graph above). correlated ,n are This assumption states that the values of e are independent; the e | added to family 1 is independent from the one | added to family 2. €;is a Normal rv] The fourth and final assumption is that e is a normal random variable, meaning the likelihood of observing a given value of e depends on the density function (the bell shaped curve), &; -N(4,0°). Recall that pis the expected values of the random variable equal to 0 (E(£)=0), and the variance o2is constant, meaning it doesn't change following changes in the value of “X”. We've now defined the parameters upon which our random variable e depends, meaning we've finished determining our simple linear regression statistical model. Bear in mind that £ is also called “noise”; the louder the noise the less accurate our results, depending on our variance (02). It's important to estimate sigma squared, to understand how “strong” our noise is. Simple linear regression model vi=BotBx+6; where: Y; = dependent variable; x; = explanatory variable; Bo. B1 = parameters(intercept and regression coefficient); £; = error term (noise). * Nature of random disturbance £,: — Ele; |x;)=0 — Var(e; |x; )=02 is costant (omoschedasticity) — &; i=1,...,n are incorrelated = &;is a Normal riv. * Ely; 1x)=4;=Bo+Bx%; the regression function f(x) = By + Bjx,describes the relationship between X and the conditional expectation of Y * Bo=E(y;1x%;=0) the intercept is the expected mean value of Y when all X=0. If X never =0, then the intercept has no intrinsic meaning. «Bi the average change in Y when X increases by one unit E; includes the effect of omitted variables and noise factors on the response variable Y If the assumptions are true/correct, we”Il have several interpretations: Y;=Bo+BiX;+ € € Thisis our generic relationship. We'll want to compute the Expectation of “Y” given a particular level of “X”. Example wise, our expected level of expenditure (Y), given our level of income (x) is: E(Y;1X;) = E(Po +B1X;+ &1X;)= = E(Bo 1 X) +E(B1X; 1X) + E(e; 1X;)= =Bot BXj+0 We'll therefore obtain: E(Y]X) = Bo + BiXi < This equation describes a straight line in the geometrical X/Y plane. Bo is a value, and the Expectation of a constant is equal to the constant itself, meaning E(B0 1X)=B,. B1X; too is a value, and meaning E#1%;) = PX. Finally, by our assumption, E(£i)=0. irc SO an” The idea now is to use a straight line to approximate this distribution of points (our observations); this is our “regression model”. We'll have to estimate the “best” line, the one which passes closest to the data sample. What does “best” mean though? In geometrical terms it's the line which passes closest to all my sample data. The line tells us the change in the average value (expectation) of “Y” as “X” increases. We'll have to define a particular measure to define the distance between a point from the data set and our hypothetical line (generated by our model). For this, we can use the “Ordinary Least Squares” (OLS) method, where the distance between the line and a given point is given by: Lodkatthe*Yavisortne D=(Y;- n above graph on the right. The idea is then to sum the distance of each point from the straight line, trying to minimize it, so: D=Liai(Y;-Y) SCRL CER AREE CO) line: y=a+bx n * Minimize: Y (y.— $)2 . nil | teli Least Squares Method 7=1 y (dependent) y-intercept xi x (independent) This formula has a problem however: sometimes the distance is positive, others it's negative, meaning the overall sum could even out to 0. To solve this issue, we'Il convert the distance to a positive value by adding a square (42). Interpretation-wise, the distance will be equal to 0 when all the observed points are on the line, meaning when the model perfectly describes the observed points. Obviously, this isn't realistic, so instead well be looking for the smallest possible value of “D”. Bear in mind however that Y, = fp + B1X;. This implies that changing Bo and 8} (the parameters in our model, “Y” and “X” are fixed) we'll obtain different values of “D”. We'll play around with our two variables, trying to find the optimal values which'Il minimize our “D”. We can obtain them by 10 compute the first order derivative of our D-function, with respect to both 85 and B;. The solution will give us our OLS estimators: OLS Estimation of the regression parameters The Ordinary Least Squares (OLS) estimates of the regression parameters, denoted È, , are the minimizers of the sum of squares Criterion: s(3)= x, -B-Bx, È il Note: y; and x; are observed values and not r.v.s The OLS estimators: They are unbiased estimators: E(È)= Bn EB)=B Look at the second equation; xy is the covariance (Var), while 0° is the variance. Since 02 will always be positive, this means that the value of Bi will always depend on the covariance. If it's positive then there's a linear relationship between our variables (Y and X), with a positive slope, if it's negative there's a linear relationship with a negative slope, and if it's equal to 0 there is no linear relationship between the two. The sign of the covariance (0xy) tells me whether there's a direct or indirect relationship between “Y” and “X”. Furthermore, the values of 8; and £h depend on the sample; changing the sample will change them. But why are Bi and 5 best suited to describe our model? They're useful for estimating the true parameters within our population. They're “unbiased estimators”; an estimator is a mathematical function applied to the sample data to obtain an estimate of the parameter of the population. Depending on the formula, it can be more or less accurate in its results. An estimator is said to be unbiased when the formula/function is considered to be “good”, accurate. Estimator: Bias & Variance: Estimator Unbiased: The average of all possible estimates is equal to the parameter Estimator biased: The average of all possible estimates is different to the parameter Lanciatore corretto e preciso : in media i suoi lanci sono intorno al centro e sono poco dispersi. Lanciatore distorto e preciso: in media i suoi lanci non sono intorno al centro e e sono poco dispersi. The diagram in the top right is a biased estimator, while the one in the top left is an unbiased one, since the average value of all the points (the little X) is located in the central spot (the true value). Obviously we”ll prefer the unbiased to the biased, and the formula of the OLS method gives it to us. 11 Example Y=home price X=the home’s squared footage È Stata Command Source | ss df Ms Number of obs = 67 = [FC 1, 65) = 148.64 Model | 7551970.02 1 7551270,02 | Prob > F 0.0000 Residual | 3302438.63 65 0806.7482] R-squared 0. 6958 - | Adj R-squared 0.6911 Total | 10854408.7 66 164460.737 | Root MSE 225.4 price | Coef. Std. Err t P>iti [958 Conf.Interval] sqft | -0995521 12.19 0.000 1.014904 1.412543 [cons | 159.8917 -4.75 0.000 -1078.11 -439.458 That -758.7838 is Rai meaning the “Y” intercept. It's the expected/average value of the price when the square footage (X) is equal to 0 (impossible, since an apartment can't be 0), meaning it's essentially a technical value. That 1.213724 is Bi the estimator of the slop, how “Y” changes following a change in “X”; the average price will increase by 1.21 following an increase of 1 unit in square footage. These are the OLS estimators regarding the parameters of the model, Bo and f}. That 50806.7482 is the estimation of the variance of the noise term, of. Example Y=home price —X= the home's squared footage Variabile dipendente: price Numero osservazioni lette |67 Numero osservazioni usate 97 Analysis of Variance Sum of Mean Origine DF Squares Square Valore F| Pr> F Modello 1 9 148.84 (<.0001 Errore CS Totale corretto | 96 Radice MSE | 225.40352 R-quadro __[0.e0: Media dip. |1191.46269 R-quadro corr (0.0911 Var coeff 19.40687 Parameter Estimates Parameter Standard Variable |DF Estimate Error Valore t Pr > Itj 95% Confidence Limits Intercept| 1 -758.78383 159.801 475 <.0001 -1078.10963 |-439.45804 saft Ù 0.00955) 12.19 /<0001 101490) 141254 These are the exact same results, only obtained through SAS. Goodness of Fit: As seen in previous lectures, there's several steps we take when conducting an analysis: 1. Identify the variables (e.g. price, square footage etc.) and the model (e.g. linear regression). 2. Estimate the parameters (e.g. 80, 81, 02) using the Ordinary Least Squares (OLS) method. 3. Determine whether our model is able to effectively describe our data or not. We've obtained a rough approximation through a straight line, but how good of a fit is it? 13 Linear regression The line approximates the average value of our data set, but how accurate is it? To measure this “fit” we'll have to introduce a measure of goodness-of-fit: * SSModel= 3(y,-y) * SSResidual=Y(y,-,) n xo —gP+Ze} hi î fi * sstotal= £0-y) = ht dx SST = SSM+SSR Yi-T Let's introduce the concept of “deviance”: En_,(Y — 7)? € This is the classical formula to compute the variance for “Y”, which can be rewritten as: n no = Y Abati 1=1 This quantity is called “deviance”, and it gives me information regarding the distance between an observed point in my data set and the average value (the line). Within the regression model it's called “Sum Squared Total” (SST). In statistics, deviance is a goodness-of-fit statistic for a statistical model; it is often used for statistical hypothesis testing. It is a generalization of the idea of using the sum of squares of residuals (SSR) in ordinary least squares to cases where model-fitting is achieved by maximum likelihood. It's equal to the distance between any y; and the average value 7. The deviance is a measure of the dispersion of points surrounding the “Y” variable. 1%) m n di e aa 2 (4:39) pae DAU(-I) ] Az | EV 7 SSE | Dev,AN CE ccp ss mM 14 Limitations of R?: Limitation of R° Itis subject to serious misunderstandings: Mi: An high value of R? indicates M2: A value of R? near 0 indicates that the estimated regression line is that X and Y are not related a good fit Consider the first graph, with an R? value of 0.7945. It's stating that 80% of the total variability of “Y” can be explained by using the linear model. In this case however, the curved points at the top suggest the relationship between our variables to be quadratic, rather than linear; the straight line is only a rough approximation of the true (non-linear) regression. In the second graph R? is close to 0; we'll therefore conclude there's little relation between “Y” and “X”. This is incorrect; there is little linear relation between “Y” and “X”, meaning a linear function is not suited to describe this relationship. Bear in mind however that R2 is a measure limited exclusively to linear regression models. r Example Y=home price X=the home"s squared footage Dimension of the sample. . reg price sqft source | ss af ms | wunber of obs = —__—- def] FC 1, 65) = 148.68 Model | |7551970.02| 1|7551970.02| Prob > F 0.000 Residual | |3302438.63| 65 |50806.7482| R-squared Recall: sa +-4--------------L----------| AG) R-squared = 0.6911 32 total | |10854408.7] 66 [164460.737| root use = 225.4 ssT= LG: 9)", SSTSSSM+SSR 10854408.7= 7551970.02+3302438. 63 SSM=Z(9- 7) 1% LY = GN _ D2(, -9, È = SSR/65=MSR =50806.75 SSR=Z079) Se And of course: = vMSR = Root MSE=225.4 SST = SSM + SSR In this example R? is at 0.6958, meaning a linear function is fairly well suited to describe the relationship between “Y” (e.g. price) and “X” (e.g. square footage). Consider there will always be other variables to take into consideration, such as geographical position of the apartment, building age, neighbourhood, accessories and so on; including these new explanatory variables will improve our accuracy, increasing the value of R?. Let's now consider the ANOVA table (top left). The first column gives us the Sum of Squares (SS) Model (M), Residual (R), and Total (T), which is the sum of the two values above it. The second column is the degree of freedom, an integer number. The Total degree of freedom is given by “n-1”, with “n” being the number of observations. The degree of freedom for the Model is “p”, the number of explanatory variables, while the degree of freedom for the Error/Residual is “n-p-1”. Observe how the sum of the degree of freedom of the Model and that of the Error/Residual gives us the Total degree of freedom. 16 d È (7era. ) AL (Mover) AE | E CRARÌ MES VAL, m-pir The last column (MS) is the Mean Square (of the Model, Residual, and Total). “Mean” is an average, so we're considering the ratio between SSM (5551970.02) and the degree of freedom (1) to obtain the Mean Square Model. Same concept applies to the Mean Square Residual, 3302438.63 _ 650 50806.7482. Observe however that the Mean Square Total (164460.737) is not the sum of the two quantities above. Now, what is the Mean Square Residual (50806.7482)? It's the Sum Squares Residual over the degree of freedom of the Error/Residual, as shown in the formula below. “Yi” is the observed point and “9” the point on the straight line. The quantity MSR is the estimate of the variance of the noise term. Look at the two bubbles connecting MSR and V(e). Example: Example Y=home price Totale coretta | 66 Ù Radice MSE Media dip. noi se X= the home"s squared footage Analysis of Variance ‘Sum of A Requadro R-quadro corr j ;M+SSR 1 D(y,—3,)} =SSR/65 10854408.7= 7551970.02+3302438.63 = MSR = Root MSE = =MSR=50806.75 225.4 17 ‘a” is usually fixed low, either 1% or 5% (the probability of the error actually occurring). The statistical test itself is: A = pal Ho) t = Re The standard error is _ — Sil (a ) a statistical term that Standard error of Br. IT] measures the accuracy with AI A which a sample distribution ,-9 fa represents a population by _. 4 = using standard deviation. = A Sl) S.0.(%4) RECALL: In our system, the null hypothesis is that 8; (Ho) = 0. But what is the standard error of f? It's equal to the standard deviation, a measure of variability, in this case of Bi. But why does Bi change? Because our model is built/estimated using a data sample; changing the sample changes Bi In other words, Bi is a random variable that changes values following changes in the sample data. The standard error of Bi is a measure of the variability of my estimator changing the sample data. In general, l’Il prefer an estimator with a standard error as small as possible. But how can be accept or reject our initial hypotheses? Well have to use a t-student random variable, with a density function as shown below: Student's £, df=25 Student”s £, df=15 \ Student's £, df=5 The degree of freedom (df) changes the shape of the curve. Increasing the degree of freedom tends to a standardized normal random variable, with an expectation p equal to 0 and variance (0) equal to 1. C=1 19 So, the t-student is similar to a normal distribution, and depends on the degree of freedom (an integer value). The shaded areas are equal to the probability of observing a P-value greater than, or equal to 10, in our example, while the white area is equal to the probability of observing a P-value lower than 10. EL 19 This is the distribution of “t” ifthe sample comes from the null hypothesis, in which we're expecting to observe 8, = 0. We're expecting to observe a “t” around 0; if it's far from 0, we'll decide the sample comes from the null hypothesis. The general idea is: I'll compute “t”, and if it's close to 0 II accept the null hypothesis, if it's far from 0 well reject it. To understand whether “t” is near or far we'll have to compute the value of the two shaded areas (e.g. t=10). We'll sum the areas, the resulting value being called “P-value”. Bear in mind that it's a probability, meaning it's a number between 0 and 1. If the P-value is close to 0, the b/ack area will be very small, meaning well have a very high “t” value. On the flip side, if the P- value is close to 1, the white area will be very small, entailing a “t” value very close to 0. So, if “t” is big Ill reject the null hypothesis, which if it's close to 0 l’Il accept it. On the other side, ifthe P-value is big (close to 1) I’Il accept the null hypothesis, if not II reject it. So, the P-value is a measure to decide whether to accept or reject the null hypothesis. But how can we determine whether “P” is small or not? We'll use our a-level (0.05 or 0.01) as cut-off value. In short: ® IfP The shadedarea is small (“t” is close to 1) > We'll reject the null hypothesis. ® IfP>a > The shaded area is big (“t” is close to 0) 3 We'll accept the null hypothesis. 20