Docsity

Business Analytics & Statistics, Appunti di Statistica Economica

Toggle sidebar
bg1
BUSINESSSTATISTICS
The relationship between two variables
The relationship between two variables can be expressed using a regression model or a
correlation coefficient.
A regression model is a mathematical equation that allows us to evaluate the magnitude of
change in one variable due to a certain change in another variable or predict the value of
one variable for a given value of another variable.
The correlation coefficient, on the other hand, simply tells us how strongly two variables
are related. It does not provide any information about the size of the change in one variable
as a result of a certain change in the other variable.
Independent and dependent variables
What factors or variables does a family consider when deciding the amount of money to be
spent on food each month? Certainly, their income is one factor.
However, many other variables also affect food expenditure: the numerosity, the preferences
of the family members, or any special dietary needs they require.
These variables are called independent or explanatory variables Xi since they all vary
independently, and they explain the variation in food expenditures among different
families.
In other words, these variables explain why different families spend different amounts of
money on food.
Food expenditure is the dependent variable Y since it depends on the independent variables.
Studying the effect of two or more independent variables on a dependent variable using
regression analysis is called multiple regression.
However, if we choose only one (usually the most important) independent variable and
we study its effect on a dependent variable, it is called a simple regression.
So, a simple regression includes only two variables: an independent and a dependent.
Note that whether it is a simple or a multiple regression analysis, it always includes just one
dependent variable.
The thing that changes between simple and multiple regressions is the number of
independent variables.
An economist can estimate the amount of
change in food expenditure due to a
certain change in the income of a
household by using the regression model.
We can predict the (approximate) food
expenditure of a household with a given
income.
MULTIPLE
REGRESSION
SIMPLE
REGRESSION
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

Anteprima parziale del testo

Scarica Business Analytics & Statistics e più Appunti in PDF di Statistica Economica solo su Docsity!

The relationship between two variables

The relationship between two variables can be expressed using a regression model or a

correlation coefficient.

A regression model is a mathematical equation that allows us to evaluate the magnitude of

change in one variable due to a certain change in another variable or predict the value of

one variable for a given value of another variable.

The correlation coefficient , on the other hand, simply tells us how strongly two variables

are related. It does not provide any information about the size of the change in one variable

as a result of a certain change in the other variable.

Independent and dependent variables

What factors or variables does a family consider when deciding the amount of money to be

spent on food each month? Certainly, their income is one factor.

However, many other variables also affect food expenditure: the numerosity , the preferences

of the family members, or any special dietary needs they require.

These variables are called independent or explanatory variables X i since they all vary

independently, and they explain the variation in food expenditures among different

families.

In other words, these variables explain why different families spend different amounts of

money on food.

Food expenditure is the dependent variable Y since it depends on the independent variables.

Studying the effect of two or more independent variables on a dependent variable using

regression analysis is called multiple regression.

However, if we choose only one (usually the most important) independent variable and

we study its effect on a dependent variable, it is called a simple regression.

So, a simple regression includes only two variables: an independent and a dependent.

Note that whether it is a simple or a multiple regression analysis, it always includes just one

dependent variable.

The thing that changes between simple and multiple regressions is the number of

independent variables.

An economist can estimate the amount of

change in food expenditure due to a

certain change in the income of a

household by using the regression model.

We can predict the (approximate) food

expenditure of a household with a given

income.

MULTIPLE

REGRESSION

SIMPLE

REGRESSION

Properties of the residual term 𝜺

𝒊

"

"

The variance of the errors is constant ∀

"

In this case we speak of homoscedasticity , which means «having the same scatter».

For it to exist in a set of data, the points must be about the same distance from the line,

as shown in the picture above.

The opposite is heteroscedasticity (“different scatter”), where points are at widely

varying distances from the regression line.

Simple Linear Regression model

The graph resulting from the equation of the regression model can assume different shapes,

including a straight line.

In this case, we speak of a linear regression model; otherwise, of a non-linear one.

Considering p explanatory variables +𝑋

$

%

/ and assuming that the relationship is

linear, the equation would be written as:

&

$

$

%

%

where:

&

is the intercept, so the expected value of Y when x is 0 à 𝛽

&

"

(𝑖 = 1 , 2 , … , 𝑝) is the regression coefficient: the slope (pendenza) of the line.

