在R中的RSSA包中访问特征值

时间:2018-02-27 16:25:22

标签: r svd eigenvalue

我在R中使用RSSA包,我需要访问特征值。

使用以下代码我可以绘制组件。但是,我需要将所有特征值作为数字访问。

require(Rssa)
t=ssa(co2)
plot(t)

eigenvalues plot

1 个答案:

答案 0 :(得分:1)

我对这个包几乎一无所知。我从上下文中获取了您想要在该图形的y轴上绘制的值。由于缺乏可重现的示例,我转向?ssa帮助页面并使用第一个示例:

> s <- ssa(co2)
> 
> plot(s)

所以这看起来像你的情节:然后我看代码

> getAnywhere(plot.ssa)
A single object matching ‘plot.ssa’ was found
It was found in the following places
  registered S3 method for plot from namespace Rssa
  namespace:Rssa
with value

function (x, type = c("values", "vectors", "paired", "series", 
    "wcor"), ..., vectors = c("eigen", "factor"), plot.contrib = TRUE, 
    numvalues = nsigma(x), numvectors = min(nsigma(x), 10), idx = 1:numvectors, 
    idy, groups) 
{
    type <- match.arg(type)
    vectors <- match.arg(vectors)
    if (identical(type, "values")) {
        .plot.ssa.values(x, ..., numvalues = numvalues)
    }
    else if (identical(type, "vectors")) {
        .plot.ssa.vectors(x, ..., what = vectors, plot.contrib = plot.contrib, 
            idx = idx)
    }
    else if (identical(type, "paired")) {
        if (missing(idy)) 
            idy <- idx + 1
        .plot.ssa.paired(x, ..., what = vectors, plot.contrib = plot.contrib, 
            idx = idx, idy = idy)
    }
    else if (identical(type, "series")) {
        if (missing(groups)) 
            groups <- as.list(1:min(nsigma(x), nu(x)))
        .plot.ssa.series(x, ..., groups = groups)
    }
    else if (identical(type, "wcor")) {
        if (missing(groups)) 
            groups <- as.list(1:min(nsigma(x), nu(x)))
        plot(wcor(x, groups = groups), ...)
    }
    else {
        stop("Unsupported type of SSA plot!")
    }
}
<environment: namespace:Rssa>

然后我看一下使用默认参数时调用的函数:

> getAnywhere(.plot.ssa.values)
A single object matching ‘.plot.ssa.values’ was found
It was found in the following places
  namespace:Rssa
with value

function (x, ..., numvalues, plot.type = "b") 
{
    dots <- list(...)
    d <- data.frame(A = 1:numvalues, B = x$sigma[1:numvalues])
    dots <- .defaults(dots, type = plot.type, xlab = "Index", 
        ylab = "norms", main = "Component norms", grid = TRUE, 
        scales = list(y = list(log = TRUE)), par.settings = list(plot.symbol = list(pch = 20)))
    do.call("xyplot", c(list(x = B ~ A, data = d, ssaobj = x), 
        dots))
}
<environment: namespace:Rssa>

所以答案似乎是:

s$sigma
 [1] 78886.190749   329.031810   327.198387   184.659743    88.695271    88.191805
 [7]    52.380502    40.527875    31.329930    29.409384    27.157698    22.334446
[13]    17.237926    14.175096    14.111402    12.976716    12.943775    12.216524
[19]    11.830642    11.614243    11.226010    10.457529    10.435998     9.774000
[25]     9.710220     9.046872     8.995923     8.928725     8.809155     8.548962
[31]     8.358872     7.699094     7.266915     7.243014     7.164837     6.203210
[37]     6.085105     6.064150     6.035110     6.028446     5.845783     5.808865
[43]     5.770708     5.753422     5.680897     5.672330     5.650324     5.612606
[49]     5.599314     5.572931