Docsity

Quantitative methods,, Appunti di Statistica

Anteprima parziale del testo

Scarica Quantitative methods, e più Appunti in PDF di Statistica solo su Docsity!

Notes for the course of Quantitative methods

Samantha Leorato

March 13, 2023

  • 1 Review material
    • 1.1 Random variables
    • 1.2 Moments
    • 1.3 Random vectors
    • 1.4 Independence, covariance correlation
    • 1.5 Simple random sampling
    • 1.6 Sampling distribution
    • 1.7 Properties of an estimator: the sample mean
    • 1.8 Sample variance
    • 1.9 Confidence intervals
    • 1.10 Tests on the mean
    • 1.11 Tests for independence
  • 2 Linear Algebra and notation
    • 2.1 Vector’s operations
    • 2.2 Vector space
    • 2.3 Scalar product
    • 2.4 Matrices
    • 2.5 Trace and determinant of a matrix
    • 2.6 Matrix inverse
    • 2.7 Solving a linear system of equations
    • 2.8 Eigenvalues and eigenvectors
    • 2.9 Spectral decomposition of a matrix
    • 2.10 Example
    • 2.11 Quadratic form and positive (semi)definite matrices
  • 3 Simple linear regression models
    • 3.1 Introduction
    • 3.2 OLS estimator
    • 3.3 Predicted values, residuals and goodness of fit
  • 4 Multiple linear regression 4 CONTENTS
    • 4.1 Omitted variable bias
    • 4.2 Definitions and notation
    • 4.3 Assumptions of the OLS
    • 4.4 OLS estimator. Definition and properties
    • 4.5 Goodness of fit
    • 4.6 Confidence intervals and testing
    • 4.7 Interpretation of coefficients
    • 4.8 Regression models with categorical covariates
    • 4.9 Multicollinearity
    • 4.10 Nonlinear transformations
    • 4.11 Assessing studies based on multiple linear regression
  • 5 Principal Component Analysis
    • 5.1 Introduction and notation
    • 5.2 The derivation of PC
    • 5.3 Interpretation of PC
    • 5.4 Graphical representation
    • 5.5 Selection of the number of PCs
    • 5.6 PCA and Regression
  • 6 Models for binary dependent variables
    • 6.1 Linear probability model.
    • 6.2 Logit and probit regressions
  • 7 Models for panel data
    • 7.1 Introduction and notation
    • 7.2 Panel data with T =
    • 7.3 Fixed and random effects
    • 7.4 Within estimation
    • 7.5 Assumptions and sample properties of the within estimator
  • 8 Cluster analysis
    • 8.1 Introduction
    • 8.2 Distances and similarities across units
    • 8.3 K-means clustering
    • 8.4 Hierarchical clustering
    • 8.5 How to choose the number of clusters and evaluate partitions
    • 8.6 How to compare partitions
  • CONTENTS
  • 9 Laboratories
    • 9.1 Lab 1: getting started
    • 9.2 Lab 2-3: Descriptive statistics using the survey data
    • 9.3 Lab 4: Random variables and distributions
    • 9.4 Lab 5: Statistical inference
    • 9.5 Lab 6: Simple linear model with caschool
    • 9.6 Lab 7-8: analysis of the effect of class size on student’s performance
    • 9.7 Lab 9-10: from multivariate linear model to PCA using sleep75
    • 9.8 Exercise
    • 9.9 Lab 11: A principal component analysis of body measures
    • 9.10 Lab 12: Customer satisfaction
    • 9.11 Lab 13: GLM with HMDA
    • 9.12 Lab 14: Can an old democrat candidate win the elections?
    • 9.13 Lab: 15: University college house prices.
    • 9.14 Lab 16: Cigarette demand, a panel data
    • 9.15 Lab 17: Cluster analysis: Penguin data
    • 9.16 Ideas for the project
  • 10 Preparing your own analysis
    • 10.1 FAQ
    • 10.2 Outline of the project
    • 10.3 Sample projects

Chapter 1

Review material

1.1 Random variables

