STATA 学习笔记 :相关系数

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 相关系数.

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值