In real life the relation is (almost) never exact, so we must add an error term (𝜀), also known

as “noise”.

&

$

$

%

%

"

The relationship may be incorrect for several reasons:

o the relationship may not be linear.

o there could be other variables (not considered and/or not observable) that affect Y.

o there may be errors of measurement of the variables.

PROBABILISTIC MODEL

DETERMINISTIC MODEL

PART 1

The expectation of Y given a level of x is equal to:

"

"

&

$

"

The variance of Y given a level of x, instead, is equal to:

[(𝛽

&

$

"

"

"

] = 𝜎

&

"

[(𝛽

$

"

"

] + 𝜎

"

OLS method

In order to determine the unknown parameters 𝛽

&

"

and 𝜎

we have different options.

One of these is the Ordinarily Least Squares (OLS), which is a geometrical method.

Estimation of 𝜷

𝟎

and 𝜷

𝒊

Let’s consider a cloud of points representing a sample

data and a regression function.

A generic point with coordinates (𝑥

"

"

) will have its

projection on the regression function with a point with

coordinates (𝑥

"

; 𝑦N

"

The same for each point: there will be a different distance for

the observed value 𝑦

"

and the expected one 𝑦N

"

The aim is to find a straight line where the sum of the square

distances between 𝑦

"

and 𝑦N

"

is minimized.

In fact, by summing all the distances between the expected values and the observed ones I

would have a problem, since sometimes the distance is sometimes negative and sometimes

positive (we can have an excess or a deficit).

The variance

of a constant

term is 0

Since we fixed the

level of 𝑥, not only 𝛽

!

is a constant, but also

𝑥.

The variance of

the error term is

constant: 𝜎

"

The variability of Y is equal to the variability of the noise term 𝜀.

As a result, the behavior of the dependent variable Y is equal to a normal random variable with

expectation 𝛽 &

"

"

and variance 𝜎

[(

&

$

"

]

𝑦" !

= 𝛽 "

  • 𝛽

𝑥 !

𝑦"

!

= 𝛽

"

  • 𝛽

𝑥

!

That’s why we should consider a squared distance: this way, all distances are positive

numbers, obtaining the minimum distance.

O

"

− 𝑦N

"

"+$

Since 𝑦N "

is equal to 𝛽

&

$

"

, we can rewrite the formula like:

O

"

&

$

"

"+$

"

and 𝑥

"

are my observed value in the sample: they are numbers.

On the other hand, 𝛽

&

and 𝛽

$

are unknown parameters.

So, this formula is a function of 𝛽 &

and 𝛽

$

: by changing even one of these two parameters,

the function will change.

&

$

) = O(𝑦

"

&

$

"

"+$

Now, our goal is to find the parameters 𝜷 𝟎

S

and 𝜷

𝟏

S

by which the function 𝑆(𝛽

&

S

$

S

) is a

minimum.

&

S

$

S

To do so, we need to we calculate the first derivative with respect to both, putting them

together in a system equal to zero.

Solving this system, we will obtain the values of 𝛽

&

S

and 𝛽

$

S

$

S

-.

-.

&

S

= 𝑦T − 𝛽

$

S

&

S

and 𝛽

$

S

are the Best Linear Unbiased Estimators (BLUE) about the true value of 𝛽

$

S

and

$

S

in my population since they represent the average of all possible values of 𝛽

&

S

and 𝛽

$

S

of

all possible samples drawn out of the population.

𝑦"

!

= 𝛽

"

  • 𝛽

𝑥

!

OBSERVED

POINT

Example

Goodness of fit: R

2

Having calculated the estimators, we can finally obtain our model, whose goodness of fit

still has to be verified.

In order to do so, we start by considering our sample data with 𝑛 observations.

As a result, we will have 𝑛 possible values for 𝑋 and 𝑌.

As we know, the numerator of the variance is the deviance

We can see that the deviance ( SSR ) is breakable in the sum between SSR and SSM, where:

  • SSR is the distance between the observed value 𝑦

"

and its projection on the regression

curve 𝑦N

"

  • SSM is the distance between 𝑦N

"

and the average value of the observations in the

sample

MS Residual is my

estimate of the

variance of the error

term.

It is also the variance

of the dependent

variable Y.

Root MSE is the

standard error of the

error term (so, it is

the root squared of

MS Residual)

𝛽

%

𝛽

!

%

It shows us the distance between the

observed values and the average one

in the sample data.

The standard error is a measure of the variability of the coefficients by

changing the sample data: the higher it is, the more probable it is that by

changing sample, the corresponding coefficient will vary dramatically.

With a low standard error, we can conclude that the coefficient is stable.

By dividing everything for SST we will obtain:

𝟐

is an index that gives us a measure of the goodness of fit of the regression line to the

observed values.

Why? Since it measures the fraction of variability explained by the linear regression with

the 𝑿 variable.

So, the higher 𝑅

is, the higher is the goodness of fit.

Generally, when:

= 1 à 𝑆𝑆𝑇 = 𝑆𝑆𝑀

All variability of Y is explained by the regression function. So, the goodness of fit is

perfect: the regression line passes exactly through the points.

= 0 à 𝑆𝑆𝑇 = 𝑆𝑆𝑅

All variability of Y is explained by other factors.

Degree of freedom and MS

It shows the fraction of

variability of Y

explained by other

factors.

It is a value

between 0 and 1

𝟐

coefficient

EXTRA

The null hypothesis is equivalent to saying that the variable 𝑋 doesn’t affect the variable 𝑌.

So, if the null hypothesis turns out to be true, then the t-statistics would be a particular

random variable: a t-student random variable with 𝑛 − 𝑝 − 1 degree of freedom.

$

S

$

S

  • 1 % 1 $

It is a continuous random variable (−∞; +∞) with:

  • a shape similar to the one of a normal random variable
  • the expected value fixed at 0
  • only one parameter (the degree of freedom), changing

which would also change the density distribution.

If the degree of freedom increases by >1000, the density distribution of the t-student will

tend to the one of a standardized normal random variable:

When we calculate the 𝑡 − 𝑠𝑡𝑎𝑡𝑖𝑠𝑡𝑖𝑐𝑠 we need to check if it is inside the acceptance area or if

it is in the tails.

If the sample come from the null hypothesis, I know that 𝑡 is a t-student random variable: I

expect to have its value around the expected one (which in this case is 0).

If 𝑡 is in the tails, I suppose that the sample come from the alternative hypothesis: we reject

the null hypothesis.

So, we need:

  • First, to calculate the t-value, obtaining t-observed
  • Then, I calculate the probability to observe values rarer than the t-value, obtaining

the p-value (that, graphically, is represented by the sum of the areas of the tails):

o if the p-value is small, I reject the null hypothesis. So, my conclusion is that

the sample comes from the alternative hypothesis.

o if the p value is high, I accept the null hypothesis

In order to understand if the p-value is small

or not, we fix a significance level 𝜶 of the

test, normally at 0.05 or 0.01.

𝒑 − 𝒗𝒂𝒍𝒖𝒆 > 𝜶 → 𝑰 𝒂𝒄𝒄𝒆𝒑𝒕 𝒕𝒉𝒆 𝒏𝒖𝒍𝒍 𝒉𝒚𝒑𝒐𝒕𝒉𝒆𝒔𝒊𝒔

𝒑 − 𝒗𝒂𝒍𝒖𝒆 < 𝜶 → 𝑰 𝒓𝒆𝒋𝒆𝒄𝒕 𝒕𝒉𝒆 𝒏𝒖𝒍𝒍 𝒉𝒚𝒑𝒐𝒕𝒉𝒆𝒔𝒊𝒔

EXTRA

Example

Since the p-value of the parameter “square feet” is lower

than 𝛼 (0.05), we can say that the value under the heading

“Coef.” is significant: it tells us: it tells us how much the

dependent variable increases or decreases as a unit of that

parameter increases

Interpretation: a unit increase in the squared footage

would lead to an increase in the average home price of

The confidence interval gives us information about the probability to have

the true value of the parameter inside that range of values.

In this case, we have a 95% of confidence (probability) that the interval

[1.014; 1.412] includes the true value of the parameter “sqft”.

Therefore, since this interval doesn’t include 0, we can suppose that in my

population 𝛽

$

is different from 0. So, come to the same conclusion of the

one when we considered the p-value à we reject the null hypothesis.

The same for the second interval, which refers to the one of the constant

term: the interval only includes negative values. So, since it doesn’t

include 0, we suppose that 𝛽

&

in my population is different from 0, arriving

to the same conclusion of the one when we considered the p-value.

The higher the t-value, the lower the p-

value will be, because as we approach

the tail, the area of probability of

having a rarer value of 𝑡 shrinks.

Normal Q-Q: comparison between

theoretical percentiles of the standardized

Normal distribution and the percentiles of

standardized residues.

The hypothesis of normality of residuals is not

violated if the points are approximately

arranged along the diagonal of the graph.

Residuals vs Leverage: Cook’s

Distance

Cook’s Distance measures how much

all the fitted values in the model

change when the 𝑖

'(

data point is

deleted.

A data point that has a large value for

Cook’s Distance indicates that it

strongly influences the fitted values.

A general rule of thumb is that any

point with a Cook’s Distance over 4 /𝑛

is an outlier.

We can have three types of outliers:

o First type : a value of Y very different from the

whole sample but not X

o Second type : values of X and Y very different

from the whole sample

o Third type : a value of X very different from the

whole sample but not Y

Spurious correlation

It is possible that we observe a correlation between Y and X values, so that we conclude that

one of the two variables depend on the other.

However, there might be a third unobservable variable Z that influences both X and Y

variables, and we might come to a wrong conclusion due to this.

This is the case of the apparent relationship between hair length and stature, that might

seem correlated. However, in the middle we have the gender: females are generally shorter

than males, and they have longer hair; males, instead, are generally taller than females and

have shorter hair.

We need to run a multivariate analysis , which considers more than one explanatory

variable.

Multiple Linear Regression model

In simple linear regression model, we only had 𝑌 and 𝑋 variables.

So, the representation of my sample data was a cloud of points

described by a straight line written as 𝑌 = 𝛽

&

$

"

It is a space with dimension R

If we have two explanatory variables, we have

a tridimensional space (R

) given by 𝑌, 𝑋

$

and

variables. In this case, the regression

function 𝑌 = 𝛽

&

$

$

represents a

plane, whose position depends on 𝛽

$

and 𝛽

Again, considering a space with 3 explanatory variables, we will have a fourfold space given

by 𝑌, 𝑋

$

and 𝑋

2

variables. My cloud of points will be represented by the regression

function 𝑌 = 𝛽

&

$

$

2

2

, which describes a hyperplane.

Unbiased estimator of the variance of the error term

An unbiased estimator of the variance of the error term 𝜎 0

is

where 𝑘 is the number of predictors (explanatory variables) in the model. It also

represents, in a certain way, the complexity: the more variables I have, the more complex

the model will be and the more the model will fit:

As the explanatory variables

increase, the fitting level 𝑅

also

increases.

However, considering the level of

fitting as the only criterium, we

will arrive at a model that

explains the data almost perfectly,

but which will be too complex.

So, first, we need to check the global test and verify if at least one explanatory variable inside

my model is significant: P-test of F has to be smaller than 𝛼.

Then, we can move on to the verification of each explanatory variable.

We have to wait since it could happen that by looking at the p-values of each parameter

right away, we might come to consider significant some parameters that in reality are not

(because perhaps the p-test of F is greater than alpha).

In this case, we can see that the p-test of F is almost 0: so, at least one of my parameters is

significant.

Then, checking each variable, we can see that only 4 variables are significant since they are

the only ones smaller than alfa.

Which is the most influential variable?

Generally, the variable with the minimum p-value is the most influential one. However, to

be sure we need to check the standardized values (generally under the heading “Beta”).

Looking at the coefficients, we might conclude that “cor” is the most influential one.

However, those values are biased by the measurement units: if we look at the column

“Beta”, which represents the standardized values, we can see that the most influential one

is “sqft”.

We need to consider the highest number in absolute terms.

Model selection

Generally, we start considering a large set of explanatory variables. How can we select the

right set of explanatory variables? We need a criterium that allows us to include only the

most important ones.

We have different options of selection:

à Backward selection à Forward selection à Stepwise selection

Using one method or another can bring to different results.

Backward selection

We start from considering the full model with all the

explanatory variables. In this case we consider a model with 4

different explanatory variables.

For each coefficient we have our P-value (the T-test):

Among all the p-values, I consider the 𝑃 345

, which in this case is 𝑝

Fixing a value of alfa at 0.05, we see that 𝑝

is greater than 0.05. So, we drop this variable.

Now, we consider a model of 3 different variables (without 𝑋

Now, 𝑃

345

is 𝑝

2

I compare it with alfa=0.05 and we can see that,

still, 𝑝

2

is greater than alfa à we drop this

variable too, arriving to a model of 2 variables.

In this case, 𝑝

$

= 0 , 015 is the 𝑃

345

, and it is smaller than alfa.

So, we stop here with a 2-variables-model.

Forward selection

Once again, we start with a model of 4 explanatory variables:

In this case we consider the 𝑃

367

between these four P-values, which is 𝑝

2

If 𝑃 367

is smaller than alfa, like in this case, then it remains in the model and it will be added

to the other variables:

Now, 𝑃

367

is 𝑝

= 0 , 001 , which is smaller than alfa. So, I

include it together with 𝑝

2

367

is 𝑝

$

= 0 , 08 , which is greater than alfa. So, I do not include it in my model, and I stop

here since if the 𝑃

367

is not enough small, then the other remaining variables will most

certainly too big.

In this first equation I try to check if 𝑋

$

is a linear combination of the other explanatory

variables.

To check the level of fitting, I consider 𝑅 $

, that if it is close to 1, there may be linear

correlation.

In this case the VIF tend to +∞, since it increases if there is a strong linear relationship with

the dependent variable and the other explanatory variables.

We set 5 as a cut-off of the level of VIF: if it is greater than 5 the linear relation is strong.

Example

In this case, these three variables have a value of VIF greater

than 5. So, we conclude that there is multicollinearity.

How do we proceed?

We re-estimate the model by dropping step-by-step these

variables (starting from the one with the highest level of VIF),

and then recalculating the VIF each time.

One-way ANOVA

The (one-way) ANOVA model is an instrument to compare the means of our dependent

variable among different samples, considering the variability around the average value.

In this case we consider a quantitative variable as dependent variable and only one

qualitative variable.

So, we want to understand if by changing the modalities of the qualitative variable, the

expectation of Y (quantitative variable) will change significantly.

Its validity requires that the following assumptions hold:

1. homoscedasticity: if I consider different modalities of the X variable, the variability

of our dependent variable Y doesn’t change

2. the behavior of Y, given different modalities, is a normal random variable 3. the samples associated with the treatments are independent samples

If I change treatment, the variability of each remains constant. The values of Y for each

treatment are like a normal random variable with average value 𝜇

"

Recoding a qualitative variable in quantitative terms

Considering a qualitative variable X (=Residential zone), with three possible modalities:

North, Centre, South.

If I want to put this information in my model, I need to recode this qualitative variable in a

quantitative way.

How can we do this?

By transforming it in 𝑘 − 1 dummy variables, where 𝑘 indicates the number of modalities.

DEMONSTRATION :

If we consider three dummy variables, each indicating a particular modality of X, we’ll have:

Dummy North

it has value 1 when

X is equal N and 0

otherwise

Dummy Central Dummy South

Modalities of the

qualitative variable X

Observations

Dummy variables

North

𝑵

𝑪

𝑺

N 1 0 0

C 0 1 0

Centre

N 1 0 0

S 0 0 1

South

C 0 1 0

N 1 0 0

S 0 0 1

We can see that “Dummy South” is obtained as 𝟏 − 𝑫𝒖𝒎𝒎𝒚 𝑵𝒐𝒓𝒕𝒉– 𝑫𝒖𝒎𝒎𝒚 𝑪𝒆𝒏𝒕𝒓𝒂𝒍

So, one dummy variable is obtainable as a linear regression of the other two.

This means that we have a redundant information: in this case, if I put in my model 3

dummy variables, I generate multicollinearity.

This is why we need to include k-1 dummy variables.

If I decide to drop south, it will become the so called “ base modality ”.

Considering “South” as base modality, then 𝛽

&

will represent the expected value of Y for

the base modality South.

So, the model will be:

If 𝑖 belongs to “South”, then 𝛽 $

and 𝛽

will be equal 0.

If 𝑖 belongs to “North”, then 𝛽

will be equal 0.

If 𝑖 belongs to “Centre”, then 𝛽

$

will be equal 0.

We can imagine 𝐷

!

, 𝐷

"

, etc. as 𝑋

!

, 𝑋

"

, since they

are simply variables, with the characteristics of

being dummy (which isn’t always specified)