R中的点双双相关 [英] Point-Biserial Correlation in R
本文介绍了R中的点双双相关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有如下示例数据(230条记录):
I have sample data (230 records) that looks like this:
Salary Success - Failure
23,300 1
44,000 1
12,400 0
23,000 1
55,000 0
…
Success =1
Fail = 0
我正在尝试将连续变量(工资)与二进制变量(成功-失败–依赖)相关联我需要一个使用Point-Biserial Correlation的上述数据集的示例R代码.
I am trying to correlate a continuous variable (salary) with a binary one (Success -Failure – dependent) I need a sample R –code for the above data set using Point-Biserial Correlation.
推荐答案
我想您的 data.frame
是 df
:
X = df$Salary
Y = df[,2]
a = sqrt(sum(Y)*(1-sum(Y))/(length(Y)**2))
point.bis.corr = a*(mean(X[Y==1])-mean(X[Y==0]))/sd(X)
这篇关于R中的点双双相关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文