找出相对于总方差的给定百分比有贡献的特征值的数量
Find the number of eigen values that contributes relatively to a given percentage of total variance
λ 是一个特征值,Λ 是一组特征值,p 是 Λ 的基数,我试图在 R 中创建一个循环,以便找到 n
这是一个输入示例(L 分量总是递减的):
> L
[1] 4.903332 4.341607 3.920309 3.716966 3.554570 3.067658 2.891222 2.553127
> sumli
[1] 28.94879
> freq <- L/sumli
> freq
[1] 0.16937952 0.14997540 0.13542221 0.12839795 0.12278821 0.10596843 0.09987368 0.08819460
L <- c(4.903332, 4.341607, 3.920309, 3.716966, 3.55457, 3.067658,
2.891222, 2.553127)
我想我们可以使用cumsum
(累计和)。
取决于你是想要第一个n
累积贡献大于95%,还是最后一个n
累积贡献小于95%,你需要
which(cumsum(L) / sum(L) > 0.95)
# [1] 8
which(cumsum(L) / sum(L) > 0.95) - 1
# or: `sum(cumsum(L) / sum(L) <= 0.95)`
# or: `max(which(cumsum(L) / sum(L) <= 0.95))`
# [1] 7
(您的示例 L
不是很有代表性,因为特征值没有急剧衰减。)
λ 是一个特征值,Λ 是一组特征值,p 是 Λ 的基数,我试图在 R 中创建一个循环,以便找到 n
这是一个输入示例(L 分量总是递减的):
> L
[1] 4.903332 4.341607 3.920309 3.716966 3.554570 3.067658 2.891222 2.553127
> sumli
[1] 28.94879
> freq <- L/sumli
> freq
[1] 0.16937952 0.14997540 0.13542221 0.12839795 0.12278821 0.10596843 0.09987368 0.08819460
L <- c(4.903332, 4.341607, 3.920309, 3.716966, 3.55457, 3.067658,
2.891222, 2.553127)
我想我们可以使用cumsum
(累计和)。
取决于你是想要第一个n
累积贡献大于95%,还是最后一个n
累积贡献小于95%,你需要
which(cumsum(L) / sum(L) > 0.95)
# [1] 8
which(cumsum(L) / sum(L) > 0.95) - 1
# or: `sum(cumsum(L) / sum(L) <= 0.95)`
# or: `max(which(cumsum(L) / sum(L) <= 0.95))`
# [1] 7
(您的示例 L
不是很有代表性,因为特征值没有急剧衰减。)