accessing eigenvalues in RSSA package in R

狂风中的少年 提交于 2020-01-16 11:27:40

问题


I am using RSSA package in R and I need to access the eigenvalues.

using the following code I can plot the components. However, I need to access all eigenvalues as numbers.

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


回答1:


I know almost nothing about this package. I'm taking from context that you want the values that are plotted on the y-axis of that graphic. Lacking a reproducible example, I turn to the ?ssa help page and use the first example:

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

So that looks like your plot: Then I look at the code

> 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>

So then I look at the function called when the default arguments are used:

> 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>

So the answer appears to be:

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


来源:https://stackoverflow.com/questions/49013393/accessing-eigenvalues-in-rssa-package-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!