繁体   English   中英

如何从 R class 载荷中提取百分比方差信息

[英]how to extract percent variance information from R class loadings

我使用varimax()来旋转矩阵,结果是class loadings如下:

Loadings:
      [,1]   [,2]   [,3]   [,4]   [,5]  
 [1,] -0.517  0.824 -0.207              
 [2,] -0.495  0.855 -0.110              
 [3,] -0.434  0.868 -0.175              
 [4,] -0.471  0.873                     
 [5,] -0.447  0.853        -0.208       
 [6,] -0.544  0.833                     
 [7,] -0.532  0.835                     
 [8,] -0.653  0.746                     
 [9,] -0.470  0.877                     
[10,] -0.658  0.737                     
[11,] -0.543  0.835                     
[12,] -0.581  0.802                     
[13,] -0.573  0.812                     
[14,] -0.613  0.774 -0.113              
[15,] -0.607  0.782 -0.110              
[16,] -0.626  0.754 -0.154              
[17,] -0.552  0.820                     
[18,] -0.571  0.808                     
[19,] -0.382  0.911         0.101       
[20,] -0.671  0.719 -0.128              
[21,] -0.507  0.806 -0.228         0.134
[22,] -0.611  0.748 -0.212              
[23,] -0.679  0.692 -0.190              
[24,] -0.539  0.792 -0.163         0.142
[25,] -0.709  0.677 -0.131              
[26,] -0.683  0.684 -0.179         0.120
[27,] -0.466  0.866                0.110
[28,] -0.621  0.741 -0.175 -0.106  0.113
[29,] -0.504  0.835                0.171
[30,] -0.559  0.757 -0.246         0.213
[31,] -0.555  0.774 -0.243         0.146
[32,] -0.609  0.713 -0.288         0.158
[33,] -0.244        -0.961              
[34,] -0.795  0.470 -0.357              
[35,] -0.852  0.470 -0.196              
[36,] -0.866  0.417 -0.230 -0.109       
[37,] -0.748  0.621 -0.159              
[38,] -0.798  0.567 -0.127 -0.127       
[39,] -0.847  0.486 -0.177              
[40,] -0.809  0.572 -0.106              
[41,] -0.733  0.647 -0.170              
[42,] -0.794  0.586 -0.130              
[43,] -0.834  0.526 -0.131              
[44,] -0.771  0.628                     
[45,] -0.739  0.661                     
[46,] -0.819  0.563                     
[47,] -0.774  0.615                     
[48,] -0.840  0.504 -0.171              
[49,] -0.813  0.567                     
[50,] -0.833  0.536                     
[51,] -0.845  0.498 -0.156              
[52,] -0.809  0.577                     
[53,] -0.837  0.514 -0.165              
[54,] -0.887  0.406 -0.171  0.103       
[55,] -0.866  0.476                     
[56,] -0.763  0.638                     
[57,] -0.882  0.450 -0.100              
[58,] -0.845  0.518 -0.111              
[59,] -0.799  0.596                     
[60,] -0.747  0.653                     
[61,] -0.782  0.617                     

                 [,1]   [,2]  [,3]  [,4]  [,5]
SS loadings    28.861 28.871 2.125 0.259 0.282
Proportion Var  0.473  0.473 0.035 0.004 0.005
Cumulative Var  0.473  0.946 0.981 0.985 0.990

我可以轻松获得负载,但我如何才能获得像Proportion var这样的摘要信息。 我试过str()并返回

'loadings' num [1:61, 1:5] -0.517 -0.495 -0.434 -0.471 -0.447 ...

我尝试了summary ,它只是给出了负载矩阵的总结。 并且dim()也只是返回了负载矩阵大小。 我只是不明白摘要信息的存储位置。

找不到它们的原因是它们没有被存储,而是作为loadings object 的打印方法的一部分计算出来的。

您可以通过检查打印 function 来了解它们是如何计算的:

getS3method("print", "loadings")

function (x, digits = 3L, cutoff = 0.1, sort = FALSE, ...) 
{
    Lambda <- unclass(x)
    p <- nrow(Lambda)
    factors <- ncol(Lambda)
    if (sort) {
        mx <- max.col(abs(Lambda))
        ind <- cbind(1L:p, mx)
        mx[abs(Lambda[ind]) < 0.5] <- factors + 1
        Lambda <- Lambda[order(mx, 1L:p), ]
    }
    cat("\nLoadings:\n")
    fx <- setNames(format(round(Lambda, digits)), NULL)
    nc <- nchar(fx[1L], type = "c")
    fx[abs(Lambda) < cutoff] <- strrep(" ", nc)
    print(fx, quote = FALSE, ...)
    vx <- colSums(x^2)
    varex <- rbind(`SS loadings` = vx)
    if (is.null(attr(x, "covariance"))) {
        varex <- rbind(varex, `Proportion Var` = vx/p)
        if (factors > 1) 
            varex <- rbind(varex, `Cumulative Var` = cumsum(vx/p))
    }
    cat("\n")
    print(round(varex, digits))
    invisible(x)
}

因此它们可以通过以下方式计算:

set.seed(5)
mat <- replicate(10, trunc(runif(50, 0, 10)))
f1 <- factanal(mat, factors = 3)

x <- loadings(f1)
vx <- colSums(x^2)

rbind(`SS loadings` = vx,
      `Proportion Var` = vx/nrow(x),
      `Cumulative Var` = cumsum(vx/nrow(x)))

                 Factor1   Factor2   Factor3
SS loadings    1.1858135 1.1654288 1.0721485
Proportion Var 0.1185813 0.1165429 0.1072149
Cumulative Var 0.1185813 0.2351242 0.3423391

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM