CFA warning message

351 views
Skip to first unread message

Gouvidé Jean GBAGUIDI

unread,
Feb 3, 2023, 2:21:12 PM2/3/23
to lavaan
Hello!,I'm running CFA . lavaan ends nrmally and I can get all the information with poor fit of the model due to the warning message.
Warning message:
    In lav_object_post_check(object) :
    lavaan WARNING: the covariance matrix of the residuals of the observed
variables (theta) is not positive definite;
use lavInspect(fit, "theta") to investigate.
Can someone please give guidance on where I should go with this error? 
See below my code and the syntax of the model.

setwd("~/My topic/My topic/DATA/VALID DATA/Data_final")
Mal<-read.csv("CC_MalariaS.csv",header = TRUE,sep = ",")
str('Mal')
head(Mal)
names(Mal)
attach(Mal)
summary(is.na(Mal))
str(Mal)
#### Convert to numerical#############
Mal$Min_Relative.Humidity<-as.numeric(as.factor(Mal$Min_Relative.Humidity))
Mal$Max_Relative.Humidity<-as.numeric(as.factor(Mal$Max_Relative.Humidity))#######
str(Mal)

####Smooth the data(non positive matrix)###########
d<-cor.smooth(Mal,eig.tol = 10^-4)### Smooth the matrix(non positive)

cfaMod2<-"F1=~Rainfall+Min_Relative.Humidity+Mean_Relative.Humidity
+Max_Relative.Humidity
F2=~a*Mean_Temperature+a*Min_Temperature
Malaria_Incidence~F1+F2
Rainfall~~Max_Temperature+Min_Relative.Humidity+Mean_Relative.Humidity
+Max_Relative.Humidity
Mean_Temperature~~Max_Temperature
Max_Temperature~~Min_Relative.Humidity+Max_Relative.Humidity+Mean_Relative.Humidity
Mean_Relative.Humidity~~Min_Relative.Humidity+Max_Relative.Humidity
Min_Relative.Humidity~~Max_Relative.Humidity
"
fit.cfaMod<-cfa(cfaMod2,sample.cov=d,sample.nobs=1193, estimator = "ML",bounds=F,std.lv=T,
                orthogonal=T)
summary(fit.cfaMod,fit.measures=TRUE,standardized=TRUE,rsq=TRUE)

> lavInspect(fit.cfaMod, "theta")
Ranfll Min_Rltv.Hmdty Men_Rltv.Hmdty Mx_R.H
Rainfall                0.684                                    
Min_Relative.Humidity   0.323          0.265                      
Mean_Relative.Humidity  0.234          0.168          0.118      
Max_Relative.Humidity   0.114          0.033          0.037  0.022
Mean_Temperature        0.000          0.000          0.000  0.000
Min_Temperature         0.000          0.000          0.000  0.000
Malaria_Incidence       0.000          0.000          0.000  0.000
Max_Temperature        -0.082         -0.087         -0.083 -0.075
Men_Tmprtr Min_Tmprtr Mlr_In Mx_Tmp
Rainfall                                                  
Min_Relative.Humidity                                    
Mean_Relative.Humidity                                    
Max_Relative.Humidity                                    
Mean_Temperature            0.369                        
Min_Temperature             0.000      0.388              
Malaria_Incidence           0.000      0.000  0.929      
Max_Temperature             0.708      0.000  0.000  0.867

Yves Rosseel

unread,
Feb 5, 2023, 11:10:03 AM2/5/23
to lav...@googlegroups.com
The residual variance for Max_Relative.Humidity is 0.022, but some other
values on that row are larger!

It looks like you have too many residual covariances in your model. You
could perhaps have one or two (if you have a good rationale for it), but
not that many.

Yves.

Gouvidé Jean GBAGUIDI

unread,
Feb 5, 2023, 1:26:04 PM2/5/23
to lav...@googlegroups.com
Than you for your answer, please I'm sorry to ask you once again how I can have one or two residuals. Should I remove some variables like max_relative humidity and others? Please . Kindly tell me what I can do to solve this warning ⚠️.
My Best regards,

