处理高度相关变量算法:
1.计算自变量的相关系数矩阵
2.找出相关系数绝对值最大的那对自变量(a和b)
3.计算a和其他自变量相关系数的均值,对b也做同样操作
4.若a的平均相关系数更大,则将a移除,否则移除b
5,重复2-4,直到所有相关系数的绝对值都低于设定的阈值为止。
#结果返回需要删除的列号,变量相关性在0.75左右,findCorrelation()为carat包中的函数
> highCorr=findCorrelation(cor(sdat),cutoff=.75)
> sdat=sdat[-highCorr]
> cor(sdat)
income store_exp online_exp store_trans online_trans
income 1.0000000 0.6005675 0.5202335 0.7077065 -0.3585446
store_exp 0.6005675 1.0000000 0.5349525 0.5399141 -0.1367433
online_exp 0.5202335 0.5349525 1.0000000 0.4420638 0.2256370
store_trans 0.7077065 0.5