library(lavaan)
library(semPlot)
speed <- read.csv("C:/Users/johna/OneDrive/Documents/speeddate_mod.csv")
nlsy <- read.csv("C:/Users/johna/OneDrive/Documents/nlsy_med.csv")

Question 1: Moderation Analysis (Speed Dating Data)

Fisman, Iyengar, Kamenica, and Simonson (2006) ran a large speed-dating experiment where participants rated their partners on several traits, including attractiveness, intelligence, and overall likability. All ratings were given on a 10-point scale.

In this analysis, we test whether perceived intelligence moderates the relationship between perceived attractiveness and overall likability.

1) Remove rows containing missing values

speed <- read.csv("speeddate_mod.csv")

# remove rows with missing values
speed_complete <- na.omit(speed)

head(speed_complete)
##   X other_like other_attr other_intel
## 1 1          7          8           9
## 2 2          8          8           4
## 3 3          8          8           8
## 4 4          7          7           7
## 5 5          7          8           7
## 6 6          7          6          10

This removes any observations with missing values so that the analyses use only complete cases.


2) Moderation analysis

To test moderation, we include an interaction term between attractiveness and intelligence.

model_mod <- lm(other_like ~ other_attr * other_intel, data = speed_complete)

summary(model_mod)
## 
## Call:
## lm(formula = other_like ~ other_attr * other_intel, data = speed_complete)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.9241 -0.7147  0.0759  0.7249  6.3658 
## 
## Coefficients:
##                         Estimate Std. Error t value Pr(>|t|)    
## (Intercept)            -0.791311   0.446842  -1.771   0.0768 .  
## other_attr              0.657284   0.076975   8.539  < 2e-16 ***
## other_intel             0.488173   0.059996   8.137 8.42e-16 ***
## other_attr:other_intel -0.017145   0.009832  -1.744   0.0814 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.248 on 1505 degrees of freedom
## Multiple R-squared:  0.5354, Adjusted R-squared:  0.5345 
## F-statistic: 578.2 on 3 and 1505 DF,  p-value: < 2.2e-16

Interpretation

The interaction term other_attr:other_intel tells us whether intelligence changes the relationship between attractiveness and likability.

Looking at the regression output, the interaction term is not statistically significant (p > .05). This suggests that intelligence does not significantly moderate the relationship between attractiveness and how much someone is liked.

In other words, attractiveness seems to influence likability in a similar way regardless of the perceived intelligence of the partner.


3) Moderation analysis after centering variables

Next, we center attractiveness and intelligence before creating the interaction term.

speed_complete$attr_c <- scale(speed_complete$other_attr, center = TRUE, scale = FALSE)
speed_complete$intel_c <- scale(speed_complete$other_intel, center = TRUE, scale = FALSE)

model_center <- lm(other_like ~ attr_c * intel_c, data = speed_complete)

summary(model_center)
## 
## Call:
## lm(formula = other_like ~ attr_c * intel_c, data = speed_complete)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.9241 -0.7147  0.0759  0.7249  6.3658 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     6.215414   0.033687 184.503   <2e-16 ***
## attr_c          0.528312   0.017921  29.480   <2e-16 ***
## intel_c         0.379965   0.024185  15.711   <2e-16 ***
## attr_c:intel_c -0.017145   0.009832  -1.744   0.0814 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.248 on 1505 degrees of freedom
## Multiple R-squared:  0.5354, Adjusted R-squared:  0.5345 
## F-statistic: 578.2 on 3 and 1505 DF,  p-value: < 2.2e-16

Interpretation

After centering the variables, the interaction term is still not statistically significant.

This means that centering the predictors did not change the conclusion of the moderation test. Centering mainly helps with interpretation and can reduce multicollinearity, but it does not change the underlying relationship between the variables.


Question 2: Mediation Analysis (NLSY Data)

Davis-Kean (2005) suggested that parents’ education may influence children’s academic achievement indirectly through the home environment.

Here we test whether Home Environment (HE) mediates the relationship between Mother’s Education (ME) and children’s math achievement (Math).


1) Conduct mediation analysis with bootstrapping

nlsy <- read.csv("nlsy_med.csv")

model_med <- '

# path from ME to HE
HE ~ a*ME

# paths predicting math
math ~ b*HE + cprime*ME

# indirect effect
ab := a*b

# total effect
total := cprime + (a*b)

'

fit_med <- sem(model_med,
               data = nlsy,
               se = "bootstrap",
               bootstrap = 5000)
## Warning: lavaan->lav_model_nvcov_bootstrap():  
##    22 bootstrap runs failed or did not converge.
summary(fit_med, standardized = TRUE, ci = TRUE)
## lavaan 0.6-21 ended normally after 1 iteration
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         5
## 
##   Number of observations                           371
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Parameter Estimates:
## 
##   Standard errors                            Bootstrap
##   Number of requested bootstrap draws             5000
##   Number of successful bootstrap draws            4978
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   HE ~                                                                  
##     ME         (a)    0.139    0.041    3.437    0.001    0.060    0.218
##   math ~                                                                
##     HE         (b)    0.465    0.126    3.687    0.000    0.222    0.720
##     ME      (cprm)    0.463    0.118    3.939    0.000    0.226    0.693
##    Std.lv  Std.all
##                   
##     0.139    0.166
##                   
##     0.465    0.165
##     0.463    0.196
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .HE                2.724    0.206   13.214    0.000    2.323    3.130
##    .math             20.621    2.900    7.111    0.000   15.536   26.843
##    Std.lv  Std.all
##     2.724    0.972
##    20.621    0.924
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     ab                0.065    0.025    2.610    0.009    0.024    0.120
##     total             0.528    0.119    4.425    0.000    0.286    0.761
##    Std.lv  Std.all
##     0.065    0.027
##     0.528    0.223

2) Are the effects significant? Does mediation exist?

There are three main effects to look at:

  • a path: ME → HE
  • c′ path: ME → math (direct effect controlling for HE)
  • ab: the indirect effect through the home environment

Based on the output:

  • The a path is significant, meaning mothers with higher education tend to provide better home environments.
  • The b path is significant, meaning the home environment is related to children’s math achievement.
  • The indirect effect (ab) is significant based on the bootstrap confidence interval.
  • The direct effect (c′) is also still significant.

Conclusion

Because both the direct effect (c′) and the indirect effect (ab) are significant, this indicates partial mediation.

This means that mothers’ education affects children’s math scores both directly and indirectly through the home environment.


3) Display the path plot

semPaths(fit_med,
         what = "std",
         layout = "tree",
         edge.label.cex = 1.2,
         sizeMan = 7,
         nCharNodes = 0)

The diagram shows the relationships between the three variables:

  • ME → HE (path a)
  • HE → math (path b)
  • ME → math (direct path c′)

The indirect pathway ME → HE → math represents the mediation effect.


References

Davis-Kean, P. E. (2005). The influence of parent education and family income on child achievement: The indirect role of parental expectations and the home environment. Journal of Family Psychology, 19(2), 294–304.

Fisman, R., Iyengar, S. S., Kamenica, E., & Simonson, I. (2006). Gender differences in mate selection: Evidence from a speed dating experiment. Quarterly Journal of Economics, 121, 673–697.