--
You received this message because you are subscribed to a topic in the Google Groups "lavaan" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lavaan/nqH_CQ0TsbM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/d642007d-e581-ee9a-46cc-a3673a1cc718%40gmail.com.

Gouvidé Jean GBAGUIDI

unread,
Feb 6, 2023, 6:42:25 AM2/6/23
to lav...@googlegroups.com
Hello Yves, thank you for feed back. I try to reduce the residuals covariance by my understanding through the syntaxbelow but I got the same warning message: 
Warning message:
In lav_object_post_check(object) :
  lavaan WARNING: the covariance matrix of the residuals of the observed
                variables (theta) is not positive definite;
                use lavInspect(fit, "theta") to investigate.


I will be very grateful for your deep help to solve this warning message

cfaMod2<-"F1=~Rainfall+Min_Relative.Humidity+Mean_Relative.Humidity
+Max_Relative.Humidity
F2=~Mean_Temperature+b1*Min_Temperature
Malaria_Incidence~F1+F2

Mean_Temperature~~Max_Temperature
Min_Relative.Humidity~~Max_Relative.Humidity
"
fit.cfaMod<-cfa(cfaMod2,sample.cov=d,sample.nobs=1193, estimator = "ML",orthogonal=T,std.lv=T,)

Le dim. 5 févr. 2023 à 17:10, Yves Rosseel <yros...@gmail.com> a écrit :
--
You received this message because you are subscribed to a topic in the Google Groups "lavaan" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lavaan/nqH_CQ0TsbM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/d642007d-e581-ee9a-46cc-a3673a1cc718%40gmail.com.


--
Gouvidé Jean GBAGUIDI
WASCAL PhD-Candidate
Climate Change and Disaster Risks Management
MSc Ecohydrologist
MSc: Natural Sciences
Secretary of Benin Jeunesse Elite NGO
Benin National Focal Point: United International Federation 
of Youth for Water and Climate(UN1FY)
E-mail: gouvid...@gmail.com/gbaguid...@yahoo.fr
Phone:(00229)96258002/95036686  (Benin)
(00228)93649692 (Togo-LOME)
Phillipians: 4:13: "I can do all things through him who gives"

Yves Rosseel

unread,
Feb 6, 2023, 7:18:04 AM2/6/23
to lav...@googlegroups.com
> cfaMod2<-"F1=~Rainfall+Min_Relative.Humidity+Mean_Relative.Humidity
> +Max_Relative.Humidity
> F2=~Mean_Temperature+b1*Min_Temperature
> Malaria_Incidence~F1+F2
>
> Mean_Temperature~~Max_Temperature
> Min_Relative.Humidity~~Max_Relative.Humidity
> "

You need to remove the last two lines of your syntax (the the two lines
with ~~ operator)

Yves.

Gouvidé Jean GBAGUIDI

unread,
Feb 6, 2023, 7:31:44 AM2/6/23
to lav...@googlegroups.com
Thank you Yves for your assistance, please Yves, when I remove 
Mean_Temperature~~Max_Temperature
Min_Relative.Humidity~~Max_Relative.Humidity
from my syntaxe I got the message: 
Warning message:
In lav_object_post_check(object) :
  lavaan WARNING: some estimated ov variances are negative


My question is how can I deal with the negative variance to reduce the residuals
This the output of my summary:

> summary(fit.cfaMod,fit.measures=TRUE,standardized=TRUE,rsq=TRUE)
lavaan 0.6.13 ended normally after 83 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        15

  Number of observations                          1193

Model Test User Model:
                                                     
  Test statistic                              3103.257
  Degrees of freedom                                13
  P-value (Chi-square)                           0.000

Model Test Baseline Model:

  Test statistic                             14022.412
  Degrees of freedom                                21
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.779
  Tucker-Lewis Index (TLI)                       0.643

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -6386.477
  Loglikelihood unrestricted model (H1)      -4834.848
                                                     
  Akaike (AIC)                               12802.953
  Bayesian (BIC)                             12879.217
  Sample-size adjusted Bayesian (SABIC)      12831.571

Root Mean Square Error of Approximation:

  RMSEA                                          0.446
  90 Percent confidence interval - lower         0.433
  90 Percent confidence interval - upper         0.460
  P-value H_0: RMSEA <= 0.050                    0.000
  P-value H_0: RMSEA >= 0.080                    1.000

Standardized Root Mean Square Residual:

  SRMR                                           0.234

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  F1 =~                                                                
    Rainfall          0.424    0.022   18.928    0.000    0.424    0.424
    Mn_Rltv.H         0.957    0.021   44.969    0.000    0.957    0.958
    Mn_Rltv.H         1.022    0.020   51.107    0.000    1.022    1.022
    Mx_Rltv.H         0.954    0.021   44.679    0.000    0.954    0.954
  F2 =~                                                                
    Mn_Tmprtr         1.260    0.122   10.302    0.000    1.260    1.260
    Mn_Tmprtr (b1)    0.498    0.055    9.025    0.000    0.498    0.498

Regressions:
                      Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  Malaria_Incidence ~                                                      
    F1                   0.069    0.018    3.858    0.000    0.069    0.069
    F2                  -0.233    0.036   -6.447    0.000   -0.233   -0.234

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  F1 ~~                                                                
    F2                0.000                               0.000    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .Rainfall          0.819    0.031   26.748    0.000    0.819    0.820
   .Min_Rltv.Hmdty    0.083    0.003   26.405    0.000    0.083    0.083
   .Men_Rltv.Hmdty   -0.045    0.002  -25.157    0.000   -0.045   -0.045
   .Max_Rltv.Hmdty    0.089    0.003   26.466    0.000    0.089    0.090
   .Mean_Temperatr   -0.587    0.307   -1.912    0.056   -0.587   -0.588
   .Min_Temperatur    0.752    0.057   13.225    0.000    0.752    0.752
   .Malaria_Incdnc    0.931    0.039   23.625    0.000    0.931    0.941
    F1                1.000                               1.000    1.000
    F2                1.000                               1.000    1.000

R-Square:
                   Estimate
    Rainfall          0.180
    Min_Rltv.Hmdty    0.917
    Men_Rltv.Hmdty       NA
    Max_Rltv.Hmdty    0.910
    Mean_Temperatr       NA
    Min_Temperatur    0.248
    Malaria_Incdnc    0.059



--
You received this message because you are subscribed to a topic in the Google Groups "lavaan" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lavaan/nqH_CQ0TsbM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lavaan+un...@googlegroups.com.

Keith Markus

unread,
Feb 6, 2023, 11:15:35 PM2/6/23
to lavaan
Gouvide,
You can think of the broader conceptual issue with residual covariances in this way:  You are fitting a model to a covariance matrix.  If you free all the residual covariances between the variables, this is sufficient to trivially reproduce their covariance matrix and any additional free parameters are redundant.  As a general rule, the more residual covariances you free, the less work there is for the rest of your model parameters to do.

So, it is actually progress that you now have negative variances.  This probably indicates that you now have enough constraints in your model to make it testable.  Quite possibly what this indicates is that your observed covariance matrix cannot be reproduced by your model structure.  Some variables may covary more than the model predicts and some parameters may therefore be estimated in a biased manner in an attempt to accommodate that.

You have two variables with negative disturbance variances, suggesting that the model is trying to predict more variance in those variables than they have.  One possibility is that,  because they are both means, your mean variables covary with one another more than they covary with other measures that are not means.  You could conceptualize that as shared method variance.  If you have enough observed variables, you can model that using multi-trait, multi-method models.  Otherwise, you might try simply removing the mean indicator for F1 from the model.

Keith
------------------------
Keith A. Markus
John Jay College of Criminal Justice, CUNY
http://jjcweb.jjay.cuny.edu/kmarkus
Frontiers of Test Validity Theory: Measurement, Causation and Meaning.
http://www.routledge.com/books/details/9781841692203/
 

Gouvidé Jean GBAGUIDI

unread,
Feb 7, 2023, 5:10:12 AM2/7/23
to lav...@googlegroups.com
Dear Keith,
Thank you for the assistance, after reading your comments, I tried to remove the variable Mean_relative Humidity from but I got the same warning message.

Warning message:
    In lav_object_post_check(object) :
    lavaan WARNING: some estimated ov variances are negative


Here is my new syntaxe
d<-cor.smooth(Mal,eig.tol = 10^-4)
cfaMod2<-"F1=~Rainfall+Min_Relative.Humidity
+Max_Relative.Humidity
F2=~Mean_Temperature+Min_Temperature
Malaria_Incidence~F1+F2

"
fit.cfaMod<-cfa(cfaMod2,sample.cov=d,sample.nobs=1193, estimator = "ML",
                orthogonal=T,std.lv=T,bounds=F)               
summary(fit.cfaMod,fit.measures=TRUE,standardized=TRUE,rsq=TRUE)

This is the output of my summary.
> summary(fit.cfaMod,fit.measures=TRUE,standardized=TRUE,rsq=TRUE)
lavaan 0.6.13 ended normally after 24 iterations


  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        13


  Number of observations                          1193

Model Test User Model:
                                                     
  Test statistic                              1870.534
  Degrees of freedom                                 8

  P-value (Chi-square)                           0.000

Model Test Baseline Model:

  Test statistic                              5682.608
  Degrees of freedom                                15

  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.671
  Tucker-Lewis Index (TLI)                       0.384

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -8247.724
  Loglikelihood unrestricted model (H1)      -7312.457
                                                     
  Akaike (AIC)                               16521.447
  Bayesian (BIC)                             16587.542
  Sample-size adjusted Bayesian (SABIC)      16546.249


Root Mean Square Error of Approximation:

  RMSEA                                          0.442
  90 Percent confidence interval - lower         0.425
  90 Percent confidence interval - upper         0.459

  P-value H_0: RMSEA <= 0.050                    0.000
  P-value H_0: RMSEA >= 0.080                    1.000

Standardized Root Mean Square Residual:

  SRMR                                           0.192


Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  F1 =~                                                                
    Rainfall          0.789    0.024   32.295    0.000    0.789    0.789
    Min_Rltv.Hmdty    1.022    0.021   49.101    0.000    1.022    1.023
    Max_Rltv.Hmdty    0.861    0.023   36.703    0.000    0.861    0.862
  F2 =~                                                                
    Mean_Temperatr    0.838    0.055   15.288    0.000    0.838    0.838
    Min_Temperatur    0.748    0.051   14.772    0.000    0.748    0.748


Regressions:
                      Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  Malaria_Incidence ~                                                      
    F1                   0.248    0.027    9.179    0.000    0.248    0.249
    F2                  -0.252    0.031   -8.088    0.000   -0.252   -0.253


Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  F1 ~~                                                                
    F2                0.000                               0.000    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .Rainfall          0.377    0.017   22.254    0.000    0.377    0.377
   .Min_Rltv.Hmdty   -0.046    0.012   -3.811    0.000   -0.046   -0.046
   .Max_Rltv.Hmdty    0.257    0.013   19.081    0.000    0.257    0.258
   .Mean_Temperatr    0.297    0.084    3.538    0.000    0.297    0.297
   .Min_Temperatur    0.440    0.069    6.405    0.000    0.440    0.440
   .Malaria_Incdnc    0.866    0.036   23.969    0.000    0.866    0.874

    F1                1.000                               1.000    1.000
    F2                1.000                               1.000    1.000

R-Square:
                   Estimate
    Rainfall          0.623
    Min_Rltv.Hmdty       NA
    Max_Rltv.Hmdty    0.742
    Mean_Temperatr    0.703
    Min_Temperatur    0.560
    Malaria_Incdnc    0.126

I would like to let you know also that I don't know how to test the first possibility,which is the  use of multi-trait, multi-method models. I'm new in lavaan and I'm not quite good in lavaan. 
I can notice that all my eigen values is positive.

> eigen(d)
eigen() decomposition
$values
[1] 4.6794554401 2.0082591013 0.9422425056 0.8286588823 0.3271748668
[6] 0.1326205058 0.0710471903 0.0099625567 0.0005789511

$vectors
            [,1]        [,2]        [,3]          [,4]        [,5]        [,6]
 [1,]  0.3953031 -0.05058885 -0.14584043  0.1573405672  0.77828175 -0.43097320
 [2,] -0.2307815 -0.56345073  0.32597342 -0.0576799319  0.11081673 -0.08695177
 [3,]  0.1263033 -0.65886525  0.06176549 -0.0750538018  0.15566622  0.46782981
 [4,] -0.4043429 -0.17441095  0.36931407 -0.0114638993  0.01239381 -0.50547677
 [5,]  0.4435527 -0.13343348  0.11857213  0.0470538894 -0.26665050 -0.11217114
 [6,]  0.4441680 -0.11190549  0.04693173  0.0770007862 -0.06238938  0.21854322
 [7,]  0.4169275 -0.14813454  0.17020707 -0.0009070617 -0.47547487 -0.45471791
 [8,] -0.1029920 -0.34572211 -0.78230345 -0.3703817083 -0.17026329 -0.25489301
 [9,]  0.1804700  0.20891744  0.27392146 -0.9059944012  0.16598412  0.01573764
             [,7]          [,8]          [,9]
 [1,] -0.06074803 -2.230407e-06  7.929241e-05
 [2,]  0.07214553 -7.032796e-01  5.424215e-03
 [3,] -0.29679119  4.573540e-01 -1.190007e-02
 [4,]  0.34262031  5.442657e-01  1.700349e-02
 [5,]  0.21315943 -3.120347e-07 -8.000383e-01
 [6,]  0.72111921  2.270963e-06  4.586870e-01
 [7,] -0.43969563  4.080371e-06  3.861080e-01
 [8,]  0.16348174  4.610788e-06 -1.123261e-03
 [9,]  0.01107399 -2.591047e-06 -2.055218e-03

--
You received this message because you are subscribed to a topic in the Google Groups "lavaan" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lavaan/nqH_CQ0TsbM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lavaan+un...@googlegroups.com.

Shu Fai Cheung (張樹輝)

unread,
Feb 7, 2023, 7:00:58 AM2/7/23
to lavaan
Dear Gouvide,

I do not have a solution but I am thinking about what else you can explore.

I tried to recover the covariance matrix from the eigenvalues and vectors, and then examine the correlations. Some of them are .80 or even .90. I don't know what the columns represent but maybe you can check whether some indicators are so strongly correlated that you may consider using only one of them.

You can also try fitting a CFA model with only F1 (Rainfall, Min_Relative.Humidity, Max_Relative.Humidity) because it is Min_Relative.Humidity that has a negative error variance:

cfaMod2_F1 <- "F1 =~ Rainfall + Min_Relative.Humidity + Max_Relative.Humidity"

The 3-indicator-1-factor model is a saturated model. We usually don't fit this model. However, I came across cases in which the error variance of an indicator can be negative in this saturated model, regardless of sample size. Maybe your case has a similar problem. If yes, then the solution may be different, although I do not yet know what the solution is, other than removing one of the indicators.

-- Shu Fai

Gouvidé Jean GBAGUIDI

unread,
Feb 7, 2023, 7:32:50 AM2/7/23
to lav...@googlegroups.com
Shu,
Thank you so much for your response and interest. The goal of this work is to model the link between climate variables(Rainfall, temperature, relative humidity, wind speed) and the incidence of malaria. I have 1193 observations after cleaning my data.
Here is the correlation between the variables.

Correlation
                       Rainfall Mean_Temperature Min_Temperature
Rainfall                      1                                
Mean_Temperature          -0.39                1                
Min_Temperature             0.3             0.63               1
Max_Temperature           -0.75             0.76           -0.02
Mean_Relative.Humidity     0.76             -0.3            0.42
Min_Relative.Humidity      0.81            -0.34             0.4
Max_Relative.Humidity      0.67            -0.25            0.41
Wind.Speed                -0.13             0.28            0.35
Malaria_Incidence           0.2             -0.3           -0.09
                       Max_Temperature Mean_Relative.Humidity
Rainfall                                                    
Mean_Temperature                                            
Min_Temperature                                              
Max_Temperature                      1                      
Mean_Relative.Humidity           -0.74                      1
Min_Relative.Humidity            -0.78                   0.97
Max_Relative.Humidity            -0.66                   0.97
Wind.Speed                        0.07                   -0.2
Malaria_Incidence                -0.31                    0.3
                       Min_Relative.Humidity Max_Relative.Humidity Wind.Speed
Rainfall                                                                    
Mean_Temperature                                                            
Min_Temperature                                                              
Max_Temperature                                                              
Mean_Relative.Humidity                                                      
Min_Relative.Humidity                      1                                
Max_Relative.Humidity                   0.88                     1          
Wind.Speed                             -0.19                 -0.19          1
Malaria_Incidence                       0.28                  0.31      -0.17
                       Malaria_Incidence
Rainfall                                
Mean_Temperature                        
Min_Temperature                        
Max_Temperature                        
Mean_Relative.Humidity                  
Min_Relative.Humidity                  
Max_Relative.Humidity                  
Wind.Speed                              
Malaria_Incidence                      1

These are the output of EFA
-Parallel analysis suggests that the number of factors =  3  and the number of components =  2 
> parallel$fa.values
[1]  4.43593272  1.20387208  0.24724435  0.02491603 -0.02509572 -0.07242975
[7] -0.13741032 -0.46940710 -0.80233980

so with the Kaiser values, I should have at least 2 factors. kaiser greater than 1 indicates the number of factors.

Factors analysis
> print(Twofactor,cut = 0.3,digits = 2)
Factor Analysis using method =  ml
Call: fa(r = data.frame(subsetMal1), nfactors = 2, rotate = "oblimin",
    SMC = F, covar = T, fm = "ML")
Standardized loadings (pattern matrix) based upon correlation matrix
                         ML1   ML2    h2     u2 com
Rainfall                0.76       0.616 0.3836 1.1
Mean_Temperature              0.94 0.995 0.0049 1.1
Min_Temperature         0.48  0.82 0.804 0.1957 1.6
Max_Temperature        -0.71  0.52 0.860 0.1400 1.8
Mean_Relative.Humidity  1.00       0.995 0.0046 1.0
Min_Relative.Humidity   0.97       0.950 0.0497 1.0
Max_Relative.Humidity   0.97       0.926 0.0743 1.0
Wind.Speed                         0.091 0.9091 1.9
Malaria_Incidence                  0.137 0.8633 1.8


                       ML1  ML2
SS loadings           4.40 1.97
Proportion Var        0.49 0.22
Cumulative Var        0.49 0.71
Proportion Explained  0.69 0.31
Cumulative Proportion 0.69 1.00

 With factor correlations of
      ML1   ML2
ML1  1.00 -0.12
ML2 -0.12  1.00

Mean item complexity =  1.4
Test of the hypothesis that 2 factors are sufficient.

The degrees of freedom for the null model are  36  and the objective function was  15.85
The degrees of freedom for the model are 19  and the objective function was  5.44

The root mean square of the residuals (RMSR) is  0.07
The df corrected root mean square of the residuals is  0.09

Fit based upon off diagonal values = 0.98
Measures of factor score adequacy            
                                                   ML1  ML2
Correlation of (regression) scores with factors   1.00 1.00
Multiple R square of scores with factors          1.00 0.99
Minimum correlation of possible factor scores     0.99 0.99