We recall that a random variable is a variable that represents numerically a random result (of an experiment) Examples are: number of children in a household, family income, the outcome “smok- er/not smoker” The sample space is the space of all possible outcome of the observation of the random variable. For example, the household income has sample space that is a subset of the positive real line, the smoker/not smoker variable hat only two possible outcomes, that are usually coded by { 0 , 1 } (f.i., 1 =smoker) Given a sample space, events are subsets of the sample space. The probability is a measure of the possibility of a particular event E to occur. In experiments with a finite sample space, it is usually the fraction of elementary events included in the event E. For example, if you roll a die, the sample space is just the 6 faces of the die (from 1 to 6), and the event “odd number” has probability 36 = (^12) Formally, probability is a measure, defined over a space of subset of the sample space and has the following properties: (i) always between 0 and 1; (ii) the probability of the whole sample space is 1; (iii) if two events, A and B, are disjoint (meaning that they can’t occur simultaneously, then P (A ∩ B) = P (A) + P (B) Random variables can be distinguished according to the characteristics of their sample space (or, of their support):

  • Discrete random variable: the sample space is discrete (finite or countably infinite). Ex. number of children, number of people queueing at the post office...
  • Continuous random variable: the sample space is continuous (or well approximated by a continuous set/interval or by the real line): household income, household ex- penditures.

7

8 CHAPTER 1. REVIEW MATERIAL

Discrete Continuous

ad es. Y ∈ { 1 , 2 , ..., K} ad es. Y ∈ (−∞, ∞) PDF: F (k) = P (Y ≤ k) = P (Y = 1) + P (Y = 2) +... + P (Y = k) F (y) = P (Y ≤ y)

pmf f (k) = P (Y = k) –

pdf – f (y) ≈ P (Y = y)dy pi`u prec., f (y) = F ′(y)

Table 1.1: scheme of the definition of probability functions for discrete and continuous ran- dom variables. PDF = probability distribution function, pmf = probability mass function, pdf = probability density function.

Each random variable is completely determined by its sample space and by the proba- bility distribution defined on it (on events subsets of the sample space). Table 1.1 presents scheme of the probability functions distinguishing between discrete and continuous r.v.’s.

Examples of discrete random variables:

  • Bernoulli, Y ∼ Bernoulli(p). F (1) = p F (0) = 1 − p;
  • Binomial, Y ∼ bin(n, p). f (k) =

(n k

pk(1 − p)n−k

  • Poisson, Y ∼ P oisson(λ)...

Examples of continuous distributions (most used in statistics):

  • Gaussian, or normal, Y ∼ N (μ, σ). f (y) = (^) σ√^12 π e−(y−μ) (^2) / 2 σ 2 ;
  • Chi-squared, Y ∼ χ^2 k. Can be obtained from independent normal distributions. In particulal, if Y ∼ N (0, 1), then Y 2 ∼ χ^21
  • Student-t, Y ∼ Tk. Defined as follows: if Y ∼ N (0, 1) and X ∼ χ^2 k, X, Y independent, then Z = Y /

X ∼ Tk

  • Fisher’s F , Y ∼ Fm,k. Can be obtained as the ratio of two independent χ^2 distr- butions, divided by their degrees of freedom: X ∼ χ^2 m, Z ∼ χ^2 k Y = X/mZ/k ∼ Fm,k .

10 CHAPTER 1. REVIEW MATERIAL

  • For any two independent random variables X, Y , constants a, b: Var(aX + bY ) = a^2 Var(X) + b^2 Var(Y )

The skewness is the third central moment: μY 3 = E(Y − EY )^3. It can be either positive or negative. If Y is symmetric (around the mean), then μY 3 = 0. Then skewness gives information about the symmetry of the distribution.

  • Positive skewness μY 3 > 0 indicates the presence of an asymmetry towards the right: the right tail of the distribution is longer. It might happen when the variable is bounded from below (ex. age of Master of science students)
  • Negative skewness μY 3 < 0 indicates the presence of an asymmetry towards the left: the left tail of the distribution is longer. It might happen when the variable is bounded from above (ex. grade at the exam)

The kurtosis is the fourth central moment: κY = E(Y − EY )^4. Sometimes divided by 3 (that is the kurtosis of a standard normal distribution). Also, the excess kurtosis is the difference κY − 3, that gives a measure of how much the kurtosis of Y is higher (or smaller) that that of a standard normal random variable. The kurtosis captures the probability mass in the tails of the distribution:

  • A kurtosis higher than 3 (excess kurtosis greater than 0) means that the tails are heavier (fatter) than the Gaussian: more likely extreme events. The variables is called leptokurtic
  • A kurtosis lower than 3 (excess kurtosis smaller than 0) means that the tails are lighter (flatter) than the Gaussian: less likely extreme events. The variables is called platikurtic

1.3 Random vectors

Let us start from two random variables X, Y. We can define the joint probability distri- bution by the function P (X ≤ x, Y ≤ y). Similarly to the random variable case, the joint probability mass function P (X = x, Y = y) = f (x, y) can be defined if both X and Y are discrete and the joint probability density function f (x, y) if both are continuous.

Given a joint distribution, the marginal distribution can be derived by the elimination of one of the two variables. The elimination is achieved by summation (if the variable is discrete) or integration (if the variable is continuous): for example PY (Y ) =

x P^ (X^ = x, Y = y) is the marginal distribution of Y , if the sum is taken over the whole support of the random variable X.

1.3. RANDOM VECTORS 11

Figure 1.1: Figure from Stock and Watson’s book. Examples of distributions with diffeerent moment characteristics

The concept of joint distribution and marginalization can be extended easily to multi- variate random variables of dimensions higher than 2: the joint distribution is the function P (X 1 ≤ x 1 ,... , Xk ≤ xk), or (for continuous random variables P (X 1 = x 1 ,... , Xk = xk) and the marginal distribution of -for example- Xk, is the function

Pk(xk) =

x 1 ,...,xk− 1

P (X 1 = x 1 ,... , Xk = xk).

Given a random vector (X, Y ) we can define its conditional distribution. The condi- tional distribution of Y given X = x, is P (Y = y | X = x) = P^ (X P =(Xx,Y=x^ =) y) (if X, Y are

continuous, the definition changes into f (y | X = x) = f f^ (Xx,y (x)) ). The conditional distribution is the probability distribution of the random variable de- fined as Y | X = x (the value of Y conditional on having observed X = x). Then all conditional moments can be defined as moments with respect to the conditional probabil- ity distribution. The conditional mean:

  • μ(x) = μY |X (x) = E(Y | X = x) =

y yP^ (Y^ =^ y^ |^ X^ =^ x) is the conditional mean. The sum is replaced by an integral if Y is continuous

  • Particular case: X is discrete and defined a group membership. For example X is a variable representing gender, say X = 1 means “female”. In this case the conditional

1.4. INDEPENDENCE, COVARIANCE CORRELATION 13

The covariance measures linear dependence between two variables: X, Y can be depen- dent (strongly) but have zero covariance. The viceversa is not true: if X, Y are independent, then they must also have zero covariance.

{Covariance =0 } ⇐ independence {Covariance =0 } 6 ⇒ independence It measures the intensity of the comovement, meaning the concordance of the movement in the same direction with respect to their means. A simpler formula for the covariance: Cov(X, Y ) = EXY − μX μY.

Note that Cov(X, X) = Var(X), by definition. When the covariance is 0, we say X, Y are uncorrelated, because they have zero corre- lation. The correlation between X, Y is the “standardized” covariance:

Corr(X, Y ) = ρXY = Cov(X, Y ) √ Var(X)Var(Y )

σXY σX σY

The correlation is always between -1 and 1 by construction. This follows from a famous inequality known as Cauchy-Schwartz inequality:

Cov(X, Y )^2 ≤ Var(X)Var(Y ).

Example. To show that incorrelation does not imply independence, consider Y = X^2 , where X is a symmetric random variable with mean μX = 0. Then Cov(X, Y ) = EX ·X^2 = 0 because of symmetry, but P (X = x, Y = y) = P (X = x, Y = x^2 ) = P (X = x) if y = x^2 and P (X = x, Y = y) = 0 if y 6 = x^2. So they are not independent because P (X = x, Y = y) 6 = P (X = x)P (Y = y). The correlation is a measure alternative to the covariance:

  • with no scale: 0 ≤ ρ^2 XY ≤ 1
  • If ρXY = 0 then X, Y are uncorrelated
  • If > 0 (< 0) ⇒ rpositive (negative) correlation
  • If = 1 (= −1) perfect positive (negative) linear association: Y = aX + b, for some constants s, b.

An intermediate form of dependence is the independence in mean: Y is mean indepen- dent from X if μ(x) = E(Y | X = x) = μ does not depend on x.

Independence ⇒ Mean independence ⇒ Uncorrelation The converse is not true. Unique exception: if X, Y are Gaussian, then Independence ⇔ Mean independence ⇔ Uncorrelation

14 CHAPTER 1. REVIEW MATERIAL

Figure 1.2: Examples of scatterplots for different values of ρ (Source: Stock and Watson)

1.5 Simple random sampling

The simple random sampling is the simplest sampling mechanism. Consists in the extrac- tion of n independent units from the same population.

  • Choose at random one unit from the population (usually though of as infinite).
  • Observe the corresponding value of the (random) variable: y 1 = first observed value of the variable Y
  • Extract another unit from the entire population (sampling with replacement) and observe y 2 ...
  • and so on
  • The sample obtained is (y 1 ,... , yn) and it consists in n idependent extractions of th same r.v. Y
  • Equivalently, (y 1 ,... , yn) is a realization of a random vector (Y 1 , Y 2 ,... , Yn), with components all independent and identically distributed, with the same probability distribution as Y

The extraction is done with replacement, to allow for independence between the ex- tracted values (mathematically modeled by random variables).

16 CHAPTER 1. REVIEW MATERIAL

First of all, since the sample mean is used to estimate the true, unknown population mean, what would we like mean and variance to be like: (i) The mean of Y¯ should be at least very close to μY , meaning that if we could repeat the sampling, averaging out all estimates obtained we would have a correct value; (ii) We want the estimator to be reliable: in most cases we can’t repeat the sampling, so we need to trust that the observed value of the estimator ¯y is not too far from its mean (and so, from its true value). The first point is related to the concept of unbiasedness of the estimator: an estimator θˆ = T (Y 1 ,... , Yn) for a parameter θ is unbiased if ET = θ. The sample mean is then an unbiased estimator for μ if E Y¯ = μY. The second point is related to the variance of the estimator: we want the estimator to have a low variance, so that it is concentrated around its mean, that coincides with the true value (if the estimator is unbiased). So, we compute mean and variance of the sample mean, that is, the mean and variance of the random variable Y¯. Under simple random sampling:

  • E Y¯ = μ (^) Y¯ = μY (the sample mean is an unbiased estimator for the mean):

E Y¯ = En−^1

∑^ n

i=

Yi = n−^1

i

EYi = n−^1

∑^ n

i=

μY = μY

Note that we only used identical distribution (same mean for all Yi) but not inde- pendence

  • Var( Y¯ ) = σ Y^2 /n, because

Var( Y¯ ) = Var

n−^1

∑^ n

i=

Yi

= (by independence) = n−^2

i

V ar(Yi) = n−^1 σ^2 Y

Here independence is necessary to use the property Var(

i Yi) =^

i Var(Yi). The second property tells us that the variance of the sample mean depends on the variance of the population (the higher the dispersion of the distribution from which we draw our data the lower the reliability of the estimate), and on the sample size (more data implieas more information impleas higher precision of the estimate). This guarantees that, if the sample size is large enough (and the population variance is not infinite), the variance of the estimator becomes arbitrarily low, guaranteeing that the distance between the estimate and the and the population mean is small with increasingly high probability.

Consistency The last concept is formalized by the definition of consistency of an esti- mator: an estimator ˆθ = T (Y 1 ,... , Yn) for a parameter θ is consistent if with probability (converging to) one, the distance θˆ − θ < δ, for any arbitrary δ > 0. It is a property so-called asymptotic, because it involves the behavour of the estimator as the sample size increases (to infinity). Intuitively: if we could observe the whole (infinite) population,

1.7. PROPERTIES OF AN ESTIMATOR: THE SAMPLE MEAN 17

there should be no estimation error and the estimator should concentrate it distribution into the true value. From the expression of the variance, and the fact that E Y¯ = μY , it is evident that

( Y¯ − μy) → 0with probability 1

so, the sample mean is consistent.

MSE. The difference M SE(θˆ) = E(T (Y 1 ,... , Yn) − θ)^2 = E(θˆ − θ)^2 is the squared mean of the difference between the estimator and the true parameter, and it is called mean squared error. If T is an unbiased estimator, then M SE(T ) = Var(T ), because θ = ET (Y 1 ,... , Yn) = E(θˆ). In general, however, there is the decomposition:

M SE(θˆ) = Var(θˆ) + (E(θˆ) − θ)^2

the second term in the right hand side is the square of the bias of θˆ.

Efficiency At a fixed sample size, we could have two estimators for the mean, both un- biased, both consistent. Which one is better? We compare the MSE. The estimator with smallest MSE for our sample size is more efficient. In (rare) cases, there are estimators that can be proved to be the most efficient within a particular class of estimators. The sample mean is one example. The sample mean is BLUE (best linear unbiased estimator), that is the estimator that has the lowest variance among all estimators unbiased for the mean and that can be written as a linear combination of the units (namely, in the form T (Y 1 ,... , Yn) =

i ciYi, for some weights ci)

Asymptotic normality A very useful property of the sample mean, and of many other estimators that can be written as a sum of random variables, it that its sampling distri- bution can be approximated with a Gaussian normal distribution. The precision of the approximation increases with the sample size. In formulas, √ n( Y¯ − μY ) ≈ N (0, σ^2 Y )

where ≈ means that the random variable

n( Y¯ − μY ) is not actually distributed as a N (0, σ Y^2 ) for finite n (that would be written as ∼ N (0, σ Y^2 )), but, if the sample size is large, the approximation can be used as if it was the true sampling distribution. Note that we should write

n( Y¯ − μY ), highlighting the fact that the statistic Y¯ = Y¯n depends on n, because it is proportional to the sum of the n observations of the variable Y , and, because of that, its sampling distribution also depends on n. This result is a consequence of the famous central limit theorem (CLT).

1.8. SAMPLE VARIANCE 19

1.8 Sample variance

One of the most important statistics, is the sample variance:

s^2 Y =

n − 1

∑^ n

i=

(Yi − Y¯ )^2.

The statistic s^2 Y is an estimator for the variance of the population distribution of the variable Y.

  • Unbiasedness: s^2 Y is an unbiased estimator of σ Y^2 :

Es^2 Y =

n − 1

i

E(Yi − Y¯ )^2 =

n − 1

i

E(Yi − μY + μY − Y¯ )^2 =

n − 1

i

E(Yi − μY )^2 +

n − 1

i

E( Y¯ − μY )^2 − 2

i

n − 1

E(Yi − μY )( Y¯ − μY )

n − 1

nσ Y^2 +

n − 1

n σ Y^2 n

n − 1

E(

i

Yi − nμY )( Y¯ − μY )

n + 1 n − 1

σ^2 Y − 2 n n − 1

E(

i

Yi n

− μY )( Y¯ − μY )

n + 1 n − 1 σ^2 Y − 2

n n − 1 E( Y¯ − μY )^2

= n + 1 n − 1

σ^2 Y −

n − 1

σ Y^2 = σ^2 Y

  • Consistency: if {Yi} ∼ iid and E(Y (^) i^4 ) < ∞, then S Y^2 is consistent S^2 Y →p σ^2 Y

We call SY the standard deviation The statistic SY /

n is an estimator of the standard error of Y¯ (SE( Y¯ ) = σ/

n),

1.9 Confidence intervals

A confidence interval for μY : a (random) interval that contains the parameter μY with a pre-determined probability, called confidence level 1 − α (usually, 0.95 or 0.99). If the variance of Y , σ^2 Y , is known: [ (^) ¯ Y ± z 1 −α/ 2 SE( Y¯ )

]

[ ¯

Y ± z 1 −α/ 2 σ/

n

]

If the variance of Y is not known, but it is estimated by s^2 Y : [ Y¯ ± tn− 1 , 1 −α/ 2 ̂SE( Y¯ )

]

[ ¯

Y ± tn− 1 , 1 −α/ 2 SY /

n

]

20 CHAPTER 1. REVIEW MATERIAL

The construction of the confidence interval relies on the asymptotic normal approxima- tion for X¯. Ex. n = 200, Y¯ = 22.64$, SY = 18.14, t 199 , 0. 975 ≈ 1 .96,

IC = [20.13; 25.15]

Because of the asymptotic Gaussian approximation (and because of the fact that the higher n the more a Student-t r.v. with n − 1 degrees of freedom is similar to a standardized Gaussian, you can replace the quantiles of the Student distribution with the normal if n is large: [ Y¯ ± z 1 −α/ 2 SÊ ( Y¯ )

]

[ ¯

Y ± z 1 −α/ 2 SY /

n

]

A similar reasoning can be applied to any parameter. A confidence interval for an arbitrary scalar parameter θ, for which we have an asymptotically normal estimator θˆ,

with estimated standard error SÊ (θˆ), the confidence interval at level 1 − α is:

[ θˆ ± z 1 −α/ 2 ̂SE(θˆ)

]

= [θˆ − z 1 −α/ 2 SÊ (θˆ); θˆ + z 1 −α/ 2 ̂ SE(θˆ)].

1.10 Tests on the mean

We want to test whether a certain hypothesis on the population mean is true or not (is the average income lower than a certain level? Is the percentage of students who have mathematical skills below or above the European average?...), using evidence from the data. The test paradigma is composed of the null hypothesis (H 0 ) and the alternative (H 1 ), the is what we assume is true if the null is rejected (true unless verified otherwise).

Possible states Decision H 0 H 1

Acceptance H 0 1 − α β [Confidence] Type I error probability

Rejection H 0 α 1 − β Type I error probability Power of the test Significance of the test

Suppose we want to test the simple hypothesis μY = μ 0. We can have different altena- tives: H 1 : μY > μ 0 , H 1 : μY < μ 0 (two one-sided alternatives), H 1 : μY 6 = μ 0 , two sided alternative. If the variance σ^2 Y is unknown but estimated by s^2 Y :