Back to schedule


Introduction to lavaan

The program lavaan is a structural equation modeling (SEM) program written in R that can be used to run path analyses (PA), confirmatory factor analyses (CFA), and the combination of the two, which is a SEM. Examples of all three models are to be presented. To learn more about structural equation modeling with `lavaan’ here.

SEM lavaan has three steps
* Specify the model.
* Estimate that model.
* Examine the output.

Basic Plan for the Day
* Path Analysis (APIM)
* Distinguishable
* Partially Indistinguishable
* Fully Indistinguishable
* Confirmatory Factor Analysis
* Distinguishable
* Indistinguishable
* Mediation
* Distinguishable
* Indistinguishable
* Common Fate Model
* Distinguishable
* Indistinguishable

lavaan relational symbols used to specify a model:
* x ~ y + z — paths from y and z to x
* x ~ c — mean of x is set to c
* x ~~ y — covariance between x and y; * x ~~ x — variance of x;
* f =~ y + x — y and x load on f where f is an unmeasured variable (not this is “backwards”)
* x ~ 2y — path from y to x is set or fixed to “2”
x ~ ay + aZ — paths from y and Z to x are symbolized as “a” (used for equality constraints)
* k := p/a – creates a new parameter k which is the ratio of two other parameters

Almost always input a dyad dataset to an SEM program. Reading a pairwise dataset is normally highly problematic.

library(lavaan)
riggsd <- read.csv("riggsd.csv", header=TRUE) 

APIM with Distinguishable Dyads

Basic Model

First shown is path analysis, the APIM with distinguishable dyads.

# Specify the model

APIM_D <- '

                  Sat_M  ~ a1*Anxiety_M  # Male actor effect
                  Sat_W  ~ a2*Anxiety_W  # Female actor effect
                  Sat_M  ~ p12*Anxiety_W  # Female to male partner effect
                  Sat_W  ~ p21*Anxiety_M  # Male to female partner effect
                  Anxiety_M ~ mx1*1 # Mean for X for men
                  Anxiety_W ~ mx2*1 # Mean for X for women
                  Sat_M ~ iy1*1  # Intercept for Y for women
                  Sat_W ~ iy2*1 # Intercept for Y for women
                  Anxiety_M ~~ vx1*Anxiety_M  # Variance for X for men
                  Anxiety_W ~~ vx2*Anxiety_W  # Variance for X for women
                  Sat_M ~~ ve1*Sat_M   # Error variance for Y for men
                  Sat_W ~~ ve2*Sat_W    # Error variance for Y for women
                  Anxiety_W ~~ cx*Anxiety_M # Covariance of X between men and women
                  Sat_W ~~ cy*Sat_M  # Covariance of errors between men and women

'

# Estimate the model 
apimd <- sem(APIM_D,fixed.x=FALSE, data = riggsd,missing="fiml")
# Examine the model.
summary(apimd, fit.measures = TRUE)
## lavaan (0.5-23.1097) converged normally after  63 iterations
## 
##   Number of observations                           155
## 
##   Number of missing patterns                         1
## 
##   Estimator                                         ML
##   Minimum Function Test Statistic                0.000
##   Degrees of freedom                                 0
##   Minimum Function Value               0.0000000000000
## 
## Model test baseline model:
## 
##   Minimum Function Test Statistic              135.383
##   Degrees of freedom                                 6
##   P-value                                        0.000
## 
## User model versus baseline model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -1492.604
##   Loglikelihood unrestricted model (H1)      -1492.604
## 
##   Number of free parameters                         14
##   Akaike (AIC)                                3013.207
##   Bayesian (BIC)                              3055.815
##   Sample-size adjusted Bayesian (BIC)         3011.502
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent Confidence Interval          0.000  0.000
##   P-value RMSEA <= 0.05                             NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Information                                 Observed
##   Standard Errors                             Standard
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Sat_M ~                                             
##     Anxity_M  (a1)   -1.680    0.427   -3.937    0.000
##   Sat_W ~                                             
##     Anxity_W  (a2)   -1.918    0.461   -4.165    0.000
##   Sat_M ~                                             
##     Anxity_W (p12)   -1.224    0.448   -2.734    0.006
##   Sat_W ~                                             
##     Anxity_M (p21)   -1.315    0.439   -2.995    0.003
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Anxiety_M ~~                                        
##     Anxiety_W (cx)    0.297    0.124    2.392    0.017
##  .Sat_M ~~                                            
##    .Sat_W     (cy)   27.385    4.195    6.528    0.000
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     Anxity_M (mx1)    2.632    0.101   25.979    0.000
##     Anxity_W (mx2)    2.927    0.097   30.295    0.000
##    .Sat_M    (iy1)   52.864    1.638   32.282    0.000
##    .Sat_W    (iy2)   53.852    1.685   31.959    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     Anxity_M (vx1)    1.592    0.181    8.803    0.000
##     Anxity_W (vx2)    1.447    0.164    8.803    0.000
##    .Sat_M    (ve1)   43.219    4.909    8.803    0.000
##    .Sat_W    (ve2)   45.759    5.198    8.803    0.000
parameterEstimates(apimd, standardized = TRUE)
##          lhs op       rhs label    est    se      z pvalue ci.lower
## 1      Sat_M  ~ Anxiety_M    a1 -1.680 0.427 -3.937  0.000   -2.517
## 2      Sat_W  ~ Anxiety_W    a2 -1.918 0.461 -4.165  0.000   -2.821
## 3      Sat_M  ~ Anxiety_W   p12 -1.224 0.448 -2.734  0.006   -2.101
## 4      Sat_W  ~ Anxiety_M   p21 -1.315 0.439 -2.995  0.003   -2.176
## 5  Anxiety_M ~1             mx1  2.632 0.101 25.979  0.000    2.434
## 6  Anxiety_W ~1             mx2  2.927 0.097 30.295  0.000    2.738
## 7      Sat_M ~1             iy1 52.864 1.638 32.282  0.000   49.654
## 8      Sat_W ~1             iy2 53.852 1.685 31.959  0.000   50.549
## 9  Anxiety_M ~~ Anxiety_M   vx1  1.592 0.181  8.803  0.000    1.237
## 10 Anxiety_W ~~ Anxiety_W   vx2  1.447 0.164  8.803  0.000    1.125
## 11     Sat_M ~~     Sat_M   ve1 43.219 4.909  8.803  0.000   33.597
## 12     Sat_W ~~     Sat_W   ve2 45.759 5.198  8.803  0.000   35.571
## 13 Anxiety_M ~~ Anxiety_W    cx  0.297 0.124  2.392  0.017    0.054
## 14     Sat_M ~~     Sat_W    cy 27.385 4.195  6.528  0.000   19.163
##    ci.upper std.lv std.all std.nox
## 1    -0.844 -1.680  -0.297  -0.297
## 2    -1.016 -1.918  -0.310  -0.310
## 3    -0.346 -1.224  -0.206  -0.206
## 4    -0.455 -1.315  -0.223  -0.223
## 5     2.831  2.632   2.087   2.087
## 6     3.116  2.927   2.433   2.433
## 7    56.073 52.864   7.395   7.395
## 8    57.154 53.852   7.239   7.239
## 9     1.946  1.592   1.000   1.000
## 10    1.769  1.447   1.000   1.000
## 11   52.841 43.219   0.846   0.846
## 12   55.947 45.759   0.827   0.827
## 13    0.541  0.297   0.196   0.196
## 14   35.607 27.385   0.616   0.616

Results
* Estimates of coefficients are the same as those from gls.
* standard errors, t-values, and p values are different (slightly more liberal).
* Fit not an issue as the model is saturated.

APIM_SEM app output

https://apimsem.ugent.be/shiny/apim_sem/

APIM Distinguishable 

The lavaan model converged after 63 iterations. A summary of results of the APIM analyses is contained in Table 3 and the overall effects in Table 4 in the output tab ‘Tables’. The variance of the errors for the Women and Men are 43.219 and 45.759, respectively. The R squared for the Women is .154, and for the Men it is .173. The partial intraclass correlation for Satisfaction controlling for the other predictor variables is equal to .616 and is statistically significant (p < .001, 95% CI [0.44, 0.82]). Thus, when one member of the dyad scores high (low) on the variable Satisfaction after controlling for the predictor variables, the other member also tends to have a high (low) score.

The intercept (the predicted score on Satisfaction when the variables of Attachment Anxiety equal zero) for Women is equal to 52.864 and is statistically significant (p < .001, 95% CI [49.65, 56.07]) different from zero. The intercept for Men is equal to 53.852 and is statistically significant (p < .001, 95% CI [50.55, 57.15]) different from zero. The difference in intercepts is equal to -0.988, this difference is not statistically significant (p = .498, 95% CI [-3.84, 1.87]), which means that there is no main effect of Gender.

The actor effect for the Women is equal to -1.680 (p < .001, 95% CI [-2.52, -0.84]). The overall standardized effect for the Women is -0.284 (partial r = -.302). The actor effect for the Men is equal to -1.918 (p < .001, 95% CI [-2.82, -1.02]) and the overall standardized actor effect for the Men is -0.324 (partial r = -.317). When tested if the two actor effects are equal, the difference was found not to be statistically significant, p = .720, 95% CI [-1.06, 1.54]. The overall actor effect is equal to -1.799 and is statistically significant (p < .001, 95% CI [-2.38, -1.22]).

The partner effect from Men to Women is equal to -1.224, which is statistically significant (p = .006, 95% CI [-2.1, -0.35]), and its overall standardized effect is -0.207 (partial r = -.214). The partner effect from Women to Men is equal to -1.315 and is statistically significant (p = .003, 95% CI [-2.18, -0.45]) and its overall standardized partner effect is -0.222 (partial r = -.234). When tested if the two partner effects are equal, the difference was found not to be statistically significant (p = .890, 95% CI [-1.21, 1.39]). The overall partner effect is equal to -1.270 is statistically significant (p < .001, 95% CI [-1.85, -0.69]).

Next, the relative sizes of the actor and partner effects are considered. If the standardized actor effects of both Women and Men are greater than .1 in absolute value and they are statistically significant, k (i.e. the ratio of the partner effect to the actor effect) can be interpreted. This is the case for this dataset. The value of k for the Women equals 0.73, the k of the Men is equal to 0.69.No further conclusions can be drawn for k, because a bootstrap analysis was not chosen to calculate the confidence intervals.

Equal Actor and Partner Effects

Two constraints * Equal actor effects (a1 = a2)
* Equal partner effects (p12 = p21)

APIM_De <- '
Sat_M ~ a*Anxiety_M + p*Anxiety_W
Sat_W ~ a*Anxiety_W + p*Anxiety_M
Anxiety_M ~ mx1*1
Anxiety_W ~ mx2*1
Sat_M ~ iy1*1
Sat_W ~ iy2*1
Anxiety_M ~~ vx1*Anxiety_M
Anxiety_W ~~ vx2*Anxiety_W
Sat_M ~~ ve1*Sat_M
Sat_W ~~ ve2*Sat_W
Anxiety_W ~~ cx*Anxiety_M
Sat_W ~~ cy*Sat_M
'
apimde <- sem(APIM_De,fixed.x=FALSE, data = riggsd,missing="fiml")
summary(apimde, fit.measures = TRUE)
## lavaan (0.5-23.1097) converged normally after  52 iterations
## 
##   Number of observations                           155
## 
##   Number of missing patterns                         1
## 
##   Estimator                                         ML
##   Minimum Function Test Statistic                0.459
##   Degrees of freedom                                 2
##   P-value (Chi-square)                           0.795
## 
## Model test baseline model:
## 
##   Minimum Function Test Statistic              135.383
##   Degrees of freedom                                 6
##   P-value                                        0.000
## 
## User model versus baseline model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.036
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -1492.833
##   Loglikelihood unrestricted model (H1)      -1492.604
## 
##   Number of free parameters                         12
##   Akaike (AIC)                                3009.666
##   Bayesian (BIC)                              3046.187
##   Sample-size adjusted Bayesian (BIC)         3008.204
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent Confidence Interval          0.000  0.101
##   P-value RMSEA <= 0.05                          0.855
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.011
## 
## Parameter Estimates:
## 
##   Information                                 Observed
##   Standard Errors                             Standard
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Sat_M ~                                             
##     Anxiety_M  (a)   -1.786    0.294   -6.076    0.000
##     Anxiety_W  (p)   -1.268    0.294   -4.306    0.000
##   Sat_W ~                                             
##     Anxiety_W  (a)   -1.786    0.294   -6.076    0.000
##     Anxiety_M  (p)   -1.268    0.294   -4.306    0.000
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Anxiety_M ~~                                        
##     Anxiety_W (cx)    0.297    0.124    2.392    0.017
##  .Sat_M ~~                                            
##    .Sat_W     (cy)   27.364    4.196    6.521    0.000
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     Anxity_M (mx1)    2.632    0.101   25.979    0.000
##     Anxity_W (mx2)    2.927    0.097   30.295    0.000
##    .Sat_M    (iy1)   53.270    1.502   35.459    0.000
##    .Sat_W    (iy2)   53.339    1.508   35.378    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     Anxity_M (vx1)    1.592    0.181    8.803    0.000
##     Anxity_W (vx2)    1.447    0.164    8.803    0.000
##    .Sat_M    (ve1)   43.242    4.914    8.800    0.000
##    .Sat_W    (ve2)   45.792    5.204    8.799    0.000
cs=fitMeasures(apimde)[3]
rmsea = fitMeasures(apimde)[23]
df=fitMeasures(apimde)[4]
nd=fitMeasures(apimde)[21]
# number of variables in the model is 4 and denoted as k
k=4
sabic =as.numeric( cs + log((nd+2)/24)*(k*(k + 3)/2 - df))
sabic0= as.numeric(log((nd+2)/24)*(k*(k + 3)/2 ))
# chi square
cs
##     chisq 
## 0.4585752
# Sabic for saturated Model
sabic0
## [1] 26.29469
# Sabic for the estimated Model
sabic
## [1] 22.99688
# RMSEA for saturated Model
rmsea
## rmsea 
##     0

Fit discussion:

Chi square with 2 df is equal to .459 (p = .795), which means that setting the actor and partner effects equal is consistent with the data.

The SABIC for the saturated model is 26.29, whereas for this model it is 23.00. The smaller value suggests that the model with equal actor and partner effects is the better model.

The RMSEA is equal to zero, which also suggests good fit.

Thus, all three ways of measuring fit say that the model with equal actor and partner effects is the better model.

Add a Covariate: Length of Relationship

Have the covariate affect both persons for both X and Y. Note that X becomes an “endogenous” (caused) variable.

APIM_Dc <- '
                  Anxiety_M ~ cx1*Rel_Length
                  Anxiety_W ~ cx2*Rel_Length
                  Sat_M  ~ a1*Anxiety_M +  p12*Anxiety_W + cy1*Rel_Length
                  Sat_W  ~ a2*Anxiety_W +  p21*Anxiety_M + cy2*Rel_Length
                  Rel_Length ~ mc*1
                  Anxiety_M ~ ix1*1
                  Anxiety_W ~ ix2*1
                  Sat_M ~ iy1*1
                  Sat_W ~ iy2*1
                  Rel_Length ~~ vv*Rel_Length
                  Anxiety_M ~~ vex1*Anxiety_M
                  Anxiety_W ~~ vex2*Anxiety_W
                  Sat_M ~~ vye1*Sat_M
                  Sat_W ~~ vye2*Sat_W
                  Anxiety_W ~~ cx*Anxiety_M
                  Sat_W ~~ cy*Sat_M
                  covXd := cx1-cx2
                  covyd := cy1-cy2
                  covXa := (cx1+cx2)/2
                  covya := (cy1+cy2)/2
                 
'

apimdc <- sem(APIM_Dc,fixed.x=FALSE, data = riggsd,missing="fiml")
summary(apimdc, fit.measures = TRUE)
## lavaan (0.5-23.1097) converged normally after  72 iterations
## 
##   Number of observations                           155
## 
##   Number of missing patterns                         1
## 
##   Estimator                                         ML
##   Minimum Function Test Statistic                0.000
##   Degrees of freedom                                 0
##   Minimum Function Value               0.0000000000000
## 
## Model test baseline model:
## 
##   Minimum Function Test Statistic              156.148
##   Degrees of freedom                                10
##   P-value                                        0.000
## 
## User model versus baseline model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -1714.641
##   Loglikelihood unrestricted model (H1)      -1714.641
## 
##   Number of free parameters                         20
##   Akaike (AIC)                                3469.281
##   Bayesian (BIC)                              3530.150
##   Sample-size adjusted Bayesian (BIC)         3466.845
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent Confidence Interval          0.000  0.000
##   P-value RMSEA <= 0.05                             NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Information                                 Observed
##   Standard Errors                             Standard
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Anxiety_M ~                                         
##     Rl_Lngth (cx1)   -0.157    0.093   -1.699    0.089
##   Anxiety_W ~                                         
##     Rl_Lngth (cx2)   -0.225    0.087   -2.582    0.010
##   Sat_M ~                                             
##     Anxity_M  (a1)   -1.785    0.421   -4.245    0.000
##     Anxity_W (p12)   -1.427    0.446   -3.198    0.001
##     Rl_Lngth (cy1)   -1.228    0.490   -2.505    0.012
##   Sat_W ~                                             
##     Anxity_W  (a2)   -2.214    0.450   -4.920    0.000
##     Anxity_M (p21)   -1.467    0.424   -3.462    0.001
##     Rl_Lngth (cy2)   -1.784    0.494   -3.611    0.000
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##  .Anxiety_M ~~                                        
##    .Anxiety_W (cx)    0.255    0.120    2.128    0.033
##  .Sat_M ~~                                            
##    .Sat_W     (cy)   24.941    3.915    6.371    0.000
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     Rl_Lngth  (mc)    1.739    0.087   19.970    0.000
##    .Anxity_M (ix1)    2.906    0.190   15.313    0.000
##    .Anxity_W (ix2)    3.319    0.179   18.560    0.000
##    .Sat_M    (iy1)   55.870    2.004   27.877    0.000
##    .Sat_W    (iy2)   58.218    2.020   28.817    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     Rl_Lngt   (vv)    1.175    0.133    8.803    0.000
##    .Anxty_M (vex1)    1.562    0.177    8.803    0.000
##    .Anxty_W (vex2)    1.387    0.158    8.803    0.000
##    .Sat_M   (vye1)   41.537    4.718    8.803    0.000
##    .Sat_W   (vye2)   42.209    4.795    8.803    0.000
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     covXd             0.068    0.116    0.588    0.557
##     covyd             0.556    0.443    1.256    0.209
##     covXa            -0.191    0.069   -2.777    0.005
##     covya            -1.506    0.440   -3.426    0.001
parameterEstimates(apimdc, standardized = TRUE)
##           lhs op         rhs label    est    se      z pvalue ci.lower
## 1   Anxiety_M  ~  Rel_Length   cx1 -0.157 0.093 -1.699  0.089   -0.339
## 2   Anxiety_W  ~  Rel_Length   cx2 -0.225 0.087 -2.582  0.010   -0.396
## 3       Sat_M  ~   Anxiety_M    a1 -1.785 0.421 -4.245  0.000   -2.609
## 4       Sat_M  ~   Anxiety_W   p12 -1.427 0.446 -3.198  0.001   -2.302
## 5       Sat_M  ~  Rel_Length   cy1 -1.228 0.490 -2.505  0.012   -2.189
## 6       Sat_W  ~   Anxiety_W    a2 -2.214 0.450 -4.920  0.000   -3.095
## 7       Sat_W  ~   Anxiety_M   p21 -1.467 0.424 -3.462  0.001   -2.298
## 8       Sat_W  ~  Rel_Length   cy2 -1.784 0.494 -3.611  0.000   -2.753
## 9  Rel_Length ~1                mc  1.739 0.087 19.970  0.000    1.568
## 10  Anxiety_M ~1               ix1  2.906 0.190 15.313  0.000    2.534
## 11  Anxiety_W ~1               ix2  3.319 0.179 18.560  0.000    2.968
## 12      Sat_M ~1               iy1 55.870 2.004 27.877  0.000   51.941
## 13      Sat_W ~1               iy2 58.218 2.020 28.817  0.000   54.259
## 14 Rel_Length ~~  Rel_Length    vv  1.175 0.133  8.803  0.000    0.913
## 15  Anxiety_M ~~   Anxiety_M  vex1  1.562 0.177  8.803  0.000    1.215
## 16  Anxiety_W ~~   Anxiety_W  vex2  1.387 0.158  8.803  0.000    1.078
## 17      Sat_M ~~       Sat_M  vye1 41.537 4.718  8.803  0.000   32.289
## 18      Sat_W ~~       Sat_W  vye2 42.209 4.795  8.803  0.000   32.812
## 19  Anxiety_M ~~   Anxiety_W    cx  0.255 0.120  2.128  0.033    0.020
## 20      Sat_M ~~       Sat_W    cy 24.941 3.915  6.371  0.000   17.269
## 21      covXd :=     cx1-cx2 covXd  0.068 0.116  0.588  0.557   -0.159
## 22      covyd :=     cy1-cy2 covyd  0.556 0.443  1.256  0.209   -0.311
## 23      covXa := (cx1+cx2)/2 covXa -0.191 0.069 -2.777  0.005   -0.326
## 24      covya := (cy1+cy2)/2 covya -1.506 0.440 -3.426  0.001   -2.368
##    ci.upper std.lv std.all std.nox
## 1     0.024 -0.157  -0.135  -0.135
## 2    -0.054 -0.225  -0.203  -0.203
## 3    -0.961 -1.785  -0.315  -0.315
## 4    -0.552 -1.427  -0.240  -0.240
## 5    -0.267 -1.228  -0.186  -0.186
## 6    -1.332 -2.214  -0.358  -0.358
## 7    -0.637 -1.467  -0.249  -0.249
## 8    -0.816 -1.784  -0.260  -0.260
## 9     1.909  1.739   1.604   1.604
## 10    3.278  2.906   2.304   2.304
## 11    3.669  3.319   2.759   2.759
## 12   59.798 55.870   7.815   7.815
## 13   62.178 58.218   7.826   7.826
## 14    1.436  1.175   1.000   1.000
## 15    1.910  1.562   0.982   0.982
## 16    1.696  1.387   0.959   0.959
## 17   50.785 41.537   0.813   0.813
## 18   51.606 42.209   0.763   0.763
## 19    0.491  0.255   0.173   0.173
## 20   32.614 24.941   0.596   0.596
## 21    0.295  0.068   0.068   0.068
## 22    1.424  0.556   0.074   0.074
## 23   -0.056 -0.191  -0.169  -0.169
## 24   -0.645 -1.506  -0.223  -0.223

Length of Relationship appears to be needed in the model, as it has statistically significant effects on both Attachment Anxiety and Satisfaction. These effects do not appear to vary by gender.

More Complications: k ratio

Estimate k, the ratio of the partner effect to the actor effect and compute its confidence interval using the bootstrap.

Look for the gender difference by testing the difference between intercepts or i1 - i2, i_diff.

APIM_Dm <- '

                  Sat_M  ~ a1*Anxiety_M
                  Sat_W  ~ a2*Anxiety_W
                  Sat_M  ~ p12*Anxiety_W
                  Sat_W  ~ p21*Anxiety_M
                  Anxiety_M ~ mx1*1
                  Anxiety_W ~ mx2*1
                  Sat_M ~ iy1*1
                  Sat_W ~ iy2*1
                  Anxiety_M ~~ vx1*Anxiety_M
                  Anxiety_W ~~ vx2*Anxiety_W
                  Sat_M ~~ ve1*Sat_M
                  Sat_W ~~ ve2*Sat_W
                  Anxiety_W ~~ cx*Anxiety_M
                  Sat_W ~~ cy*Sat_M 
                  p_diff := p12 - p21
                  k1 := p12/a1
                  k2 := p21/a2
                  k_diff := k1 - k2
                  i_diff := iy1 - iy2
                  a_ave := (a1 + a2)/2
                  p_ave := (p12 + p21)/2
                  i_ave := (iy1 +iy2)/2
                  sum1 := (p12 + a1)/2
                  sum2 := (p21 + a2)/2
                  cont1 := a1 - p12
                  cont2 := a2 - p21
'

# Change to "bootstrap = 5000" to get reliable values for the confidence interval.  
apimdm <- sem(APIM_Dm,fixed.x=FALSE, data = riggsd,missing="fiml",
              se = "boot",bootstrap= 50)
summary(apimdm, fit.measures = TRUE)
## lavaan (0.5-23.1097) converged normally after  63 iterations
## 
##   Number of observations                           155
## 
##   Number of missing patterns                         1
## 
##   Estimator                                         ML
##   Minimum Function Test Statistic                0.000
##   Degrees of freedom                                 0
##   Minimum Function Value               0.0000000000000
## 
## Model test baseline model:
## 
##   Minimum Function Test Statistic              135.383
##   Degrees of freedom                                 6
##   P-value                                        0.000
## 
## User model versus baseline model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -1492.604
##   Loglikelihood unrestricted model (H1)      -1492.604
## 
##   Number of free parameters                         14
##   Akaike (AIC)                                3013.207
##   Bayesian (BIC)                              3055.815
##   Sample-size adjusted Bayesian (BIC)         3011.502
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent Confidence Interval          0.000  0.000
##   P-value RMSEA <= 0.05                             NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Information                                 Observed
##   Standard Errors                            Bootstrap
##   Number of requested bootstrap draws               50
##   Number of successful bootstrap draws              50
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Sat_M ~                                             
##     Anxity_M  (a1)   -1.680    0.490   -3.430    0.001
##   Sat_W ~                                             
##     Anxity_W  (a2)   -1.918    0.508   -3.778    0.000
##   Sat_M ~                                             
##     Anxity_W (p12)   -1.224    0.432   -2.832    0.005
##   Sat_W ~                                             
##     Anxity_M (p21)   -1.315    0.483   -2.721    0.007
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Anxiety_M ~~                                        
##     Anxiety_W (cx)    0.297    0.122    2.443    0.015
##  .Sat_M ~~                                            
##    .Sat_W     (cy)   27.385    3.610    7.586    0.000
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     Anxity_M (mx1)    2.632    0.090   29.135    0.000
##     Anxity_W (mx2)    2.927    0.094   31.045    0.000
##    .Sat_M    (iy1)   52.864    1.306   40.479    0.000
##    .Sat_W    (iy2)   53.852    1.892   28.466    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     Anxity_M (vx1)    1.592    0.132   12.017    0.000
##     Anxity_W (vx2)    1.447    0.145    9.974    0.000
##    .Sat_M    (ve1)   43.219    4.335    9.969    0.000
##    .Sat_W    (ve2)   45.759    5.141    8.901    0.000
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     p_diff            0.091    0.695    0.132    0.895
##     k1                0.728    0.473    1.541    0.123
##     k2                0.686    0.408    1.680    0.093
##     k_diff            0.043    0.760    0.056    0.955
##     i_diff           -0.988    1.289   -0.766    0.443
##     a_ave            -1.799    0.355   -5.076    0.000
##     p_ave            -1.270    0.306   -4.147    0.000
##     i_ave            53.358    1.510   35.331    0.000
##     sum1             -1.452    0.257   -5.647    0.000
##     sum2             -1.617    0.362   -4.461    0.000
##     cont1            -0.457    0.779   -0.586    0.558
##     cont2            -0.603    0.691   -0.873    0.383
parameterEstimates(apimdm, standardized = TRUE)
##          lhs op         rhs  label    est    se      z pvalue ci.lower
## 1      Sat_M  ~   Anxiety_M     a1 -1.680 0.490 -3.430  0.001   -2.717
## 2      Sat_W  ~   Anxiety_W     a2 -1.918 0.508 -3.778  0.000   -2.943
## 3      Sat_M  ~   Anxiety_W    p12 -1.224 0.432 -2.832  0.005   -2.250
## 4      Sat_W  ~   Anxiety_M    p21 -1.315 0.483 -2.721  0.007   -2.224
## 5  Anxiety_M ~1                mx1  2.632 0.090 29.135  0.000    2.463
## 6  Anxiety_W ~1                mx2  2.927 0.094 31.045  0.000    2.726
## 7      Sat_M ~1                iy1 52.864 1.306 40.479  0.000   49.675
## 8      Sat_W ~1                iy2 53.852 1.892 28.466  0.000   49.690
## 9  Anxiety_M ~~   Anxiety_M    vx1  1.592 0.132 12.017  0.000    1.292
## 10 Anxiety_W ~~   Anxiety_W    vx2  1.447 0.145  9.974  0.000    1.136
## 11     Sat_M ~~       Sat_M    ve1 43.219 4.335  9.969  0.000   34.203
## 12     Sat_W ~~       Sat_W    ve2 45.759 5.141  8.901  0.000   35.591
## 13 Anxiety_M ~~   Anxiety_W     cx  0.297 0.122  2.443  0.015    0.024
## 14     Sat_M ~~       Sat_W     cy 27.385 3.610  7.586  0.000   20.004
## 15    p_diff :=     p12-p21 p_diff  0.091 0.695  0.132  0.895   -1.164
## 16        k1 :=      p12/a1     k1  0.728 0.473  1.541  0.123    0.026
## 17        k2 :=      p21/a2     k2  0.686 0.408  1.680  0.093    0.179
## 18    k_diff :=       k1-k2 k_diff  0.043 0.760  0.056  0.955   -1.996
## 19    i_diff :=     iy1-iy2 i_diff -0.988 1.289 -0.766  0.443   -3.687
## 20     a_ave :=   (a1+a2)/2  a_ave -1.799 0.355 -5.076  0.000   -2.609
## 21     p_ave := (p12+p21)/2  p_ave -1.270 0.306 -4.147  0.000   -2.004
## 22     i_ave := (iy1+iy2)/2  i_ave 53.358 1.510 35.331  0.000   49.833
## 23      sum1 :=  (p12+a1)/2   sum1 -1.452 0.257 -5.647  0.000   -2.153
## 24      sum2 :=  (p21+a2)/2   sum2 -1.617 0.362 -4.461  0.000   -2.309
## 25     cont1 :=      a1-p12  cont1 -0.457 0.779 -0.586  0.558   -2.468
## 26     cont2 :=      a2-p21  cont2 -0.603 0.691 -0.873  0.383   -1.832
##    ci.upper std.lv std.all std.nox
## 1    -0.691 -1.680  -0.297  -0.297
## 2    -0.791 -1.918  -0.310  -0.310
## 3    -0.037 -1.224  -0.206  -0.206
## 4    -0.376 -1.315  -0.223  -0.223
## 5     2.842  2.632   2.087   2.087
## 6     3.089  2.927   2.433   2.433
## 7    56.111 52.864   7.395   7.395
## 8    57.585 53.852   7.239   7.239
## 9     1.894  1.592   1.000   1.000
## 10    1.816  1.447   1.000   1.000
## 11   50.702 43.219   0.846   0.846
## 12   58.480 45.759   0.827   0.827
## 13    0.549  0.297   0.196   0.196
## 14   37.173 27.385   0.616   0.616
## 15    1.860  0.091   0.017   0.017
## 16    2.382  0.728   0.694   0.694
## 17    2.099  0.686   0.719   0.719
## 18    2.097  0.043  -0.025  -0.025
## 19    1.457 -0.988   0.156   0.156
## 20   -0.899 -1.799  -0.303  -0.303
## 21   -0.582 -1.270  -0.214  -0.214
## 22   56.847 53.358   7.317   7.317
## 23   -0.975 -1.452  -0.251  -0.251
## 24   -0.863 -1.617  -0.267  -0.267
## 25    1.014 -0.457  -0.091  -0.091
## 26    1.106 -0.603  -0.087  -0.087

Because of sampling error due to bootstrap sampling, CIs and p values may differ some.

Both k values are near .7 and not significantly different from each other (p = .963).
For Men the k is 0.728 with a 95% confidence interval (CI) is from 0.164 to 2.0130.
For Women the k is 0.686 with a 95% confidence interval (CI) is from 0.209 to 1.504.
The two k’s suggest that k is greater than zero, and may equal 1.

Women are more satisfied than men by a point more but this difference (i_diff) is not significant (p = .416) and so it is concluded that men and women do not differ in Satisfaction after controlling for both of their levels of Anxiety.

APIM Indistinguishable

Six equality constraints
* equal actor effects (a1 = a2)
* equal partner effects (p12 = p21) * equal X means mx1 = mx2
* equal X variances vx1 = vx2
* equal Y intercepts i1 = i2
* equal Y error variances ve1 = ve2

APIM_I <- '

                  Sat_M  ~ a*Anxiety_M + p*Anxiety_W 
                  Sat_W  ~ a*Anxiety_W + p*Anxiety_M
                  Anxiety_M ~ mx*1
                  Anxiety_W ~ mx*1
                  Sat_M ~ iy*1
                  Sat_W ~ iy*1
                  Anxiety_M ~~ vx*Anxiety_M
                  Anxiety_W ~~ vx*Anxiety_W
                  Sat_M ~~ ve*Sat_M
                  Sat_W ~~ ve*Sat_W
                  Anxiety_W ~~ cx*Anxiety_M
                  Sat_W ~~ cy*Sat_M 
                  k := p/a
'

# Change to "bootstrap = 5000" to get reliable values for the confidence interval.  
apimi <- sem(APIM_I,fixed.x=FALSE, data = riggsd,missing="fiml"
             ,se = "boot",bootstrap= 50)
summary(apimi, fit.measures = TRUE)
## lavaan (0.5-23.1097) converged normally after  43 iterations
## 
##   Number of observations                           155
## 
##   Number of missing patterns                         1
## 
##   Estimator                                         ML
##   Minimum Function Test Statistic                6.450
##   Degrees of freedom                                 6
##   P-value (Chi-square)                           0.375
## 
## Model test baseline model:
## 
##   Minimum Function Test Statistic              135.383
##   Degrees of freedom                                 6
##   P-value                                        0.000
## 
## User model versus baseline model:
## 
##   Comparative Fit Index (CFI)                    0.997
##   Tucker-Lewis Index (TLI)                       0.997
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -1495.829
##   Loglikelihood unrestricted model (H1)      -1492.604
## 
##   Number of free parameters                          8
##   Akaike (AIC)                                3007.657
##   Bayesian (BIC)                              3032.005
##   Sample-size adjusted Bayesian (BIC)         3006.683
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.022
##   90 Percent Confidence Interval          0.000  0.108
##   P-value RMSEA <= 0.05                          0.601
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.052
## 
## Parameter Estimates:
## 
##   Information                                 Observed
##   Standard Errors                            Bootstrap
##   Number of requested bootstrap draws               50
##   Number of successful bootstrap draws              50
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Sat_M ~                                             
##     Anxiety_M  (a)   -1.789    0.294   -6.079    0.000
##     Anxiety_W  (p)   -1.277    0.310   -4.114    0.000
##   Sat_W ~                                             
##     Anxiety_W  (a)   -1.789    0.294   -6.079    0.000
##     Anxiety_M  (p)   -1.277    0.310   -4.114    0.000
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   Anxiety_M ~~                                        
##     Anxiety_W (cx)    0.275    0.127    2.166    0.030
##  .Sat_M ~~                                            
##    .Sat_W     (cy)   27.363    2.940    9.306    0.000
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     Anxiety_M (mx)    2.780    0.079   35.002    0.000
##     Anxiety_W (mx)    2.780    0.079   35.002    0.000
##    .Sat_M     (iy)   53.339    1.257   42.427    0.000
##    .Sat_W     (iy)   53.339    1.257   42.427    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     Anxiety_M (vx)    1.541    0.109   14.103    0.000
##     Anxiety_W (vx)    1.541    0.109   14.103    0.000
##    .Sat_M     (ve)   44.518    3.449   12.908    0.000
##    .Sat_W     (ve)   44.518    3.449   12.908    0.000
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     k                 0.714    0.181    3.951    0.000
parameterEstimates(apimi, standardized = TRUE)
##          lhs op       rhs label    est    se      z pvalue ci.lower
## 1      Sat_M  ~ Anxiety_M     a -1.789 0.294 -6.079   0.00   -2.520
## 2      Sat_M  ~ Anxiety_W     p -1.277 0.310 -4.114   0.00   -1.957
## 3      Sat_W  ~ Anxiety_W     a -1.789 0.294 -6.079   0.00   -2.520
## 4      Sat_W  ~ Anxiety_M     p -1.277 0.310 -4.114   0.00   -1.957
## 5  Anxiety_M ~1              mx  2.780 0.079 35.002   0.00    2.608
## 6  Anxiety_W ~1              mx  2.780 0.079 35.002   0.00    2.608
## 7      Sat_M ~1              iy 53.339 1.257 42.427   0.00   50.415
## 8      Sat_W ~1              iy 53.339 1.257 42.427   0.00   50.415
## 9  Anxiety_M ~~ Anxiety_M    vx  1.541 0.109 14.103   0.00    1.268
## 10 Anxiety_W ~~ Anxiety_W    vx  1.541 0.109 14.103   0.00    1.268
## 11     Sat_M ~~     Sat_M    ve 44.518 3.449 12.908   0.00   37.125
## 12     Sat_W ~~     Sat_W    ve 44.518 3.449 12.908   0.00   37.125
## 13 Anxiety_M ~~ Anxiety_W    cx  0.275 0.127  2.166   0.03   -0.025
## 14     Sat_M ~~     Sat_W    cy 27.363 2.940  9.306   0.00   20.201
## 15         k :=       p/a     k  0.714 0.181  3.951   0.00    0.321
##    ci.upper std.lv std.all std.nox
## 1    -1.304 -1.789  -0.304  -0.304
## 2    -0.497 -1.277  -0.217  -0.217
## 3    -1.304 -1.789  -0.304  -0.304
## 4    -0.497 -1.277  -0.217  -0.217
## 5     2.982  2.780   2.239   2.239
## 6     2.982  2.780   2.239   2.239
## 7    55.714 53.339   7.311   7.311
## 8    55.714 53.339   7.311   7.311
## 9     1.771  1.541   1.000   1.000
## 10    1.771  1.541   1.000   1.000
## 11   50.605 44.518   0.836   0.836
## 12   50.605 44.518   0.836   0.836
## 13    0.608  0.275   0.179   0.179
## 14   33.284 27.363   0.615   0.615
## 15    1.152  0.714   0.714   0.714

The fit of the model reflects the six equality constraints. In this case, it tells us that ignoring gender does not worsen the fit of the model. If dyad members were truly indistinguishable, it would only tell us about the arbitrary assignment of persons to 1 and 2. More on this when we talk about CFA.

APIM_SEM app output

https://apimsem.ugent.be/shiny/apim_sem/

APIM Indistinguishable 

The lavaan model converged after 43 iterations. A summary of results of the APIM analyses is contained in Table 3 and the overall effects in Table 4 in the output tab ‘Tables’. The variance of the errors is 44.518. The R squared is 0.164. The partial intraclass correlation for Satisfaction controlling for the other predictor variables is equal to .615 and is statistically significant (p < .001, 95% CI [0.43, 0.8]). Thus, when one member of the dyad scores high (low) on the variable Satisfaction after controlling for the predictor variables, the other member also tends to have a high (low) score.

The intercept (the predicted score on Satisfaction when the variables of Attachment Anxiety equal zero) for indistinguishable members is equal to 53.339 and is statistically significant (p < .001, 95% CI [50.43, 56.25]).

The actor effect is equal to -1.789 (p < .001, 95% CI [-2.36, -1.22]). The standardized actor effect is -0.316 (partial r = -.311). The partner effect is equal to -1.277, which is statistically significant (p < .001, 95% CI [-1.85, -0.7]), and its overall standardized effect is -0.225 (partial r = -.222).

Next, the relative sizes of the actor and partner effects are considered. If the standardized actor effect is greater than .1 in absolute value and is statistically significant, k (i.e. the ratio of the partner effect to the actor effect) can be interpreted in the output. This is the case for this dataset. The value of k equals 0.71. No further conclusions can be drawn for k, because a bootstrap analysis was not chosen to calculate its confidence interval.

APIM Figure

The figure for the distinguishable case is:

library(semPlot)

semPaths(apimd, 
         # general lay-out for a nice APIM:
           fade = F, "est", layout='tree2', rotation = 2, style = "ram",
           intercepts = F, residuals = F, 
           optimizeLatRes = T, curve = 3.1,  
         # labels and their sizes:
           nodeLabels=c("Male Satisfaction", "Female Satisfaction", "Male Anxiety",
                        "Female Anxiety"), sizeMan=18,  sizeMan2=10,
         # position and size of parameter estimates:
           edge.label.position = 0.45, edge.label.cex=1.5
        )


Back to schedule