background-image: url("../pic/slide-front-page.jpg") class: center,middle exclude: FALSE # 统计学原理(Statistic) <!--- chakra: libs/remark-latest.min.js ---> ### 胡华平 ### 西北农林科技大学 ### 经济管理学院数量经济教研室 ### huhuaping01@hotmail.com ### 2023-05-08
--- class: center, middle, duke-orange,hide_logo name:chapter exclude: FALSE # 第五章 相关和回归分析 ### [.white[5.1 变量间关系的度量]](#corl) ### [5.2 回归分析的基本思想](#concept) ### [5.3 OLS方法与参数估计](#ols) ### [5.4 假设检验](#hypothesis) ### [5.5 拟合优度与残差分析](#goodness) ### [5.6 回归预测分析](#forecast) ### [5.7 回归报告解读](#report) --- layout: false class: center, middle, duke-softblue,hide_logo name: corl # 5.1 变量间关系的度量 ### [变量间的关系](#corl-vars) ### [相关关系的描述与测度](#corl-measure) ### [相关系数的显著性检验](#corl-test) --- 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="#corl"> 5.1 变量间关系的度量 </a> </span></div> --- ### (示例)变量间的关系:经济学专业解读 <img src="../pic/chpt05-intro-1-econ.png" width="60%" style="display: block; margin: auto;" /> > “我们数据不少,做了很严格的回归,但异常值略多略多,符合理论的数值反而难找……” --- ### (示例)变量间的关系:金融学专业解读 <img src="../pic/chpt05-intro-2-fin.png" width="60%" style="display: block; margin: auto;" /> > “我们的数据多如牛毛,无孔不入。即使做完回归,也会发现异常值和符合理论的数值多得不忍直视。” --- ### (示例)变量间的关系:土木工程专业解读 <img src="../pic/chpt05-intro-3-engine.png" width="60%" style="display: block; margin: auto;" /> > “我们得要设计余量,所以理论设计得远高于实际承受……” --- ### (示例)变量间的关系:物理学专业解读 <img src="../pic/chpt05-intro-4-physics.png" width="60%" style="display: block; margin: auto;" /> > “我们的理论和数据严丝合缝,bingo!” --- ### (示例)变量间的关系:环境科学专业解读 <img src="../pic/chpt05-intro-5-eniron.png" width="60%" style="display: block; margin: auto;" /> > “我们的理论和数据大致吻合,就是……应用范围有点蛋疼。” --- ### (示例)变量间的关系:历史学专业解读 <img src="../pic/chpt05-intro-6-history.png" width="60%" style="display: block; margin: auto;" /> > “数据虽然很多,可我们能用理论把他们统统连起来!” --- ### (示例)变量间的关系:政治学专业解读 <img src="../pic/chpt05-intro-7-politics.png" width="60%" style="display: block; margin: auto;" /> > “世界大势一日三变,尽管我们数据不少,可……我们的理论跟数据趋势是反着来的……” --- ### (示例)变量间的关系:社会学专业解读 <img src="../pic/chpt05-intro-8-sociology.png" width="60%" style="display: block; margin: auto;" /> > “学海无涯苦作舟。那么多数据,那么多理论,慢慢学,恩……” --- ### (示例)变量间的关系:数学专业解读 <img src="../pic/chpt05-intro-9-math.png" width="60%" style="display: block; margin: auto;" /> > “数据很少,但能建立理论~” --- ### (示例)变量间的关系:新闻学专业解读 <img src="../pic/chpt05-intro-10-journalism.png" width="60%" style="display: block; margin: auto;" /> > (示例)“只有一个数据,也能建立理论……” --- ### (示例)变量间的关系:哲学专业解读 <img src="../pic/chpt05-intro-11-philosophy.png" width="60%" style="display: block; margin: auto;" /> > “没有数据,依然建立理论……” --- ### (示例)变量间的关系:文学批评专业解读 <img src="../pic/chpt05-intro-12-literary.png" width="60%" style="display: block; margin: auto;" /> > “如图所示,你懂的……” --- name: corl-vars ## 变量间的关系:函数关系 两个变量若存在是一一对应的确定关系,则称之为二者具有**函数关系**。 <div class="notes"> <p>设有两个变量 <span class="math inline">\(X\)</span>和 <span class="math inline">\(Y\)</span>,变量 <span class="math inline">\(Y\)</span>随变量 <span class="math inline">\(X\)</span>一起变化,并完全依赖于 <span class="math inline">\(X\)</span>,当变量 <span class="math inline">\(X\)</span>取某个数值时, <span class="math inline">\(Y\)</span>依确定的关系取相应的值,则称 <span class="math inline">\(Y\)</span>是 <span class="math inline">\(X\)</span>的函数,记为 <span class="math inline">\(Y = f(X)\)</span>,其中 <span class="math inline">\(X\)</span>称为自变量, <span class="math inline">\(Y\)</span>称为因变量。</p> </div> > 从**几何学**角度来看,数据集各观测点会落在一条曲线上。 --- ### (示例)函数关系 某种商品的销售额 `\(Y\)`与销售量 `\(X\)`之间的关系可表示为( `\(P\)`为单价): `$$Y_i = P_i\cdot X_i$$` 圆的面积 `\(S\)`与半径 `\(R\)`之间的关系可表示为: `$$S = \pi R^2$$` 企业的原材料消耗额 `\(Y\)`与产量 `\(X1\)` 、单位产量消耗 `\(X2\)` 、原材料价格 `\(X3\)`之间的关系可表示为: `$$Y = X_1 \cdot X_2 \cdot X_3$$` --- ## 变量间的关系:相关关系(correlation) <div class="figure" style="text-align: center"> <img src="../pic/chpt05-measure-rel.png" alt="相关关系的类型" width="90%" /> <p class="caption">相关关系的类型</p> </div> --- ### (示例)相关关系 <div class="case"> <ul> <li><p>父亲身高 <span class="math inline">\(Y\)</span>与子女身高 <span class="math inline">\(X\)</span>之间的关系</p></li> <li><p>收入水平 <span class="math inline">\(Y\)</span>与受教育程度 <span class="math inline">\(X\)</span>之间的关系</p></li> <li><p>粮食单位面积产量 <span class="math inline">\(Y\)</span>与施肥量 <span class="math inline">\(X1\)</span> 、降雨量 <span class="math inline">\(X2\)</span>、温度 <span class="math inline">\(X3\)</span>之间的关系</p></li> <li><p>商品的消费量 <span class="math inline">\(Y\)</span>与居民收入 <span class="math inline">\(X\)</span>之间的关系</p></li> <li><p>商品销售额 <span class="math inline">\(Y\)</span>与广告费支出 <span class="math inline">\(X\)</span>之间的关系</p></li> </ul> </div> --- ## 相关关系的描述与测度:问题与假定 相关分析要解决的问题: - 变量之间是否存在关系? - 如果存在关系,它们之间是什么样的关系? - 变量之间的关系强度如何? - 样本所反映的变量之间的关系能否代表总体变量之间的关系? 相关分析中的总体假定: - 两个变量之间是线性关系 - 两个变量都是随机变量 --- ## 相关关系的描述与测度:散点图 .fl.w-50[ <img src="../pic/chpt05-scatter-p0.png" width="583" style="display: block; margin: auto;" /> ] -- .fl.w-50[ <img src="../pic/chpt05-scatter-p1.png" width="583" style="display: block; margin: auto;" /> ] --- ## 相关关系的描述与测度:散点图 .fl.w-50[ <img src="../pic/chpt05-scatter-n0.png" width="583" style="display: block; margin: auto;" /> ] -- .fl.w-50[ <img src="../pic/chpt05-scatter-n1.png" width="583" style="display: block; margin: auto;" /> ] --- ## 相关关系的描述与测度:散点图 .fl.w-50[ <img src="../pic/chpt05-scatter-nonline.png" width="584" style="display: block; margin: auto;" /> ] -- .fl.w-50[ <img src="../pic/chpt05-scatter-independence.png" width="584" style="display: block; margin: auto;" /> ] --- ## 相关关系的描述与测度:散点图 <img src="../pic/chpt05-scatter-all-cases.png" width="90%" style="display: block; margin: auto;" /> --- ### (示例)两类油价的散点图 <img src="../pic/chpt05-scatter-oil-price.png" width="90%" style="display: block; margin: auto;" /> --- ### (示例)传染病与认知水平的散点图 <img src="../pic/chpt05-scatter-disease.png" width="80%" style="display: block; margin: auto;" /> --- name: corl-measure ## 相关关系的描述与测度:相关系数 **相关系数**(correlation coefficient):是度量变量之间关系强度的一个统计量。 - 它是对两个变量之间线性相关强度的一种度量。 - 一般称为**简单相关系数**,也称为**线性相关系数**(linear correlation coefficient) 。 - 或称为**Pearson相关系数**(Pearson’s correlation coefficient) 。 相关系数记号表达: - 若相关系数是根据总体全部数据计算的,称为总体相关系数,记为 `\(\rho\)`。 - 若是根据样本数据计算的,则称为样本相关系数,简称为相关系数,记为 `\(r\)`。 --- ## 相关关系的描述与测度:计算公式 .mb1.pa1.bg-light-blue[ 简单相关系数的大FF计算公式: `$$\begin{align} r & = \frac{n \sum X_i Y_i -\sum X_i \sum Y_i}{\sqrt{n \sum X_i^{2}-\left(\sum X_i\right)^{2}} \cdot \sqrt{n \sum Y_i^{2}-\left(\sum Y_i\right)^{2}}} \tag{eq01} \end{align}$$` ] .mb1.pa1.bg-light-blue[ 简单相关系数的小ff计算公式: `$$\begin{align} r & = \frac{ \sum{\left( (X_i - \overline{X})(Y_i - \overline{Y})\right ) } }{\sqrt{\sum{(X_i - \overline{X})^2 }\sum{(Y_i - \overline{Y})^2}}} = \frac{S S_{XY}}{\sqrt{S S_{XX}} \sqrt{S S_{YY}}} = \frac{\sum{x_iy_i}}{\sqrt{\sum{x_i^2}\sum{y_i^2}}} \tag{eq02} \end{align}$$` ] .mb1.pa1.bg-lightest-blue[ `$$\begin{align} S S_{X X} =\sum_{i=1}^{n}\left(X_{i}-\overline{X}\right)^{2} ;\quad S S_{Y Y} =\sum_{i=1}^{n}\left(Y_{i}-\overline{Y}\right)^{2} ;\quad S S_{X Y}=\sum_{i=1}^{n}\left(X_{i}-\overline{X}\right)\left(Y_{i}-\overline{Y}\right) \end{align}$$` ] --- ## 相关关系的描述与测度:特征 简单相关系数的特征: **性质1**: `\(r\)`的取值范围是 `\([-1,1]\)`, `\(|r|\)`越趋于1表示相关关系越强; `\(|r|\)`越趋于0表示相关关系越弱。 - 如果 `\(|r|=1\)`,为完全相关。其中 `\(r =1\)`,为完全正相关; `\(r =-1\)`,为完全负正相关 - 如果 `\(r = 0\)`,不存在线性相关关系 - 如果 `\(-1<r<0\)`,为负相关;如果 `\(0<r<1\)`,为正相关。 **性质2**:r具有对称性。即 `\(X\)`与 `\(Y\)`之间的相关系数和 `\(Y\)`与 `\(X\)`之间的相关系数相等,即 `\(r_{XY}= r_{YX}\)`。 --- ## 相关关系的描述与测度:特征 简单相关系数的特征: **性质3**: `\(r\)`数值大小与 `\(X\)`和 `\(Y\)`原点及尺度无关,即改变 `\(X\)`和 `\(Y\)`的数据原点及计量尺度,并不改变 `\(r\)`数值大小。 **性质4**:仅仅是 `\(X\)`与 `\(Y\)`之间线性关系的一个度量,它不能用于描述非线性关系。这意为着, `\(r=0\)`只表示两个变量之间不存在线性相关关系,并不说明变量之间没有任何关系 **性质5**: `\(r\)`虽然是两个变量之间线性关系的一个度量,却不一定意味着 `\(X\)`与 `\(Y\)`一定有因果关系。 --- ## 相关关系的描述与测度:解释 <div class="fyi"> <p>下面给出实证研究时,对相关系数的经验解释:</p> <ul> <li><p>当 <span class="math inline">\(|r|<0.8\)</span>时,可视为两个变量之间高度相关。</p></li> <li><p>当 <span class="math inline">\(0.5<|r|<0.8\)</span>时,可视为中度相关。</p></li> <li><p>当 <span class="math inline">\(0.3<|r|<0.5\)</span>时,视为低度相关。</p></li> <li><p>当 <span class="math inline">\(|r|<0.3\)</span>时,说明两个变量之间的相关程度极弱,可视为不相关。</p></li> </ul> <p>而且上述解释必须建立在对相关系数的显著性进行检验的基础之上。</p> </div> --- ## 相关关系的描述与测度:简单相关系数 **简单相关系数**(simple correlation coefficient): .pull-left[ - `\(Y_i\)`和 `\(X_{2i}\)`之间的相关系数: `$$\begin {align} r_{12}=\frac{\sum y_{i} x_{2 i}}{\sqrt{\sum y_{i}^{2}} \sqrt{\sum x_{2 i}^{2}}} \end {align}$$` - `\(Y_i\)`和 `\(X_{3i}\)`之间的相关系数: `$$\begin {align} r_{13}=\frac{\sum y_{i} x_{3 i}}{\sqrt{\sum y_{i}^{2}} \sqrt{\sum x_{3 i}^{2}}} \end {align}$$` ] .pull-right[ - `\(X_{2i}\)`和 `\(X_{3i}\)`之间的相关系数: `$$\begin {align} r_{23}=\frac{\sum x_{2 i} x_{3 i}}{\sqrt{\sum x_{2 i}^{2}} \sqrt{\sum x_{3 i}^{2}}} \end {align}$$` ] --- ## 相关关系的描述与测度:偏相关系数 **偏相关系数**(partial correlation coefficient): 一个不依赖于 `\(X_{2i}\)`的,对 `\(X_{3i}\)`和 `\(Y_i\)`的影响的一种相关系数。 .pull-left[ - 保持 `\(X_{3i}\)`不变, `\(Y_i\)`和 `\(X_{2i}\)`之间的相关系数: `$$\begin {align} r_{12 \cdot 3}=\frac{r_{12}-r_{13} r_{23}}{\sqrt{\left(1-r_{13}^{2}\right)\left(1-r_{23}^{2}\right)}} \end {align}$$` - 保持 `\(X_{2i}\)`不变, `\(Y_i\)`和 `\(X_{3i}\)`之间的相关系数: `$$\begin {align} r_{13.2}=\frac{r_{13}-r_{12} r_{23}}{\sqrt{\left(1-r_{12}^{2}\right)\left(1-r_{23}^{2}\right)}} \end {align}$$` ] .pull-right[ - 保持 `\(Y_i\)`不变, `\(X_{2i}\)`和 `\(X_{3i}\)`之间的相关系数: `$$\begin {align} r_{23.1}=\frac{r_{23}-r_{12} r_{13}}{\sqrt{\left(1-r_{12}^{2}\right)\left(1-r_{13}^{2}\right)}} \end {align}$$` ] --- name: corl-test ## 相关系数的显著性检验 **相关系数的显著性检验**,是指检验两个变量之间是否存在线性相关关系。 相关系数的显著性检验方法包括: - 等价于对回归斜率系数 `\(\beta_1\)`的检验(仅针对一元回归) - 采用R. A. Fisher提出的t检验 --- ## 相关系数的显著性检验 相关系数的显著性检验步骤: 1)提出假设: `\(H_0: \rho =0; H_1: \rho \neq 0\)` 2)计算样本统计量 `$$T^{\ast} = |r|\sqrt{\frac{n-2}{1-r^2}} \quad \sim t(n-2)$$` 3)给定显著性水平 `\(\alpha\)`,确定t理论分布值 `\(t_{1-\alpha/2}(n-2)\)`。 4)得到假设检验结论: - 若 `\(T^{\ast}> t_{1-\alpha/2}(n-2)\)`,则拒绝 `\(H_0\)`,认为显著存在相关关系; - 若 `\(T^{\ast} < t_{1-\alpha/2}(n-2)\)`,则无法拒绝 `\(H_0\)`,认为相关关系不显著。 --- ### 附录:假设检验的分布及统计量证明1/3 $$ `\begin{align} \sum_y y h(y \mid x)& =\sum_y y \frac{f(x, y)}{f_X(x)}= \beta_1 + \beta_2 x && \text{(1)} \end{align}` $$ $$ `\begin{align} \sum_y y f(x, y)&=(\beta_1+ \beta_2 x) f_X(x) && \text{(2)}\\ \sum_{x } \sum_y y f(x, y) &=\sum_{x }(\beta_1+ \beta_2 x) f_X(x) && \text{(3)} \\ \sum_{x } \sum_y x y f(x, y) &=\sum_{x }\left(\beta_1 x+ \beta_2 x^2\right) f_X(x) && \text{(4)} \\ E(X Y)&=\beta_1 E(X)+ \beta_2 E\left(X^2\right) && \text{(5)}\\ \end{align}` $$ $$ `\begin{align} \mu_Y&=\beta_1 + \beta_2 \mu_X && \text{(6 <--2)} \\ \mu_X \mu_Y+\rho \sigma_X \sigma_Y &=\beta_1 \mu_X+\beta_2\left(\mu_X^2+\sigma_X^2\right) && \text{(7 <--5)} \end{align}` $$ .footnote[ 当然,故事其实比上面还要更复杂。大家可以深入思考和讨论。参看:[1] Hogg R V, Tanis E A, Zimmerman D L. Probability and statistical inference[M]. 第10版. NJ,Hoboken:Pearson, 2020. pg 148 (section 4.3) ] --- ### 附录:假设检验的分布及统计量证明2/3 利用上述二元一次方程组,可以解出参数: $$ `\begin{align} \beta_1 &=\mu_Y-\rho \frac{\sigma_Y}{\sigma_X} \mu_X && \text{(8)} \\ \beta_2 &=\rho \frac{\sigma_Y}{\sigma_X} && \text{(9)} \end{align}` $$ $$ `\begin{align} E(Y \mid X_i)= \beta_1 +\beta_2X_i = \beta_1 + \rho \frac{\sigma_Y}{\sigma_X} X_i && \text{(10)} \end{align}` $$ 相关系数 `\(\rho\)`的显著性检验等价于一元线性回归分析中斜率参数 `\(\beta_2\)`的t检验过程,也即: `\(H_0: \rho = 0; \quad H_1: \rho \neq 0\)`;等价于 `\(H_0: \beta_2 = 0; \quad H_1: \beta_2 \neq 0\)` --- ### 附录:假设检验的分布及统计量证明3/3 一元线性回归 `\(Y_i = \beta_1 +\beta_2X_i + u_i\)`;斜率系数t检验 `\(H_0: \beta_2 = 0; H_1: \beta_2 \neq 0\)` $$ `\begin{align} t=\frac{\hat{\beta_2} -\beta_2}{\hat{\sigma}_{\hat{\beta}_2}} =\frac{\hat{\beta_2}}{\sqrt{\frac{\hat{\sigma}^2}{\sum\left(X_i-\bar{X}\right)^2}}} =\frac{\hat{\beta_2}-0}{\sqrt{\frac{\mathrm{MSE}}{\sum\left(X_i-\bar{X}\right)^2}}} =\frac{r \cdot \left(S_Y / S_X\right)}{\sqrt{\frac{(n-1) S_Y^2 \left(1-r^2\right)}{(n-2) } \cdot \frac{1}{(n-1)S_X^2}}} =\frac{r \sqrt{n-2}}{\sqrt{1-r^2}} \end{align}` $$ $$ `\begin{align} r &= \frac{S_{XY}}{S_X S_Y} \\ \hat{\beta}_2 &=\frac{\frac{1}{n-1} \sum_{i=1}^n\left(X_i-\bar{X}\right)\left(Y_i-\bar{Y}\right)}{\frac{1}{n-1} \sum_{i=1}^n\left(X_i-\bar{X}\right)^2}=\frac{S_{XY}}{S_X^2}=r \cdot \frac{S_Y}{S_X}\\ \hat{\beta}_1 & = \overline{Y} - \hat{\beta}_2 \overline{X} \\ M S E \equiv \sigma^2 &= \frac{\sum_{i=1}^n\left(Y_i-\hat{Y}_i\right)^2}{n-2}=\frac{\sum_{i=1}^n\left[Y_i-\left(\bar{Y}+\frac{S_{XY}}{S_X^2}\left(X_i-\bar{X}\right)\right)\right]^2}{n-2}=\frac{(n-1) S_Y^2\left(1-r^2\right)}{n-2} \end{align}` $$ ??? 参看队长问答[Why Test Statistic for the Pearson Correlation Coefficient](https://stats.stackexchange.com/questions/270612/why-test-statistic-for-the-pearson-correlation-coefficient-is-frac-r-sqrtn-2/321382#321382) 终极回答见[Three Tests for Rho](https://web.archive.org/web/20130625153233/https://onlinecourses.science.psu.edu/stat414/node/254) --- exclude: true ## (案例)银行贷款 --- ### (案例)银行贷款:案例数据 **案例说明**:某银行共有25家分行,分行及所在地区的相关变量数据如下表所示。
.footnote[**说明**:上述变量的含义分别是ID.bank(分行编号)、loan.bad(不良贷款)、loan.surplus(各项贷款余额 )、loan.receivable(本年累计应收贷款)、loan.numbers(贷款项目个数)、investment.fixed(本年固定资产投资额)。] --- ### (案例)银行贷款:不良贷款VS贷款余额的散点图 <div class="figure" style="text-align: center"> <img src="05-01-relationship_files/figure-html/unnamed-chunk-30-1.png" alt="不良贷款VS贷款余额散点图" /> <p class="caption">不良贷款VS贷款余额散点图</p> </div> --- ### (案例)银行贷款:不良贷款VS贷款余额的相关系数(大FF)
--- ### (案例)银行贷款:不良贷款VS贷款余额的相关系数(大FF) 相关系数 `\(r\)`的大FF计算公式(`eq01`): `$$\begin{align} r & = \frac{n \sum X_i Y_i -\sum X_i \sum Y_i}{\sqrt{n \sum X_i^{2}-\left(\sum X_i\right)^{2}} \cdot \sqrt{n \sum Y_i^{2}-\left(\sum Y_i\right)^{2}}} \\ & = \frac{25 \times 17080.14 - 3006.7 \times 93.2}{\sqrt{25 \times 516543.37-\left(3006.7\right)^2} \cdot \sqrt{25 \times 660.1-\left( 93.2\right)^{2}}} \\ & = 0.8436 \end{align}$$` --- ### (案例)银行贷款:不良贷款VS贷款余额的相关系数(小ff)
--- ### (案例)银行贷款:不良贷款VS贷款余额的相关系数 相关系数 `\(r\)`的小FF计算公式(`eq02`): `$$\begin{align} r & = \frac{ \sum{\left( (X_i - \overline{X})(Y_i - \overline{Y})\right ) } }{\sqrt{\sum{(X_i - \overline{X})^2 (Y_i - \overline{Y})^2}}} \\ & = \frac{\sum{x_i y_i}}{\sqrt{\sum{x_i^2}\sum{y_i^2}}} \\ & = \frac{5871.16}{\sqrt{ 154933.57 \times 312.65}} \\ & = 0.8436 \end{align}$$` --- ### (案例)银行贷款:相关系数矩阵表(Pearson) ```r corl_pearson<- round(cor(df_loan[,-1], method = "pearson"),4) corl_pearson[upper.tri(corl_pearson)]<- NA ``` <template id="4dde0b23-fa9f-4a5d-b505-50177ade3948"><style> .tabwid table{ border-spacing:0px !important; border-collapse:collapse; line-height:1; margin-left:auto; margin-right:auto; border-width: 0; display: table; margin-top: 1.275em; margin-bottom: 1.275em; border-color: transparent; } .tabwid_left table{ margin-left:0; } .tabwid_right table{ margin-right:0; } .tabwid td { padding: 0; } .tabwid a { text-decoration: none; } .tabwid thead { background-color: transparent; } .tabwid tfoot { background-color: transparent; } .tabwid table tr { background-color: transparent; } </style><div class="tabwid"><style>.cl-e37eba66{}.cl-e35f4b18{font-family:'Arial';font-size:19pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-e35f4b19{font-family:'Arial';font-size:19pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(255, 0, 0, 1.00);background-color:transparent;}.cl-e35f4b1a{font-family:'Arial';font-size:19pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(255, 165, 0, 1.00);background-color:transparent;}.cl-e35f4b1b{font-family:'Arial';font-size:19pt;font-weight:normal;font-style:normal;text-decoration:none;background-color:transparent;}.cl-e35f992e{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-e3605c9c{width:157.8pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3605c9d{width:135.7pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3605c9e{width:123pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3605c9f{width:93.4pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3605ca0{width:148.3pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3605ca1{width:135.7pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3605ca2{width:93.4pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3605ca3{width:157.8pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3605ca4{width:123pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3605ca5{width:148.3pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3605ca6{width:157.8pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e36083ac{width:148.3pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e36083ad{width:123pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e36083ae{width:93.4pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e36083af{width:135.7pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e36083b0{width:123pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e36083b1{width:157.8pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e36083b2{width:135.7pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e36083b3{width:93.4pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e36083b4{width:148.3pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e36083b5{width:157.8pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e36083b6{width:135.7pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e360aaa8{width:123pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e360aaa9{width:148.3pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e360aaaa{width:93.4pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style><table class='cl-e37eba66'><caption class="Table Caption"> Pearson相关系数矩阵 </caption><thead><tr style="overflow-wrap:break-word;"><td class="cl-e36083b5"><p class="cl-e35f992e"><span class="cl-e35f4b18"> </span></p></td><td class="cl-e360aaaa"><p class="cl-e35f992e"><span class="cl-e35f4b18">loan.bad</span></p></td><td class="cl-e360aaa8"><p class="cl-e35f992e"><span class="cl-e35f4b18">loan.surplus</span></p></td><td class="cl-e360aaa9"><p class="cl-e35f992e"><span class="cl-e35f4b18">loan.receivable</span></p></td><td class="cl-e36083b6"><p class="cl-e35f992e"><span class="cl-e35f4b18">loan.numbers</span></p></td><td class="cl-e36083b5"><p class="cl-e35f992e"><span class="cl-e35f4b18">investment.fixed</span></p></td></tr></thead><tbody><tr style="overflow-wrap:break-word;"><td class="cl-e3605c9c"><p class="cl-e35f992e"><span class="cl-e35f4b18">loan.bad</span></p></td><td class="cl-e3605c9f"><p class="cl-e35f992e"><span class="cl-e35f4b18">1.0000</span></p></td><td class="cl-e3605c9e"><p class="cl-e35f992e"><span class="cl-e35f4b1b"></span></p></td><td class="cl-e3605ca0"><p class="cl-e35f992e"><span class="cl-e35f4b1b"></span></p></td><td class="cl-e3605c9d"><p class="cl-e35f992e"><span class="cl-e35f4b1b"></span></p></td><td class="cl-e3605c9c"><p class="cl-e35f992e"><span class="cl-e35f4b1b"></span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-e3605ca3"><p class="cl-e35f992e"><span class="cl-e35f4b18">loan.surplus</span></p></td><td class="cl-e3605ca2"><p class="cl-e35f992e"><span class="cl-e35f4b19">0.8436</span></p></td><td class="cl-e3605ca4"><p class="cl-e35f992e"><span class="cl-e35f4b18">1.0000</span></p></td><td class="cl-e3605ca5"><p class="cl-e35f992e"><span class="cl-e35f4b1b"></span></p></td><td class="cl-e3605ca1"><p class="cl-e35f992e"><span class="cl-e35f4b1b"></span></p></td><td class="cl-e3605ca3"><p class="cl-e35f992e"><span class="cl-e35f4b1b"></span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-e3605ca6"><p class="cl-e35f992e"><span class="cl-e35f4b18">loan.receivable</span></p></td><td class="cl-e36083ae"><p class="cl-e35f992e"><span class="cl-e35f4b1a">0.7315</span></p></td><td class="cl-e36083ad"><p class="cl-e35f992e"><span class="cl-e35f4b18">0.6788</span></p></td><td class="cl-e36083ac"><p class="cl-e35f992e"><span class="cl-e35f4b18">1.0000</span></p></td><td class="cl-e36083af"><p class="cl-e35f992e"><span class="cl-e35f4b1b"></span></p></td><td class="cl-e3605ca6"><p class="cl-e35f992e"><span class="cl-e35f4b1b"></span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-e3605ca6"><p class="cl-e35f992e"><span class="cl-e35f4b18">loan.numbers</span></p></td><td class="cl-e36083ae"><p class="cl-e35f992e"><span class="cl-e35f4b1a">0.7003</span></p></td><td class="cl-e36083ad"><p class="cl-e35f992e"><span class="cl-e35f4b19">0.8484</span></p></td><td class="cl-e36083ac"><p class="cl-e35f992e"><span class="cl-e35f4b18">0.5858</span></p></td><td class="cl-e36083af"><p class="cl-e35f992e"><span class="cl-e35f4b18">1.0000</span></p></td><td class="cl-e3605ca6"><p class="cl-e35f992e"><span class="cl-e35f4b1b"></span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-e36083b1"><p class="cl-e35f992e"><span class="cl-e35f4b18">investment.fixed</span></p></td><td class="cl-e36083b3"><p class="cl-e35f992e"><span class="cl-e35f4b18">0.5185</span></p></td><td class="cl-e36083b0"><p class="cl-e35f992e"><span class="cl-e35f4b1a">0.7797</span></p></td><td class="cl-e36083b4"><p class="cl-e35f992e"><span class="cl-e35f4b18">0.4724</span></p></td><td class="cl-e36083b2"><p class="cl-e35f992e"><span class="cl-e35f4b1a">0.7466</span></p></td><td class="cl-e36083b1"><p class="cl-e35f992e"><span class="cl-e35f4b18">1.0000</span></p></td></tr></tbody></table></div></template> <div class="flextable-shadow-host" id="f53191a6-1fe3-48e7-a300-115aa4ab76df"></div> <script> var dest = document.getElementById("f53191a6-1fe3-48e7-a300-115aa4ab76df"); var template = document.getElementById("4dde0b23-fa9f-4a5d-b505-50177ade3948"); var caption = template.content.querySelector("caption"); if(caption) { caption.style.cssText = "display:block;text-align:center;"; var newcapt = document.createElement("p"); newcapt.appendChild(caption) dest.parentNode.insertBefore(newcapt, dest.previousSibling); } var fantome = dest.attachShadow({mode: 'open'}); var templateContent = template.content; fantome.appendChild(templateContent); </script> --- ### (案例)银行贷款:相关系数矩阵(Spearman) ```r corl_spearman<- round(cor(df_loan[,-1], method = "spearman"),4) corl_spearman[upper.tri(corl_spearman)] <- NA ``` <template id="6b7585c0-bded-4914-a982-dad435b9317a"><style> .tabwid table{ border-spacing:0px !important; border-collapse:collapse; line-height:1; margin-left:auto; margin-right:auto; border-width: 0; display: table; margin-top: 1.275em; margin-bottom: 1.275em; border-color: transparent; } .tabwid_left table{ margin-left:0; } .tabwid_right table{ margin-right:0; } .tabwid td { padding: 0; } .tabwid a { text-decoration: none; } .tabwid thead { background-color: transparent; } .tabwid tfoot { background-color: transparent; } .tabwid table tr { background-color: transparent; } </style><div class="tabwid"><style>.cl-e4035348{}.cl-e3e5b932{font-family:'Arial';font-size:19pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-e3e5b933{font-family:'Arial';font-size:19pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(255, 0, 0, 1.00);background-color:transparent;}.cl-e3e5b934{font-family:'Arial';font-size:19pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(255, 165, 0, 1.00);background-color:transparent;}.cl-e3e5b935{font-family:'Arial';font-size:19pt;font-weight:normal;font-style:normal;text-decoration:none;background-color:transparent;}.cl-e3e5e060{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-e3e65568{width:157.8pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e65569{width:135.7pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e6556a{width:123pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e6556b{width:93.4pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e6556c{width:148.3pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e6556d{width:135.7pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e6556e{width:93.4pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e6556f{width:157.8pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e65570{width:123pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e65571{width:148.3pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e65572{width:157.8pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e67c6e{width:148.3pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e67c6f{width:123pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e67c70{width:93.4pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e67c71{width:135.7pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e67c72{width:123pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e67c73{width:157.8pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e67c74{width:135.7pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e67c75{width:93.4pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e67c76{width:148.3pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e67c77{width:157.8pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e67c78{width:135.7pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e6a37e{width:123pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e6a37f{width:148.3pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-e3e6a380{width:93.4pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style><table class='cl-e4035348'><caption class="Table Caption"> Spearman相关系数矩阵 </caption><thead><tr style="overflow-wrap:break-word;"><td class="cl-e3e67c77"><p class="cl-e3e5e060"><span class="cl-e3e5b932"> </span></p></td><td class="cl-e3e6a380"><p class="cl-e3e5e060"><span class="cl-e3e5b932">loan.bad</span></p></td><td class="cl-e3e6a37e"><p class="cl-e3e5e060"><span class="cl-e3e5b932">loan.surplus</span></p></td><td class="cl-e3e6a37f"><p class="cl-e3e5e060"><span class="cl-e3e5b932">loan.receivable</span></p></td><td class="cl-e3e67c78"><p class="cl-e3e5e060"><span class="cl-e3e5b932">loan.numbers</span></p></td><td class="cl-e3e67c77"><p class="cl-e3e5e060"><span class="cl-e3e5b932">investment.fixed</span></p></td></tr></thead><tbody><tr style="overflow-wrap:break-word;"><td class="cl-e3e65568"><p class="cl-e3e5e060"><span class="cl-e3e5b932">loan.bad</span></p></td><td class="cl-e3e6556b"><p class="cl-e3e5e060"><span class="cl-e3e5b932">1.0000</span></p></td><td class="cl-e3e6556a"><p class="cl-e3e5e060"><span class="cl-e3e5b935"></span></p></td><td class="cl-e3e6556c"><p class="cl-e3e5e060"><span class="cl-e3e5b935"></span></p></td><td class="cl-e3e65569"><p class="cl-e3e5e060"><span class="cl-e3e5b935"></span></p></td><td class="cl-e3e65568"><p class="cl-e3e5e060"><span class="cl-e3e5b935"></span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-e3e6556f"><p class="cl-e3e5e060"><span class="cl-e3e5b932">loan.surplus</span></p></td><td class="cl-e3e6556e"><p class="cl-e3e5e060"><span class="cl-e3e5b933">0.8339</span></p></td><td class="cl-e3e65570"><p class="cl-e3e5e060"><span class="cl-e3e5b932">1.0000</span></p></td><td class="cl-e3e65571"><p class="cl-e3e5e060"><span class="cl-e3e5b935"></span></p></td><td class="cl-e3e6556d"><p class="cl-e3e5e060"><span class="cl-e3e5b935"></span></p></td><td class="cl-e3e6556f"><p class="cl-e3e5e060"><span class="cl-e3e5b935"></span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-e3e65572"><p class="cl-e3e5e060"><span class="cl-e3e5b932">loan.receivable</span></p></td><td class="cl-e3e67c70"><p class="cl-e3e5e060"><span class="cl-e3e5b934">0.7331</span></p></td><td class="cl-e3e67c6f"><p class="cl-e3e5e060"><span class="cl-e3e5b932">0.8148</span></p></td><td class="cl-e3e67c6e"><p class="cl-e3e5e060"><span class="cl-e3e5b932">1.0000</span></p></td><td class="cl-e3e67c71"><p class="cl-e3e5e060"><span class="cl-e3e5b935"></span></p></td><td class="cl-e3e65572"><p class="cl-e3e5e060"><span class="cl-e3e5b935"></span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-e3e65572"><p class="cl-e3e5e060"><span class="cl-e3e5b932">loan.numbers</span></p></td><td class="cl-e3e67c70"><p class="cl-e3e5e060"><span class="cl-e3e5b934">0.7172</span></p></td><td class="cl-e3e67c6f"><p class="cl-e3e5e060"><span class="cl-e3e5b933">0.8559</span></p></td><td class="cl-e3e67c6e"><p class="cl-e3e5e060"><span class="cl-e3e5b932">0.7393</span></p></td><td class="cl-e3e67c71"><p class="cl-e3e5e060"><span class="cl-e3e5b932">1.0000</span></p></td><td class="cl-e3e65572"><p class="cl-e3e5e060"><span class="cl-e3e5b935"></span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-e3e67c73"><p class="cl-e3e5e060"><span class="cl-e3e5b932">investment.fixed</span></p></td><td class="cl-e3e67c75"><p class="cl-e3e5e060"><span class="cl-e3e5b932">0.4407</span></p></td><td class="cl-e3e67c72"><p class="cl-e3e5e060"><span class="cl-e3e5b934">0.6582</span></p></td><td class="cl-e3e67c76"><p class="cl-e3e5e060"><span class="cl-e3e5b932">0.5469</span></p></td><td class="cl-e3e67c74"><p class="cl-e3e5e060"><span class="cl-e3e5b934">0.5975</span></p></td><td class="cl-e3e67c73"><p class="cl-e3e5e060"><span class="cl-e3e5b932">1.0000</span></p></td></tr></tbody></table></div></template> <div class="flextable-shadow-host" id="6fe286ba-df8d-4993-882b-b5ae0bf877b9"></div> <script> var dest = document.getElementById("6fe286ba-df8d-4993-882b-b5ae0bf877b9"); var template = document.getElementById("6b7585c0-bded-4914-a982-dad435b9317a"); var caption = template.content.querySelector("caption"); if(caption) { caption.style.cssText = "display:block;text-align:center;"; var newcapt = document.createElement("p"); newcapt.appendChild(caption) dest.parentNode.insertBefore(newcapt, dest.previousSibling); } var fantome = dest.attachShadow({mode: 'open'}); var templateContent = template.content; fantome.appendChild(templateContent); </script> --- ### (案例)银行贷款:相关系数矩阵图 ```r #remotes::install_github("r-link/corrmorant") require("corrmorant") corrmorant::corrmorant(df_loan[,-1], style = "binned")+ theme_dark() + theme(text = element_text(size = 14)) ``` ??? 参考:[Correlation Analysis Different Types of Plots in R](https://finnstats.com/index.php/2021/05/13/correlation-analysis-plot/) --- ### (案例)银行贷款:相关系数矩阵图 ```r ggcorrm(data = df_loan[,-1]) + lotri(geom_point(alpha = 0.5)) + lotri(geom_smooth()) + utri_heatmap() + utri_corrtext() + dia_names(y_pos = 0.15, size = 3) + dia_histogram(lower = 0.3, fill = "grey80", color = 1) + scale_fill_corr() + theme(text = element_text(size = 14)) ``` --- ### (案例)银行贷款:偏相关系数 假定我们认为不良贷款(`loan.bad`)与贷款余额(`loan.surplus`)及贷款项目数(`loan.number`)存在相互关系。 前面我们已经计算出如下的简单相关系数: `$$r_{12} = r_{_{bad},_{sur}}= 0.8436; \quad r_{13} = r_{_{bad},_{num}}= 0.7003; \quad r_{23} = r_{_{num},_{sur}}= 0.8484$$` 因此我们可以分别计算出**偏相关系数** --- ### (案例)银行贷款:偏相关系数 - 保持 `\(X_{3i}\)`不变, `\(Y_i\)`和 `\(X_{2i}\)`之间的相关系数: `$$\begin {align} r_{12 \cdot 3}=\frac{r_{12}-r_{13} r_{23}}{\sqrt{\left(1-r_{13}^{2}\right)\left(1-r_{23}^{2}\right)}} =\frac{0.84-0.7\times 0.85}{\sqrt{\left(1-0.7^{2}\right)\left(1-0.85^{2}\right)}} = 0.6601 \end {align}$$` - 保持 `\(X_{2i}\)`不变, `\(Y_i\)`和 `\(X_{3i}\)`之间的相关系数: `$$\begin {align} r_{13.2}=\frac{r_{13}-r_{12} r_{23}}{\sqrt{\left(1-r_{12}^{2}\right)\left(1-r_{23}^{2}\right)}} =\frac{0.7-0.84 \times 0.85}{\sqrt{\left(1-0.84^{2}\right)\left(1-0.85^{2}\right)}} = -0.0542 \end {align}$$` - 保持 `\(Y_i\)`不变, `\(X_{2i}\)`和 `\(X_{3i}\)`之间的相关系数: `$$\begin {align} r_{23.1}=\frac{r_{23}-r_{12} r_{13}}{\sqrt{\left(1-r_{12}^{2}\right)\left(1-r_{13}^{2}\right)}} =\frac{0.85-0.84 \times 0.7}{\sqrt{\left(1-0.84^{2}\right)\left(1-0.7^{2}\right)}} = 0.6722 \end {align}$$` --- ### (案例)银行贷款:相关系数显著性检验(手算) 对于前述`loan.surplus`与`loan.bad`进行相关系数显著性检验(Pearson): - 1)提出假设: `\(H_0: \rho =0; H_1: \rho \neq 0\)` - 2)计算样本统计量: `$$\begin{align} T^{\ast} = |r|\sqrt{\frac{n-2}{1-r^2}} =0.84 \times \sqrt{\frac{25-2}{1-0.84^2}} = 7.53 \end{align}$$` - 3)给定显著性水平 `\(\alpha=0.05\)`,确定t理论分布值 `\(t_{1-\alpha/2}(n-2)=t_{1-0.05/2}(25-2)=t_{0.975}(23)=2.07\)`。 - 4)得到假设检验结论:因为t样本统计量大于t理论查表值,也即 `$$\left[T^{\ast}= 7.53\right] > \left[t_{0.975}(23) =2.07\right]$$` 因此拒绝原假设 `\(H_0\)`,认为变量`loan.surplus`(贷款余额)与`loan.bad`(不良贷款)显著存在相关关系。 --- ### (案例)银行贷款:相关系数显著性检验(R软件) 我们可以使用R软件函数`cor.test()`对上述两个变量进行相关系数显著性检验: ```r cor.test(df_rel1$loan.surplus, df_rel1$loan.bad, method = "pearson") ``` ``` Pearson's product-moment correlation data: df_rel1$loan.surplus and df_rel1$loan.bad t = 8, df = 23, p-value = 0.0000001 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: 0.67 0.93 sample estimates: cor 0.84 ``` --- layout:false background-image: url("../pic/thank-you-gif-funny-little-yellow.gif") class: inverse,center # 本节结束