eigen()的用法

这方面的资料,还是去看R语言官方的帮助文档(在命令行敲下面的命令):

 help("eigen")

可以得到网页版的页面:

 

eigen的中文含义就是本征的意思,在学习线性代数的时候不是学过特征向量,特征值,其实意思是一样的

用法:

eigen(x, symmetric, only.values = FALSE, EISPACK = FALSE)

具体参数参考官方文档,我们通常这这样用:
 

eigen(x)

然后运行可以得到如下:

values

a vector containing the p eigenvalues of x, sorted in decreasing order, according to Mod(values) in the asymmetric case when they might be complex (even for real matrices). For real asymmetric matrices the vector will be complex only if complex conjugate pairs of eigenvalues are detected.

vectors

either a p * p matrix whose columns contain the eigenvectors of x, or NULL if only.values is TRUE. The vectors are normalized to unit length.

Recall that the eigenvectors are only defined up to a constant: even when the length is specified they are still only defined up to a scalar of modulus one (the sign for real matrices).

 讲了这么多,直接运行一下官方文档给的例子,结果如下:

> eigen(cbind(c(1,-1), c(-1,1)))
eigen() decomposition
$values
[1] 2 0

$vectors
           [,1]       [,2]
[1,] -0.7071068 -0.7071068
[2,]  0.7071068 -0.7071068

其实就是矩阵:

1  -1

-1  1

这个矩阵的特征向量就是2    0

然后化为单位矩阵

0.7071068      0.7071068
-0.7071068     0.7071068
 

具体应用:

我们通常用eigen函数是为了判断统计学上的共线性问题

比如这样的数据:

 分析一下

> XX<-cor(data[1:4])
> XX
           X1         X2         X3         X4
X1  1.0000000  0.2285795 -0.8241338 -0.2454451
X2  0.2285795  1.0000000 -0.1392424 -0.9729550
X3 -0.8241338 -0.1392424  1.0000000  0.0295370
X4 -0.2454451 -0.9729550  0.0295370  1.0000000
> kappa(XX)
[1] 2158.818
> eigen(XX)
eigen() decomposition
$values
[1] 2.235704035 1.576066070 0.186606149 0.001623746

$vectors
           [,1]       [,2]       [,3]      [,4]
[1,]  0.4759552  0.5089794  0.6755002 0.2410522
[2,]  0.5638702 -0.4139315 -0.3144204 0.6417561
[3,] -0.3940665 -0.6049691  0.6376911 0.2684661
[4,] -0.5479312  0.4512351 -0.1954210 0.6767340

官方文档说特征值是降序排列的,很显然第4个特征值特别特别小,几乎趋于0 ,于是

0.2410522X1+0.6417561X2+0.2684661X3+0.6767340
X4=0.001623746=近似等于0

而且系数差距不大,可以认为X1,X2,X3,X4共线性的

 

  • 5
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值