The different syntax of my model

Model1: One factor
cfaMod1<-'F=~Rainfall+Min_Relative.Humidity+Mean_Relative.Humidity
+Max_Relative.Humidity
Malaria_Incidence~F
Malaria_Incidence~~Malaria_Incidence'

Model2: Two factors

cfaMod2<-"F1=~Rainfall+Min_Relative.Humidity+Mean_Relative.Humidity
+Max_Relative.Humidity
F2=~Mean_Temperature+Min_Temperature
Malaria_Incidence~F1+F2
"
fit.cfaMod<-cfa(cfaMod2,sample.cov=d,sample.nobs=1193, estimator = "ML",orthogonal=T,std.lv=T,)
               
summary(fit.cfaMod,fit.measures=TRUE,standardized=TRUE,rsq=TRUE)

I got the same warning message when I run the two different model.

Warning message:
In lav_object_post_check(object) :
  lavaan WARNING: some estimated ov variances are negative


Thank you for more attention on the data ,Shu

I attach my data 

CC_MalariaS.csv

Prof. Gavin Brown

unread,
Feb 7, 2023, 2:51:18 PM2/7/23
to lavaan

Hi Gouvidé

Your negative variance result happens for a number of reasons.

One reason is randomness. It is possible to set a negative value to a small positive value if the standard error range crosses zero into positive territory and if there is evidence from previous studies that the true value is positive.

In your case

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all

.Min_Rltv.Hmdty   -0.046    0.012   -3.811    0.000   -0.046   -0.046
the value for this variable is clearly much larger than the standard error (see the z value) so you should not force it to become .005

So this speaks to a serious mis-specification of your model.

I suspect this variable is highly correlated with .Max_Rltv.Hmdty  (I bet these are statistically and logically linearly dependent). In that case I would delete one of these two variables (preferably the one with the negative error value).

 See

Chen, F., Bollen, K. A., Paxton, P., Curran, P. J., & Kirby, J. B. (2001). Improper solutions in structural equation models: Causes, consequences, and strategies. Sociological Methods & Research, 29(4), 468-508. https://doi.org/10.1177/0049124101029004003

Gouvidé Jean GBAGUIDI

unread,
Feb 7, 2023, 4:33:33 PM2/7/23
to lav...@googlegroups.com
Thank you so much Prof Gavin. Yes exactly, I have tried to remove Min_Relative Humidity from the syntax but the issu is that lavan indicates that Pearson correlations of the raw data were found when I compute the code: > d<-cor.smooth(Mal,eig.tol = 10^-4)### Smooth the matrix(non positive). 

I can compute the number of factors
frr<-char2numeric(subsetMal1)
> parallel <-fa.parallel(frr,fm="ML",fa='both',
+                        main="Parallel Analysis Scree Plots",SMC=T,n.obs = 1193)
In smc, smcs < 0 were set to .0
Parallel analysis suggests that the number of factors =  4  and the number of components =  2 

> parallel$fa.values
[1]  3.54167884  1.45748687  0.46106118  0.12922021 -0.02409378 -0.03378708
[7] -0.18159654 -0.72522599

But I got error when I compute  this code: 
twofactor<-fa(data.frame(subsetMal1),nfactors =2,rotate ="oblimin",fm="ML",SMC = T,covar = T)
summary(threefactor)

> threefactor<-fa(data.frame(subsetMal1),nfactors =2,rotate ="oblimin",fm="ML",SMC = T,covar = T)
In smc, smcs < 0 were set to .0
In smc, smcs < 0 were set to .0
Error in optim(start, FAfn, FAgr, method = "L-BFGS-B", lower = 0.005,  :
  L-BFGS-B needs finite values of 'fn'
In addition: Warning message:
In log(e) : NaNs produced


So I was unable to determine the variables of each factor before defining the syntax of the CFA

Thank you for your attention.

I will be grateful to solve these issues  

Reply all
Reply to author
Forward
0 new messages