I am trying to replicate a principal component analysis in R based on one I have performed in SPSS. I am using the psych package and the principal function, but I cannot get it to account for the weighting.
I tried performing the analysis with and without weighting, and I got the same results. Example:
pc0 <- principal(mtcars[,c(8:11)], cor = "cov", covar = TRUE)
print(pc0)
Call: principal(r = mtcars[, c(8:11)], covar = TRUE, cor = "cov")
Unstandardized loadings (pattern matrix) based upon covariance matrix
PC1 h2 u2 H2 U2
vs -0.29 0.0854 0.169 0.336 0.664
am 0.05 0.0028 0.246 0.011 0.989
gear 0.24 0.0559 0.488 0.103 0.897
carb 1.61 2.5983 0.011 0.996 0.004
PC1
SS loadings 2.74
Proportion Var 0.75
Standardized loadings (pattern matrix)
V PC1 h2 u2
vs 1 -0.58 0.336 0.664
am 2 0.11 0.011 0.989
gear 3 0.32 0.103 0.897
carb 4 1 0.996 0.004
PC1
SS loadings 3.00
Proportion Var 0.75
Mean item complexity = 1
Test of the hypothesis that 1 component is sufficient.
The root mean square of the residuals (RMSR) is 0.13
with the empirical chi-square 6.87 with prob < 0.032
Fit based upon off-diagonal values = 0.95
With weighting:
pc1 <- principal(mtcars[,c(8:11)], cor = "cov", weight = mtcars[,c("wt")], covar = TRUE)
print(pc1)
Call: principal(r = mtcars[, c(8:11)], covar = TRUE, cor = "cov", weight = mtcars[,
c("wt")])
Unstandardized loadings (pattern matrix) based upon covariance matrix
PC1 h2 u2 H2 U2
vs -0.29 0.0854 0.169 0.336 0.664
am 0.05 0.0028 0.246 0.011 0.989
gear 0.24 0.0559 0.488 0.103 0.897
carb 1.61 2.5983 0.011 0.996 0.004
PC1
SS loadings 2.74
Proportion Var 0.75
Standardized loadings (pattern matrix)
V PC1 h2 u2
vs 1 -0.58 0.336 0.664
am 2 0.11 0.011 0.989
gear 3 0.32 0.103 0.897
carb 4 1 0.996 0.004
PC1
SS loadings 3.00
Proportion Var 0.75
Mean item complexity = 1
Test of the hypothesis that 1 component is sufficient.
The root mean square of the residuals (RMSR) is 0.13
with the empirical chi-square 6.87 with prob < 0.032
Fit based upon off-diagonal values = 0.95
The results are identical in both cases, suggesting that the weighting is not being applied correctly.
I am trying to replicate a principal component analysis in R based on one I have performed in SPSS. I am using the psych package and the principal function, but I cannot get it to account for the weighting.
I tried performing the analysis with and without weighting, and I got the same results. Example:
pc0 <- principal(mtcars[,c(8:11)], cor = "cov", covar = TRUE)
print(pc0)
Call: principal(r = mtcars[, c(8:11)], covar = TRUE, cor = "cov")
Unstandardized loadings (pattern matrix) based upon covariance matrix
PC1 h2 u2 H2 U2
vs -0.29 0.0854 0.169 0.336 0.664
am 0.05 0.0028 0.246 0.011 0.989
gear 0.24 0.0559 0.488 0.103 0.897
carb 1.61 2.5983 0.011 0.996 0.004
PC1
SS loadings 2.74
Proportion Var 0.75
Standardized loadings (pattern matrix)
V PC1 h2 u2
vs 1 -0.58 0.336 0.664
am 2 0.11 0.011 0.989
gear 3 0.32 0.103 0.897
carb 4 1 0.996 0.004
PC1
SS loadings 3.00
Proportion Var 0.75
Mean item complexity = 1
Test of the hypothesis that 1 component is sufficient.
The root mean square of the residuals (RMSR) is 0.13
with the empirical chi-square 6.87 with prob < 0.032
Fit based upon off-diagonal values = 0.95
With weighting:
pc1 <- principal(mtcars[,c(8:11)], cor = "cov", weight = mtcars[,c("wt")], covar = TRUE)
print(pc1)
Call: principal(r = mtcars[, c(8:11)], covar = TRUE, cor = "cov", weight = mtcars[,
c("wt")])
Unstandardized loadings (pattern matrix) based upon covariance matrix
PC1 h2 u2 H2 U2
vs -0.29 0.0854 0.169 0.336 0.664
am 0.05 0.0028 0.246 0.011 0.989
gear 0.24 0.0559 0.488 0.103 0.897
carb 1.61 2.5983 0.011 0.996 0.004
PC1
SS loadings 2.74
Proportion Var 0.75
Standardized loadings (pattern matrix)
V PC1 h2 u2
vs 1 -0.58 0.336 0.664
am 2 0.11 0.011 0.989
gear 3 0.32 0.103 0.897
carb 4 1 0.996 0.004
PC1
SS loadings 3.00
Proportion Var 0.75
Mean item complexity = 1
Test of the hypothesis that 1 component is sufficient.
The root mean square of the residuals (RMSR) is 0.13
with the empirical chi-square 6.87 with prob < 0.032
Fit based upon off-diagonal values = 0.95
The results are identical in both cases, suggesting that the weighting is not being applied correctly.
Share Improve this question edited Mar 13 at 16:37 user29972384 asked Mar 13 at 16:24 user29972384user29972384 12 bronze badges1 Answer
Reset to default 0This appears to be undocumented, but whether the weight
argument is used depends on the cor
argument. In particular this part:
switch(cor, cor = {
if (!is.null(weight)) {
r <- cor.wt(r, w = weight)$r
} else {
r <- cor(r, use = use)
}
}, cov = {
r <- cov(r, use = use)
covar <- TRUE
}, wtd = {
r <- cor.wt(r, w = weight)$r
}, spearman = {
r <- cor(r, use = use, method = "spearman")
}, kendall = {
r <- cor(r, use = use, method = "kendall")
}, tet = {
r <- tetrachoric(r, correct = correct, weight = weight)$rho
}, poly = {
r <- polychoric(r, correct = correct, weight = weight)$rho
}, tetrachoric = {
r <- tetrachoric(r, correct = correct, weight = weight)$rho
}, polychoric = {
r <- polychoric(r, correct = correct, weight = weight)$rho
}, mixed = {
r <- mixedCor(r, use = use, correct = correct)$rho
}, Yuleb = {
r <- YuleCor(r, , bonett = TRUE)$rho
}, YuleQ = {
r <- YuleCor(r, 1)$rho
}, YuleY = {
r <- YuleCor(r, 0.5)$rho
})
We can see that only for some of the options the weights are taken into account. As this appears to undocumented, I would consider this a bug (although it looks very intentional...).
Note that a cov.wt
function is available, so it is relatively straightforward to edit the code and make it available.