Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can I obtain the predicted variance covariance matrix from SEM?

    Is there a quick way to obtain the predicted means and variance-covariance matrix from SEM? It is easy to get the estimated residuals using estat residual, but it does not seem to provide the predicted means or variance-covariance matrix as output or as a stored result.

    I want this to compute the SRMR myself as I do not trust the SRMRs in the output (Stata is calculating an SRMR>1, which makes no sense - see my other post and tread on this topic))

  • #2
    Could you create them yourself from the observed + residuals?
    Code:
    sysuse auto
    sem (length turn displacement gear_ratio <- F), nolog
    
    estat residuals
    
    matrix define ImpliedCovariances = e(S) + r(res_cov)
    matrix list ImpliedCovariance
    
    matrix define ImpliedMeans = e(means) + r(res_mean)
    matrix list ImpliedMeans

    Comment


    • #3
      estat framework computes the fitted mean vector and variance matrix.
      The means vector is stored in r(mu), the variance matrix is stored in r(Sigma).

      We are looking into this problem with SRMR for SEM with fitted means.
      In the mean time, here is how George might go about computing SRMS by hand.

      Using the first example in the [SEM] manual, the following fits a CFA model
      without and with means, calls estat gof to report SRMR for each, then
      hand computes SRMR in Mata using results from estat framekwork and
      some hidden estimation results in e() (from the model with fitted means).

      Code:
      . webuse sem_1fmm
      (single-factor measurement model)
      
      . quietly sem x* <- L, method(adf) nomeans
      
      . estat gof, stats(residual)
      
      ----------------------------------------------------------------------------
      Fit statistic        |      Value   Description
      ---------------------+------------------------------------------------------
      Size of residuals    |
                      SRMR |      0.008   Standardized root mean squared residual
                        CD |      0.973   Coefficient of determination
      ----------------------------------------------------------------------------
      
      . quietly sem x* <- L, method(adf)
      
      . estat gof, stats(residual)
      
      ----------------------------------------------------------------------------
      Fit statistic        |      Value   Description
      ---------------------+------------------------------------------------------
      Size of residuals    |
                      SRMR |      0.010   Standardized root mean squared residual
                        CD |      0.973   Coefficient of determination
      ----------------------------------------------------------------------------
      
      . quietly estat framework
      
      . return list
      
      scalars:
             r(standardized) =  0
                 r(N_groups) =  1
      
      matrices:
                       r(mu) :  1 x 5
                    r(Sigma) :  5 x 5
                    r(kappa) :  1 x 1
                    r(alpha) :  1 x 4
                      r(Phi) :  1 x 1
                      r(Psi) :  4 x 4
                    r(Gamma) :  4 x 1
                     r(Beta) :  4 x 4
                     r(nobs) :  1 x 1
      
      . mata:
      ------------------------------------------------- mata (type end to exit) -----
      : S = st_matrix("e(S)")                           // hidden result
      
      : noy = cols(S)
      
      : Sigma = st_matrix("r(Sigma)")[1..noy,1..noy]
      
      : srmr0 = sqrt(2*sum(vech(corr(S) - corr(Sigma)):^2)/(noy*(noy+1)))
      
      : m = st_matrix("e(means)")':/sqrt(diagonal(S))           // hidden result
      
      : mu = st_matrix("r(mu)")[1..noy]':/sqrt(diagonal(Sigma))
      
      : srmr1 = sqrt(2*(sum(m-mu):^2+sum(vech(corr(S) - corr(Sigma)):^2))/(noy*(noy+3
      > )))
      
      : printf("SRMR without means: %6.4f\n", srmr0)
      SRMR without means: 0.0083
      
      : printf("SRMR with    means: %6.4f\n", srmr1)
      SRMR with    means: 0.0095
      
      : end
      -------------------------------------------------------------------------------

      Comment


      • #4
        Thanks to you both. Just what I needed.

        By the way, Stata has been investigating my issue and has concluded that there is, indeed, a bug in the computation of the SRMR. See my other thread for details.

        Comment

        Working...
        X