STATA 学习笔记 :相关系数

为什么要计算变量之间的相关系数?
检测变量之间的多重共线性

相关系数呈现的几种方法

1. 散点图矩阵

help graph matrix
Description:
graph matrix draws scatterplot matrices

sysuse auto,clear
graph matrix price weight length mpg

在这里插入图片描述

2. Pearson 相关系数

(1)corr var1 var2

Description

The correlate command displays the correlation matrix or covariance matrix for a group of variables. If varlist is not specified, the matrix is
displayed for all variables in the dataset.

pwcorr displays all the pairwise correlation coefficients between the variables in varlist or, if varlist is not specified, all the variables in the
dataset.
corr price weight length mpg

在这里插入图片描述
(2)pwcorr var1 var2

pwcorr price weight length mpg
//Estimate all pairwise correlations

在这里插入图片描述

pwcorr price weight length mpg,sig
//Add significance level to each entry

在这里插入图片描述

pwcorr price weight length mpg,star(0.01)
//Add stars to correlations significant at the 1% level 

在这里插入图片描述
pwcorr 的缺陷在于,默认保留晓书丹后四位小数,且无法调整,不符合一般期刊的格式要求

3. Spearman 相关系数

sysuse auto,clear
spearman mpg rep78
//Two variables; output displayed in tabular form by default
spearman mpg rep78, matrix
//Two variables; output displayed in matrix form
spearman mpg price rep78, pw
//Use all nonmissing observations between a pair of variables
spearman mpg price rep78, pw star(0.05)
// Star all correlation coefficients significant at the 5% level or lower

在这里插入图片描述

4. Pearson &Spearman 系数合并显示

命令 corsp varlist
Description

corsp displays a correlation matrix of the variables in varlist. By default, Pearson's correlation coefficients are shown in the lower triangle,
including the diagonal, while Spearman's rank correlations appear above the diagonal. Optionally, corsp calculates Kendall's tau.
corsp mpg price rep78,format(%7.3f)

在这里插入图片描述

corsp mpg price rep78

在这里插入图片描述

5. Pearson &Spearman 系数的区别

如果变量同时满足以下三个条件,Pearson &Spearman 系数都可以使用,此时使用Pearson 系数更好
①连续变量
②正态分布
③ 线性关系
以上任意一个条件不满足,只能使用spearman 相关系数,不能用 Pearson 相关系数.

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