R:irlba错误

时间:2014-08-28 09:01:15

标签: r matrix-decomposition

我尝试使用R包irlba分解方阵,但收到以下消息:

  

" V [,1:(k + dim(F)[2])]中的错误< - cbind(V [,1:(dim(Bsvd $ v)[1]),drop = FALSE]%*%:要替换的项目数不是替换长度的倍数"

然而,使用svdeigen分解矩阵。我发现this post elsewhere暗示了同样的问题(没有回复)。

我会感激任何可以帮助我解决这个问题的人!

代码:

library(irlba)

C.i <- structure(c(0.107821513562202, 0.0629415996952743, -0.0346069282137902, 
-0.0410208578535759, 0.0629415996952743, 0.136205395050303, -0.00378166611862939, 
0.00237156895349009, -0.0346069282137902, -0.00378166611862939, 
0.0122114763151942, -0.00635448918784993, -0.0410208578535759, 
0.00237156895349009, -0.00635448918784993, 0.0431193044924), .Dim = c(4L, 4L), 
.Dimnames = list(c("Sepal.Length", "Sepal.Width", "Petal.Length",
"Petal.Width"), c("Sepal.Length", "Sepal.Width", "Petal.Length", 
"Petal.Width")))

irlba(C.i, nu=1, nv=1)

# These work
svd(C.i)
eigen(C.i)

2 个答案:

答案 0 :(得分:1)

irlba(C.i, nu=0, nv=0)我得到:

$d
[1] 0.1938809

$u
           [,1]
[1,]  0.6595482
[2,]  0.7216141
[3,] -0.1355695
[4,] -0.1609040

$v
           [,1]
[1,]  0.6590202
[2,]  0.7214017
[3,] -0.1432499
[4,] -0.1573256

$iter
[1] 1

$mprod
[1] 6

这是你在找什么?

(很抱歉在回答中提问,但我没有足够的意见来评论这个问题。:|)

答案 1 :(得分:0)

我收到了包裹作者关于​​错误的回复 - 这确实是一个错误。使用irlba软件包的更新版本已解决此问题。更新的软件包最终将提交给CRAN,但同时您可以通过GitHub进行安装:

remove.packages("irlba")
library("devtools")
install_github("IRL","bwlewis",quick=TRUE)

library("irlba")

C.i <- structure(c(0.107821513562202, 0.0629415996952743, -0.0346069282137902, 
-0.0410208578535759, 0.0629415996952743, 0.136205395050303, -0.00378166611862939, 
0.00237156895349009, -0.0346069282137902, -0.00378166611862939, 
0.0122114763151942, -0.00635448918784993, -0.0410208578535759, 
0.00237156895349009, -0.00635448918784993, 0.0431193044924), .Dim = c(4L, 4L), 
.Dimnames = list(c("Sepal.Length", "Sepal.Width", "Petal.Length",
"Petal.Width"), c("Sepal.Length", "Sepal.Width", "Petal.Length", 
"Petal.Width")))

irlba(C.i, nu=1, nv=1)

#$d
#[1] 0.1938898
#
#$u
#           [,1]
#[1,]  0.6593389
#[2,]  0.7216000
#[3,] -0.1349355
#[4,] -0.1623519
#
#$v
#           [,1]
#[1,]  0.6593384
#[2,]  0.7216001
#[3,] -0.1349364
#[4,] -0.1623526
#
#$iter
#[1] 2
#
#$mprod
#[1] 10