background-image: url("../pic/slide-front-page.jpg") class: center,middle exclude: FALSE # 统计学原理(Statistic) ### 胡华平 ### 西北农林科技大学 ### 经济管理学院数量经济教研室 ### huhuaping01@hotmail.com ### 2021-05-18
--- class: center, middle, duke-orange,hide_logo name:chapter exclude: FALSE # 第五章 相关和回归分析 ### [5.1 变量间关系的度量](#corl) ### [5.2 回归分析的基本思想](#oncept) ### [.white[5.3 OLS方法与参数估计]](#ols) ### [5.4 假设检验](#hypthesis) ### [5.5 拟合优度与残差分析](#goodness) ### [5.6 回归预测分析](#forecast) ### [5.7 回归报告解读](#report) --- layout: false class: center, middle, duke-softblue,hide_logo name: ols # 5.3 OLS方法与参数估计 ### [普通最小二乘法(OLS)](#ols-method) ### [参数估计](#ols-estimate) ### [估计精度](#ols-sd) ### [区间估计](#ols-interval) --- layout: true <div class="my-header-h2"></div> <div class="watermark1"></div> <div class="watermark2"></div> <div class="watermark3"></div> <div class="my-footer"><span>huhuaping@    <a href="#chapter"> 第05章 相关和回归分析 </a>                       <a href="#ols"> 5.3 OLS方法与参数估计 </a> </span></div> --- name: ols-method ## 普通最小二乘法(OLS):引子 我们如何估计回归函数中的系数? .pull-left[ 总体回归: `$$\begin{cases} \begin{align} E(Y|X_i) &= \beta_1 +\beta_2X_i && \text{(PRF)} \\ Y_i &= \beta_1 +\beta_2X_i + u_i && \text{(PRM)} \end{align} \end{cases}$$` ] .pull-right[ 样本回归: `$$\begin{cases} \begin{align} \hat{Y}_i & =\hat{\beta}_1 + \hat{\beta}_2X_i && \text{(SRF)} \\ Y_i &= \hat{\beta}_1 + \hat{\beta}_2X_i +e_i && \text{(SRM)} \end{align} \end{cases}$$` ] 首先需要回答的问题是,我们该如何估计得出样本回归函数中的系数?事实上,方法有多种多样: - 图解法:比较粗糙,但提供了基本的视觉认知 - 最小二乘法(order lease squares, OLS):最常用的方法 - 最大似然法(maximum likelihood, ML) - 矩估计方法(Moment method, MM) --- ## 普通最小二乘法(OLS):回顾和比较 .pull-left[ .pa2.bg-lightest-blue[ 总体回归函数PRF: `$$\begin{align} E(Y|X_i) &= \beta_1 +\beta_2X_i \end{align}$$` 总体回归模型PRM: `$$\begin{align} Y_i &= \beta_1 +\beta_2X_i + u_i \end{align}$$` ] ] .pull-right[ .pa2.bg-light-blue[ 样本回归函数SRF: `$$\begin{align} \hat{Y}_i =\hat{\beta}_1 + \hat{\beta}_2X_i \end{align}$$` 样本回归模型SRM: `$$\begin{align} Y_i &= \hat{\beta}_1 + \hat{\beta}_2X_i +e_i \end{align}$$` ] ] -- 思考: - PRF无法直接观测,只能用SRF近似替代 - 估计值与观测值之间存在偏差 - SRF又是怎样决定的呢? --- ## 普通最小二乘法(OLS):原理 认识普通最小二乘法的原理:一个图示 <div class="figure" style="text-align: center"> <img src="../pic/extra/chpt3-OLS-demo.png" alt="最小二乘法的原理" width="469" /> <p class="caption">最小二乘法的原理</p> </div> --- ## 普通最小二乘法(OLS):原理 OLS的基本原理:残差平方和最小化。 `$$\begin{align} e_i &= Y_i - \hat{Y}_i \\ &= Y_i - (\hat{\beta}_1 +\hat{\beta}_2X_i) \end{align}$$` `$$\begin{align} Q &= \sum{e_i^2} \\ &= \sum{(Y_i - \hat{Y}_i)^2} \\ &= \sum{\left( Y_i - (\hat{\beta}_1 +\hat{\beta}_2X_i) \right)^2} \\ &\equiv f(\hat{\beta}_1,\hat{\beta}_2) \end{align}$$` `$$\begin{align} Min(Q) &= Min \left ( f(\hat{\beta}_1,\hat{\beta}_2) \right) \end{align}$$` --- ### (示例) 普通最小二乘法(OLS)的一个数值试验 假设存在下面所示的4组观测值 `\((X_i, Y_i)\)`: <div class="figure" style="text-align: center"> <img src="../pic/extra/chpt3-OLS-compare1.png" alt="数值试验:数据" width="2504" /> <p class="caption">数值试验:数据</p> </div> --- ### (示例) 普通最小二乘法(OLS)的一个数值试验 假设猜想两个SRF,完成下表计算,并分析哪个SRF给出的 `\((\hat{\beta}_1, \hat{\beta}_2)\)`要更好? `$$\begin{align} SRF1:\hat{Y}_{1i} & = \hat{\beta}_1 +\hat{\beta}_2X_i = 1.572 + 1.357X_i \\ SRF2:\hat{Y}_{2i} & = \hat{\beta}_1 +\hat{\beta}_2X_i = 3.0 + 1.0X_i \end{align}$$` <div class="figure" style="text-align: center"> <img src="../pic/extra/chpt3-OLS-compare2.png" alt="数值试验:计算" width="821" /> <p class="caption">数值试验:计算</p> </div> --- name: ols-estimate ## 参数估计:回归参数的OLS点估计 - 最小化求解: `$$\begin{align} Min(Q) &= Min \left ( f(\hat{\beta}_1,\hat{\beta}_2) \right)\\ &= Min\left(\sum{\left( Y_i - (\hat{\beta}_1 +\hat{\beta}_2X_i) \right)^2} \right) \\ &= Min \sum{\left( Y_i - \hat{\beta}_1 - \hat{\beta}_2X_i \right)^2} \end{align}$$` - 方程组变形,得到**正规方程组**: `$$\begin{align} \left \{ \begin{split} \sum{\left[ \hat{\beta}_1 - (Y_i -\hat{\beta}_2X_i) \right]} &=0 \\ \sum{\left[ X_i^2\hat{\beta}_2 - (Y_i-\hat{\beta}_1 )X_i \right ] }&=0 \end{split} \right. \end{align}$$` `$$\begin{align} \left \{ \begin{split} \sum{Y_i} - n\hat{\beta}_1- (\sum{X_i})\hat{\beta}_2 &=0 \\ \sum{X_iY_i}-(\sum{X_i})\hat{\beta}_1 - (\sum{X_i^2})\hat{\beta}_2 &=0 \end{split} \right. \end{align}$$` --- ## 参数估计:回归参数的OLS点估计 进而得到回归系数的计算公式1(Favorite Five,FF): `$$\begin{align} \left \{ \begin{split} \hat{\beta}_2 &=\frac{n\sum{X_iY_i}-\sum{X_i}\sum{Y_i}}{n\sum{X_i^2}-\left ( \sum{X_i} \right)^2}\\ \hat{\beta}_1 &=\frac{n\sum{X_i^2Y_i}-\sum{X_i}\sum{X_iY_i}}{n\sum{X_i^2}-\left ( \sum{X_i} \right)^2} \end{split} \right. &&\text{(FF solution)} \end{align}$$` --- ## 参数估计:回归参数的OLS点估计 此外我们也可以得到如下的离差公式(favorite five,ff) `$$\begin{align} \left \{ \begin{split} \hat{\beta}_2 &=\frac{\sum{x_iy_i}}{\sum{x_i^2}}\\ \hat{\beta}_1 &=\bar{Y}_i-\hat{\beta}_2\bar{X}_i \end{split} \right. && \text{(ff solution)} \end{align}$$` 其中离差计算 `\(x_i=X_i-\bar{X};\ y_i=Y_i - \bar{Y}\)`。 --- ### (测试题) 以下式子为什么是等价的?你能推导出来么? `$$\begin{align} \left\{ \begin{split} \sum{x_iy_i} &= \sum{\left[ (X_i-\bar{X})(Y_i-\bar{Y})\right]} &&= \sum{X_iY_i} - \frac{1}{n}\sum{X_i}\sum{Y_i} \\ \sum{x_i^2} &= \sum{(X_i- \bar{X})^2} &&= \sum{X_i^2} -\frac{1}{n} \left( \sum{X_i} \right)^2 \end{split} \right. \end{align}$$` --- ## 参数估计:随机干扰项参数的OLS点估计 PRM公式变形: `$$\begin{alignedat}{2} &\left. \begin{split} Y_i &&= \beta_1 - &&\beta_2X_i +u_i \ && \text{(PRM)} \Rightarrow \\ \hat{Y} &&= \beta_1 - &&\beta_2\bar{X} +\bar{u} && \\ \end{split} \right \} \Rightarrow \\ & y_i = \beta_2x_i +(u_i- \bar{u}) \end{alignedat}$$` 残差公式变形: `$$\begin{alignedat}{2} &\left. \begin{split} & e_i = y_i - \hat{\beta}_2x_i \\ & e_i = \beta_2x_i +(u_i- \bar{u}) -\hat{\beta}_2x_i \end{split} \right \} \Rightarrow \\ & e_i =-(\hat{\beta}_2- \beta_2)x_i + (u_i- \hat{u}) \end{alignedat}$$` --- ## 参数估计:随机干扰项参数的OLS点估计 求解残差平方和: `$$\begin{alignedat}{2} & \sum{e_i^2} && = (\hat{\beta}_2 - \beta_2)^2\sum{x_i^2} + \sum{(u-\bar{u})^2} - 2(\hat{\beta}_2 - \beta_2)\sum{x_i(u-\bar{u})} \end{alignedat}$$` 求残差平方和的期望: `$$\begin{align} E(\sum{e_i^2}) &= \sum{x_i^2 E \left[ (\hat{\beta}_2 - \beta_2)^2 \right ]}+ E\left[ \sum{(u-\bar{u})^2} \right ]\\ &+ 2E \left[ (\hat{\beta}_2 - \beta_2)\sum{x_i(u-\bar{u})} \right ] \\ & \equiv A + B + C \\ & = \sigma^2 + (n-1)\sigma^2 -2\sigma^2 \\ & = (n-2)\sigma^2 \end{align}$$` --- ## 参数估计:随机干扰项参数的OLS点估计 **回归误差方差**(Deviation of Regression Error): - 采用OLS方法下,总体回归模型PRM中随机干扰项 `\(u_i\)`的总体方差的无偏估计量,记为 `\(E(\sigma^2) \equiv \hat{\sigma}^2\)`,简单地记为 `\(\hat{\sigma}^2\)`。 `$$\begin{align} \hat{\sigma}^2=\frac{\sum{e_i^2}}{n-2} \end{align}$$` -- **回归误差标准差**(Standard Deviation of Regression Error):有时候也记为**se**。 `$$\begin{align} \hat{\sigma}=\sqrt{\frac{\sum{e_i^2}}{n-2}} \end{align}$$` ??? - 采用OLS方法下,总体回归模型PRM中随机干扰项 `\(u_i\)`的总体标准差的无偏估计量,记为 `\(E(\sigma) \equiv \hat{\sigma}\)`,代数表达式一般简单地记为 `\(\hat{\sigma}\)` --- ### (附录)A过程证明 `$$\begin{align} A & = \sum{x_i^2 E \left[ (\hat{\beta}_2 - \beta_2)^2 \right ]} \\ & = \sum{ \left[ x_i^2 \cdot var(\hat{\beta}_2) \right] } \\ & = var(\hat{\beta}_2) \cdot \sum{x_i^2} \\ & = \frac{\sigma^2}{\sum{ x_i^2}} \cdot \sum{ x_i^2} \\ & = \sigma^2 \end{align}$$` --- ### (附录)B过程证明 `$$\begin{align} B = E \left[ \sum{(u-\bar{u})^2} \right ] & = E(\sum{u_i^2}) - 2E \left[ \sum{(u_i\bar{u})} \right] +nE(\bar{u}^2) \\ & = n \cdot Var(u_i) - 2E \left[ \sum{(u_i \cdot \frac{\sum{u_i}}{n} )} \right] + nE(\frac{\sum{u_i}}{n})^2 \\ & = n \sigma^2 - 2E \left[ \frac{\sum{u_i}}{n} \sum{u_i} \right] + E\left[ \frac{(\sum{u_i})^2}{n} \right]\\ & = n \sigma^2- E\left[ (\sum{u_i})^2/{n} \right] = n \sigma^2 - \frac{E(u_i^2) + E(u_2^2) + \cdots + E(u_n^2) )}{n} \\ & = n \sigma^2 - \frac{nVar{u_i}}{n} = n \sigma^2 - \sigma^2 = (n-1) \sigma^2 \end{align}$$` --- ### (附录)C过程证明 `$$\begin{align} C &= - 2E \left[ (\hat{\beta}_2 - \beta_2)\sum{x_i(u_i-\bar{u})} \right ] \\ &= - 2E \left[ \frac{\sum{x_iu_i}}{\sum{x_i^2}} \left( \sum{x_iu_i}-\bar{u}\sum{x_i} \right) \right ] \\ &= - 2E \left[ \frac{ \left( \sum{x_iu_i} \right)^2}{\sum{x_i^2}} \right ] \\ &= -2E \left[(\hat{\beta}_2 - \beta_2)^2 \right] = -2\sigma^2 \end{align}$$` -- - 其中: `$$\begin{align} \hat{\beta}_2 & = \sum{k_iY_i} = \sum{k_i(\beta_1 +\beta_2X_i +u_i)} = \beta_1\sum{k_i} +\beta_2 \sum{k_iX_i}+\sum{k_iu_i} = \beta_2 +\sum{k_iu_i} \\ \hat{\beta}_2 - \beta_2 & = \sum{k_iu_i} = \frac{ \sum{x_iu_i} }{\sum{x_i^2}} \end{align}$$` --- exclude:true ## (案例)教育程度与时均工资 ``` Warning: `funs()` was deprecated in dplyr 0.8.0. Please use a list of either functions or lambdas: # Simple named list: list(mean = mean, median = median) # Auto named with `tibble::lst()`: tibble::lst(mean, median) # Using lambdas list(~ mean(., trim = .2), ~ median(., na.rm = TRUE)) ``` --- ### (案例)计算表FF和ff <table class="table" style="font-size: 22px; margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="text-align:center;"> obs </th> <th style="text-align:center;"> `\(X_i\)` </th> <th style="text-align:center;"> `\(Y_i\)` </th> <th style="text-align:center;"> `\(X_iY_i\)` </th> <th style="text-align:center;"> `\(X_i^2\)` </th> <th style="text-align:center;"> `\(Y_i^2\)` </th> <th style="text-align:center;"> `\(x_i\)` </th> <th style="text-align:center;"> `\(y_i\)` </th> <th style="text-align:center;"> `\(x_iy_i\)` </th> <th style="text-align:center;"> `\(x_i^2\)` </th> <th style="text-align:center;"> `\(y_i^2\)` </th> </tr> </thead> <tbody> <tr> <td style="text-align:center;"> 1 </td> <td style="text-align:center;"> 6.00 </td> <td style="text-align:center;"> 4.46 </td> <td style="text-align:center;"> 26.74 </td> <td style="text-align:center;"> 36.00 </td> <td style="text-align:center;"> 19.86 </td> <td style="text-align:center;"> -6.00 </td> <td style="text-align:center;"> -4.22 </td> <td style="text-align:center;"> 25.31 </td> <td style="text-align:center;"> 36.00 </td> <td style="text-align:center;"> 17.79 </td> </tr> <tr> <td style="text-align:center;"> 2 </td> <td style="text-align:center;"> 7.00 </td> <td style="text-align:center;"> 5.77 </td> <td style="text-align:center;"> 40.39 </td> <td style="text-align:center;"> 49.00 </td> <td style="text-align:center;"> 33.29 </td> <td style="text-align:center;"> -5.00 </td> <td style="text-align:center;"> -2.90 </td> <td style="text-align:center;"> 14.52 </td> <td style="text-align:center;"> 25.00 </td> <td style="text-align:center;"> 8.44 </td> </tr> <tr> <td style="text-align:center;"> 3 </td> <td style="text-align:center;"> 8.00 </td> <td style="text-align:center;"> 5.98 </td> <td style="text-align:center;"> 47.83 </td> <td style="text-align:center;"> 64.00 </td> <td style="text-align:center;"> 35.74 </td> <td style="text-align:center;"> -4.00 </td> <td style="text-align:center;"> -2.70 </td> <td style="text-align:center;"> 10.78 </td> <td style="text-align:center;"> 16.00 </td> <td style="text-align:center;"> 7.27 </td> </tr> <tr> <td style="text-align:center;"> 4 </td> <td style="text-align:center;"> 9.00 </td> <td style="text-align:center;"> 7.33 </td> <td style="text-align:center;"> 65.99 </td> <td style="text-align:center;"> 81.00 </td> <td style="text-align:center;"> 53.75 </td> <td style="text-align:center;"> -3.00 </td> <td style="text-align:center;"> -1.34 </td> <td style="text-align:center;"> 4.03 </td> <td style="text-align:center;"> 9.00 </td> <td style="text-align:center;"> 1.80 </td> </tr> <tr> <td style="text-align:center;"> 5 </td> <td style="text-align:center;"> 10.00 </td> <td style="text-align:center;"> 7.32 </td> <td style="text-align:center;"> 73.18 </td> <td style="text-align:center;"> 100.00 </td> <td style="text-align:center;"> 53.56 </td> <td style="text-align:center;"> -2.00 </td> <td style="text-align:center;"> -1.36 </td> <td style="text-align:center;"> 2.71 </td> <td style="text-align:center;"> 4.00 </td> <td style="text-align:center;"> 1.84 </td> </tr> <tr> <td style="text-align:center;"> 6 </td> <td style="text-align:center;"> 11.00 </td> <td style="text-align:center;"> 6.58 </td> <td style="text-align:center;"> 72.43 </td> <td style="text-align:center;"> 121.00 </td> <td style="text-align:center;"> 43.35 </td> <td style="text-align:center;"> -1.00 </td> <td style="text-align:center;"> -2.09 </td> <td style="text-align:center;"> 2.09 </td> <td style="text-align:center;"> 1.00 </td> <td style="text-align:center;"> 4.37 </td> </tr> <tr> <td style="text-align:center;"> 7 </td> <td style="text-align:center;"> 12.00 </td> <td style="text-align:center;"> 7.82 </td> <td style="text-align:center;"> 93.82 </td> <td style="text-align:center;"> 144.00 </td> <td style="text-align:center;"> 61.12 </td> <td style="text-align:center;"> 0.00 </td> <td style="text-align:center;"> -0.86 </td> <td style="text-align:center;"> -0.00 </td> <td style="text-align:center;"> 0.00 </td> <td style="text-align:center;"> 0.73 </td> </tr> <tr> <td style="text-align:center;"> 8 </td> <td style="text-align:center;"> 13.00 </td> <td style="text-align:center;"> 7.84 </td> <td style="text-align:center;"> 101.86 </td> <td style="text-align:center;"> 169.00 </td> <td style="text-align:center;"> 61.39 </td> <td style="text-align:center;"> 1.00 </td> <td style="text-align:center;"> -0.84 </td> <td style="text-align:center;"> -0.84 </td> <td style="text-align:center;"> 1.00 </td> <td style="text-align:center;"> 0.70 </td> </tr> <tr> <td style="text-align:center;"> 9 </td> <td style="text-align:center;"> 14.00 </td> <td style="text-align:center;"> 11.02 </td> <td style="text-align:center;"> 154.31 </td> <td style="text-align:center;"> 196.00 </td> <td style="text-align:center;"> 121.49 </td> <td style="text-align:center;"> 2.00 </td> <td style="text-align:center;"> 2.35 </td> <td style="text-align:center;"> 4.70 </td> <td style="text-align:center;"> 4.00 </td> <td style="text-align:center;"> 5.51 </td> </tr> <tr> <td style="text-align:center;"> 10 </td> <td style="text-align:center;"> 15.00 </td> <td style="text-align:center;"> 10.67 </td> <td style="text-align:center;"> 160.11 </td> <td style="text-align:center;"> 225.00 </td> <td style="text-align:center;"> 113.93 </td> <td style="text-align:center;"> 3.00 </td> <td style="text-align:center;"> 2.00 </td> <td style="text-align:center;"> 6.00 </td> <td style="text-align:center;"> 9.00 </td> <td style="text-align:center;"> 4.00 </td> </tr> <tr> <td style="text-align:center;"> 11 </td> <td style="text-align:center;"> 16.00 </td> <td style="text-align:center;"> 10.84 </td> <td style="text-align:center;"> 173.38 </td> <td style="text-align:center;"> 256.00 </td> <td style="text-align:center;"> 117.42 </td> <td style="text-align:center;"> 4.00 </td> <td style="text-align:center;"> 2.16 </td> <td style="text-align:center;"> 8.65 </td> <td style="text-align:center;"> 16.00 </td> <td style="text-align:center;"> 4.67 </td> </tr> <tr> <td style="text-align:center;"> 12 </td> <td style="text-align:center;"> 17.00 </td> <td style="text-align:center;"> 13.62 </td> <td style="text-align:center;"> 231.46 </td> <td style="text-align:center;"> 289.00 </td> <td style="text-align:center;"> 185.37 </td> <td style="text-align:center;"> 5.00 </td> <td style="text-align:center;"> 4.94 </td> <td style="text-align:center;"> 24.70 </td> <td style="text-align:center;"> 25.00 </td> <td style="text-align:center;"> 24.41 </td> </tr> <tr> <td style="text-align:center;"> 13 </td> <td style="text-align:center;"> 18.00 </td> <td style="text-align:center;"> 13.53 </td> <td style="text-align:center;"> 243.56 </td> <td style="text-align:center;"> 324.00 </td> <td style="text-align:center;"> 183.09 </td> <td style="text-align:center;"> 6.00 </td> <td style="text-align:center;"> 4.86 </td> <td style="text-align:center;"> 29.14 </td> <td style="text-align:center;"> 36.00 </td> <td style="text-align:center;"> 23.58 </td> </tr> <tr> <td style="text-align:center;font-weight: bold;color: red !important;"> sum </td> <td style="text-align:center;font-weight: bold;color: red !important;"> 156.00 </td> <td style="text-align:center;font-weight: bold;color: red !important;"> 112.77 </td> <td style="text-align:center;font-weight: bold;color: red !important;"> 1485.04 </td> <td style="text-align:center;font-weight: bold;color: red !important;"> 2054.00 </td> <td style="text-align:center;font-weight: bold;color: red !important;"> 1083.38 </td> <td style="text-align:center;font-weight: bold;color: red !important;"> 0.00 </td> <td style="text-align:center;font-weight: bold;color: red !important;"> 0.00 </td> <td style="text-align:center;font-weight: bold;color: red !important;"> 131.79 </td> <td style="text-align:center;font-weight: bold;color: red !important;"> 182.00 </td> <td style="text-align:center;font-weight: bold;color: red !important;"> 105.12 </td> </tr> </tbody> </table> --- ### (案例)计算回归系数 公式1: (Favorite Five,FF形式) `$$\begin{align} \hat{\beta}_2 &=\frac{n\sum{X_iY_i}-\sum{X_i}\sum{Y_i}}{n\sum{X_i^2}-\left ( \sum{X_i} \right)^2}\\ &=\frac{13\ast1485.04-156\ast112.771}{13\ast2054-156^2}=0.7241 \end{align}$$` `$$\begin{align} \hat{\beta_1} &= \bar{Y} - \hat{\beta}_2 \bar{X} =8.6747-0.7241\ast12=-0.0145 \end{align}$$` --- ### (案例)计算回归系数 公式2:(离差形式,favorite five,ff形式) `$$\begin{align} \hat{\beta}_2 =\frac{\sum{x_iy_i}}{\sum{x_i^2}} =\frac{131.786}{182}=0.7241 \end{align}$$` `$$\begin{align} \hat{\beta_1} = \bar{Y} - \hat{\beta}_2 \bar{X} =8.6747-0.7241\ast12=-0.0145 \end{align}$$` --- ### (案例)样本回归方程SRF `$$\begin{align} \hat{Y}_i= \hat{\beta}_1 + \hat{\beta}_2 X_i =-0.0145+0.7241X_i \end{align}$$` --- ### (案例)样本回归线SRL <img src="05-03-reg-ols_files/figure-html/unnamed-chunk-14-1.png" width="95%" style="display: block; margin: auto;" /> --- ### (案例)样本回归线SRL <img src="05-03-reg-ols_files/figure-html/unnamed-chunk-15-1.png" width="95%" style="display: block; margin: auto;" /> --- ### (案例)计算得到拟合值和残差 .pull-left[ <table class="table" style="font-size: 20px; margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="text-align:left;"> obs </th> <th style="text-align:right;"> `\(X_i\)` </th> <th style="text-align:right;"> `\(Y_i\)` </th> <th style="text-align:right;"> `\(\hat{Y}_i\)` </th> <th style="text-align:right;"> `\(e_i\)` </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> 1 </td> <td style="text-align:right;"> 6 </td> <td style="text-align:right;"> 4.5 </td> <td style="text-align:right;"> 4.3 </td> <td style="text-align:right;"> 0.127 </td> </tr> <tr> <td style="text-align:left;"> 2 </td> <td style="text-align:right;"> 7 </td> <td style="text-align:right;"> 5.8 </td> <td style="text-align:right;"> 5.1 </td> <td style="text-align:right;"> 0.716 </td> </tr> <tr> <td style="text-align:left;"> 3 </td> <td style="text-align:right;"> 8 </td> <td style="text-align:right;"> 6.0 </td> <td style="text-align:right;"> 5.8 </td> <td style="text-align:right;"> 0.200 </td> </tr> <tr> <td style="text-align:left;"> 4 </td> <td style="text-align:right;"> 9 </td> <td style="text-align:right;"> 7.3 </td> <td style="text-align:right;"> 6.5 </td> <td style="text-align:right;"> 0.829 </td> </tr> <tr> <td style="text-align:left;"> 5 </td> <td style="text-align:right;"> 10 </td> <td style="text-align:right;"> 7.3 </td> <td style="text-align:right;"> 7.2 </td> <td style="text-align:right;"> 0.092 </td> </tr> <tr> <td style="text-align:left;"> 6 </td> <td style="text-align:right;"> 11 </td> <td style="text-align:right;"> 6.6 </td> <td style="text-align:right;"> 8.0 </td> <td style="text-align:right;"> -1.366 </td> </tr> <tr> <td style="text-align:left;"> 7 </td> <td style="text-align:right;"> 12 </td> <td style="text-align:right;"> 7.8 </td> <td style="text-align:right;"> 8.7 </td> <td style="text-align:right;"> -0.857 </td> </tr> <tr> <td style="text-align:left;"> 8 </td> <td style="text-align:right;"> 13 </td> <td style="text-align:right;"> 7.8 </td> <td style="text-align:right;"> 9.4 </td> <td style="text-align:right;"> -1.564 </td> </tr> <tr> <td style="text-align:left;"> 9 </td> <td style="text-align:right;"> 14 </td> <td style="text-align:right;"> 11.0 </td> <td style="text-align:right;"> 10.1 </td> <td style="text-align:right;"> 0.899 </td> </tr> <tr> <td style="text-align:left;"> 10 </td> <td style="text-align:right;"> 15 </td> <td style="text-align:right;"> 10.7 </td> <td style="text-align:right;"> 10.8 </td> <td style="text-align:right;"> -0.173 </td> </tr> <tr> <td style="text-align:left;"> 11 </td> <td style="text-align:right;"> 16 </td> <td style="text-align:right;"> 10.8 </td> <td style="text-align:right;"> 11.6 </td> <td style="text-align:right;"> -0.735 </td> </tr> <tr> <td style="text-align:left;"> 12 </td> <td style="text-align:right;"> 17 </td> <td style="text-align:right;"> 13.6 </td> <td style="text-align:right;"> 12.3 </td> <td style="text-align:right;"> 1.320 </td> </tr> <tr> <td style="text-align:left;"> 13 </td> <td style="text-align:right;"> 18 </td> <td style="text-align:right;"> 13.5 </td> <td style="text-align:right;"> 13.0 </td> <td style="text-align:right;"> 0.512 </td> </tr> <tr> <td style="text-align:left;font-weight: bold;color: red !important;"> sum </td> <td style="text-align:right;font-weight: bold;color: red !important;"> 156 </td> <td style="text-align:right;font-weight: bold;color: red !important;"> 112.8 </td> <td style="text-align:right;font-weight: bold;color: red !important;"> 112.8 </td> <td style="text-align:right;font-weight: bold;color: red !important;"> 0.000 </td> </tr> </tbody> </table> ] .pull-right[ 根据以上样本回归方程,可以计算得到 `\(Y_i\)`的回归拟合值 `\(\hat{Y}_i\)`,以及回归残差 `\(e_i\)`。 `$$\begin{align} \hat{Y}_i &=\hat{\beta}_1 +\hat{\beta}_2X_i\\ e_i &= Y_i - \hat{Y}_i \end{align}$$` ] --- ### (案例)计算回归误差方差和标准差 回归误差方差 `\(\hat{\sigma}^2\)` `$$\begin{align} \hat{\sigma}^2= \frac{\sum{e_i^2}} {(n-2)} =\frac{9.693}{11}=0.8812 \end{align}$$` 回归误差标准差 `\(\hat{\sigma}\)`: `$$\begin{align} \hat{\sigma}=\sqrt{\frac{\sum{e_i^2}}{(n-2)}} =\sqrt{0.8812}=0.9387 \end{align}$$` --- ## 参数估计:“估计值”与“估计量” 理解OLS方法下的“估计值”与“估计量” 回归系数的计算公式1(Favorite Five,FF): `$$\begin{align} \left \{ \begin{split} \hat{\beta}_2 &=\frac{n\sum{X_iY_i}-\sum{X_i}\sum{Y_i}}{n\sum{X_i^2}-\left ( \sum{X_i} \right)^2}\\ \hat{\beta_1} &=\frac{n\sum{X_i^2Y_i}-\sum{X_i}\sum{X_iY_i}}{n\sum{X_i^2}-\left ( \sum{X_i} \right)^2} \end{split} \right. &&\text{(FF solution)} \end{align}$$` - 如果给出的参数估计结果是由一个具体样本资料计算出来的,它是一个“估计值”,或者“点估计”,是参数估计量的一个具体数值; - 如果把上式看成参数估计的一个表达式,那么,则它是 `\((X_i,Y_i)\)`的函数,而 `\(Y_i\)`是随机变量,所以参数估计也是随机变量,在这个角度上,称之为“估计量”。 --- ## 参数估计:SRF和SRM的特征 OLS估计量是纯粹由可观测的(即样本)量(指X和Y)表达的,因此它们很容易计算。 它们是点估计量(point estimators),即对于给定样本,每个估计量仅提供有关总体参数的一个(点)值<sup>*</sup>。 一旦从样本数据得到OLS估计值,便容易画出样本回归线。 .footnote[注:我们以后还将考虑区间估计量(interval Estimators)] --- ## 参数估计:SRF和SRM的特征 - 特征1:样本回归线一定会经过样本均值点 `\((\bar{X}, \bar{Y})\)`: `$$\begin{align} \bar{Y} = \hat{\beta}_1 +\hat{\beta}_2\bar{X} \end{align}$$` - 特征2: `\(Y_i\)`的**估计值**( `\(\hat{Y}_i\)`)的均值( `\(\bar{\hat{Y_i}}\)`)等于Y的样本均值( `\(\bar{Y}\)`) `$$\begin{align} \hat{Y_i} &= \hat{\beta}_1 +\hat{\beta}_2\bar{X} \\ & =(\bar{Y} - \hat{\beta}_2\bar{X}) + \hat{\beta_2}X_i \\ & = \bar{Y} - \hat{\beta}_2(X_i - \bar{X}) \end{align}$$` `$$\begin{align} &\Rightarrow 1/n\sum{\hat{Y_i}} = 1/n\sum{\bar{Y} - \hat{\beta}_2(X_i - \bar{X})} \\ &\Rightarrow \bar{\hat{Y_i}} = \bar{Y} \end{align}$$` --- ## 参数估计:SRF和SRM的特征 - 特征3:残差的均值( `\(\bar{e_i}\)`)为零: `$$\begin{align} \sum{\left[ \hat{\beta}_1 - (Y_i -\hat{\beta}_2X_i) \right]} &=0 \\ \sum{\left[ Y_i- \hat{\beta}_1 - \hat{\beta}_2X_i) \right]} &=0 \\ \sum{( Y_i- \hat{Y}_i )} &=0 \\ \sum{e_i} &=0 \\ \bar{e_i} &=0 \end{align}$$` --- ## 参数估计:SRF和SRM的特征 - 特征4:SRM和SRF可以写成离差形式: `$$\begin{align} & \left. \begin{split} Y_i && = \hat{\beta}_1 + \hat{\beta}_2X_i + e_i \\ \bar{Y} &&= \hat{\beta}_1 + \hat{\beta}_2\bar{X} \end{split} \right \} \Rightarrow \\ & Y_i - \bar{Y} =\hat{\beta_2}(X_i - \bar{X}) + e_i \Rightarrow \\ & y_i=\hat{\beta_2}x_i +e_i \ &&\text{(SRM-dev)} \end{align}$$` `$$\begin{align} & \left. \begin{split} \hat{Y}_i && = \hat{\beta}_1 + \hat{\beta}_2X_i\\ \bar{Y} &&= \hat{\beta}_1 + \hat{\beta}_2\bar{X} \end{split} \right \} \Rightarrow \\ & \hat{Y}_i - \bar{Y} =\hat{\beta_2}(X_i - \bar{X}) \Rightarrow \\ & \hat{y}_i=\hat{\beta_2}x_i \ &&\text{(SRF-dev)} \end{align}$$` --- ## 参数估计:SRF和SRM的特征 - 特征5:残差( `\(e_i\)`)和 `\(Y_i\)`的拟合值( `\(\hat{Y_i}\)`)不相关 `$$\begin{align} Cov(e_i, \hat{Y_i}) &= E \left[ \left( e_i-E(e_i)\right )\cdot \left( \hat{Y_i}-E(\hat{Y_i})\right ) \right] = E(e_i \cdot \hat{y_i}) \\ & = \sum(e_i \cdot \hat{\beta_2}x_i) \\ & = \sum{ \left[ (y_i-\hat{\beta_2}x_i) \cdot \hat{\beta_2}x_i \right]} \\ & = \hat{\beta_2}\sum \left[ (y_i-\hat{\beta_2}x_i)\cdot x_i \right]\\ & = \hat{\beta_2}\sum \left[ (y_ix_i-\hat{\beta_2}x_i^2) \right]\\ & = \hat{\beta_2}\sum{x_iy_i}-\hat{\beta}_2^2\sum{x_i^2} && \Leftarrow \hat{\beta_2} = \frac{\sum{x_iy_i}}{x_i^2} \\ & = \hat{\beta}_2^2\sum{x_i^2}- \hat{\beta_2}^2\sum{x_i^2} = 0 \end{align}$$` - 特征6:残差( `\(e_i\)`)和自变量( `\(X_i\)`)不相关 --- ## 参数估计:离差公式 - 离差定义与符号: `$$\begin{align} x_i &= X_i - \bar{X} \\ y_i &= Y_i - \bar{Y} \\ \hat{y}_i &= \hat{Y}_i - \bar{\hat{Y}}_i = \hat{Y}_i - \bar{Y} \end{align}$$` - PRM及其离差形式: `$$\begin{align} & \left. \begin{split} Y_i && = \beta_1 + \beta_2X_i + u_i \\ \bar{Y} &&= \beta_1 + \beta_2\bar{X} + \bar{u} \end{split} \right \} \Rightarrow \\ & Y_i - \bar{Y} =\beta_2x_i + (u_i- \bar{u}) \Rightarrow \\ & y_i=\hat{\beta_2}x_i + (u_i- \bar{u}) \ &&\text{(PRM-dev)} \end{align}$$` --- ## 参数估计:离差公式 -- .pull-left[ - SRM及其离差形式: `$$\begin{align} & \left. \begin{split} Y_i && = \hat{\beta}_1 + \hat{\beta}_2X_i + e_i \\ \bar{Y} &&= \hat{\beta}_1 + \hat{\beta}_2\bar{X} \end{split} \right \} \Rightarrow \\ & Y_i - \bar{Y} =\hat{\beta_2}(X_i - \bar{X}) + e_i \Rightarrow \\ & y_i=\hat{\beta_2}x_i +e_i \end{align}$$` ] -- .pull-right[ - SRF及其离差形式: `$$\begin{align} & \left. \begin{split} \hat{Y}_i && = \hat{\beta}_1 + \hat{\beta}_2X_i\\ \bar{Y} &&= \hat{\beta}_1 + \hat{\beta}_2\bar{X} \end{split} \right \} \Rightarrow \\ & \hat{Y}_i - \bar{Y} =\hat{\beta_2}(X_i - \bar{X}) \Rightarrow \\ & \hat{y}_i=\hat{\beta_2}x_i \ \end{align}$$` ] -- - 残差的离差形式: `$$\begin{align} y_i=\hat{\beta_2}x_i +e_i &&\text{(SRM-dev)} \ \Rightarrow \\ e_i =y_i - \hat{\beta_2}x_i \ &&\text{(residual-dev)} \end{align}$$` --- ## 参数估计:思考与讨论 **内容小结**: - 普通最小二乘方法(OLS)采用“铅垂线距离平方和最小化”的思想,来拟合一条样本回归线,进而求解出模型参数估计量。 - 大家需要很熟练地记住OLS参数估计量公式,以及它们的几大重要特征! **思考讨论**: - OLS采用的“铅垂线距离平方和最小化”这一方案,凭什么它被奉为计量分析的经典方法?你觉得还有其他可行替代方案么? - 回归标准误差 `\(se\)`的现实含义是什么?回归参数估计与随机干扰项的方差估计有什么内在联系么? - OLS方法的几个特征,是不是使它“天生丽质”、“娘胎里生下来就含着金钥匙”?为什么能这么说? ??? 可以是“垂线距离平方和最小化”么?如果是距离的3次方或4次方之和,又会怎样?距离的绝对值之和可以么?对于这些方案,你有什么想法? --- name: ols-sd ## 估计精度:引子 我们已经使用OLS方法分别得到总体回归模型(PRM)的3个重要参数(实际不止3个)的点估计量: `$$\begin{align} Y_i &= \beta_1 +\beta_2X_i + u_i \\ \hat{\beta}_2 &=\frac{\sum{x_iy_i}}{\sum{x_i^2}} ; \quad \hat{\beta}_1 =\bar{Y}_i-\hat{\beta}_2\bar{X}_i ; \quad \hat{\sigma}^2 =\frac{\sum{e_i^2}}{n-2} \end{align}$$` >问题是:我们如何知道OLS方法点估计量是否可靠?OLS方法的点估计量是否稳定? OLS方法的点估计量是否可信? 因此,我们需要找到一种表达OLS方法估计稳定性或估计精度的指标! - 点估计量的**方差**(variance)和**标准差**(standard deviation)就是衡量估计稳定性或估计精度的一类重要指标! --- ## 估计精度:斜率系数的方差和样本方差 .pull-left[ .fl.pa2.bg-lightest-blue[ 斜率系数( `\(\hat{\beta}_2\)`)的**总体方差**( `\(\sigma^2_{\hat{\beta}_2}\)`)和**总体标准差**( `\(\sigma_{\hat{\beta}_2}\)`): `$$\begin{align} Var(\hat{\beta}_2) \equiv \sigma_{\hat{\beta}_2}^2 & =\frac{\sigma^2}{\sum{x_i^2}} \\ \sigma_{\hat{\beta}_2} &=\sqrt{\frac{\sigma^2}{\sum{x_i^2}}} \end{align}$$` - 其中, `\(Var(u_i) \equiv \sigma^2\)`表示随机干扰项 `\(u_i\)`的总体方差。 ] ] .pull-right[ .fl.pa2.bg-light-green[ 斜率系数( `\(\hat{\beta}_2\)`)的**样本方差**( `\(S^2_{\hat{\beta}_2}\)`)和**样本标准差**( `\(S_{\hat{\beta}_2}\)`): `$$\begin{align} S_{\hat{\beta}_2}^2 &=\frac{\hat{\sigma}^2}{\sum{x_i^2}} \\ S_{\hat{\beta}_2} &=\sqrt{\frac{\hat{\sigma}^2}{\sum{x_i^2}}} \end{align}$$` - 其中, `\(E(\sigma^2) = \hat{\sigma}^2 = \frac{\sum{e_i^2}}{n-2}\)`表示对随机干扰项( `\(u_i\)`)的总体方差的**无偏估计量**。 ] ] --- ### (附录)证明过程1 **步骤1** `\(\hat{\beta}_2\)`的变形: `$$\begin{align} \hat{\beta}_2 &=\frac{\sum{x_iy_i}}{\sum{x_i^2}}= \frac{\sum{\left[ x_i (Y_i -\bar{Y}) \right]} }{\sum{x_i^2}} \\ & = \frac{\sum{ x_iY_i}- \sum{ x_i \bar{Y} } }{\sum{x_i^2}} \\ & = \frac{\sum{x_iY_i}- \bar{Y}\sum{x_i} }{\sum{x_i^2}} && \leftarrow \left[ \sum{x_i}=\sum{(X_i -\bar{X})} = 0 \right] \\ & = \sum{ \left(\frac{x_i}{\sum{x_i^2}} \cdot Y_i \right) } && \leftarrow \left[ k_i \equiv \frac{x_i}{\sum{x_i^2}} \right]\\ & = \sum{k_iY_i} \end{align}$$` > - 其中, `\(k_i \equiv \frac{x_i}{\sum{x_i^2}}\)`。 --- ### (附录)证明过程2 **步骤2**:计算 `\(\hat{\beta}_2\)`的**总体方差**( `\(\sigma^2_{\hat{\beta}_2}\)`): `$$\begin{align} \sigma^2_{\hat{\beta}_2} & \equiv Var(\hat{\beta}_2) = Var(\sum{k_iY_i} ) \\ & = \sum{\left( k_i^2Var(Y_i) \right)} \\ & = \sum{\left( k_i^2Var(\beta_1 +\beta_2X_i +u_i) \right)} \\ & = \sum{ \left( k_i^2Var(u_i) \right)} && \leftarrow \left[ k_i \equiv \frac{x_i}{\sum{x_i^2}} \right]\\ & = \sum{ \left( \left(\frac{x_i}{\sum{x_i^2}} \right)^2 \cdot \sigma^2 \right)} \\ & = \frac{\sigma^2}{\sum{x_i^2}} \end{align}$$` > 其中, `\(Var(u_i) \equiv \sigma^2\)`表示随机干扰项 `\(u_i\)`的总体方差。 --- ## 估计精度:截距系数的方差和样本方差 .pull-left[ .fl.pa2.bg-lightest-blue[ 截距系数( `\(\hat{\beta}_1\)`)的**总体方差**( `\(\sigma^2_{\hat{\beta}_1}\)`)和**总体标准差**( `\(\sigma_{\hat{\beta}_1}\)`): `$$\begin{align} Var(\hat{\beta}_1) \equiv \sigma_{\hat{\beta}_1}^2 &=\frac{\sum{X_i^2}}{n} \cdot \frac{\sigma^2}{\sum{x_i^2}} \\ \sigma_{\hat{\beta}_1} & =\sqrt{\frac{\sum{X_i^2}}{n} \cdot \frac{\sigma^2}{\sum{x_i^2}}} \end{align}$$` - 其中, `\(Var(u_i) \equiv \sigma^2\)`表示随机干扰项 `\((u_i)\)`的总体方差。 ] ] .pull-right[ .fl.pa2.bg-light-green[ 截距系数 `\((\hat{\beta}_1)\)`的**样本方差** `\((S^2_{\hat{\beta}_1})\)`和**样本标准差** `\((S_{\hat{\beta}_1})\)`: `$$\begin{align} S_{\hat{\beta}_1}^2 &=\frac{\sum{X^2_i}}{n} \cdot \frac{\hat{\sigma}^2}{\sum{x_i^2}} \\ S_{\hat{\beta}_1} &=\sqrt{\frac{\sum{X^2_i}}{n} \cdot \frac{\hat{\sigma}^2}{\sum{x_i^2}}} \end{align}$$` - 其中, `\(E(\sigma^2) = \hat{\sigma}^2 = \frac{\sum{e_i^2}}{n-2}\)`表示对随机干扰项 `\((u_i)\)`的总体方差的**无偏估计量**。 ] ] --- ### (附录)证明过程1 **步骤1** `\(\hat{\beta}_1\)`的变形: `$$\begin{align} \hat{\beta_1} & = \bar{Y}_i-\hat{\beta}_2\bar{X}_i && \leftarrow \left[ \hat{\beta}_2= \sum{k_iY_i} \right] \\ & = \frac{1}{n} \sum{Y_i} - \sum{\left( k_iY_i \cdot \bar{X} \right)} \\ & = \sum{\left( (\frac{1}{n} - k_i\bar{X}) \cdot Y_i \right)} && \leftarrow \left[ w_i \equiv \frac{1}{n} - k_i\bar{X} \right]\\ & = \sum{w_iY_i} \end{align}$$` > - 其中:令 `\(w_i \equiv \frac{1}{n} - k_i\bar{X}\)` --- ### (附录)证明过程2 **步骤2**计算 `\(\hat{\beta}_1\)`的**总体方差**( `\(\sigma^2_{\hat{\beta}_1}\)`): `$$\begin{align} \sigma^2_{\hat{\beta}_1} & \equiv Var(\hat{\beta_1}) = Var(\sum{w_iY_i}) \\ & = \sum{\left( w_i^2Var(\beta_1 +\beta_2X_i + u_i) \right)} && \leftarrow \left[w_i \equiv \frac{1}{n} - k_i\bar{X} \right]\\ & = \sum{\left( \left( \frac{1}{n} - k_i\bar{X} \right)^2Var(u_i) \right)} \\ & = \sigma^2 \cdot \sum{ \left( \frac{1}{n^2} - \frac{2 \bar{X} k_i}{n} + k_i^2 \bar{X}^2 \right) } && \leftarrow \left[ \sum{k_i} = \sum{\left( \frac{x_i}{\sum{x_i^2}} \right)= \frac{\sum{x_i}} {\sum{x_i^2}}}=0 \right] \\ & = \sigma^2 \cdot \left( \frac{1}{n} + \bar{X}^2\sum{k_i^2} \right) && \leftarrow \left[ k_i \equiv \frac{x_i}{\sum{x_i^2}} \right]\\ & = \sigma^2 \cdot \left( \frac{1}{n} + \bar{X}^2\sum{ \left( \frac{x_i}{\sum{x_i^2}} \right) ^2} \right) \end{align}$$` --- ### (附录)证明过程2(续) **步骤2**计算 `\(\hat{\beta}_1\)`的**总体方差**( `\(\sigma^2_{\hat{\beta}_1}\)`)(续前): `$$\begin{align} & = \sigma^2 \cdot \left( \frac{1}{n} + \bar{X}^2 \frac{\sum{x_i^2}}{\left( \sum{x_i^2} \right)^2} \right) \\ & = \sigma^2 \cdot \left( \frac{1}{n} + \frac{ \bar{X}^2 } { \sum{x_i^2} } \right) \\ & = \frac{\sum{x_i^2} + n\bar{X}^2} {n\sum{x_i^2}} \cdot \sigma^2 && \leftarrow \left[ \sum{x_i^2} + n\bar{X}^2 = \sum{(X_i-\bar{X})^2} + n\bar{X}^2 = \sum{X_i^2}\right]\\ & = \frac{\sum{X_i^2}}{n} \cdot \frac{\sigma^2}{\sum{x_i^2}} \end{align}$$` --- ## 估计精度:小结与思考 现在做一个**内容小结**: - 为了衡量OLS方法的点估计量是否稳定或是否可信,我们一般采用方差和标准差指标来表达。 - 大家应熟记**斜率**和**截距**估计量的**总体方差**和**样本方差**最终公式。 请大家**思考**如下问题: - 总体方差和样本方差都是确定的数么? - 二者分别受那些因素的影响?二者又有什么联系? - 证明过程中,约定的 `\(k_i\)`和 `\(w_i\)`,有什么特征? -- .pull-left[ `$$\begin{cases} \begin{align} \sum{k_i} & =0 \\ \sum{k_iX_i} & = 1 \end{align} \end{cases}$$` ] .pull-right[ `$$\begin{cases} \begin{align} \sum{w_i} & =1 \\ \sum{w_iX_i} & = 0 \end{align} \end{cases}$$` ] --- ###(案例)计算回归系数的样本方差 对于“教育程度案例”,利用FF-ff计算表,以及我们已算出的如下计算量: - 回归误差方差: `\(\hat{\sigma}^2=\)` 0.8812。 则可以进一步计算出,回归系数的样本方差的标准差分别为: `$$\begin{align} S^2_{\hat{\beta}_2} &= \frac{\hat{\sigma}^2} {\sum{x_i^2}} =\frac{0.8812}{182}=0.0048\\ S_{\hat{\beta}_2} &= \sqrt{\frac{\hat{\sigma}^2} {\sum{x_i^2}}} =\sqrt{0.0048}=0.0696 \end{align}$$` `$$\begin{align} S^2_{\hat{\beta}_1} &= \frac{\sum{X_i^2}} {n} \frac{\hat{\sigma}^2} {\sum{x_i^2}} =\frac{2054}{13}\frac{0.8812}{182}=0.765\\ S_{\hat{\beta}_1} &= \sqrt{\frac{\sum{X_i^2}}{n}\frac{\hat{\sigma}^2} {\sum{x_i^2}}} =\sqrt{0.765}=0.8746 \end{align}$$` --- name: ols-interval ## 区间估计:斜率系数 `$$\begin{align} \hat{\beta}_2 & \sim N(\mu_{\hat{\beta}_2}, \sigma^2_{\hat{\beta}_2}) && \leftarrow \left[ \mu_{\hat{\beta}_2}= \beta_2; \quad \sigma^2_{\hat{\beta}_2} = \frac{\sigma^{2}}{\sum x_{i}^{2}} \right] \end{align}$$` `$$\begin {align} &Z=\frac{\left(\hat{\beta}_{2}-\beta_{2}\right)}{\sqrt{\operatorname{var}\left(\hat{\beta}_{2}\right)}} =\frac{\left(\hat{\beta}_{2}-\beta_{2}\right)}{\sqrt{\sigma_{\beta_{2}}^{2}}} =\frac{\hat{\beta}_{2}-\beta_{2}}{\sigma_{\hat{\beta}_{2}}} =\frac{\left(\hat{\beta}_{2}-\beta_{2}\right)}{\sqrt{\frac{\sigma^{2}}{\sum x_{i}^{2}}}} && \leftarrow Z \sim N(0, 1) \end {align}$$` `$$\begin{align} T&=\frac{\left(\hat{\beta}_{2}-\beta_{2}\right)}{\sqrt{S_{\beta_{2}}^{2}}} =\frac{\hat{\beta}_{2}-\beta_{2}}{\sqrt{S_{\beta_{2}}^{2}}} =\frac{\hat{\beta}_{2}-\beta_{2}}{S_{\hat{\beta}_{2}}} && \leftarrow T \sim t(n-2) \end{align}$$` `$$\begin{align} S^2_{\hat{\beta}_2} =\frac{\hat{\sigma}^{2}}{\sum x_{i}^{2}} ; \quad \hat{\sigma}^{2}=\frac{\sum e_{i}^{2}}{n-2} \end{align}$$` `$$\begin{align} \operatorname{Pr}\left[-t_{\alpha / 2,(n-2)} \leq \mathrm{T} \leq t_{\alpha / 2,(n-2)}\right]=1-\alpha \end{align}$$` --- ## 区间估计:斜率系数 `$$\begin {align} \operatorname{Pr}\left[-t_{\alpha / 2,(n-2)} \leq \frac{\hat{\beta}_{2}-\beta_{2}}{S_{\hat{\beta}_{2}}} \leq t_{\alpha / 2 ,(n-2)}\right]=1-\alpha \end {align}$$` `$$\begin {align} \operatorname{Pr}\left[\hat{\beta}_{2}-t_{\alpha / 2,(n-2)} \cdot S_{\hat{\beta}_{2}} \leq \beta_{2} \leq \hat{\beta}_{2}+t_{\alpha / 2,(n-2)} \cdot S_{\hat{\beta}_{2}}\right]=1-\alpha \end {align}$$` 因此, `\(\beta_2\)`的 `\(100(1-\alpha)\%\)`置信上限和下限分别为: `$$\hat{\beta}_{2} \pm t_{\alpha / 2} \cdot S_{\hat{\beta}_{2}}$$` `\(\beta_2\)`的 `\(100(1-\alpha)\%\)`置信区间为: `$$\left[ \hat{\beta}_{2} - t_{\alpha / 2} \cdot S_{\hat{\beta}_{2}}, \quad \hat{\beta}_{2} + t_{\alpha / 2} \cdot S_{\hat{\beta}_{2}} \right]$$` --- ## 区间估计:截距系数 `$$\begin{align} \hat{\beta}_1 & \sim N(\mu_{\hat{\beta}_1}, \sigma^2_{\hat{\beta}_1}) && \leftarrow \left[ \mu_{\hat{\beta}_1}= \beta_1; \quad \sigma^2_{\hat{\beta}_1} = \frac{\sum{X_i^2}}{n} \frac{\sigma^{2}}{\sum x_{i}^{2}} \right] \end{align}$$` `$$\begin {align} &Z=\frac{\left(\hat{\beta}_{1}-\beta_{1}\right)}{\sqrt{\operatorname{var}\left(\hat{\beta}_{1}\right)}} =\frac{\left(\hat{\beta}_{1}-\beta_{1}\right)}{\sqrt{\sigma_{\beta_{1}}^{2}}} =\frac{\hat{\beta}_{1}-\beta_{1}}{\sigma_{\hat{\beta}_{1}}} =\frac{\left(\hat{\beta}_{1}-\beta_{1}\right)}{\sqrt{\frac{\sum{X^2_i}}{n} \cdot \frac{\sigma^{2}}{\sum x_{i}^{2}}}} && \leftarrow Z \sim N(0, 1) \end {align}$$` `$$\begin{align} T&=\frac{\left(\hat{\beta}_{1}-\beta_{1}\right)}{S^2_{\hat{\beta}_1}} =\frac{\hat{\beta}_{1}-\beta_{1}}{\sqrt{S_{\beta_{1}}^{2}}} =\frac{\hat{\beta}_{1}-\beta_{1}}{S_{\hat{\beta}_{1}}} && \leftarrow T \sim t(n-2) \end{align}$$` `$$\begin{align} S^2_{\hat{\beta}_1} =\frac{\sum{X_i^2}}{n} \cdot \frac{\hat{\sigma}^{2}}{\sum x_{i}^{2}} ; \quad \hat{\sigma}^{2}=\frac{\sum e_{i}^{2}}{n-2} \end{align}$$` `$$\begin{align} \operatorname{Pr}\left[-t_{\alpha / 2,(n-2)} \leq \mathrm{T} \leq t_{\alpha / 2,(n-2)}\right]=1-\alpha \end{align}$$` --- ## 区间估计:截距系数 `$$\begin {align} \operatorname{Pr}\left[-t_{\alpha / 2,(n-2)} \leq \frac{\hat{\beta}_{1}-\beta_{1}}{S_{\hat{\beta}_{1}}} \leq t_{\alpha / 2 ,(n-2)}\right]=1-\alpha \end {align}$$` `$$\begin {align} \operatorname{Pr}\left[\hat{\beta}_{1}-t_{\alpha / 2,(n-2)} \cdot S_{\hat{\beta}_{1}} \leq \beta_{1} \leq \hat{\beta}_{1}+t_{\alpha / 2,(n-2)} \cdot S_{\hat{\beta}_{1}}\right]=1-\alpha \end {align}$$` 因此, `\(\beta_1\)`的 `\(100(1-\alpha)\%\)`置信上限和下限分别为: `$$\hat{\beta}_{1} \pm t_{\alpha / 2} \cdot S_{\hat{\beta}_{1}}$$` `\(\beta_1\)`的 `\(100(1-\alpha)\%\)`置信区间为: `$$\left[ \hat{\beta}_{1} - t_{\alpha / 2} \cdot S_{\hat{\beta}_{1}}, \quad \hat{\beta}_{1} + t_{\alpha / 2} \cdot S_{\hat{\beta}_{1}} \right]$$` --- ## 区间估计:随机干扰项的方差 `$$\begin {align} \chi^{2} & =(n-2) \frac{\hat{\sigma}^{2}}{\sigma^{2}} &&\leftarrow \quad \chi^{2} \sim \chi^{2}(n-2) \end {align}$$` `$$\begin {align} \operatorname{Pr}\left(\chi_{\alpha / 2}^{2} \leq \chi^{2} \leq \chi_{\alpha / 2}^{2}\right)=1-\alpha \end {align}$$` `$$\begin {align} \operatorname{Pr}\left(\chi_{\alpha / 2}^{2} \leq (n-2) \frac{\hat{\sigma}^{2}}{\sigma^{2}} \leq \chi_{1-\alpha / 2}^{2}\right)=1-\alpha \end {align}$$` `$$\begin {align} \operatorname{Pr}\left[(n-2) \frac{\hat{\sigma}^{2}}{\chi_{1-\alpha/2}^{2}} \leq \sigma^{2} \leq (n-2) \frac{\hat{\sigma}^{2}}{\chi_{\alpha / 2}^{2}}\right]=1-\alpha \end {align}$$` 因此, `\(\sigma^2\)`的 `\(100(1-\alpha)\%\)`为: `$$\left[ (n-2) \frac{\hat{\sigma}^{2}}{\chi_{1-\alpha/2}^{2}}, \quad (n-2) \frac{\hat{\sigma}^{2}}{\chi_{\alpha / 2}^{2}}\right]$$` --- ### (案例)主模型 我们继续利用样本数据对**教育和工资案例**进行分析。 > **教育和工资案例**的总体回归模型(PRM)如下: `$$\begin{align} Wage_i & = \beta_1 + \beta_2 Edu_i +u_i \\ Y_i & = \beta_1 + \beta_2 X_i +u_i \\ \end{align}$$` > **教育和工资案例**的总体回归模型(SRM)如下: `$$\begin{align} \widehat{Wage}_i & = \hat{\beta}_1 + \hat{\beta}_2 Edu_i +e_i \\ \hat{Y}_i & = \hat{\beta}_1 + \hat{\beta}_2 X_i + e_i \\ \end{align}$$` --- ### (案例)相关计算量 我们之前已算出“教育程度案例”中的如下计算量: - 回归系数: `\(\hat{\beta}_1 =\)` -0.0145; `\(\hat{\beta}_2 =\)` 0.7241; `\(\hat{\sigma}^2=\)` 0.8812 。 - 回归误差方差: `\(\hat{\sigma}^2=\)` 0.8812。 - 回归系数的样本方差: `\(S^2_{\hat{\beta}_1} = \frac{\sum{X_i^2}}{n} \cdot \frac{\hat{\sigma}^2} {\sum{x_i^2}}=\)` 0.7650; `\(S^2_{\hat{\beta}_2} = \frac{\hat{\sigma}^2} {\sum{x_i^2}}=\)` 0.0048; - 回归系数的样本标准差: `\(S_{\hat{\beta}_1} =\)` 0.8746; `\(S_{\hat{\beta}_2} =\)` 0.0696。 给定 `\(\alpha=0.05,\quad (1-\alpha) 100 \%=95 \%\)`,我们可以查t分布表得到理论参照值: `\(t_{\alpha / 2}(n-2)=t_{0.05 / 2}(11)=\)` 2.2010 --- ### (案例)回归系数的区间估计 下面我们进一步计算回归系数的置信区间: 那么,截距参数 `\(\beta_1\)`的95%置信区间为: `$$\begin{align} \hat{\beta}_{1} - t_{\alpha / 2} \cdot S_{\hat{\beta}_{1}} \quad \leq & \beta_1 \leq \quad \hat{\beta}_{1} + t_{\alpha / 2} \cdot S_{\hat{\beta}_{1}} \\ -0.0145-2.201\ast0.8746\quad \leq & \beta_1 \quad \leq-0.0145+2.201\ast0.8746\\ -1.9395\quad \leq & \beta_1 \quad \leq1.9106\\ \end{align}$$` 那么,斜率参数 `\(\beta_2\)`的95%置信区间为: `$$\begin{align} \hat{\beta}_{2} - t_{\alpha / 2} \cdot S_{\hat{\beta}_{2}} \quad \leq & \beta_2 \leq \quad \hat{\beta}_{2} + t_{\alpha / 2} \cdot S_{\hat{\beta}_{2}} \\ 0.7241-2.201\ast0.0696\quad \leq & \beta_2 \quad \leq0.7241+2.201\ast0.0696\\ 0.5709\quad \leq & \beta_2 \quad \leq0.8772\\ \end{align}$$` --- ### (案例)随机干扰项方差的区间估计 - 给定 `\(\alpha=0.05,\quad (1-\alpha) 100 \%=95 \%\)` - 查卡方分布表可知: - `\(\chi^2_{\alpha / 2}(n-2)=\chi^2_{0.05 / 2}(11)=\chi^2_{0.025}(11)=\)` 3.8157 - `\(\chi^2_{1-\alpha / 2}(n-2)=\chi^2_{1-0.05 / 2}(11)=\chi^2_{0.975}(11)=\)` 21.9200 们之前已算出回归误差方差 `\(\hat{\sigma}^2=\frac{\sum{e_i^2}}{n-2}=\)` 0.8812 。因此可以算出 `\(\sigma^2\)`的95%置信区间为: `$$\begin {align}\\ (n-2) \frac{\hat{\sigma}^{2}}{\chi_{\alpha}^{2}} \leq \sigma^{2} \leq(n-2) \frac{\hat{\sigma}^{2}}{\chi_{1-\alpha / 2}^{2}}\\ 11\ast \frac{0.8812}{21.92} \leq \sigma^2 \leq11\ast \frac{0.8812}{3.8157}\\ 0.4422\leq \sigma^2 \leq2.5403\\ \end {align}$$` --- layout:false background-image: url("../pic/thank-you-gif-funny-little-yellow.gif") class: inverse,center # 本节结束