Warning: Bad notes below. May be misleading or contain serious errors.Please see Regression analysis for an attempt to summarise the topic better. Statistical program: STATA - Easier and better than SPSS## Statistical concepts## Random variable**Random variable**:Â In probability and statistics, a random variable or stochastic variable is a variable whose value is not known.- Two types:
**Discrete variable**: Can only take a limited number of values, e.g. number of computers in household (0,1,2,3).**Continous variable**: Can take any value, e.g. the interest rate, stock market indexes, household income.**Expected value**:Â The expected valueÂ of a random variable is the weighted average of all possible values that this random variable can take on.- E(x) =Â Î¼Â
- With constant: E(a) = a
- E(a * x) = a * E(x)
- E(a * x + b) = a * E(x) + b
**Variance**: The larger the variance, the greater the spread of the numbers. E.g. 0-40 have a larger variance than 10-30. Can never be negative(?). Denoted by:Â- Ïƒ
^{2} - var(x) =Â Ïƒ
^{2}= E(x - E(x))^{2}= E(x^{2}) - (E(x))^{2}Â - Two constants a and b that we take the variance of:
- Var(ax + b) = a
^{2}Â * Var(x) - Use definitions above: Var(ax + b) = E[ax + b - E(ax + b)]
^{2}Â - Var(ax + b) =Â E[ax + b - a *Â Î¼ - b]
^{2}Â - Var(ax + b)Â =Â E[ax - aÎ¼]
^{2}Â = E[a(x-Î¼)]^{2}Â - Var(ax + b)Â = a
^{2}* E(x -Â Î¼))2 = a^{2}* Var(x) **Two**random variables in combination: E(ax + by) = a * E(x) + b * E(y)**n (any)**number of random variables: x1, x2, ..., xn random variables:- E(a1x1 + a2x2 + ... + anxn) = a * E(x1) + a2 * E(x2) + ... + an * E(xn)
**Covariance**: cov(x, y) = E(xy) - E(x) * E(y)- If x and y are independent: E(xy) = E(x) * E(y) then cov(x, y) = 0
- If independent or correlated variables: var(ax + by) = a
^{2}* var(x) + b^{2}* var(y) - If correlated, add the following at the end: +/- 2 * ab * cov(x, y)
**Correlation coefficient**:Â- P(x, y) = cov(x, y) / sqrt(var(x) * var(y))
- -1 <= P <= 1
- If all numbers form a downward sloping straight line, we have a perfect negative linear relationship, if upward sloping, positive relationship. If all dots are placed randomly, then there's no correlation. If they form an U, it's a perfect non-linear relationship.
Example B7:x1, x2, ..., xn are independent random variables with the same probability distribution with meanÂ Î¼ (the expected value) andÂ Ïƒ ^{2}.x =Â Îµx/nE( x) = E(Îµx/n) = 1/n * [E(x1) + E(x2) + .... + E(xn)]= 1/n * [Î¼ +Â Î¼ + ..... +Â Î¼] = n *Â Î¼ / n =Â Î¼ We want to find the variance. Because they're independent, the covariance between each pair of random variables = 0: Var( x) = Var(1/n *Â Îµx) = 1/n^{2} * [Var(x1) + Var(x2) + ... + Var(xn)]= 1/n ^{2} * [Ïƒ^{2} +Â Ïƒ^{2} + ... +Â Ïƒ^{2}] = nÏƒ^{2} / n^{2} =Â Ïƒ^{2} / nExample B8:y1, y2, y3 is a sample of observations from N(Î¼,Â Ïƒ ^{2})cov(y1, y2) = cov(y1, y3) = cov(y2, y3) = 0.5 *Â Ïƒ ^{2}y = (y1 + y2 + y3) / 3a) E (y) = E((y1 + y2 + y3) / 3) = 1/3 * [E(y1) + E(y2) + E(y3)]= 1/3 * (Î¼ +Â Î¼ +Â Î¼) = 3Î¼ / 3 =Â Î¼ We want to find the variance. Variables are not independent so we have a covariance: Var( y) = Var((y1 + y2 + y3) / 3)= 1/3 ^{2} * [Var(y1) + Var(y2) + Var(y3) + 2 * cov(y1, y2) + 2 * cov(y1, y3) + 2 * cov(y2, y3)= 1/9 * [Ïƒ^2 +Â Ïƒ^2 +Â Ïƒ^2 + 2 * 0.5Ïƒ^2Â + 2 * 0.5Ïƒ^2Â + 2 * 0.5Ïƒ^2] = 6Ïƒ^2 / 9 = 2/3 *Â Ïƒ^2 ## DistributionNormal distribution. Wikipedia: "In probability theory, the normal (or Gaussian) distribution, is a continuous probability distribution that is often used as a first approximation to describe real-valued random variables that tend to cluster around a single mean value"Example: f(x) = 1/sqrt(2Ï€Ïƒ ^{2}) * exp -(x-Î¼)^{2} / 2Ïƒ^{2}x ~ N(Î¼,Â Ïƒ ^{2})Z = (x -Â Î¼) /Â Ïƒ E(Z) = E((x -Â Î¼)/Ïƒ) = (E(x) -Â Î¼)/Ïƒ = (Î¼-Î¼)/Ïƒ = 0 Var(Z) = Var((x -Â Î¼)/Ïƒ) = Var(x/Ïƒ) = 1/Ïƒ^2 * Var(x) =Â Ïƒ^2 /Â Ïƒ^2 = 1 Z ~ N(0,1) Normal variable: f(x) = 1/sqrt(2Ï€Ïƒ^2) * e^(-(x-Î¼)^2/(2Ïƒ^2) Z ~ N(0,1) Example B12:A mutual fond. Its value is normally distributed. x = Annual rate of return for a certain mutual fund Z ~ N(0.10,0.04^2) a) What is the probability of getting a negative return for this fund? We have to transform the x variable to standard normal: P(x < 0) = P((x -Â Î¼)/Ïƒ < (0 -Â Î¼)/Ïƒ) = P(Z <Â (0 -Â Î¼)/Ïƒ) =Â P(Z <Â (0 -Â 0.10)/0.04) =Â P(Z < -2.5) = 1 -Â P(Z < -2.5) = 1 - 0.9938 = 0.0062 The probability of getting a negative one-year rate of return is 0.62% b) What is the probability of getting a return higher than 15%? Transform x to standard normal: P(x > 0.15) = P((x -Â Î¼)/Ïƒ > (0.15 -Â Î¼)/Ïƒ) =Â P(Z >Â (0.15 -Â 0.10)/0.04) =Â P(Z > 1.25) Because we're looking for a certain area in the graph, we must reverse sign: = 1 - P(Z < 1.25) = 1-0.0944 = 0.1056 Probability 10.56% c) The fund manager can raise the mean (average?) return to 12%, but the risk will increase as well (standard deviation = 5%). Would you advice the manager to make this portfolio change? They could increase the expected value to 12% but the standard deviation would increase to 5%: (x ~ N(0.10,0.04^2)) / (x ~ N(0.12,0.05^2)) In a) we get: P(x < 0) = P((x -Â Î¼)/Ïƒ < (0 -Â Î¼)/Ïƒ) = P(Z <Â (0 -Â Î¼)/Ïƒ) =Â P(Z <Â (0 -Â 0.12)/0.05) =Â P(Z < -2.4) = 1 -Â P(Z < -2.4) = 1 - 0.9918 = 0.0082 The probability of having a negative return is now 0.82% which is higher than before the change. In b) we get: P(x > 0.15) = P((x -Â Î¼)/Ïƒ > (0.15 -Â Î¼)/Ïƒ) =Â P(Z >Â (0.15 -Â 0.12)/0.05) =Â P(Z > 0.60) Because we want a certain probability we must reverse sign: = 1 - P(Z < 1.25) = 1-0.07257 = 0.2743 The probability of getting a higher return is now 27.43% which is also higher than before the change. Conclusion: The probability of having a negative return as well as a higher return increases. Our choice depends on the mutual fund manager's risk preference. If he's risk avert, he might want to choose the first option. ## Simple linear regression modelOne dependant variable that depends on one or more explanatory variables Measures the linear association between two variables. Can answer questions like: How does economic growth affect poverty? What is the economic value of a public good like forests or clean air? What is the correlation between smoking and cancer? We also want to explain how much. That's the difference between correlation and regression analysis. We don't just want to know if there's a positive or negative relationship, but how much one variable changes if the other changes. We have different types of data:- Cross-sectional data: Data collected at a certain point of time. E.g. what's household income in Sweden at the end of 2009? Unemployment at a 1 Jan 2011?
- Time series data: Data collected over several years. E.g. the daily profits from a company or the inflation rates per month.
- Panel data: A mix between the two above. Multi-dimensional data (the two above are one-dimensional). Panel data contains observations on multiple phenomena observed over multiple time periods for the same firms or individuals. The database called Linda, containing records of many individuals in Sweden, is an example of such data.
Example:Let's say we want to examine the relationship between household income and expenditure on food. Simple economic theories state that the average household expenditures depend on household income. E(y|x) = Î²1 + Î²2 * x An upward sloping line. Î²1 =Â Even if people have 0 income they'll have some income (by taking loans etc). This is denoted. Î²2Â = The slope of the line If income changes by 1 unit, the expenditures will change by the following: Î²2Â = dE(y|x)/dx Because we're measuring average values, this means we can have some variance.Â y = The observed value ei = yi -Â Î²1 - Î²2 * xi This gives us the linear regression model: yi =Â Î²1 + Î²2 * xi + ei In this model, we have just one explanatory variable. Assumptions in linear regression models:- Linear model: y =Â Î²1 + Î²2 * x + e
- Expected value: E(e) = 0
- Variance: var(e) =Â Ïƒ
- Covariance: cov(e
_{i}, e_{j}) = 0 - The variable x is not random and must take at least two values. If there's no variance in x, it's a constant, and we can not estimate any relations.
- eÂ ~ N(0,Â Ïƒ
^{2})
In cross-sectional data, the variance is most likely not constant. We have some problems with assumption 3). In time-series data, we have dependancy over time, so most likely we have covariance, which is problematic with 4). Least Squares Principle - If we have a linear model with variance. We want to find the varianceÂ Î²1 + Î²2 that minimizes the sum of Â square errors.In the example above, we know that: ei = yi -Â Î²1 - Î²2 * xi We want to use summation on the equation: sum(ei)^2 = sum(yi -Â Î²1 - Î²2 * xi)^2 And derivate: (âˆ‚ sum(ei)^2)/(âˆ‚Â Î²2)Â = 2 *Â sum(yi -Â Î²1 - Î²2 * xi) * (-1) = 0 (âˆ‚ sum(ei)^2)/(âˆ‚Â Î²2)Â = 2 *Â sum(yi -Â Î²1 - Î²2 * xi) - (xi) = 0 -2 *Â sum(yi) + 2NÎ²1 + 2Î²2 * sum(xi) = 0 -2 *Â sum(xi) * yi + 2Î²1 * sum(xi) + 2Î²2 * sum(xi^2) = 0 We changeÂ Î² into b: sum(yi) - Nb1 - b2 * sum(xi) = 0 sum(xi) * yi - b1 * sum(xi) - b2 * sum(xi^2) = 0 Nb1 + b2 * sum(xi) = sum(yi) Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (1) b1 * sum(xi) + b2 * sum(xi^2) = sum(xi) - yi Â Â Â (2) From (1) we get that: Nb1 + b1 * sum(xi) = sum(yi) Nb2 = sum(yi) - b1 * sum(xi) b1 = sum(yi)/N - b2 * sum(xi)/N b1 = y - b2 * xWe now want to find out b2. We do it by multiplying (1) by sum(xi) and multiply (2) by N: Nb1 * sum(xi) + b2(sum(xi))^2 = sum(xi) * sum(yi) Nb1 * sum(xi) + Nb2 * sum(xi^2) = N * sum(xi) * yi Nb1 * sum(xi) - Nb1 * sum(xi) + Nb2 * sum(xi^2) - b2(sum(xi))^2 = N sum(xi) * yi - sum(x) * sum(y) We divide by N: Nb2/N * sum(xi^2) - (b2 * sum(xi^2)) / N = (N * sum(xi) * yi) / N - (sum(x) sum(y)) / N b2 * ((sum(x^2) - (sum(x))^2)/N) = sum(x) * y - (sum(x) * sum(y))/N b2 = (sum(x) * y - (sum(x) * sum(y)) / N) / sum(x^2) - (sum(x))^2/n yÂ = b1 + b2 * xÎµ = d y / dx * x /Â y = b2 * x/yIf x increases by 1% then an average y changes by (b2 *Â x/y)%Summary - equations:- y =Â Î²1 + Î²2 * x + e
__y__Â = b1 + b2 * x- b1 =Â
__y__Â - b2 *Â__x__ - b2 = ((sum(x) * y - (sum(x) * sum(y)) / N) / (sum(x^2) - (sum(x))^2/n) = (sum(x-
__x__)(y-__y__)) / sum(x-__x__)^2
Making use of 4) we get: b2 =Â (sum(x- x)(y-y)) / sum(x-x)^2= (sum(x- x) * y - y * sum(x-x)) / sum(x-x)^2= (sum(x- x) * y) / sum(x-x)^2wi = (xi - x) / sum(xi - x)^2b2 = sum(wi) * yi = sum(wi) * (Î²1 +Â Î²2 * xi + ei) =Â Î²1 * sum(wi) +Â Î²2 * sum(wi) * xi + sum(wi) * ei sum(wi) = ? sum(xi - x) / sum(xi - x)^2 = 1/sum(xi - x)^2 * sum(xi-x) = 0sum((wi) * xi : (sum(xi - x) * xi) / sum(xi - x)^2 = (sum(xi)^2 - xÂ * sum(xi)) / sum(xi - x)^2= (sum(xi)^2 - x * sum(xi) + xÂ * sum(xi) - xÂ * sum(xi)) / sum(xi - x)^2= (sum(xi)^2 - 2 * xÂ * sum(xi) + xÂ * sum(xi)) / sum(xi - x)^2= (sum(xi)^2 - 2 xÂ * sum(xi)+ x(sum(xi)/N)^x * N / (sum(xi-x)^2)= (sum(xi)^2 - 2 xÂ * sum(xi) + N * x^2) / sum(x-x)^2= sum(x- x)^2 / sum(x-x)^2 = 1b2 =Â Î²2 + sum(wi) * ei E(b2) = E(Î²2) + E(sum(wi) * ei) =Â Î²2 + sum(w) * E(ei) We assume that E(ei) = 0 so: =Â Î²2 + 0 =Â Î²2 Gauss-Markov theorem: Wikipedia: "In a linear regression model in which the errors have expectation zero and are uncorrelated and have equal variances, the best linear unbiased estimator (BLUE) of the coefficients is given by the ordinary least squares estimator. Here "best" means giving the lowest possible mean squared error of the estimate."b1 ~ N(Î²1, (Ïƒ^2 * sum(xi)^2) / (N * sum(x- x)^2))b2 ~ N(Î²2, (Ïƒ^2 / sum(x- x)^2))Ïƒ^2 = sum( ei)^2 / (N-2)e = y-yvar(b1) =Â Ïƒ^2 * [sum(x)^2 / (N * sum(x-x)^2]se(b1) = sqrt( var(b1))var(b1) =Â Ïƒ^2 / sum(x-x)^2se(b2) = sqrt( var(b2))cov(b1, b2) =Â Ïƒ^2 * [- xÂ / sum(x-x)^2]b = (x1 * x)^-1 * x1 * y cov(b) =Â Ïƒ^2 * (x1 * x)^-1 Example 2.7 - Least square principle:y =Â Î²1 +Â Î²2 * x + e yÂ = b1 + b2 * xN = 51 a)Estimated error variance: Ïƒ^2 = 2.04672 The residual sum of squares: Ïƒ^2 = SSE/(N-2)) Gives us: SSE =Â Ïƒ^2 * (N-2) = 2.04672 * (51-2) SSE = 100.29 b)var(b2) = 0.00098se(b2) = sqrt( var(b2)) = sqrt(0.00098) = 0.0313What is: sum(x- x)^2 = ?Definition of variance for b2: var(b2) =Â Ïƒ^2 / sum(x- x)^2sum(x- x)^2 =Â Ïƒ^2 / var(b2)sum(x- x)^2 = 2.04672/0.00098 = 2088.5c)b2 = 0.18 d)We assume that the average of x is: x = 69.139The average of y is: y = 15.187We want to calculate the intercept: b1 = y - b * xÂ b1 = 15.187 - 0.18 * 69.139 = 2.742 Our estimated line is: y = 2.742 - 0.18xe)We want to find the sum of squared of x: sum(x)^2 = ? We know that: sum(x- x)^2 = sum(x)^2 - N * x^2So: sum(x)^2 =Â sum(x- x)^2 +Â N *Â x^2We also know the values from earlier, so: sum(x)^2Â = 2088.5 + 51 * 69139 = 245879 f)We want to calculate the residual. y = b1 + b2 * x + ee = y - yWe can calculate the predicted value: y = 2.742 - 0.18 * 58.3y = 13.236Now we can calculate the residual: eÂ = y - yÂ = 12.274 - 13.236 = -0.962This means we're below the line(?) Interval estimation / Confidence intervalsÂ - We create an interval where the two parameters could line with a certain confidence. Wikipedia: "A particular kind of interval estimate of a population parameter used to indicate the reliability of an estimate."Hypothesis tests - First of all test if the parameters = 0. Secondly, test ifÂ Â Î²1 andÂ Î²2 = 1. Wikipedia: "A method of making decisions using data, whether from a controlled experiment or an observational study (not controlled)"Confidence intervalsb2Â ~ N(Î²2,Â Ïƒ^2 / sum(x- x)^2)Z = (b2Â -Â Î²2) / sqrt(Ïƒ^2 / sum(x- x)^2)We can use the t-distribution, which replacesÂ Ïƒ withÂ Ïƒ:t = (b2Â -Â Î²2) / sqrt( Ïƒ^2 / sum(x-x)^2)t-distribution: Wikipedia: "a continuous probability distribution that arises when estimating the mean of a normally distributed population in situations where the sample size is small"P(-tc <= t <= tc) = 1 -Â Î± b2 +/- t * Î±/2, N-2 * se(b2)100 * (1 -Â Î±)% Î± = 0.05 (1-Î±) = 0.95 Hypothesis tests- Determine H0 and H2
- Specify a test statistics
- Select a significance (Î±) and determine the rejection region
- Calculate the value of the test statistics
- State your conclusion
We could test thatÂ Î²2 = C: H0 :Â Î²2 = C We also want an alternative hypothesis: H1 :Â Î²2 != C Another test: H0 :Â Î²2 = C H1 :Â Î²2 > C Or: H0 :Â Î²2 = C H1 :Â Î²2 < C E.g. if a certain company's stock has a lower risk than the market. Test statistics (the same for all three tests): t = (b2 -Â Î²2) / se(b2) Then we must choose the significance-level:Â Î± This is normallyÂ Î± = 0.05 E.g. Even 5% of the innocent will be sent to jail We need a critical value. Critical region: Can be either positive or negative. We go to the t-table: tÂ Î±/2, N - 2 +/- t * 0.025, N-2 If the observed t value is larger than the critical value. tc = tÎ±, N-2 tc = -tÎ±, N-2 ## The ordinary least squares (OLS) assumption- Must be a linear relationship: yi =Â Î²0 +Â Î²1 * xi + ei
- Expected value: E(e) = 0
- Variance: var(e) = Ïƒ
^{2}is constant for all i. If it's violated, then ei is said to be "heteroskedastic". - Covariance: cov(e
_{i}, e_{j}) = 0 for all iÂ â‰ j.Â If assumption 4 i violated, then ei is said to be "serially corelated" or "autocorrelated". - xi is non-random, takes on at least 2 values
- Normal distribution: eÂ ~ N(0,Â Ïƒ
^{2})
## Violations of the ordinary least squares (OLS) assumptionsGoal: Use our observation to explain a simpler relation. ## Assumption 1We take our observation on y and x and run it through theÂ linear model: yi =Â Î²0 +Â Î²1 * xi + ei ## Assumption 2Most important, together with assumption 1. Expected value on the left hand side and right hand side: E(yi) = E(Î² _{0} +Â Î²_{1} * xi + ei)Using the rule E(ax) = aE(x) we can transform this into: E(yi) = Î² _{0}Â +Â Î²_{1}Â * E(xi) + E(ei) =Â Î²_{0}Â +Â Î²_{1}Â * E(xi)It takes on the same value, but on repeated samples we should recieve the same value. Example: If we draw repeated samples of the monetary policy rate from a group of countries, we should arrive at the same result. The most important reason for why we need assumption 2 is to ensure thatÂ Î²1 andÂ Î²0 is unbiased. Which is better? - Î²1 that is biasedÂ but with low variance, or;
- Î²1* that is unbiased but with high variance
A trade-off between bias and variance. Which should be choose? Answer: Number #2. Having a low variance of a biased variable is actually worse than a biased variable with high variance, because a biased variable with a high variance at least have some chance of ending up at the correct value, while this probability decreases if its variance is low. Unbias is extremely important and thus we should choose the least biased sample. Unbias: If x is an estimator of Î¼ and E(x) = Î¼ then x is unbiased. To show that the least squares is unbiased, we want to show that E(b1) =Â Î²1 To show this we need assumption 1, 2 and 5. ## Assumption 3If var(ei) is constant, that is: the variance of ei does not depend on xi, then ei is homoskedastic. Otherwise, it's heteroskedastic.Â The formula when calculating variance will not be correct anymore. When might we expect heteroskedasticity to occur? Consider the following regression: Food expenditures = B0 + B1 * Income + error For low income households we can expect food expenditures to be a large part of their budget. But for high income households, it'll be lower (spend less part of their money on food and more on other things). So the error term will look very different, with lower variance for low income households and higher variance for high income households. The variance will depend on which variable you look at. This isÂ heteroskedastic, which is problematic. ## Scenarios- ei =Â Î²2 * zi + ui
- E(ei) =Â Î²2 * zi + E(ui) =Â Î²2 * ziÂ â‰ 0
- The observation is biased and not valid, the so called omitted variable bias.
- To make it unbiased, we must include zi in the regression as an additional variable.
- var(ei) = xi^2 *Â Ïƒ^2
- Because x varies with each i, the variance is not constant. We're unbiased, but have a problem with assumption 3.
## Assumption 5The assumption that xi is non-random is only for simplicity. It means that if we made repeated drawings of y1, ..., yN and x1, ..., xN from the population, then the values of xi will be the same in each drawing. Example: If yi is money supply at time i for a particular country, and xi is the policy interest rate of the ECB, then xi would be the same if we were to sample different countries. Â If xi is random, then we need to assume that cov(xi, ei) = 0 This is required to ensure unbias. The assumption that xi takes on at least two values means that it cannot be perfectly collinear with the intercept.Â If xi takes only one value, the least squares cannot be computed. Static model - Contains only the contemporaneous valus, that is no lags Lags - Variables that are lagged in time The error terms are autocorrelated if Example: money demand_t = B0 + B1 * income_t + e_t A monetary policy shock is not included in the normal variables, so it must be included in the error term (e_t) e_t = f(r_t, r_t-1) But e_t-1 = f(r_t-1, r_t-2) We have autocorrelation(?) BothÂ heteroskedasticityÂ and autocorrelation are the result of omitted variables that end up in the error term because they're not included as a separate variable. That is, the dependant variable and independant variables must have similar trends, otherwise we'll have the separate trends captured in the error term. The countermeasures are the same for both: We can use GLS We can try to rubustify the standard errors |