covariance matrix for cfa

13 Views Asked by At

I am working on a CFA project, which provided a correlation matrix, standard deviation matrix and model specified. I got error message: Error in lav_matrix_lower2full(x, diagonal = diagonal) : p == round(p, 0) is not TRUE in step 3.

Is that because I used Lower was a full matrix or because I entered the correlation matrix as a full matrix?

library(lavaan)
library(lavaanPlot)
library(semPlot)

# Step1: transfer correlation matrix into covariance model
> Correlation <- matrix(c(
   1.0,    .88,  .87,  .33,  .34,  .31,  .04,  .24,  -.22,
   .88,    1.0,  .80,  .40,  .42,  .33,  .11,  .34,  -.21,
   .87,    .80,  1.0,  .37,  .42,  .24, -.03,  .25,  -.26,
   .33,    .40,  .37,  1.0,  .67, -.16, -.35,  .05,  -.23, 
   .34,    .42,  .42,  .67,  1.0, -.29, -.46,  .17,  -.38,
   .31,    .33,  .24, -.16, -.29, 1.0,   .77,  .37,   .33,
   .04,    .11, -.03, -.35, -.46,  .77,  1.0,  .40,   .48,
   .24,    .34,  .25,  .05,  .17,  .37,  .40,  1.0,   .21,
  -.22,   -.21, -.26, -.23, -.38,  .33,  .48,  .21,   1.0), ncol=9, nrow=9, byrow=T)

> sd <- c(1.1, 1.6, 1.1, 2.2, 1.2, 3.3, 1.4, 1.2, 1.3)
> (Cov <- cor2cov(Correlation,sd))
         [,1]    [,2]    [,3]    [,4]    [,5]    [,6]    [,7]   [,8]    [,9]
 [1,]  1.2100  1.5488  1.0527  0.7986  0.4488  1.1253  0.0616 0.3168 -0.3146
 [2,]  1.5488  2.5600  1.4080  1.4080  0.8064  1.7424  0.2464 0.6528 -0.4368
 [3,]  1.0527  1.4080  1.2100  0.8954  0.5544  0.8712 -0.0462 0.3300 -0.3718
 [4,]  0.7986  1.4080  0.8954  4.8400  1.7688 -1.1616 -1.0780 0.1320 -0.6578
 [5,]  0.4488  0.8064  0.5544  1.7688  1.4400 -1.1484 -0.7728 0.2448 -0.5928
 [6,]  1.1253  1.7424  0.8712 -1.1616 -1.1484 10.8900  3.5574 1.4652  1.4157
 [7,]  0.0616  0.2464 -0.0462 -1.0780 -0.7728  3.5574  1.9600 0.6720  0.8736
 [8,]  0.3168  0.6528  0.3300  0.1320  0.2448  1.4652  0.6720 1.4400  0.3276
 [9,] -0.3146 -0.4368 -0.3718 -0.6578 -0.5928  1.4157  0.8736 0.3276  1.6900

# Step 2: build three latent variable model

> Model= '
  # Latent Variables
    Evaluation =~ CourseRating + SelfRating + AnotherClass
    ExpectedGrade =~ ExpGrade + RelExpGrade
    WorkLoad =~ HoursWork + Interlectual + Involvement + Effort
    
  # Correlation of Latent Variables
    ExpectedGrade ~~ Evaluation
    ExpectedGrade ~~ WorkLoad
    WorkLoad ~~ Evaluation
'
# Step3: use Cov matrix values get from step1 to build covariance matrix Lower

> Lower <- '
 1.2100  1.5488  1.2100  1.9360  0.5280  1.5246  0.5082  0.1452 0.4862
-0.3696  2.2272  1.4080  3.5200  0.7104  2.2176  0.5376 -0.0576 0.5200
-0.3146  0.5808  0.4840  0.8954  1.3200  2.4321 -0.2464 -0.4620 0.0715
-0.5566  1.1968  1.0164  2.0328  1.7688  7.2600 -0.8932 -1.2144 1.0582
-0.5016  0.5952  0.4356  0.6336 -0.2304 -1.1484  1.6800  1.1088 0.6240
 1.1979  2.1120  0.3993 -0.2178 -1.3860 -5.0094  3.5574  3.9600 1.7160
 0.7392  0.5376  0.5236  0.7700  0.0840  0.7854  0.7252  0.6720 1.8200
 0.2772 -0.4224 -0.2772 -0.6864 -0.3312 -1.5048  0.5544  0.6912 0.3276
 1.4300  2.0800  1.2584  2.8600  1.2480  1.7160  0.7644  0.5148 0.1859
'

> Covariance <- 
  getCov(Lower, names = 
           c("CourseRating",
           "SelfRating",
           "AnotherClass",
           "ExpGrade",
           "RelExpGrade",
           "HoursWork",
           "Interlectual",
           "Involvement",
           "Effort"))

> Covariance 
> Sample_Size = 205

# Step4: use Model, Covariance, Sample_Size to build cfa model

> CFA.1 = cfa(model = Model, 
            sample.cov = Covariance, 
            sample.nobs = Sample_Size)
> summary(CFA.1, fit = T, ci = T, rsquare = T)
0

There are 0 best solutions below