楼主: yangan87
4476 4

弱问R问题 [推广有奖]

  • 10关注
  • 0粉丝

本科生

44%

还不是VIP/贵宾

-

威望
0
论坛币
62 个
通用积分
4.0000
学术水平
1 点
热心指数
0 点
信用等级
0 点
经验
994 点
帖子
75
精华
0
在线时间
95 小时
注册时间
2008-3-12
最后登录
2023-5-18

楼主
yangan87 发表于 2008-7-17 14:37:00 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
问一下R中如果要直接使用summary得到的结果,该用什么命令。
例如主成份分析中,
Importance of components:
                          Comp.1    Comp.2    Comp.3     Comp.4      Comp.5
Standard deviation     5.7142472 2.5355505 1.9139183 1.49277754 0.428013590
Proportion of Variance 0.7231022 0.1423725 0.0811201 0.04934826 0.004056923
Cumulative Proportion  0.7231022 0.8654747 0.9465948 0.99594308 1.000000000
如何直接得到standard deviation这一向量,赋值给任一变量?


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Proportion cumulative importance Components Deviation

回帖推荐

janus 发表于4楼  查看完整内容

不太明白你的意思。> getS3method("prcomp", "default")function (x, retx = TRUE, center = TRUE, scale. = FALSE, tol = NULL,     ...) {    x <- as.matrix(x)    x <- scale(x, center = center, scale = scale.)    cen <- attr(x, "scaled:center")    sc <- attr(x, "scaled:scale")    if (any(sc == 0))  &# ...

本帖被以下文库推荐

沙发
janus 发表于 2008-7-17 15:00:00
查看帮助,   
 'prcomp' returns a list with class '"prcomp"' containing the
     following components:

    sdev: the standard deviations of the principal components (i.e.,
          the square roots of the eigenvalues of the
          covariance/correlation matrix, though the calculation is
          actually done with the singular values of the data matrix).
…………

>pca <- prcomp(~ Murder + Assault + Rape, data = USArrests, scale = TRUE)
>summary(pca)
Importance of components:
                         PC1   PC2    PC3
Standard deviation     1.536 0.677 0.4282
Proportion of Variance 0.786 0.153 0.0611
Cumulative Proportion  0.786 0.939 1.0000
>names(pca)
[1] "sdev"     "rotation" "center"   "scale"    "x"        "call" 

>pca$sdev
[1] 1.5357670 0.6767949 0.4282154
> (x <-  pca$sdev)
[1] 1.5357670 0.6767949 0.4282154

无无无

藤椅
goodpanda 发表于 2008-7-17 15:15:00
我是初学,可能是sdev(),就向loading()一样吧

板凳
janus 发表于 2008-7-17 15:41:00

不太明白你的意思。
> getS3method("prcomp", "default")
function (x, retx = TRUE, center = TRUE, scale. = FALSE, tol = NULL,
    ...)
{
    x <- as.matrix(x)
    x <- scale(x, center = center, scale = scale.)
    cen <- attr(x, "scaled:center")
    sc <- attr(x, "scaled:scale")
    if (any(sc == 0))
        stop("cannot rescale a constant/zero column to unit variance")
    s <- svd(x, nu = 0)
    s$d <- s$d/sqrt(max(1, nrow(x) - 1))
    if (!is.null(tol)) {
        rank <- sum(s$d > (s$d[1L] * tol))
        if (rank < ncol(x)) {
            s$v <- s$v[, 1L:rank, drop = FALSE]
            s$d <- s$d[1L:rank]
        }
    }
    dimnames(s$v) <- list(colnames(x), paste("PC", seq_len(ncol(s$v)),
        sep = ""))
    r <- list(sdev = s$d, rotation = s$v, center = if (is.null(cen)) FALSE else cen,
        scale = if (is.null(sc)) FALSE else sc)
    if (retx)
        r$x <- x %*% s$v
    class(r) <- "prcomp"
    r
}

list(sdev = s$d, rotation = s$v, center = if (is.null(cen)) FALSE else cen,
        scale = if (is.null(sc)) FALSE else sc)
函数prcomp返回的结果其实是一个列表,既然如此,当然可以利用names函数察看列表中每一项的名称,进而可以用‘$’操作符提取你需要的信息了。

已有 1 人评分论坛币 学术水平 收起 理由
crystal8832 + 10 + 1 热心帮助其他会员

总评分: 论坛币 + 10  学术水平 + 1   查看全部评分

无无无

报纸
yangan87 发表于 2008-7-17 15:44:00
  谢谢Janus!!

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-26 07:19