cortest .mat 函数中的计算奇异错误

computationally singular Error in cortest .mat function

我有一些相关矩阵,想测试它们在统计上是否相等。为此,我使用 psych 包中的 cortest.mat 函数,但出现以下错误:

Error in solve.default(R1) : system is computationally singular: reciprocal condition number = 4.96434e-18

使用随机数也会产生同样的错误,即:

Random<-cor(matrix(rnorm(400, 0, .25), nrow=(20), ncol=(20)))
cortest.mat(Random,Random,n1=400, n2=400)

因为这个包是用来比较相关矩阵的,所以我不明白我做错了什么。

套餐: http://www.personality-project.org/r/html/cortest.mat.html

提前致谢。

你需要你的矩阵是一个包含 类 psychsim 元素的对象,你可以使用 psych 中的 sim.congeneric 函数来实现=]

#The code below results in a sample and population matrix for x and y
y <- sim.congeneric(loads =c(.20,.19,.18,.17,.16,.15,.14,.13,.12,.11,.10,
      .9,.8,.7,.6,.5,.4,.3,.2,.1),N=1000,short=FALSE)
x <- sim.congeneric(loads =c(.20,.19,.18,.17,.16,.15,.14,.13,.12,.11,.10,
      .9,.8,.7,.6,.5,.4,.3,.2,.1),N=1000,short=FALSE)

#To show the class
class(x)
[1] "psych" "sim" 
class(y)
[1] "psych" "sim" 

#Now you can run the test
cortest.mat(x$r,y$r,n1=1000,n2=1000) #here we extract the sample matrix using '$r' and run the test

Tests of correlation matrices 
Call:cortest.mat(R1 = x$r, R2 = y$r, n1 = 1000, n2 = 1000)
 Chi Square value 403.47  with df =  380   with probability < 0.2 

让我们生成一个新的较小尺寸的相关矩阵,以便我们检查:

sim.congeneric(loads =c(.5,.4,.3,.2,.1),N=1000,short=FALSE)

Call: NULL

 $model (Population correlation matrix) 
     V1   V2   V3   V4   V5
V1 1.00 0.20 0.15 0.10 0.05
V2 0.20 1.00 0.12 0.08 0.04
V3 0.15 0.12 1.00 0.06 0.03
V4 0.10 0.08 0.06 1.00 0.02
V5 0.05 0.04 0.03 0.02 1.00

$r  (Sample correlation matrix  for sample size =  1000 )
     V1    V2    V3     V4     V5
V1 1.00 0.151 0.124 0.1471 0.0303
V2 0.15 1.000 0.137 0.1083 0.0507
V3 0.12 0.137 1.000 0.0894 0.0159
V4 0.15 0.108 0.089 1.0000 0.0018
V5 0.03 0.051 0.016 0.0018 1.0000

请注意,sim.congeneric 创建了一个包含两个矩阵的对象 - 一个用于样本,另一个用于总体 - 我们在测试中使用了样本矩阵(显然)。